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_double_pointer():
src = """
typedef struct Error {
int dummy;
} Error;
void func_with_p2pp(const char *, Error **);
"""
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()
ast.show()
assert gen.visit(ast).find("func_with_p2pp(const char *, Error **)") != -1
def test_asm_volatile_1():
src = """
void read_tsc(void) {
long val;
asm("rdtsc" : "=A" (val));
} """
from pycparserext.ext_c_parser import GnuCParser
p = GnuCParser()
ast = p.parse(src)
ast.show()
from pycparserext.ext_c_generator import GnuCGenerator
print(GnuCGenerator().visit(ast))
def test_funky_header_code_5():
src = """ void do_foo(void) __asm(__STRING(do_foo));"""
from pycparserext.ext_c_parser import GnuCParser
p = GnuCParser()
ast = p.parse(src)
ast.show()
from pycparserext.ext_c_generator import GnuCGenerator
print(GnuCGenerator().visit(ast))
int __m;
if (__x == 0)
__asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x));
else
__asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x));
return __m & 0x8;
}
"""
from pycparserext.ext_c_parser import GnuCParser
p = GnuCParser()
ast = p.parse(src)
ast.show()
from pycparserext.ext_c_generator import GnuCGenerator
print(GnuCGenerator().visit(ast))
def test_array_ptr_decl_attribute():
src = """
int* __attribute__((weak)) array[256];
"""
from pycparserext.ext_c_parser import GnuCParser
p = GnuCParser()
ast = p.parse(src)
ast.show()
from pycparserext.ext_c_generator import GnuCGenerator
print(GnuCGenerator().visit(ast))
def test_func_ret_ptr_decl_attribute():
src = """
extern void* memcpy(const void* src, const void *dst, int len)
__attribute__((unused));
"""
from pycparserext.ext_c_parser import GnuCParser
p = GnuCParser()
ast = p.parse(src)
ast.show()
from pycparserext.ext_c_generator import GnuCGenerator
print(GnuCGenerator().visit(ast))
src = """
extern __inline int __attribute__ ((__nothrow__)) __signbitf (float __x)
{
int __m;
__asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x));
return __m & 0x8;
}
"""
from pycparserext.ext_c_parser import GnuCParser
p = GnuCParser()
ast = p.parse(src)
ast.show()
from pycparserext.ext_c_generator import GnuCGenerator
print(GnuCGenerator().visit(ast))
def test_lvalue_gnu_statement_expression():
src = """
int func(int a) {
int ret=(int)({; ; *(int*)&a;});
return ret;
}
"""
from pycparserext.ext_c_parser import GnuCParser
p = GnuCParser()
ast = p.parse(src)
ast.show()
from pycparserext.ext_c_generator import GnuCGenerator
print(GnuCGenerator().visit(ast))