jextract and bit fields

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Mon Jan 30 16:39:58 UTC 2023


Hey Remi,
while jextract does not support bitfields, it should also not crash when 
seeing them :-)

I have tried extracting a simple header containing the struct in your 
email using the jextract binary at [1].

I could successfully extract it, and obtain a |my_struct| Java wrapper, 
with this layout:

|static final GroupLayout $struct$LAYOUT = MemoryLayout.structLayout( 
MemoryLayout.structLayout( 
MemoryLayout.paddingLayout(1).withName("foo"), 
MemoryLayout.paddingLayout(31) ) ).withName("my_struct"); |

As expected, the contents of the struct are just padding.

That said, I’m beginnin to suspect that you are seeing this issue with a 
more recent version of jextract, perhaps the one for the “panama” 
branch? We have made recent changes to how padding layouts are defined - 
e.g. so that their size/alignment must be a multiple of 8. This would 
cause the issue you are seeing.

Maurizio

On 30/01/2023 13:25, Rémy Maucherat wrote:

> Hi,
>
> When processing certain bit-fields, jextract produces an error:
> "Invalid bitSize: 1"
> In addition to not being really helpful (it took me some time to find
> out what the problem was since no reference to a location is given,
> nor that this is about a bit-field).
>
> A typical example causing the error is something like:
> struct my_struct {
>     unsigned int foo : 1;
> };
>
> Obviously we don't have these sort of memory saving "smart" fancy
> tricks in Java (which is probably good since they can cause serious
> problems when misused ...).
>
> Is support for this planned eventually, or should bit-fields be
> avoided for Panama compatibility ?
>
> Thanks !
>
> Rémy

​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jextract-dev/attachments/20230130/a87736fb/attachment-0001.htm>


More information about the jextract-dev mailing list