Varargs bindings do not work in java 19 on the macbook pro M1 MAX
Jorn Vernee
jorn.vernee at oracle.com
Mon Oct 24 13:21:04 UTC 2022
Hi Mark,
It looks like you are missing a call to
`FunctionDescriptor::asVariadic`. This doesn't matter on every platform,
but on M1 it does, since it affects how arguments are passed.
Looking at the C code you have, the function descriptor you use should
be `FunctionDescriptor.of(JAVA_INT, JAVA_INT).asVariadic(JAVA_INT,
JAVA_INT)`
Jorn
On 24/10/2022 14:40, Mark Hammons wrote:
> Hi all,
>
> I was testing panama on java 19 with my work issued macbook pro, and
> my varargs method bindings were returning invalid data.
>
> I thought that maybe it was a failure in my own code, but I couldn't
> work around it so I created a test instance using manually written code:
>
> test("manual varargs") {
> vallinker= Linker.nativeLinker().nn
> valsl= SymbolLookup.loaderLookup().nn
> valmh= linker
> .downcallHandle(
> sl.lookup("add_var").nn.orElseThrow(),
> FunctionDescriptor.of(JAVA_INT, JAVA_INT, JAVA_INT, JAVA_INT)
> )
> .nn;
> valres= MethodHandleFacade.callVariadic(mh, 2, 1, 2).asInstanceOf[Int]
> assertEquals(res, 3)
> }
> #include<stdarg.h>
> #include<stdio.h>
> intadd_var(intn, ...) {
> intSum = 0;
> va_list ptr;
> va_start(ptr, n);
> for(inti = 0; i < n; i++) {
> inti = va_arg(ptr, int);
> printf("lala %d", i);
> Sum += va_arg(ptr, int);
> }
> va_end(ptr);
> returnSum;
> } The output of the test code is consistent with my autogenerated code,
> the Ints are not reaching the add_var function in a proper state, and
> therefore
> add_var is returning something like 840370212 instead of 3.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/panama-dev/attachments/20221024/d9c1c078/attachment.htm>
More information about the panama-dev
mailing list