PerlFFI / FFI-Platypus

Write Perl bindings to non-Perl libraries with FFI. No XS required.
89 stars 23 forks source link

varargs float should (probably) be promoted to double #323

Closed plicease closed 3 years ago

plicease commented 3 years ago
✅ starscream% perl -MFFI::Platypus -E 'FFI::Platypus->new( lib => [undef] )->function( printf => ["string"] => ["double"] )->call("%f\n", 3.14 );'
3.140000
✅ starscream% perl -MFFI::Platypus -E 'FFI::Platypus->new( lib => [undef] )->function( printf => ["string"] => ["float"] )->call("%f\n", 3.14 );'
0.000000

example is on AMD64 Linux. The actual behavior is probably undefined.

Helpful reading from another project: https://github.com/java-native-access/jna/issues/463

alternatively using a float in a vararg could be an exception, but silently promoting it when the function is created shouldn't be too costly and probably safe users trying to do something that would automatically happen in C.

plicease commented 3 years ago

Note: there is some discussion on the libffi mainiling list as it if this should be handled at that level, and that would be fine, but since we support older versions of libffi it would be good to work around it in Platypus.