php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77706 Improve error messages in FFI for incompatible arguments
Submitted: 2019-03-07 13:24 UTC Modified: 2019-03-07 13:24 UTC
From: ircmaxell@php.net Assigned: dmitry (profile)
Status: Closed Package: Unknown/Other Function
PHP Version: Next Minor Version OS: any
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ircmaxell@php.net
New email:
PHP Version: OS:

 

 [2019-03-07 13:24 UTC] 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-03-07 13:24 UTC] ircmaxell@php.net
-Assigned To: +Assigned To: dmitry
 [2019-03-11 10:28 UTC] dmitry@php.net
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)
 [2019-03-11 10:28 UTC] dmitry@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 06 20:01:27 2024 UTC