-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing the FfmTerminal to run on JDK 22 and on Linux. #945
Conversation
Added one more fix here: the problem this is trying to fix is when (e.g.) the VINTR control character is set to some value (like
then the code attempts to write the value at the proper slot in the control characters array. And this works. But, on Linux, there is apparently no
and that rewrites the value of This change proposes to always set all the index variables for control characters, and just use |
This looks good, I need to review more carefully, but this is definitely something which should get in. |
terminal-ffm/src/main/java/org/jline/terminal/impl/ffm/FfmTerminalProvider.java
Outdated
Show resolved
Hide resolved
@@ -115,4 +119,13 @@ public int systemStreamWidth(SystemStream stream) { | |||
public String toString() { | |||
return "TerminalProvider[" + name() + "]"; | |||
} | |||
|
|||
static VarHandle lookupVarHandle(MemoryLayout layout, PathElement... element) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe name this layoutVarHandle
or something?
…inalProvider.java Co-authored-by: ExE Boss <[email protected]>
(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.