pypy/module/cpyext/test/test_translate.py::test_llhelper
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7ffa91d55190>
def test_llhelper(monkeypatch):
"""Show how to get function pointers used in type slots"""
FT = lltype.FuncType([], lltype.Signed)
FTPTR = lltype.Ptr(FT)
def make_wrapper(self, space):
def wrapper():
return self.callable(space)
return wrapper
monkeypatch.setattr(pypy.module.cpyext.api.ApiFunction, '_make_wrapper', make_wrapper)
@specialize.memo()
def get_tp_function(space, typedef):
@slot_function([], lltype.Signed, error=-1)
def slot_tp_function(space):
return typedef.value
api_func = slot_tp_function.api_func
return lambda: llhelper(api_func.functype, api_func.get_wrapper(space))
class Space:
_cache = {}
@specialize.memo()
def fromcache(self, key):
try:
return self._cache[key]
except KeyError:
result = self._cache[key] = self.build(key)
return result
def _freeze_(self):
return True
class TypeDef:
def __init__(self, value):
self.value = value
def _freeze_(self):
return True
class W_Type:
def __init__(self, typedef):
self.instancetypedef = typedef
def _freeze(self):
try:
del self.funcptr
except AttributeError:
pass
return False
w_type1 = W_Type(TypeDef(123))
w_type2 = W_Type(TypeDef(456))
space = Space()
def run(x):
if x:
w_type = w_type1
else:
w_type = w_type2
typedef = w_type.instancetypedef
w_type.funcptr = get_tp_function(space, typedef)()
return w_type.funcptr()
> fn = compile(run, [bool])
module/cpyext/test/test_translate.py:68:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../rpython/translator/c/test/test_genc.py:106: in compile
policy=annotatorpolicy, thread=thread, **kwds)
../rpython/translator/interactive.py:25: in __init__
graph = self.context.buildflowgraph(entry_point)
../rpython/translator/translator.py:55: in buildflowgraph
graph = build_flow(func)
../rpython/flowspace/objspace.py:49: in build_flow
ctx.build_flow()
../rpython/flowspace/flowcontext.py:405: in build_flow
self.record_block(block)
../rpython/flowspace/flowcontext.py:413: in record_block
next_offset = self.handle_bytecode(next_offset)
../rpython/flowspace/flowcontext.py:492: in handle_bytecode
offset = getattr(self, methodname)(oparg)
../rpython/flowspace/flowcontext.py:999: in CALL_FUNCTION
self.call_function(oparg)
../rpython/flowspace/flowcontext.py:973: in call_function
self.pushvalue(hlop.eval(self))
../rpython/flowspace/operation.py:675: in eval
return sc(ctx, *args_w)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ = <rpython.flowspace.flowcontext.FlowContext object at 0x7ffa91d55c50>
args = ()
@register_flow_sc(locals)
def sc_locals(_, *args):
raise Exception(
> "A function calling locals() is not RPython. "
"Note that if you're translating code outside the PyPy "
"repository, a likely cause is that py.test's --assert=rewrite "
"mode is getting in the way. You should copy the file "
"pytest.ini from the root of the PyPy repository into your "
"own project.")
E Exception: A function calling locals() is not RPython. Note that if you're translating code outside the PyPy repository, a likely cause is that py.test's --assert=rewrite mode is getting in the way. You should copy the file pytest.ini from the root of the PyPy repository into your own project.
../rpython/flowspace/specialcase.py:36: Exception
(somefailed=True in module/cpyext/test/test_translate.py)
builder: own-linux-x86-64 build #10810
test: pypy/module/cpyext/test/test_translate/py/test_llhelper