jextract error when string contains newline character

Michael Ennen mike.ennen at gmail.com
Sat Sep 19 00:07:02 UTC 2020


 I am running jextract on Windows.h header file thusly:

jextract --source -d . -t com.dx12 -I "$I\um" -I "$I\shared" -C
"-DWIN32_LEAN_AND_MEAN" -- "$I\um\Windows.h"

In one of the generated constants files (specifically
Windows_h$constants$39.java) it generates the following:

    static final MemorySegment IMAGE_ARCHIVE_START$SEGMENT_CONSTANT_ =
CLinker.toCString("!<arch>
");
    public static jdk.incubator.foreign.MemorySegment IMAGE_ARCHIVE_START()
{ return IMAGE_ARCHIVE_START$SEGMENT_CONSTANT_; }

    static final MemorySegment IMAGE_ARCHIVE_END$SEGMENT_CONSTANT_ =
CLinker.toCString("`
");
    public static jdk.incubator.foreign.MemorySegment IMAGE_ARCHIVE_END() {
return IMAGE_ARCHIVE_END$SEGMENT_CONSTANT_; }

    static final MemorySegment IMAGE_ARCHIVE_PAD$SEGMENT_CONSTANT_ =
CLinker.toCString("
");

It may be hard to see but if you take, for instance, the
IMAGE_ARCHIVE_START segment, it is defined as the following string literal
(from looking at various windows header files)

"!<arch>\n"

When jextract encounters the newline character it seems it is putting it in
literally:

CLinker.toCString("!<arch>
");

and since it is not a valid multi-line string, java compilation fails.I
believe it should be put in either as "\n" or as a valid multi-line string
or as a string literal with plus symbols.


More information about the panama-dev mailing list