php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77768 FFI: Builtin Types Should Not Raise Error On Redeclaration
Submitted: 2019-03-19 14:30 UTC Modified: 2019-03-24 18:54 UTC
From: ircmaxell@php.net Assigned: dmitry (profile)
Status: Closed Package: Unknown/Other Function
PHP Version: Next Minor Version OS:
Private report: No CVE-ID: None
 [2019-03-19 14:30 UTC] ircmaxell@php.net
Description:
------------
In line with other FFI implementations, defining builtin types such as va_args, __builtin_va_list and __gnuc_va_list should not raise a redefinition error, but should be silently ignored.

For example, LUAJIT's FFI documentation (https://luajit.org/ext_ffi_semantics.html) contains the following lines:

The following C types are pre-defined by the C parser (like a typedef, except re-declarations will be ignored):

Vararg handling: va_list, __builtin_va_list, __gnuc_va_list.
From <stddef.h>: ptrdiff_t, size_t, wchar_t.
From <stdint.h>: int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t.

The problem is that hard erroring on these types means users of FFI who want to include an entire library's header files need to manually be careful to not include these definitions.

Additionally, the error message raised is incorrect, as it's not a syntax error but instead the redefinition of a known type.

Test script:
---------------
<?php 

$cdef = '
typedef __builtin_va_list __gnuc_va_list;
';

$ffi = FFI::cdef($cdef, "/lib/x86_64-linux-gnu/libc.so.6");

Expected result:
----------------
valid FFI instance

Actual result:
--------------
Fatal error: Uncaught FFI\ParserException: unexpected '<ID>' at line 2 in test.php:7
Stack trace:
#0 test.php(7): FFI::cdef('\ntypedef __buil...', '/lib/x86_64-lin...')
#1 {main}
  thrown in test.php on line 7


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-03-19 14:30 UTC] ircmaxell@php.net
-Assigned To: +Assigned To: dmitry
 [2019-03-24 18:54 UTC] kalle@php.net
-Summary: Builtin Types Should Not Raise Error On Redeclaration +Summary: FFI: Builtin Types Should Not Raise Error On Redeclaration
 [2019-03-28 21:03 UTC] dmitry@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a3e52afebe77517ca10d98ba57fefe3f178d56b6
Log: Fixed bug #77768 (FFI: Builtin Types Should Not Raise Error On Redeclaration)
 [2019-03-28 21:03 UTC] dmitry@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Jun 26 10:01:26 2019 UTC