Skip to content
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

Incorrect parse on struct field that is a pointer to a function with attributes that returns a function pointer #85

Open
lambdadog opened this issue Sep 17, 2024 · 2 comments

Comments

@lambdadog
Copy link

Repro:

from pycparserext.ext_c_parser import GnuCParser

repro = """
struct x {
   void (*(*__attribute__((whatever)) ret_fn_ptr_attr) (void)) (void);
};
"""

p = GnuCParser()
p.parse(repro).show(attrnames=True, nodenames=True)

Expected->Actual:

 FileAST:
   Decl <ext[0]>: name=None, quals=[], storage=[], funcspec=[]
     Struct <type>: name=x
-      Decl <decls[0]>: name=ret_fn_ptr_attr, quals=[], storage=[], funcspec=[]
-        PtrDecl <type>: quals=[]
+        Decl <decls[0]>: name=ret_fn_ptr_attr, quals=[], storage=[], funcspec=[]
           FuncDeclExt <type>:
             ParamList <args>:
               Typename <params[0]>: name=None, quals=[]
                 TypeDecl <type>: declname=None, quals=[]
                   IdentifierType <type>: names=['void']
             PtrDecl <type>: quals=[]
               FuncDeclExt <type>:
                 ParamList <args>:
                   Typename <params[0]>: name=None, quals=[]
                     TypeDecl <type>: declname=None, quals=[]
                       IdentifierType <type>: names=['void']
                 TypeDeclExt <type>: declname=ret_fn_ptr_attr, quals=[]
                   IdentifierType <type>: names=['void']
                 ExprList <attributes>:
             ExprList <attributes>:
-              ID <exprs[0]>: name=whatever

Seen in the real world here in the emacs dynamic module interface (ultimately included in emacs_module.h here, via templating).

@inducer
Copy link
Owner

inducer commented Sep 17, 2024

Thanks for the report! I'm unlikely to have time to dig into this anytime soon, but I'd be happy to look at a patch (ideally with a test).

@lambdadog
Copy link
Author

lambdadog commented Sep 17, 2024

Will look into it! It's been a while since I've poked at lex and yacc but I might be able to knock something out.

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

No branches or pull requests

2 participants