[prev in list] [next in list] [prev in thread] [next in thread]
List: pypy-svn
Subject: [pypy-svn] r73216 - in
From: xoraxax () codespeak ! net
Date: 2010-03-31 15:03:49
Message-ID: 20100331150349.5C47B282BD8 () codespeak ! net
[Download RAW message or body]
Author: xoraxax
Date: Wed Mar 31 17:03:47 2010
New Revision: 73216
Modified:
pypy/branch/cpython-extension/pypy/translator/c/node.py
pypy/branch/cpython-extension/pypy/translator/c/test/test_genc.py
Log:
Clean up hack a bit and write a test for it.
Modified: pypy/branch/cpython-extension/pypy/translator/c/node.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/c/node.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/c/node.py Wed Mar 31 17:03:47 2010
@@ -924,12 +924,10 @@
else:
assert fnobj.external == 'CPython'
return [CExternalFunctionCodeGenerator(fnobj, db)]
+ elif hasattr(fnobj._callable, "c_name"):
+ return []
else:
- # HACK! sandboxing missing here
- graph = db.translator.annotator.bookkeeper.getdesc(fnobj._callable).getuniquegraph()
- exception_policy = getattr(fnobj, 'exception_policy', None)
- return [FunctionCodeGenerator(graph, db, exception_policy, functionname)]
- #raise ValueError, "don't know how to generate code for %r" % (fnobj,)
+ raise ValueError, "don't know how to generate code for %r" % (fnobj,)
class ExtType_OpaqueNode(ContainerNode):
nodekind = 'rpyopaque'
Modified: pypy/branch/cpython-extension/pypy/translator/c/test/test_genc.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/c/test/test_genc.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/c/test/test_genc.py Wed Mar 31 17:03:47 2010
@@ -429,3 +429,53 @@
t.view()
assert ' BarStruct ' in t.driver.cbuilder.c_source_filename.read()
+def test_recursive_llhelper():
+ from pypy.rpython.annlowlevel import llhelper
+ from pypy.rpython.lltypesystem import lltype
+ from pypy.rlib.objectmodel import specialize
+ from pypy.rlib.nonconst import NonConstant
+ FT = lltype.ForwardReference()
+ FTPTR = lltype.Ptr(FT)
+ STRUCT = lltype.Struct("foo", ("bar", FTPTR))
+ FT.become(lltype.FuncType([lltype.Ptr(STRUCT)], lltype.Signed))
+
+ class A:
+ def __init__(self, func, name):
+ self.func = func
+ self.name = name
+ def _freeze_(self):
+ return True
+ @specialize.memo()
+ def make_func(self):
+ f = getattr(self, "_f", None)
+ if f is not None:
+ return f
+ f = lambda *args: self.func(*args)
+ f.c_name = self.name
+ f.relax_sig_check = True
+ f.__name__ = "WRAP%s" % (self.name, )
+ self._f = f
+ return f
+ def get_llhelper(self):
+ return llhelper(FTPTR, self.make_func())
+ def f(s):
+ if s.bar == t.bar:
+ lltype.free(s, flavor="raw")
+ return 1
+ lltype.free(s, flavor="raw")
+ return 0
+ def g(x):
+ return 42
+ def chooser(x):
+ s = lltype.malloc(STRUCT, flavor="raw")
+ if x:
+ s.bar = llhelper(FTPTR, a_f.make_func())
+ else:
+ s.bar = llhelper(FTPTR, a_g.make_func())
+ return f(s)
+ a_f = A(f, "f")
+ a_g = A(g, "g")
+ t = lltype.malloc(STRUCT, flavor="raw")
+ t.bar = llhelper(FTPTR, a_f.make_func())
+ fn = compile(chooser, [bool])
+ assert fn(True)
_______________________________________________
pypy-svn mailing list
pypy-svn@codespeak.net
http://codespeak.net/mailman/listinfo/pypy-svn
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic