Fixing the FfmTerminal to run on JDK 22 and on Linux. #945
+111
−49
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(As a foreword, I assume this PR will need some discussion and/or changes, as it changes the required JDK for build to JDK 22.)
I am working on an upgrade of the JLine inside the OpenJDK, and since JLine now has a Foreign Function and Memory (FFM) Terminal implementation, I would ideally want like to use that instead of the custom native code OpenJDK uses now.
Note the FFM was a preview API in JDK 21, and is final in JDK 22.
But, when I tried to use the FFM-base Terminal, there were some problems:
allocateArray
,allocateUtf8String
) got changed,VarHandle
s returned fromMemoryLayout.varHandle(...)
now accept one more "offset" parametertermios
structure has a different layout and types than on Mac OS/X. The layout in JLine was the Mac OS/X layout, and this lead to some very weird behavior.The changes proposed in this patch are:
allocateArray
,allocateUtf8String
methods are changed to what I believe are their new versionsVarHandle
s, there's a utility that will inject offset0L
, to keep the handles easy to usetermios
on Mac and on Linux. The provider will fail on other platforms, as I don't know what are the layout there - can be improved by someone who has access to other platforms.VarHandle
s fortermios
are adapted fromint
tolong
, so they appear the same as on Mac to other code.java.lang.foreign.MemorySegment length = arena.allocate(java.lang.foreign.ValueLayout.JAVA_INT, 0);
, which is, as far as I can tell, used to store how many characters were read from the input. The0
there does not make much sense to me, and it didn't work for me. Using1
in this patch (effectively allocating an array ofJAVA_INT
of size 1, at least per my understanding).Please let me know what you think! Thanks.