inducer / pycparserext

Extensions for Eli Bendersky's pycparser
http://pypi.python.org/pypi/pycparserext
Other
83 stars 28 forks source link

Generating incorrect code for const char* #19

Closed jfoote closed 8 years ago

jfoote commented 8 years ago

Hello,

pycparserext seems to be inserting an empty __attribute__ list when * should occur. This can be reproduced by this POC with pycparserext installed from the master branch:

#!/usr/bin/env python

from pycparserext import ext_c_parser, ext_c_generator

src = '''
struct foo {
        const char                      *bar;
        const char                      *baz;
};

int main () {
    return 0;
}
'''

parser = ext_c_parser.GnuCParser()
ast = parser.parse(src)
gen = ext_c_generator.GnuCGenerator()
print gen.visit(ast)

Running this program results in the following output:

struct foo
{
  const char bar __attribute__(());
  const char baz __attribute__(());
};
int main()
{
  return 0;
}

I'm not very familiar with the codebase, but for what its worth I think the bug may occur during parsing rather than generation.

Thanks for all the good work on this project so far.