Req #78745 [Com]: Allow to define FFI callbacks with CData return type
Edit report at https://bugs.php.net/bug.php?id=78745&edit=1
ID: 78745
Comment by: lisachenko dot it at gmail dot com
Reported by: lisachenko dot it at gmail dot com
Summary: Allow to define FFI callbacks with CData return type
Status: Open
Type: Feature/Change Request
Package: *Extensibility Functions
PHP Version: 7.4Git-2019-10-23 (Git)
Block user comment: N
Private report: N
New Comment:
This issue was resolved by Dmitry in https://github.com/php/php-src/commit/c744531fff9ee03c027ca3c18b21f3382023ff7e
Should be closed after recheck.
Previous Comments:
------------------------------------------------------------------------
[2019-10-23 16:31:19] lisachenko dot it at gmail dot com
Description:
------------
FFI can be used to define a native PHP callback via Closure instance for traditional C function
pointers (hooks) as described in https://www.php.net/manual/en/ffi.examples-callback.php
This works well for simple return types, like void, double, int, etc. But if a C callback has a
complex C return-type/struct, then FFI can't assign a callback to it, failing with a message:
Uncaught FFI\Exception: FFI internal error. Unsupported return type
It would be nice to have an additional CData type check for a PHP callback and perform some run-time
checks to allow PHP hook even for that complex callback types.
Test script:
---------------
Here is a pseudo-code for the PHP zend_compile_string callback defined as following:
ZEND_API zend_op_array *(*zend_compile_string)(zval *source_string, char *filename);
$php->zend_compile_string = function (CData $sourceString, CData $filename): CData {
echo 'In the hook';
$code = Core::new('zend_op_array[10]');
// ... some opcode initialization logic
return FFI::addr($code);
};
Expected result:
----------------
No errors about unsupported return type
Actual result:
--------------
Fatal error: Uncaught FFI\Exception: FFI internal error. Unsupported return type
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78745&edit=1
Thread (3 messages)