eliben / pycparser

:snake: Complete C99 parser in pure Python
Other
3.26k stars 612 forks source link

pid_t causes ParseError in ply.yacc #467

Closed b0urb0n closed 2 years ago

b0urb0n commented 2 years ago

Using pycparser==2.21, I get a ParseError when processing a variable of type pid_t. I'm working with some C source I don't control and would like to avoid forking/editing if possible.

I haven't taken a look at pycparser's internals to know how types are derived but I wonder if there's a way to alias pid_t to int.

ffi.cdef("""
struct pid_struct {
    pid_t pid;
};
""")
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/cffi/cparser.py", line 336, in _parse
    ast = _get_parser().parse(fullcsource)
  File "/usr/local/lib/python3.7/dist-packages/pycparser/c_parser.py", line 150, in parse
    debug=debug)
  File "/usr/local/lib/python3.7/dist-packages/pycparser/ply/yacc.py", line 331, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
  File "/usr/local/lib/python3.7/dist-packages/pycparser/ply/yacc.py", line 1199, in parseopt_notrack
    tok = call_errorfunc(self.errorfunc, errtoken, self)
  File "/usr/local/lib/python3.7/dist-packages/pycparser/ply/yacc.py", line 193, in call_errorfunc
    r = errorfunc(token)
  File "/usr/local/lib/python3.7/dist-packages/pycparser/c_parser.py", line 1934, in p_error
    column=self.clex.find_tok_column(p)))
  File "/usr/local/lib/python3.7/dist-packages/pycparser/plyparser.py", line 67, in _parse_error
    raise ParseError("%s: %s" % (coord, msg))
pycparser.plyparser.ParseError: <cdef source string>:3:5: before: pid_t
eliben commented 2 years ago

Please read https://github.com/eliben/pycparser#3using