Req #78745 [NEW]: Allow to define FFI callbacks with CData return type
From: lisachenko dot it at gmail dot com
Operating system:
PHP version: 7.4Git-2019-10-23 (Git)
Package: *Extensibility Functions
Bug Type: Feature/Change Request
Bug description:Allow to define FFI callbacks with CData return type
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 bug report at https://bugs.php.net/bug.php?id=78745&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=78745&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=78745&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=78745&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=78745&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=78745&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=78745&r=support
Expected behavior: https://bugs.php.net/fix.php?id=78745&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=78745&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=78745&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=78745&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=78745&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=78745&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=78745&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=78745&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78745&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=78745&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=78745&r=mysqlcfg
Thread (3 messages)
- lisachenko dot it at gmail dot com