Skip to content

Conversation

@bkgood
Copy link
Contributor

@bkgood bkgood commented Jun 22, 2016

Namely so that default methods can be used to emulate macros defined in
header files we're often replacing when doing ffi work.

We must use reflection to call Method.isDefault as it's only available
as of Java SE 8 (as are default methods).

Implementing a library's API's macros next to the rest of the ffi declarations seems like a sensible thing to do. Currently, a default method's implementation will be ignored and a link error will result on trying to call the method (if it is indeed only a macro and not an exported symbol). Issues could arise if someone is relying on this behavior, although that would strike me as odd. This could be mitigated with a @Ignore annotation on default methods (which would similarly cause the interface scanner to ignore the method), which I'm happy to implement if there's concern.

bkgood added 2 commits June 22, 2016 17:00
Namely so that default methods can be used to emulate macros defined in
header files we're often replacing when doing ffi work.

We must use reflection to call Method.isDefault as it's only available
as of Java SE 8 (as are default methods).
@bkgood
Copy link
Contributor Author

bkgood commented Jun 22, 2016

Turns out I tried to catch an exception that's not available in Java 6 and thus the build is broken in my first commit. I don't know what your build-breaking policies are; should I squash the fix in and resubmit?

@headius
Copy link
Member

headius commented Sep 21, 2016

Sorry for the delay on this.

We don't have a strict policy that every commit be buildable, and Java 6 and 7 are largely EOL, so we'll just accept this with the post fix.

I'll review.

@headius
Copy link
Member

headius commented Sep 21, 2016

I'd like to see a test for this, conditionally on Java 8+, using one of the built-in interfaces with default methods (e.g. java.util.Collection, but perhaps something smaller).

Otherwise it looks good to me.

@headius headius added this to the 2.0.10 milestone Sep 21, 2016
@headius headius merged commit 54180d3 into jnr:master Sep 22, 2016
@headius
Copy link
Member

headius commented Sep 22, 2016

I'll add a test.

headius added a commit that referenced this pull request Sep 22, 2016
The test will be skipped on Java 7, but on Java 8 it will ensure
that the function mapper does not try to map over top of any
default methods in the interface.
This was referenced Aug 25, 2017
goto1134 added a commit to goto1134/jnr-ffi that referenced this pull request Aug 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants