bariumbitmap bariumbitmap - 2 months ago 20
C Question

pycparser.plyparser.ParseError on complex struct

I'm trying to use

pycparser
to parse this C code:

https://github.com/nbeaver/mx-trunk/blob/0b80678773582babcd56fe959d5cfbb776cc0004/libMx/d_adsc_two_theta.c

A repo with a minimal example and Makefile is here:

https://github.com/nbeaver/pycparser-problem

Using
pycparser
v2.14 (from pip) and gcc 4.9.2 on Debian Jessie.

Things I have tried:


  • Pass the
    -nostdinc
    flag to
    gcc
    and including the
    fake_libc_include
    folder.

  • Use
    -D'__attribute__(x)='
    to take out GCC extensions

  • Use fake headers for e.g.
    <sys/param.h>

  • Use the
    -std=c99
    in case the code is not C99 compatible.

  • Reproduce the redis example in case there is something weird with my machine.



This is what the traceback looks like:

Traceback (most recent call last):
File "just_parse.py", line 21, in <module>
parse(path)
File "just_parse.py", line 9, in parse
ast = pycparser.parse_file(filename)
File "/home/nathaniel/.local/lib/python2.7/site-packages/pycparser/__init__.py", line 93, in parse_file
return parser.parse(text, filename)
File "/home/nathaniel/.local/lib/python2.7/site-packages/pycparser/c_parser.py", line 146, in parse
debug=debuglevel)
File "/home/nathaniel/.local/lib/python2.7/site-packages/pycparser/ply/yacc.py", line 265, in parse
return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
File "/home/nathaniel/.local/lib/python2.7/site-packages/pycparser/ply/yacc.py", line 1047, in parseopt_notrack
tok = self.errorfunc(errtoken)
File "/home/nathaniel/.local/lib/python2.7/site-packages/pycparser/c_parser.py", line 1680, in p_error
column=self.clex.find_tok_column(p)))
File "/home/nathaniel/.local/lib/python2.7/site-packages/pycparser/plyparser.py", line 55, in _parse_error
raise ParseError("%s: %s" % (coord, msg))
pycparser.plyparser.ParseError: in/d_adsc_two_theta.c:63:82: before: .


The traceback points to this line:

https://github.com/nbeaver/mx-trunk/blob/0b80678773582babcd56fe959d5cfbb776cc0004/libMx/d_adsc_two_theta.c#L63

Which in turn points to this
#define
macro:

https://github.com/nbeaver/mx-trunk/blob/0b80678773582babcd56fe959d5cfbb776cc0004/libMx/mx_motor.h#L484

Answer

The cause appears to be the offsetof() function. The minimal working examples are fixed by recent commits, however:

https://github.com/eliben/pycparser/issues/87

Comments