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 char* in function declaration #20

Closed jfoote closed 8 years ago

jfoote commented 8 years ago

Hello again,

The patch for #19 worked -- thank you for the quick fix!

pycparserext seems to be appending an empty __attribute__ to declarations of functions that return pointer types (*). This is similar to #19 but slightly different. This bug 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 = '''
char* foo() {
    return "";
} 

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:

char *foo() __attribute__(())
{
  return "";
}

int main()
{
  return 0;
}