pythoncentos7pycparser

Pycparser parse error on byteswap.h


I know that this is a pretty specific issue but I've done about all I can to search for an answer and still haven't come up with anything of value. I'm using pycparser to try and parse some code in (surprise, surprise) and when it does the linking it fails with the error below. If anyone has any thoughts, I'd be grateful for some help.

  File "test.py", line 14, in <module>
    cpp_args=['-E', r'-Iutils/fake_libc_include'])
  File "/usr/lib/python2.7/site-packages/pycparser/__init__.py", line 93, in parse_file
    return parser.parse(text, filename)
  File "/usr/lib/python2.7/site-packages/pycparser/c_parser.py", line 146, in parse
    debug=debuglevel)
  File "/usr/lib/python2.7/site-packages/ply/yacc.py", line 265, in parse
    return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
  File "/usr/lib/python2.7/site-packages/ply/yacc.py", line 1047, in parseopt_notrack
    tok = self.errorfunc(errtoken)
  File "/usr/lib/python2.7/site-packages/pycparser/c_parser.py", line 1680, in p_error
    column=self.clex.find_tok_column(p)))
  File "/usr/lib/python2.7/site-packages/pycparser/plyparser.py", line 55, in
_parse_error
    raise ParseError("%s: %s" % (coord, msg))

/usr/include/bits/byteswap.h:46:1: before: {

This is on CentOS 7.

The code:

      (((x) & 0x0000ff00) <<  8) | (((x) & 0x000000ff) << 24))

#ifdef __GNUC__
# if __GNUC_PREREQ (4, 3)
static __inline unsigned int
__bswap_32 (unsigned int __bsx)
{
  return __builtin_bswap32 (__bsx);
}
# elif __GNUC__ >= 2
#  if __WORDSIZE == 64 || (defined __i486__ || defined __pentium__            \
                           || defined __pentiumpro__ || defined __pentium4__  \
                           || defined __k8__ || defined __athlon__            \
                           || defined __k6__ || defined __nocona__            \
                           || defined __core2__ || defined __geode__          \
                           || defined __amdfam10__)

Solution

  • So I don't really have an answer but I'll at least post this as a workaround in case anyone else is having the same issue. I have to manually run my code through a preprocessor as I think there are some compiler issues that give pycparser issues (its weird, I know). Anyway, preprocessing the code manually then parsing using pycparser worked for me!