[swift-users] Passing a pointer to self to C function

John Brownie john_brownie at sil.org
Fri Sep 30 05:10:09 CDT 2016


Still working on the expat wrapper. The thing I need to do is to pass a 
pointer to self to be stored in the userData that will be passed to 
callbacks, allowing me to get at the local instance. I did this in Swift 
2.2 as:

XML_SetUserData(parser, unsafeBitCast(self, 
UnsafeMutablePointer<Void>.self))

The migrator turned this into:

XML_SetUserData(parser, unsafeBitCast(self, to: 
UnsafeMutableRawPointer.self))

but it doesn't work. I don't get an appropriate pointer back in the 
callback that I can turn into what I need.

 From reading the migration documentation, I don't want to use 
unsafeBitCast if at all possible, but I'm not clear what the alternative is.

Also, getting the userData back is something I will need. I currently use:

let theParser = userData!.bindMemory(to: ExpatSwift.self, capacity: 1)

I think that's correct, but I'm not getting a valid object reference.

Any insight is greatly appreciated!
-- 
John Brownie
In Finland on furlough from SIL Papua New Guinea
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160930/8fecc55a/attachment.html>


More information about the swift-users mailing list