[swift-users] IUO from C Library Interface

Ryan Lovelett swift-dev at ryan.lovelett.me
Mon Oct 24 17:09:13 CDT 2016


> Not being able to assign the function reference is a bug. As a
> workaround, you should be able to unsafeBitCast CC_SHA1_Update to the
> appropriate type.
> 
> -Joe

Two questions:

1. Is this an already reported bug? If so, would you happen to know what
it is so I can track it for resolution (to remove the work-around when
it is resolved)?

I made the protocol def this:
var bar: (UnsafeMutablePointer<Context>?, UnsafeRawPointer?, CC_LONG) ->
Int32 { get }

Then the imp this:
let bar = unsafeBitCast(CC_SHA1_Update, to:
((UnsafeMutablePointer<CC_SHA1_CTX>?, UnsafeRawPointer?, CC_LONG) ->
Int32).self)

2. Perhaps I'm doing something wrong here but I feel like this just make
the code less safe. It seems now I can send in an optional, read: nil,
pointer to this `bar` method. On face, this seems dangerous. The
`CC_SHA1_Update` method seems explicit in that it will not deal with
`nil`. So it seems that this thing is now reporting a safer API than
what is actually there. Or did I misunderstand? Should I be dropping the
IUO all together and just make it `UnsafeMutablePointer<Context>` and
`UnsafeRawPointer`?


More information about the swift-users mailing list