Author: Armin Rigo <[email protected]>
Branch: cffi-1.0
Changeset: r76979:c33d7ff70346
Date: 2015-05-02 17:09 +0200
http://bitbucket.org/pypy/pypy/changeset/c33d7ff70346/
Log: Finish to pass these tests
diff --git a/pypy/module/_cffi_backend/parse_c_type.py
b/pypy/module/_cffi_backend/parse_c_type.py
--- a/pypy/module/_cffi_backend/parse_c_type.py
+++ b/pypy/module/_cffi_backend/parse_c_type.py
@@ -17,7 +17,11 @@
return rffi.llexternal(name, args, result, compilation_info=eci, **kwds)
-GLOBAL_S = rffi.CStruct('struct _cffi_global_s')
+GLOBAL_S = rffi.CStruct('struct _cffi_global_s',
+ ('name', rffi.CCHARP),
+ ('address', rffi.VOIDP),
+ ('type_op', rffi.SIGNED),
+ ('size', rffi.SIZE_T))
STRUCT_UNION_S = rffi.CStruct('struct _cffi_struct_union_s',
('name', rffi.CCHARP),
('type_index', rffi.INT),
@@ -32,7 +36,9 @@
('type_index', rffi.INT),
('type_prim', rffi.INT),
('enumerators', rffi.CCHARP))
-TYPENAME_S = rffi.CStruct('struct _cffi_typename_s')
+TYPENAME_S = rffi.CStruct('struct _cffi_typename_s',
+ ('name', rffi.CCHARP),
+ ('type_index', rffi.INT))
PCTX = rffi.CStructPtr('struct _cffi_type_context_s',
('types', rffi.VOIDPP),
diff --git a/pypy/module/_cffi_backend/test/test_parse_c_type.py
b/pypy/module/_cffi_backend/test/test_parse_c_type.py
--- a/pypy/module/_cffi_backend/test/test_parse_c_type.py
+++ b/pypy/module/_cffi_backend/test/test_parse_c_type.py
@@ -1,5 +1,6 @@
import sys, re, os, py
from rpython.rtyper.lltypesystem import lltype, rffi
+from rpython.rtyper.annlowlevel import llhelper
from pypy.module._cffi_backend import parse_c_type, cffi_opcode
@@ -40,40 +41,44 @@
ctx.c_enums = ctx_enums
rffi.setintfield(ctx, 'c_num_enums', len(enum_names))
-## c_identifier_names = [ffi.new("char[]", _n.encode('ascii'))
-## for _n in identifier_names]
-## ctx_identifiers = ffi.new("struct _cffi_typename_s[]",
len(identifier_names))
-## for _i in range(len(identifier_names)):
-## ctx_identifiers[_i].name = c_identifier_names[_i]
-## ctx_identifiers[_i].type_index = 100 + _i
-## ctx.typenames = ctx_identifiers
-## ctx.num_typenames = len(identifier_names)
+c_identifier_names = [rffi.str2charp(_n.encode('ascii'))
+ for _n in identifier_names]
+ctx_identifiers = lltype.malloc(rffi.CArray(parse_c_type.TYPENAME_S),
+ len(identifier_names), flavor='raw', zero=True,
+ track_allocation=False)
+for _i in range(len(identifier_names)):
+ ctx_identifiers[_i].c_name = c_identifier_names[_i]
+ rffi.setintfield(ctx_identifiers[_i], 'c_type_index', 100 + _i)
+ctx.c_typenames = ctx_identifiers
+rffi.setintfield(ctx, 'c_num_typenames', len(identifier_names))
-## @ffi.callback("int(unsigned long long *)")
-## def fetch_constant_five(p):
-## p[0] = 5
-## return 0
-## @ffi.callback("int(unsigned long long *)")
-## def fetch_constant_zero(p):
-## p[0] = 0
-## return 1
-## @ffi.callback("int(unsigned long long *)")
-## def fetch_constant_neg(p):
-## p[0] = 123321
-## return 1
+def fetch_constant_five(p):
+ p[0] = rffi.cast(rffi.ULONGLONG, 5)
+ return rffi.cast(rffi.INT, 0)
+def fetch_constant_zero(p):
+ p[0] = rffi.cast(rffi.ULONGLONG, 0)
+ return rffi.cast(rffi.INT, 1)
+def fetch_constant_neg(p):
+ p[0] = rffi.cast(rffi.ULONGLONG, 123321)
+ return rffi.cast(rffi.INT, 1)
+FETCH_CB_P = rffi.CCallback([rffi.ULONGLONGP], rffi.INT)
-## ctx_globals = ffi.new("struct _cffi_global_s[]", len(global_names))
-## c_glob_names = [ffi.new("char[]", _n.encode('ascii')) for _n in
global_names]
-## for _i, _fn in enumerate([fetch_constant_five,
-## fetch_constant_neg,
-## fetch_constant_zero]):
-## ctx_globals[_i].name = c_glob_names[_i]
-## ctx_globals[_i].address = _fn
-## ctx_globals[_i].type_op = ffi.cast("_cffi_opcode_t",
-## cffi_opcode.OP_CONSTANT_INT if _i !=
1
-## else cffi_opcode.OP_ENUM)
-## ctx.globals = ctx_globals
-## ctx.num_globals = len(global_names)
+ctx_globals = lltype.malloc(rffi.CArray(parse_c_type.GLOBAL_S),
+ len(global_names), flavor='raw', zero=True,
+ track_allocation=False)
+c_glob_names = [rffi.str2charp(_n.encode('ascii')) for _n in global_names]
+_helpers_keepalive = []
+for _i, _fn in enumerate([fetch_constant_five,
+ fetch_constant_neg,
+ fetch_constant_zero]):
+ llf = llhelper(FETCH_CB_P, _fn)
+ _helpers_keepalive.append(llf)
+ ctx_globals[_i].c_name = c_glob_names[_i]
+ ctx_globals[_i].c_address = rffi.cast(rffi.VOIDP, llf)
+ ctx_globals[_i].c_type_op = (cffi_opcode.OP_CONSTANT_INT if _i != 1
+ else cffi_opcode.OP_ENUM)
+ctx.c_globals = ctx_globals
+rffi.setintfield(ctx, 'c_num_globals', len(global_names))
def parse(input):
@@ -301,6 +306,7 @@
'->', Pointer(0)]
def test_cffi_opcode_sync():
+ py.test.skip("XXX")
import cffi.model
for name in dir(lib):
if name.startswith('_CFFI_'):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit