Author: Armin Rigo <ar...@tunes.org> Branch: cffi-1.0 Changeset: r77198:4180e31602c9 Date: 2015-05-08 10:24 +0200 http://bitbucket.org/pypy/pypy/changeset/4180e31602c9/
Log: non-integer constants diff --git a/pypy/module/_cffi_backend/lib_obj.py b/pypy/module/_cffi_backend/lib_obj.py --- a/pypy/module/_cffi_backend/lib_obj.py +++ b/pypy/module/_cffi_backend/lib_obj.py @@ -1,5 +1,5 @@ from rpython.rlib import jit -from rpython.rtyper.lltypesystem import rffi +from rpython.rtyper.lltypesystem import lltype, rffi from pypy.interpreter.error import oefmt from pypy.interpreter.baseobjspace import W_Root @@ -43,20 +43,16 @@ # A function: in the PyPy version, these are all equivalent # and 'g->address' is a pointer to a function of exactly the # C type specified - type_index = getarg(g.c_type_op) - opcodes = self.ctx.c_types - w_ct = realize_c_type.realize_c_type_or_func(self.ffi, opcodes, - type_index) + w_ct = realize_c_type.realize_c_type_or_func( + self.ffi, self.ctx.c_types, getarg(g.c_type_op)) w_ct = realize_c_type.unwrap_fn_as_fnptr(w_ct) ptr = rffi.cast(rffi.CCHARP, g.c_address) w_result = W_CData(space, ptr, w_ct) # elif op == cffi_opcode.OP_GLOBAL_VAR: # A global variable of the exact type specified here - type_index = getarg(g.c_type_op) - opcodes = self.ctx.c_types - w_ct = realize_c_type.realize_c_type(self.ffi, opcodes, - type_index) + w_ct = realize_c_type.realize_c_type( + self.ffi, self.ctx.c_types, getarg(g.c_type_op)) g_size = rffi.getintfield(g, 'c_size') if g_size != w_ct.size and g_size != 0 and w_ct.size > 0: raise oefmt(self.ffi.w_FFIError, @@ -72,6 +68,18 @@ # is obtained by calling the function at g->address w_result = realize_c_type.realize_global_int(self.ffi, g) # + elif op == cffi_opcode.OP_CONSTANT: + # A constant which is not of integer type + w_ct = realize_c_type.realize_c_type( + self.ffi, self.ctx.c_types, getarg(g.c_type_op)) + fetch_funcptr = rffi.cast( + realize_c_type.FUNCPTR_FETCH_CHARP, + g.c_address) + assert w_ct.size > 0 + with lltype.scoped_alloc(rffi.CCHARP.TO, w_ct.size) as ptr: + fetch_funcptr(ptr) + w_result = w_ct.convert_to_object(ptr) + # else: raise oefmt(space.w_NotImplementedError, "in lib_build_attr: op=%d", op) diff --git a/pypy/module/_cffi_backend/realize_c_type.py b/pypy/module/_cffi_backend/realize_c_type.py --- a/pypy/module/_cffi_backend/realize_c_type.py +++ b/pypy/module/_cffi_backend/realize_c_type.py @@ -87,6 +87,7 @@ return newtype._new_array_type(ffi.space, w_ctitemptr, length) +FUNCPTR_FETCH_CHARP = lltype.Ptr(lltype.FuncType([rffi.CCHARP], lltype.Void)) FUNCPTR_FETCH_LONGLONG = lltype.Ptr(lltype.FuncType([rffi.ULONGLONGP], rffi.INT)) def realize_global_int(ffi, g): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit