> On 24 Oct 2017, at 18:23, Johannes Weiß <johanneswe...@apple.com> wrote:
> 
> How do people think about this proposed change?

I think keeping type information on OpaquePointer would be extremely useful, 
and definitely improves some of the sharp edges of that type.

> this should solve your problem:
> 
> - when you receive a pointer from the C library, store it as OpaquePointer
>    let myOpaquePointer: OpaquePointer = 
> OpaquePointer(c_library_create_function())
>  which now should work regardless of whether you're linking the old or the 
> new version of the C library
> - when you pass a pointer to the C library:
>    c_library_consuming_function(.init(myOpaquePointer))
>  which should (modulo it doesn't right now 
> https://bugs.swift.org/browse/SR-6211) select the right initialiser for you, 
> only it doesn’t 😲

Yeah, this approach is probably acceptable. I’m going to stop short of calling 
it “good”, because frankly it remains a pretty unfortunate hack. It would be 
nicer if there was a way to tell the Swift compiler that the user should never 
initialise the structure, regardless of whether it’s opaque (that is, to tell 
the Swift compiler that when it sees SSL_CTX * it should translate that to 
OpaquePointer<SSL_CTX> instead of UnsafePointer<SSL_CTX>), but I will concede 
that adding support for that case is likely to be a bit too niche for the 
community to have much interest.

In the absence of that better version, your proposed interface will get the job 
done without being too gross. Thanks!

Cory

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to