Thanks Joe, this is incredibly helpful, especially the note about how enums are passed in 'piecewise'.
re. your question: I was indeed calling the C++ function from Swift and directly passing in the enum (in pseudo-Swift): let myEnum : SomeEnumType = ... cplusplusFunction(value: myEnum, type: SomeEnumType.self) // incorrect How would I pass a pointer to the enum's value from Swift? I don't think Swift exposes any mechanism to get the memory address of a Swift object. Perhaps I should create an UnsafeMutablePointer<SomeEnumType>, set its memory to (a copy of) the enum value, and pass that pointer object in instead? Austin On Wed, Jan 6, 2016 at 12:04 PM, Joe Groff <jgr...@apple.com> wrote: > > > On Jan 1, 2016, at 10:58 PM, Austin Zheng via swift-dev < > swift-dev@swift.org> wrote: > > > > Hello, > > (...) > > Swift structs are (currently) passed by passing each stored property > individually. _EnumMirror is defined as a struct with owner/value/type > fields, and the 'self' parameter to its methods gets broken down this way. > > > * What I really want to do is to get the tag of an enum. I wrote a > different entry point that omits the unused "owner" property and simply > calls swift_EnumMirror_caseName with nullptr as the first argument. This > other C++ function takes 'value' (an OpaqueValue*) and 'type' (a > Metadata*). I've surmised that 'type' should be the Swift metatype of the > enum instance (e.g. myEnum.dynamicType), and I do get the case names table. > However, if I pass in the enum instance itself as 'value', my tag is always > retrieved as 0. I noticed that there's some sort of indirection in the form > of "vw_getEnumTag", which goes through something called the "value > witness". Is there somewhere I can read up about the value witness concept? > I assume the reason the 'original' code worked was because it was passing > in a different object as 'value', maybe one that could serve as a value > witness for the reflected-upon instance's type. > > 'value' is a pointer to the value in memory, not the value itself. Are you > passing the enum's literal representation by value instead of passing a > pointer to it? > > -Joe > >
_______________________________________________ swift-dev mailing list swift-dev@swift.org https://lists.swift.org/mailman/listinfo/swift-dev