From 0badc7de9681b3bafefd88c79603e1929b2918aa Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 15 Sep 2021 14:48:33 +0300 Subject: [PATCH] Fixed bug #79576 ("TYPE *" shows unhelpful message when type is not defined) --- NEWS | 4 ++++ ext/ffi/ffi.g | 2 +- ext/ffi/ffi_parser.c | 2 +- ext/ffi/tests/bug79576.phpt | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 ext/ffi/tests/bug79576.phpt diff --git a/NEWS b/NEWS index 2b681b516b0..e354dde6bb5 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,10 @@ PHP NEWS . Fixed bug #81433 (DOMElement::setIdAttribute() called twice may remove ID). (Viktor Volkov) +- FFI: + . Fixed bug #79576 ("TYPE *" shows unhelpful message when type is not + defined). (Dmitry) + - PCRE: . Fixed bug #81424 (PCRE2 10.35 JIT performance regression). (cmb) diff --git a/ext/ffi/ffi.g b/ext/ffi/ffi.g index 68c002df844..6e0a66114c5 100644 --- a/ext/ffi/ffi.g +++ b/ext/ffi/ffi.g @@ -147,7 +147,7 @@ declaration_specifiers(zend_ffi_dcl *dcl): specifier_qualifier_list(zend_ffi_dcl *dcl): "__extension__"? - ( ?{sym != YY_ID || zend_ffi_is_typedef_name((const char*)yy_text, yy_pos - yy_text)} + ( ?{sym != YY_ID || zend_ffi_is_typedef_name((const char*)yy_text, yy_pos - yy_text) || (dcl->flags & ZEND_FFI_DCL_TYPE_SPECIFIERS) == 0} ( type_specifier(dcl) | type_qualifier(dcl) | attributes(dcl) diff --git a/ext/ffi/ffi_parser.c b/ext/ffi/ffi_parser.c index efb0cf96ca8..e63194c520f 100644 --- a/ext/ffi/ffi_parser.c +++ b/ext/ffi/ffi_parser.c @@ -2190,7 +2190,7 @@ static int parse_specifier_qualifier_list(int sym, zend_ffi_dcl *dcl) { } else { yy_error_sym("unexpected", sym); } - } while ((YY_IN_SET(sym, (YY_VOID,YY_CHAR,YY_SHORT,YY_INT,YY_LONG,YY_FLOAT,YY_DOUBLE,YY_SIGNED,YY_UNSIGNED,YY__BOOL,YY__COMPLEX,YY_COMPLEX,YY___COMPLEX,YY___COMPLEX__,YY_STRUCT,YY_UNION,YY_ENUM,YY_ID,YY_CONST,YY___CONST,YY___CONST__,YY_RESTRICT,YY___RESTRICT,YY___RESTRICT__,YY_VOLATILE,YY___VOLATILE,YY___VOLATILE__,YY__ATOMIC,YY___ATTRIBUTE,YY___ATTRIBUTE__,YY___DECLSPEC,YY___CDECL,YY___STDCALL,YY___FASTCALL,YY___THISCALL,YY___VECTORCALL), "\000\000\376\377\377\107\360\017\000\000\000\002\000")) && (sym != YY_ID || zend_ffi_is_typedef_name((const char*)yy_text, yy_pos - yy_text))); + } while ((YY_IN_SET(sym, (YY_VOID,YY_CHAR,YY_SHORT,YY_INT,YY_LONG,YY_FLOAT,YY_DOUBLE,YY_SIGNED,YY_UNSIGNED,YY__BOOL,YY__COMPLEX,YY_COMPLEX,YY___COMPLEX,YY___COMPLEX__,YY_STRUCT,YY_UNION,YY_ENUM,YY_ID,YY_CONST,YY___CONST,YY___CONST__,YY_RESTRICT,YY___RESTRICT,YY___RESTRICT__,YY_VOLATILE,YY___VOLATILE,YY___VOLATILE__,YY__ATOMIC,YY___ATTRIBUTE,YY___ATTRIBUTE__,YY___DECLSPEC,YY___CDECL,YY___STDCALL,YY___FASTCALL,YY___THISCALL,YY___VECTORCALL), "\000\000\376\377\377\107\360\017\000\000\000\002\000")) && (sym != YY_ID || zend_ffi_is_typedef_name((const char*)yy_text, yy_pos - yy_text) || (dcl->flags & ZEND_FFI_DCL_TYPE_SPECIFIERS) == 0)); return sym; } diff --git a/ext/ffi/tests/bug79576.phpt b/ext/ffi/tests/bug79576.phpt new file mode 100644 index 00000000000..4e85736877d --- /dev/null +++ b/ext/ffi/tests/bug79576.phpt @@ -0,0 +1,35 @@ +--TEST-- +Bug #79576 ("TYPE *" shows unhelpful message when type is not defined) +--SKIPIF-- + +--FILE-- +getMessage()."\n"; +} +try { + FFI::cdef('struct tree *get_tree(oid, size_t, struct tree *);'); +} catch (Throwable $e) { + echo get_class($e) . ": " . $e->getMessage()."\n"; +} +try { + FFI::cdef(' +typedef struct _simple_struct { + const some_not_declared_type **property; + } simple_struct; +'); +} catch (Throwable $e) { + echo get_class($e) . ": " . $e->getMessage()."\n"; +} +?> +DONE +--EXPECT-- +FFI\ParserException: undefined C type 'oid' at line 1 +FFI\ParserException: undefined C type 'oid' at line 1 +FFI\ParserException: undefined C type 'some_not_declared_type' at line 3 +DONE