Req #78745 [Opn->Csd]: Allow to define FFI callbacks with CData return type

From: Date: Thu, 07 Nov 2019 10:32:33 +0000
Subject: Req #78745 [Opn->Csd]: Allow to define FFI callbacks with CData return type
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-223623@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78745&edit=1 ID: 78745 Updated by: nikic@php.net Reported by: lisachenko dot it at gmail dot com Summary: Allow to define FFI callbacks with CData return type -Status: Open +Status: Closed Type: Feature/Change Request Package: *Extensibility Functions PHP Version: 7.4Git-2019-10-23 (Git) -Assigned To: +Assigned To: nikic Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2019-10-24 07:31:26] lisachenko dot it at gmail dot com This issue was resolved by Dmitry in https://github.com/php/php-src/commit/c744531fff9ee03c027ca3c18b21f3382023ff7e Should be closed after recheck. ------------------------------------------------------------------------ [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

« previous php.bugs (#223623) next »