<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p>Hey Nils,</p>
<p>Jextract uses clang under the hood to do the parsing, so it is
clang that is managing the <font face="monospace">__INCLUDE_LEVEL__</font>
value, and I'm assuming it does that correctly.<br>
</p>
<p>I think the issue here is that, normally, you would write a
program that includes sd-daemon.h, so the include level of that
file starts out at 1, with the main program translation unit being
level 0. But, since jextract uses clang to parse the sd-daemon.h
file directly, it has include level 0 instead, and this
implementation header seems to end up with include level 1,
failing the check. You should see the same error if you directly
pass sd-daemon.h to clang (or gcc).<br>
</p>
<p>I think another way to work around this would be to create a
wrapper header file in which you <font face="monospace">#include
sd-deamon.h</font>, and then pass that wrapper header file to
jextract.<br>
</p>
<p>Jorn<br>
</p>
<div class="moz-cite-prefix">On 13-2-2025 17:51, Nils Kattenbeck
wrote:<br>
</div>
<blockquote type="cite" cite="mid:CAKkJDRdNikfAhR8pkontZU6XaFi0na4jKPxS7Q_fHkp7FKCFuQ@mail.gmail.com">
<div dir="ltr">
<div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Dear all,</div>
<div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br>
</div>
<div class="gmail_default" style="font-family:arial,helvetica,sans-serif">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:</div>
<div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br>
</div>
<div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><span style="font-family:monospace"><span style="color:rgb(24,24,178);background-color:rgb(255,255,255)">../jextract-21/bin/jextract
</span><span style="color:rgb(24,178,178);background-color:rgb(255,255,255)">--source
-t foo.bar </span><span style="color:rgb(24,178,178);background-color:rgb(255,255,255)">/usr/include/systemd/sd-daemon.h</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br>
<span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">WARNING:
A restricted method in java.lang.foreign.AddressLayout has
been called</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br>
<span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">WARNING:
java.lang.foreign.AddressLayout::withTargetLayout has been
called by module org.openjdk.jextract</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br>
<span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">WARNING:
Use --enable-native-access=org.openjdk.jextract to avoid a
warning for this module</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br>
<br>
<span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">/usr/include/systemd/_sd-common.h:23:4:
error: "Do not include _sd-common.h directly; it is a
private header."</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)"></span></span><br>
</div>
<div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br>
</div>
<div class="gmail_default" style="font-family:arial,helvetica,sans-serif">which comes
down to the following preprocessor code in _sd-common.h (which
is included by sd-daemon.h):</div>
<div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br>
</div>
<div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><span style="font-family:monospace"><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">#if
defined(__INCLUDE_LEVEL__) && __INCLUDE_LEVEL__
<= 1 && !defined(__COVERITY__)</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br>
<span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">#
error "Do not include _sd-common.h directly; it is a
private header."</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br>
<span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">#endif</span><br>
</span></div>
<br>
<div><span class="gmail_default" style="font-family:arial,helvetica,sans-serif">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.</span></div>
<div><span class="gmail_default" style="font-family:arial,helvetica,sans-serif">The fix would
be to either a) not set it at all or b) correctly increment
it when parsing files from an #include statement.</span></div>
<div><span class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br>
</span></div>
<div><span class="gmail_default" style="font-family:arial,helvetica,sans-serif">For now I
have been able to circumvent this by telling jextract to
also define </span><span style="font-family:monospace"><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">__COVERITY__<span class="gmail_default" style="font-family:arial,helvetica,sans-serif"> though
this is only a very dirty hack and will not work in
every instance.</span></span></span></div>
<div><span style="font-family:monospace"><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br>
</span></span></span></div>
<div><span style="font-family:monospace"><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail_default" style="font-family:arial,helvetica,sans-serif">Cheers,</span></span></span></div>
<div><span style="font-family:monospace"><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail_default" style="font-family:arial,helvetica,sans-serif">Nils</span></span></span></div>
</div>
</blockquote>
</body>
</html>