[pypy-svn] r61025 - in pypy/branch/oo-jit/pypy/rpython/lltypesystem: . test
fijal at codespeak.net
fijal at codespeak.net
Fri Jan 16 09:54:31 CET 2009
Author: fijal
Date: Fri Jan 16 09:54:30 2009
New Revision: 61025
Modified:
pypy/branch/oo-jit/pypy/rpython/lltypesystem/ll2ctypes.py
pypy/branch/oo-jit/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
Log:
Since we're keeping all the callbacks alive forever, let's cache
them. This makes lltype2ctypes return the same number for the same
pointer
Modified: pypy/branch/oo-jit/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/branch/oo-jit/pypy/rpython/lltypesystem/ll2ctypes.py (original)
+++ pypy/branch/oo-jit/pypy/rpython/lltypesystem/ll2ctypes.py Fri Jan 16 09:54:30 2009
@@ -433,7 +433,8 @@
# ctypes does not keep callback arguments alive. So we do. Forever
# we need to think deeper how to approach this problem
# additionally, this adds mess to __del__ "semantics"
-_all_callbacks = []
+_all_callbacks = {}
+_all_callback_results = []
_callback2obj = {}
# this is just another hack that passes around references to applevel types
@@ -479,6 +480,8 @@
return new_opaque_object(llobj)
container = llobj._obj
if isinstance(T.TO, lltype.FuncType):
+ if llobj._obj in _all_callbacks:
+ return _all_callbacks[llobj._obj]
v1voidlist = [(i, getattr(container, '_void' + str(i), None))
for i in range(len(T.TO.ARGS))
if T.TO.ARGS[i] is lltype.Void]
@@ -505,7 +508,7 @@
return None
res = lltype2ctypes(llres)
if isinstance(T.TO.RESULT, lltype.Ptr):
- _all_callbacks.append(res)
+ _all_callbacks_results.append(res)
res = ctypes.cast(res, ctypes.c_void_p).value
if res is None:
return 0
@@ -530,8 +533,8 @@
else:
ctypes_func_type = get_ctypes_type(T)
res = ctypes_func_type(callback)
- _all_callbacks.append(res)
_callback2obj[ctypes.cast(res, ctypes.c_void_p).value] = container
+ _all_callbacks[llobj._obj] = res
return res
if container._storage is None:
Modified: pypy/branch/oo-jit/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
==============================================================================
--- pypy/branch/oo-jit/pypy/rpython/lltypesystem/test/test_ll2ctypes.py (original)
+++ pypy/branch/oo-jit/pypy/rpython/lltypesystem/test/test_ll2ctypes.py Fri Jan 16 09:54:30 2009
@@ -364,7 +364,9 @@
return n+1
FUNCTYPE = lltype.FuncType([lltype.Signed], lltype.Signed)
- cdummy = lltype2ctypes(llhelper(lltype.Ptr(FUNCTYPE), dummy))
+ helper = llhelper(lltype.Ptr(FUNCTYPE), dummy)
+ cdummy = lltype2ctypes(helper)
+ cdummy2 = lltype2ctypes(helper)
assert isinstance(cdummy,
ctypes.CFUNCTYPE(ctypes.c_long, ctypes.c_long))
res = cdummy(41)
More information about the Pypy-commit
mailing list