Bug #77706 [Asn->Csd]: Improve error messages in FFI for incompatible arguments
| From: | dmitry@php.net | Date: | Mon, 11 Mar 2019 10:28:12 +0000 |
| Subject: | Bug #77706 [Asn->Csd]: Improve error messages in FFI for incompatible arguments | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-219905@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77706&edit=1
ID: 77706
Updated by: dmitry@php.net
Reported by: ircmaxell@php.net
Summary: Improve error messages in FFI for incompatible
arguments
-Status: Assigned
+Status: Closed
Type: Bug
Package: Unknown/Other Function
Operating System: any
PHP Version: Next Minor Version
Assigned To: dmitry
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a1868d22917ac189dde1f6974bc43e1c498e1c6a
Log: Fixed bug #77706 (Improve error messages in FFI for incompatible arguments)
Previous Comments:
------------------------------------------------------------------------
[2019-03-07 13:24:04] ircmaxell@php.net
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 this bug report at https://bugs.php.net/bug.php?id=77706&edit=1