Growing jextract

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Wed Feb 21 10:52:31 UTC 2024


On 20/02/2024 20:29, Manuel Bleichenbacher wrote:
> Hi Panama team
>
> Thanks again for quickly addressing the issues. I was able to upgrade 
> my library to JDK 22 using the latest jextract version on all three 
> platforms.
>
> All issues that I have reported previously are fixed.
>
>
> I've discovered one more issue. For a particular type (on macOS), 
> jextract creates code because a dependency was not specified. I guess 
> it would be supposed to abort with an error regarding the missing 
> dependency. The problem is quickly fixed if the dependency is included.
>
> The minimal commands to reproduce it is:
>
> JEXTRACT=../../../../jextract/build/jextract/bin/jextract
> SDK_DIR=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
>
> $JEXTRACT --output ../../src/main/java \
>   -I $SDK_DIR/usr/include \
>   -lIOKit.framework \
>   --header-class-name IOKit \
>   --target-package net.codecrete.usb.macos.gen.iokit \
>   --include-struct IOCFPlugInInterfaceStruct \
>   iokit_helper.h
>
> The file iokit_helper.h:
>
> #include <IOKit/usb/IOUSBLib.h>
> #include <IOKit/IOCFPlugIn.h>
>
> The missing dependency is CFUUIDBytes and the path to it is that a 
> typedef (REFIID) referring to it is used in a parameter of a function 
> pointer (QueryInterface) of IOCFPlugInInterfaceStruct.
We'll take a look, something is likely off in the dependency analyzer.
>
>
> I notice that I don't use any "--include-typedef" anymore. Since 
> jextract resolves typedefs to the underlying type, only the referred 
> struct needs to be included. Is there any use left for 
> "--include-typedef"?

If your goal is to generate correct code, yes, typedef are not as much 
needed. But if your goal is to get as close as possible to C, perhaps 
you want them. E.g. you might have something like this:

```
struct __Foo { int x; };
typedef Foo __Foo;
```

Then, in your java code, you might want to do:

Foo.allocate(...)

And not

__Foo.allocate(...)

In other words, generated typedefs are mostly alias/sugar, nothing more.

Maurizio




More information about the jextract-dev mailing list