Bug #77706 [NEW]: Improve error messages in FFI for incompatible arguments

From: Date: Thu, 07 Mar 2019 13:24:05 +0000
Subject: Bug #77706 [NEW]: Improve error messages in FFI for incompatible arguments
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219881@lists.php.net to get a copy of this message
From: ircmaxell Operating system: any PHP version: Next Minor Version Package: Unknown/Other Function Bug Type: Bug Bug description:Improve error messages in FFI for incompatible arguments Description: ------------ When using FFI, very little useful debugging information is provided when type checking arguments for function calls/etc. In the test script, the syntax for fprintf is FILE*, const char*, ... I made a "mistake" by passing a number for the second argument. FFI gave me no indication as to which parameter was incorrect, leading to either trial-and-error debugging, or breaking out GDB to see which argument was the problem. Test script: --------------- <?php $header = ' typedef struct _IO_FILE FILE; extern FILE *stdout; extern FILE *stdin; extern FILE *stderr; int fprintf(FILE *, const char *, ...); '; $ffi = FFI::cdef($header, 'libc.so.6'); $ffi->fprintf($ffi->stdout, 123, "Hello %s\n", "World"); Expected result: ---------------- Fatal error: Uncaught FFI\Exception: Passing incompatible pointer to argument 2 of function fprintf, expecting const char*, found long long in /.../test.php:14 Stack trace: #0 /.../test.php(14): FFI->fprintf(Object(FFI\CData:<struct>*), 123, 'Hello %s\n', 'World') #1 {main} thrown in /.../test.php on line 14 Actual result: -------------- Fatal error: Uncaught FFI\Exception: Passing incompatible pointer in /.../test.php:14 Stack trace: #0 /.../test.php(14): FFI->fprintf(Object(FFI\CData:<struct>*), 123, 'Hello %s\n', 'World') #1 {main} thrown in /.../test.php on line 14 -- Edit bug report at https://bugs.php.net/bug.php?id=77706&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77706&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77706&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77706&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=77706&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=77706&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=77706&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=77706&r=needscript Try newer version: https://bugs.php.net/fix.php?id=77706&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=77706&r=support Expected behavior: https://bugs.php.net/fix.php?id=77706&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=77706&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=77706&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=77706&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77706&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=77706&r=dst IIS Stability: https://bugs.php.net/fix.php?id=77706&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=77706&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=77706&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=77706&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=77706&r=mysqlcfg

« previous php.bugs (#219881) next »