Author: Armin Rigo <[email protected]>
Branch:
Changeset: r77638:beece8a05340
Date: 2015-05-28 11:34 +0200
http://bitbucket.org/pypy/pypy/changeset/beece8a05340/
Log: update to cffi/1283fea71028 for issue 198.
fix another reftracker issue (before translation only)
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
@@ -131,9 +131,10 @@
g.c_address)
assert fetch_funcptr
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)
+ ptr = lltype.malloc(rffi.CCHARP.TO, w_ct.size, flavor='raw')
+ self.ffi._finalizer.free_mems.append(ptr)
+ fetch_funcptr(ptr)
+ w_result = w_ct.convert_to_object(ptr)
#
elif op == cffi_opcode.OP_DLOPEN_FUNC:
# For dlopen(): the function of the given 'name'. We use
diff --git a/pypy/module/_cffi_backend/test/test_recompiler.py
b/pypy/module/_cffi_backend/test/test_recompiler.py
--- a/pypy/module/_cffi_backend/test/test_recompiler.py
+++ b/pypy/module/_cffi_backend/test/test_recompiler.py
@@ -66,6 +66,9 @@
""")
ffiobject = space.getitem(w_res, space.wrap(0))
ffiobject._test_recompiler_source_ffi = ffi
+ if not hasattr(space, '_cleanup_ffi'):
+ space._cleanup_ffi = []
+ space._cleanup_ffi.append(ffiobject)
return w_res
@@ -84,6 +87,10 @@
""")
def teardown_method(self, meth):
+ if hasattr(self.space, '_cleanup_ffi'):
+ for ffi in self.space._cleanup_ffi:
+ del ffi.cached_types # try to prevent cycles
+ del self.space._cleanup_ffi
self.space.appexec([self._w_modules], """(old_modules):
import sys
for key in sys.modules.keys():
@@ -799,3 +806,19 @@
assert addr(0xABC05) == 47
assert isinstance(addr, ffi.CData)
assert ffi.typeof(addr) == ffi.typeof("long(*)(long)")
+
+ def test_issue198(self):
+ ffi, lib = self.prepare("""
+ typedef struct{...;} opaque_t;
+ const opaque_t CONSTANT;
+ int toint(opaque_t);
+ """, 'test_issue198', """
+ typedef int opaque_t;
+ #define CONSTANT ((opaque_t)42)
+ static int toint(opaque_t o) { return o; }
+ """)
+ def random_stuff():
+ pass
+ assert lib.toint(lib.CONSTANT) == 42
+ random_stuff()
+ assert lib.toint(lib.CONSTANT) == 42
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit