Skip to content

In FFI, assume that identifier is a typedef if followed by '*' in parameter list #5733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

alexdowad
Copy link
Contributor

@alexdowad alexdowad commented Jun 17, 2020

Bug #79576 reports that the error message shown by FFI when parsing a C function declaration which uses typedef's it doesn't know about can be confusing.

For example, given this definition:

int func(oid *);

Since FFI has not seen a typedef for 'oid', it treats 'oid' as being the name of a parameter. But since it is followed by '*', it fails with this message:

unsupported type specifier combination

Interestingly, GCC is able to detect that 'oid' is a type name and reports:

unknown type name 'oid'

Implement a simple workaround: If the identifier in the above case is directly followed by '*', take it as being a typedef. This does not actually allow the parse to succeed, but does make it fail with a more informative message:

undefined C type 'oid'

Since this fix is quite simplistic, there are probably more complicated cases where it will still not display the most informative error message.

I fully expect that there may be problems with this approach, and am hoping the maintainers can point me in a better direction if necessary.

…ameter list

Bug #79576 (https://bugs.php.net/bug.php?id=79576) reports that the error message
shown by FFI when parsing a C function declaration which uses typedef's it doesn't
know about can be confusing.

For example, given this definition:

    int func(oid *);

Since FFI has not seen a typedef for 'oid', it treats 'oid' as being the name of
a parameter. But since it is followed by '*', it fails with this message:

    unsupported type specifier combination

Interestingly, GCC is able to detect that 'oid' is a type name and reports:

    unknown type name 'oid'

Implement a simple workaround: If the identifier in the above case is directly
followed by '*', take it as being a typedef. This does not actually allow the
parse to succeed, but does make it fail with a more informative message:

    undefined C type 'oid'

Since this fix is quite simplistic, there are probably more complicated cases
where it will still not display the most informative error message.
@alexdowad alexdowad changed the title In FFI, assume that identifier is a typedef if followed by '*' in par… In FFI, assume that identifier is a typedef if followed by '*' in parameter list Jun 17, 2020
@nikic nikic requested a review from dstogov June 18, 2020 08:02
@@ -143,7 +158,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) || peek_sym() == YY__STAR}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably check for YY__LBRACK as well, to cater to unknown_type[].

Copy link
Member

@dstogov dstogov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See a better fix #7496

Unfortunately, it disclose memory leaks caused by incomplete cleanup after parser error.

@dstogov
Copy link
Member

dstogov commented Sep 15, 2021

The bug is fixed via #7496

@dstogov dstogov closed this Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants