Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_no_added_attr():
src = """
char* foo() {
return "";
}
int main() {
return 0;
}
"""
import pycparserext.ext_c_parser as ext_c_parser
import pycparserext.ext_c_generator as ext_c_generator
parser = ext_c_parser.GnuCParser()
ast = parser.parse(src)
gen = ext_c_generator.GnuCGenerator()
print(gen.visit(ast))
assert "attr" not in gen.visit(ast)
def test_pointer_reproduction():
src = """
struct foo {
const char *bar;
const char *baz;
};
int main () {
return 0;
}
"""
import pycparserext.ext_c_parser as ext_c_parser
import pycparserext.ext_c_generator as ext_c_generator
parser = ext_c_parser.GnuCParser()
ast = parser.parse(src)
gen = ext_c_generator.GnuCGenerator()
print(gen.visit(ast))
def read_user_h(path, include_path):
text = get_header_text(path, include_path)
parser = ext_c_parser.GnuCParser()
fileast = parser.parse(text, path)
if not isinstance(fileast, c_ast.FileAST):
die('could not parse user.h')
typedefs = parse_typedefs(fileast)
structs = {'user_regs_struct', 'user_fpregs_struct'}
return parse_structs(fileast, structs, typedefs)
def read_signal_h(path, include_path):
text = get_header_text(path, include_path)
parser = ext_c_parser.GnuCParser()
fileast = parser.parse(text, path)
if not isinstance(fileast, c_ast.FileAST):
die('could not parse signal.h')
typedefs = parse_typedefs(fileast)
structs = {'siginfo_t'}
return parse_structs(fileast, structs, typedefs)
def read_ptrace_h(path, include_path):
text = get_header_text(path, include_path)
parser = ext_c_parser.GnuCParser()
fileast = parser.parse(text, path)
if not isinstance(fileast, c_ast.FileAST):
die('could not parse user.h')
output = ['\n']
for decl in fileast.ext:
if (not isinstance(decl, c_ast.Decl) or
not isinstance(decl.type, c_ast.Enum)):
continue
for item in decl.type.values.enumerators:
if item.name.startswith('PTRACE_'):
output.append('{} = {}'.format(
item.name, render_const(item.value)))