jextract fails to work on sd-daemon.h due to wrong handling of __INCLUDE_LEVEL__
Nils Kattenbeck
nilskemail at gmail.com
Thu Feb 13 16:51:09 UTC 2025
Dear all,
Today I tried to use jextract on sd-daemon.h (from systemd) to access the
sd_notify* class of functions. To my surprise this did not work and
returned in the following error message:
../jextract-21/bin/jextract --source -t foo.bar
/usr/include/systemd/sd-daemon.h
WARNING: A restricted method in java.lang.foreign.AddressLayout has been
called
WARNING: java.lang.foreign.AddressLayout::withTargetLayout has been called
by module org.openjdk.jextract
WARNING: Use --enable-native-access=org.openjdk.jextract to avoid a warning
for this module
/usr/include/systemd/_sd-common.h:23:4: error: "Do not include _sd-common.h
directly; it is a private header."
which comes down to the following preprocessor code in _sd-common.h (which
is included by sd-daemon.h):
#if defined(__INCLUDE_LEVEL__) && __INCLUDE_LEVEL__ <= 1 &&
!defined(__COVERITY__)
# error "Do not include _sd-common.h directly; it is a private header."
#endif
It seems like jextract does not increase the __INCLUDE_LEVEL__ resulting in
this error. However, it does seem to define it which makes this more
curious.
The fix would be to either a) not set it at all or b) correctly increment
it when parsing files from an #include statement.
For now I have been able to circumvent this by telling jextract to also
define __COVERITY__ though this is only a very dirty hack and will not work
in every instance.
Cheers,
Nils
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jextract-dev/attachments/20250213/7a05cf52/attachment.htm>
More information about the jextract-dev
mailing list