[swift-users] Annotating C APIs without changing the original header files

Geordie Jay geojay at gmail.com
Thu May 4 19:04:55 CDT 2017


Fantastic! Thanks for the info, this is great news.

While I have you, I'm interested in annotating function pointers.
Specifically, the JNI environment instance is a pointer to a pointer, so as
is you have to type env.pointee.pointee.FunctionName(env, param1, param2)

Ideally this would just look like env.FunctionName(param1, param2). It's a
long shot but is this goal at all reasonable via annotations alone?

Cheers,
Geordie
Douglas Gregor <dgregor at apple.com> schrieb am Fr. 5. Mai 2017 um 01:59:

> On May 4, 2017, at 4:57 PM, Geordie Jay <geojay at gmail.com> wrote:
>
> Great, thanks for reminding me of this feature. I couldn't see how it
> could be used outside of the stdlib though, is it possible to use apinotes
> when simply linking a C module via its modulemap ?
>
>
> You can put
>
> <modulename>.apinotes
>
> into the same directory as the module map.
>
> - Doug
>
> Douglas Gregor <dgregor at apple.com> schrieb am Fr. 5. Mai 2017 um 01:55:
>
>>
>> On May 3, 2017, at 4:10 PM, Geordie J via swift-users <
>> swift-users at swift.org> wrote:
>>
>> Hi everyone,
>>
>> I’m about to start on another big project with Swift on Android and would
>> like to annotate that JNI headers as much as possible before I do:
>> specifically I’d like to make _Nonnull and CF_SWIFT_NAME annotations to the
>> headers found in a user's jni.h.
>>
>> The question is: is it possible to annotate headers this without changing
>> the original header files? Specifically I’m looking for an options that
>> allows annotations in a separate file, probably one that is read when
>> loading the package’s module.modulemap.
>>
>> I’d like to distribute the annotations in a SwiftPM package that also
>> exposes the original (hopefully annotated) headers. Up until now I’ve been
>> using Swift to override methods in code, but this isn’t as clean or
>> extensible and I fear it may have other (particularly performance)
>> implications.
>>
>> I guess the alternative would be to just maintain and distribute a
>> modified version of jni.h with the annotations, but that would be a "last
>> resort” option.
>>
>>
>>
>> This is the role of API notes, which you can see here:
>>
>> https://github.com/apple/swift/tree/master/apinotes
>>
>> with some rough documentation-in-source here:
>>
>>
>> https://github.com/apple/swift-clang/blob/stable/lib/APINotes/APINotesYAMLCompiler.cpp
>>
>> - Doug
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170505/9cb1c2c1/attachment.html>


More information about the swift-users mailing list