<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p>I wonder how this interacts with the fact that jextract now also
accepts multiple headers and, in that case, it will generate an
intermediate header that includes the specified headers.</p>
<p>Can you try passing jextract _two_ headers, both sd-daemon.h and
something else, and see what happens? My feeling is that things
should work in that case.</p>
<p>Which, if true, would advocate for jextract to handle both cases
in the same way: with an intermediate header including the
specified header file(s).</p>
<p>Maurizio<br>
</p>
<p><br>
</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 15/02/2025 16:46, Nils Kattenbeck
wrote:<br>
</div>
<blockquote type="cite" cite="mid:CAKkJDRdW5d=OniJhO-icJTSe6fQQUNCJjCirh4eZi-0AGuJ_qQ@mail.gmail.com">
<div dir="ltr">
<div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Hi Jorn,</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">Your assessment
seems to be correct. In C the main.c would be level 0 which
libclang sidesteps in this case. Creating a dummy header file
which simply includes the <span style="font-family:monospace">sd-daemon.h</span>
file seems to fix the problem.</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">That being said
I think it would still make sense for jextract to work around
this issue. Given that the resulting Java classes would be
similar to the main translation unit in C it would make sense
for jextract to emulate this behaviour and read the header
files as if they already were at level 1. This could e.g. be
done creating such a dummy header file automatically (like I
now did manually). This would better match expectations,
resolve the issue in this specific instance with systemd but
more importantly would prevent hard to troubleshoot issues in
the future.</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">Cheers, Nils</div>
</div>
<br>
<div class="gmail_quote gmail_quote_container">
<div dir="ltr" class="gmail_attr">On Fri, Feb 14, 2025 at
11:46 PM Jorn Vernee <<a href="mailto:jorn.vernee@oracle.com" moz-do-not-send="true" class="moz-txt-link-freetext">jorn.vernee@oracle.com</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<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>On 13-2-2025 17:51, Nils Kattenbeck wrote:<br>
</div>
<blockquote type="cite">
<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>
</div>
</blockquote>
</div>
</blockquote>
</body>
</html>