Pass unions by value with the C ABI's register classes - #10
Draft
aminmansuri wants to merge 10 commits into
Draft
aminmansuri wants to merge 10 commits into
aminmansuri wants to merge 10 commits into
Conversation
union_spec.rb and UnionTest.c match the ffi gem's March 2026 versions without its JRuby skips; union_by_value_spec.rb adds mixed-class, nested, oversize and callback shapes.
Pick the libffi filler from the union's leaves: the float type for a homogeneous floating aggregate, per-eightbyte SSE/INTEGER cells on SysV x86_64, an integer of the union's alignment otherwise.
A 4-aligned union whose cells differ in class, nested at offset 4, takes the enclosing struct's eightbytes: (INTEGER, SSE) on SysV x86_64. Argument, return and callback forms.
libffi merges the cells into eightbytes at the union's offset inside an enclosing struct; a per-cell class is exact there and unchanged for a union passed on its own.
No behaviour change: the one-argument newUnion hands the host platform to the overload, which tests can call with any CPU and OS.
A union of one floating type is a floating-point aggregate on AArch64, ARM, PPC64 ELFv2 and x86_64; riscv64, loongarch64 and s390x pass every union in integer registers, so the integer filler must stay there.
riscv64, loongarch64 and s390x pass unions in integer registers while libffi would put a struct of doubles into FP registers; keep the integer filler there and the float one on AArch64, ARM, PPC64 ELFv2 and x86_64.
JRuby's FFI rejects :long_double layout members, so no union has a long double leaf or an alignment of 16; the integer filler list is now what its name says.
master names riscv64 as a CPU of its own (jruby-10.0 reports it as UNKNOWN); like s390x and loongarch64 it must keep the integer filler.
A failing assertion printed the jffi Type objects by identity; it now prints the cell names, so a wrong filler reads as SINT64 versus DOUBLE.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Makes JRuby pass C unions by value the way a C compiler does.
Before, every 8-byte union went in an integer register, so a union of floats came back as garbage and a callback receiving one crashed the JVM.
Now the union's members decide the register class, on x86_64 and ARM64.