pid_t causes ParseError
The stack trace below shows that pycparser
is to blame for this but I thought you all may want to be aware of it as well.
FWIW, in Python3, you should be using Exception Chaining. cffi.cparser
L367 should be changed to the following in order to "chain" the exceptions together for a cleaner traceback:
raise CDefError(msg) from e
The issue with pycparser
using pid_t
:
ffi.cdef("""
struct pid_struct {
pid_t pid;
};
""")
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
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 5, in <module>
File "/usr/local/lib/python3.7/dist-packages/cffi/api.py", line 112, in cdef
self._cdef(csource, override=override, packed=packed, pack=pack)
File "/usr/local/lib/python3.7/dist-packages/cffi/api.py", line 126, in _cdef
self._parser.parse(csource, override=override, **options)
File "/usr/local/lib/python3.7/dist-packages/cffi/cparser.py", line 389, in parse
self._internal_parse(csource)
File "/usr/local/lib/python3.7/dist-packages/cffi/cparser.py", line 394, in _internal_parse
ast, macros, csource = self._parse(csource)
File "/usr/local/lib/python3.7/dist-packages/cffi/cparser.py", line 338, in _parse
self.convert_pycparser_error(e, csource)
File "/usr/local/lib/python3.7/dist-packages/cffi/cparser.py", line 367, in convert_pycparser_error
raise CDefError(msg)
cffi.CDefError: cannot parse "pid_t pid;"
<cdef source string>:3:5: before: pid_t
Edited by bourbon