pycparserext icon indicating copy to clipboard operation
pycparserext copied to clipboard

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

Open lambdadog opened this issue 1 year ago • 2 comments

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).

lambdadog avatar Sep 17 '24 14:09 lambdadog

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).

inducer avatar Sep 17 '24 15:09 inducer

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.

lambdadog avatar Sep 17 '24 16:09 lambdadog

Closed by #92.

inducer avatar Oct 13 '25 16:10 inducer