[php-src] Issue #7796: FFI: Allow CData to be passed as valid argument to primitive ffi functions

From: Date: Sun, 19 Dec 2021 17:57:38 +0000
Subject: [php-src] Issue #7796: FFI: Allow CData to be passed as valid argument to primitive ffi functions
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-238493@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/7796 Author: the-eater ### Description Currently one can only pass a float (C) from the PHP's float, which is a double. When using a lot of floats with C libraries, this means that float's are constantly converted from float's to double' and double's to floats. I hereby would like to request the option to send the CData class to FFI bound functions, to bypass this type juggling I guess this would also mean that there should be an option to get the return as the "raw" CData value, which I have no idea how to fully implement from a user standpoint ($ffi->atan->raw(0.5) or something?) A simple code example (that has no bearing on reality) that displays the "issue" would be the following: ```php <?php $c = FFI::cdef('float atanf (float x);', 'libm.so.6'); $x = $c->atanf(0.4); $z = FFI::new('float'); $z->cdata = $x; $y = $c->atanf($z); echo $y.$x."\n"; ``` php will now simply throw a warning "PHP Warning: Object of class FFI\CData could not be converted to float", and use 1.0 instead

« previous php.bugs (#238493) next »