-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Should JNA promote float vararg arguments to double? #463
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
Comments
Can you determine if this is part of the C spec or part of GCC’s varargs handling?
|
Looks like it's part of the C spec:
Confirmed with:
From what I can see, JNA flattens the varargs into the regular argument array that it then passes to libffi. Libffi takes care of the promotion of char and short (because it applies to regular arguments and vararg arguments). But only floats in varargs need to be promoted, not regular arguments. So libffi (respectively the native part of JNA) can't differentiate between those two cases. So I suggest that JNA handles the promotion while flattening the varargs:
|
Sounds reasonable, please provide a suitable PR and associated tests.
|
I'm sitting on a couple of JNA improvements and fixes. I'm very busy currently but will try to make PRs in the near future. |
This seems like a bug in libffi, but for now we'll follow what JNA does: java-native-access/jna#463
could you make this functionality pluggable? this breaks objective-c 's obj-c sidehttps://github.com/umjammer/rococoa/blob/0.8.5/rococoa-core/src/main/native/test.m#L121-L125 java sidelog
i traced around before call below using debugger
then i found jna/src/com/sun/jna/Function.java Line 776 in 3705b84
do this. is this patch really common things? is my obj-c case rare? on 28 Jun 2021 |
C seems to require promoting of float vararg arguments to double:
include <stdarg.h>
void foo(int bar, ...) {
va_list baz;
va_arg(baz, float);
}
GCC says:
warning: ‘float’ is promoted to ‘double’ when passed through ‘...’
note: (so you should pass ‘double’ not ‘float’ to ‘va_arg’)
note: if this code is reached, the program will abort
JNA doesn't promote vararg floats. Should users do this themselves or should JNA be changed? I think it would be better if JNA was handling this because it's very hard to debug. What do the JNA maintainers think?
The text was updated successfully, but these errors were encountered: