Varargs bindings do not work in java 19 on the macbook pro M1 MAX

Mark Hammons markehammons at gmail.com
Mon Oct 24 12:40:17 UTC 2022


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") {
val linker = Linker.nativeLinker().nn
val sl = SymbolLookup.loaderLookup().nn

val mh = linker
.downcallHandle(
sl.lookup("add_var").nn.orElseThrow(),
FunctionDescriptor.of(JAVA_INT, JAVA_INT, JAVA_INT, JAVA_INT)
)
.nn;

val res = MethodHandleFacade.callVariadic(mh, 2, 1, 2).asInstanceOf[Int]
assertEquals(res, 3)
}

#include <stdarg.h>
#include <stdio.h>

int add_var(int n, ...) {
int Sum = 0;

va_list ptr;

va_start(ptr, n);

for(int i = 0; i < n; i++) {
int i = va_arg(ptr, int);
printf("lala %d", i);
Sum += va_arg(ptr, int);
}

va_end(ptr);

return Sum;
}

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/91459d3e/attachment.htm>


More information about the panama-dev mailing list