[pypy-svn] r50318 - in pypy/dist/pypy/rpython/lltypesystem: . test
arigo at codespeak.net
arigo at codespeak.net
Fri Jan 4 17:51:37 CET 2008
Author: arigo
Date: Fri Jan 4 17:51:37 2008
New Revision: 50318
Modified:
pypy/dist/pypy/rpython/lltypesystem/rffi.py
pypy/dist/pypy/rpython/lltypesystem/test/test_rffi.py
Log:
Tests and fix for a bug found by test_ll_thread.py.
Modified: pypy/dist/pypy/rpython/lltypesystem/rffi.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rffi.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/rffi.py Fri Jan 4 17:51:37 2008
@@ -31,12 +31,23 @@
def lltype(self):
return self.TP
-def isfunctype(TP):
+def _isfunctype(TP):
""" Evil hack to get rid of flow objspace inability
to accept .TO when TP is not a pointer
"""
return isinstance(TP, lltype.Ptr) and isinstance(TP.TO, lltype.FuncType)
-isfunctype._annspecialcase_ = 'specialize:memo'
+_isfunctype._annspecialcase_ = 'specialize:memo'
+
+def _isllptr(p):
+ """ Second evil hack to detect if 'p' is a low-level pointer or not """
+ return isinstance(p, lltype._ptr)
+class _IsLLPtrEntry(ExtRegistryEntry):
+ _about_ = _isllptr
+ def compute_result_annotation(self, s_p):
+ result = isinstance(s_p, annmodel.SomePtr)
+ return self.bookkeeper.immutablevalue(result)
+ def specialize_call(self, hop):
+ return hop.inputconst(lltype.Bool, hop.s_result.const)
def llexternal(name, args, result, _callable=None,
compilation_info=ExternalCompilationInfo(),
@@ -104,7 +115,7 @@
# XXX leaks if a str2charp() fails with MemoryError
# and was not the first in this function
freeme = arg
- elif isfunctype(TARGET):
+ elif _isfunctype(TARGET) and not _isllptr(arg):
# XXX pass additional arguments
if invoke_around_handlers:
arg = llhelper(TARGET, _make_wrapper_for(TARGET, arg,
Modified: pypy/dist/pypy/rpython/lltypesystem/test/test_rffi.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/test/test_rffi.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/test/test_rffi.py Fri Jan 4 17:51:37 2008
@@ -389,6 +389,18 @@
fn = self.compile(f, [int])
assert fn(13) == -1
+ def test_callback_already_llptr(self):
+ eating_callback = self.eating_callback()
+ def g(i):
+ return i + 3
+ G = lltype.Ptr(lltype.FuncType([lltype.Signed], lltype.Signed))
+
+ def f():
+ return eating_callback(3, llhelper(G, g))
+
+ fn = self.compile(f, [])
+ assert fn() == 6
+
class TestRffiInternals:
def test_struct_create(self):
X = CStruct('xx', ('one', INT))
More information about the Pypy-commit
mailing list