Author: Armin Rigo <ar...@tunes.org> Branch: cffi-1.0 Changeset: r1727:228423fdb5a5 Date: 2015-04-16 10:32 +0200 http://bitbucket.org/cffi/cffi/changeset/228423fdb5a5/
Log: Killing OP_TYPENAME was a bad idea. Test and fix. diff --git a/new/cffi_opcode.py b/new/cffi_opcode.py --- a/new/cffi_opcode.py +++ b/new/cffi_opcode.py @@ -27,6 +27,7 @@ OP_CPYTHON_BLTN_V = 23 # varargs OP_CPYTHON_BLTN_N = 25 # noargs OP_CPYTHON_BLTN_O = 27 # O (i.e. a single arg) +OP_TYPENAME = 29 PRIM_VOID = 0 PRIM_BOOL = 1 diff --git a/new/parse_c_type.c b/new/parse_c_type.c --- a/new/parse_c_type.c +++ b/new/parse_c_type.c @@ -568,8 +568,7 @@ { int n = search_in_typenames(tok->info->ctx, tok->p, tok->size); if (n >= 0) { - t1 = _CFFI_OP(_CFFI_OP_NOOP, - tok->info->ctx->typenames[n].type_index); + t1 = _CFFI_OP(_CFFI_OP_TYPENAME, n); break; } n = search_standard_typename(tok->p, tok->size); diff --git a/new/parse_c_type.h b/new/parse_c_type.h --- a/new/parse_c_type.h +++ b/new/parse_c_type.h @@ -21,6 +21,7 @@ #define _CFFI_OP_CPYTHON_BLTN_V 23 // varargs #define _CFFI_OP_CPYTHON_BLTN_N 25 // noargs #define _CFFI_OP_CPYTHON_BLTN_O 27 // O (i.e. a single arg) +#define _CFFI_OP_TYPENAME 29 #define _CFFI_PRIM_VOID 0 #define _CFFI_PRIM_BOOL 1 diff --git a/new/realize_c_type.c b/new/realize_c_type.c --- a/new/realize_c_type.c +++ b/new/realize_c_type.c @@ -190,6 +190,16 @@ x = _realize_c_type_or_func(ctx, opcodes, _CFFI_GETARG(op)); break; + case _CFFI_OP_TYPENAME: + { + /* essential: the TYPENAME opcode resolves the type index looked + up in the 'ctx->typenames' array, but it does so in 'ctx->types' + instead of in 'opcodes'! */ + int type_index = ctx->typenames[_CFFI_GETARG(op)].type_index; + x = _realize_c_type_or_func(ctx, ctx->types, type_index); + break; + } + default: PyErr_Format(PyExc_NotImplementedError, "op=%d", (int)_CFFI_GETOP(op)); return NULL; diff --git a/new/recompiler.py b/new/recompiler.py --- a/new/recompiler.py +++ b/new/recompiler.py @@ -431,11 +431,15 @@ outputfilename = ffiplatform.compile(tmpdir, ext) return outputfilename -def verify(ffi, module_name, preamble, *args, **kwds): +def verify2(ffi, module_name, preamble, *args, **kwds): import imp assert module_name not in sys.modules, "module name conflict: %r" % ( module_name,) outputfilename = recompile(ffi, module_name, preamble, *args, **kwds) module = imp.load_dynamic(module_name, outputfilename) - ffi._verified(module.ffi) - return module.lib + return module.ffi, module.lib + +def verify(ffi, module_name, preamble, *args, **kwds): + ffi2, lib = verify2(ffi, module_name, preamble, *args, **kwds) + ffi._verified(ffi2) + return lib diff --git a/new/test_parse_c_type.py b/new/test_parse_c_type.py --- a/new/test_parse_c_type.py +++ b/new/test_parse_c_type.py @@ -93,6 +93,7 @@ Func = make_getter('FUNCTION') FuncEnd = make_getter('FUNCTION_END') Struct = make_getter('STRUCT_UNION') +Typename = make_getter('TYPENAME') def test_simple(): @@ -239,8 +240,8 @@ def test_identifier(): for i in range(len(identifier_names)): - assert parse("%s" % (identifier_names[i])) == ['->', NoOp(100 + i)] - assert parse("%s*" % (identifier_names[i])) == [NoOp(100 + i), + assert parse("%s" % (identifier_names[i])) == ['->', Typename(i)] + assert parse("%s*" % (identifier_names[i])) == [Typename(i), '->', Pointer(0)] def test_cffi_opcode_sync(): diff --git a/new/test_recompiler.py b/new/test_recompiler.py --- a/new/test_recompiler.py +++ b/new/test_recompiler.py @@ -1,5 +1,5 @@ import py -from recompiler import Recompiler, verify +from recompiler import Recompiler, verify, verify2 from cffi1 import FFI @@ -79,7 +79,8 @@ def test_verify_typedef(): ffi = FFI() ffi.cdef("typedef int **foo_t;") - lib = verify(ffi, 'test_verify_typedef', 'typedef int **foo_t;') + ffi2, lib = verify2(ffi, 'test_verify_typedef', 'typedef int **foo_t;') + assert ffi2.sizeof("foo_t") == ffi.sizeof("void *") def test_global_var_int(): ffi = FFI() _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit