本文整理汇总了Python中pypy.rpython.annlowlevel.llhelper函数的典型用法代码示例。如果您正苦于以下问题:Python llhelper函数的具体用法?Python llhelper怎么用?Python llhelper使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了llhelper函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_call_stubs
def test_call_stubs():
c0 = GcCache(False)
ARGS = [lltype.Char, lltype.Signed]
RES = lltype.Char
descr1 = get_call_descr(c0, ARGS, RES)
def f(a, b):
return 'c'
call_stub = descr1.call_stub
fnptr = llhelper(lltype.Ptr(lltype.FuncType(ARGS, RES)), f)
res = call_stub(rffi.cast(lltype.Signed, fnptr), [1, 2], None, None)
assert res == ord('c')
ARRAY = lltype.GcArray(lltype.Signed)
ARGS = [lltype.Float, lltype.Ptr(ARRAY)]
RES = lltype.Float
def f(a, b):
return float(b[0]) + a
fnptr = llhelper(lltype.Ptr(lltype.FuncType(ARGS, RES)), f)
descr2 = get_call_descr(c0, ARGS, RES)
a = lltype.malloc(ARRAY, 3)
opaquea = lltype.cast_opaque_ptr(llmemory.GCREF, a)
a[0] = 1
res = descr2.call_stub(rffi.cast(lltype.Signed, fnptr),
[], [opaquea], [longlong.getfloatstorage(3.5)])
assert longlong.getrealfloat(res) == 4.5
示例2: chooser
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)
示例3: h
def h(x, y, z):
s = malloc(S)
s.x = x
s.y = y
fptr = llhelper(F, f)
gptr = llhelper(G, g)
assert typeOf(fptr) == F
return fptr(s, z)+fptr(s, z*2)+gptr(s)
示例4: setup_buffer_buffer_procs
def setup_buffer_buffer_procs(space, pto):
c_buf = lltype.malloc(PyBufferProcs, flavor='raw', zero=True)
lltype.render_immortal(c_buf)
c_buf.c_bf_getsegcount = llhelper(str_segcount.api_func.functype,
str_segcount.api_func.get_wrapper(space))
c_buf.c_bf_getreadbuffer = llhelper(buf_getreadbuffer.api_func.functype,
buf_getreadbuffer.api_func.get_wrapper(space))
pto.c_tp_as_buffer = c_buf
示例5: get_on_leave_jitted_int
def get_on_leave_jitted_int(self, save_exception,
default_to_memoryerror=False):
if default_to_memoryerror:
f = llhelper(self._ON_JIT_LEAVE_FUNC, self.on_leave_jitted_memoryerr)
elif save_exception:
f = llhelper(self._ON_JIT_LEAVE_FUNC, self.on_leave_jitted_save_exc)
else:
f = llhelper(self._ON_JIT_LEAVE_FUNC, self.on_leave_jitted_noexc)
return rffi.cast(lltype.Signed, f)
示例6: type_attach
def type_attach(space, py_obj, w_type):
"""
Fills a newly allocated PyTypeObject from an existing type.
"""
from pypy.module.cpyext.object import PyObject_Del
assert isinstance(w_type, W_TypeObject)
pto = rffi.cast(PyTypeObjectPtr, py_obj)
typedescr = get_typedescr(w_type.instancetypedef)
# dealloc
pto.c_tp_dealloc = typedescr.get_dealloc(space)
# buffer protocol
if space.is_w(w_type, space.w_str):
setup_string_buffer_procs(space, pto)
if space.is_w(w_type, space.gettypefor(Buffer)):
setup_buffer_buffer_procs(space, pto)
pto.c_tp_free = llhelper(PyObject_Del.api_func.functype,
PyObject_Del.api_func.get_wrapper(space))
pto.c_tp_alloc = llhelper(PyType_GenericAlloc.api_func.functype,
PyType_GenericAlloc.api_func.get_wrapper(space))
if pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE:
w_typename = space.getattr(w_type, space.wrap('__name__'))
heaptype = rffi.cast(PyHeapTypeObject, pto)
heaptype.c_ht_name = make_ref(space, w_typename)
from pypy.module.cpyext.stringobject import PyString_AsString
pto.c_tp_name = PyString_AsString(space, heaptype.c_ht_name)
else:
pto.c_tp_name = rffi.str2charp(w_type.getname(space))
pto.c_tp_basicsize = -1 # hopefully this makes malloc bail out
pto.c_tp_itemsize = 0
# uninitialized fields:
# c_tp_print, c_tp_getattr, c_tp_setattr
# XXX implement
# c_tp_compare and the following fields (see http://docs.python.org/c-api/typeobj.html )
w_base = best_base(space, w_type.bases_w)
pto.c_tp_base = rffi.cast(PyTypeObjectPtr, make_ref(space, w_base))
finish_type_1(space, pto)
finish_type_2(space, pto, w_type)
pto.c_tp_basicsize = rffi.sizeof(typedescr.basestruct)
if pto.c_tp_base:
if pto.c_tp_base.c_tp_basicsize > pto.c_tp_basicsize:
pto.c_tp_basicsize = pto.c_tp_base.c_tp_basicsize
# will be filled later on with the correct value
# may not be 0
if space.is_w(w_type, space.w_object):
pto.c_tp_new = rffi.cast(newfunc, 1)
update_all_slots(space, w_type, pto)
pto.c_tp_flags |= Py_TPFLAGS_READY
return pto
示例7: get_dealloc
def get_dealloc(self, space):
if tp_dealloc:
return llhelper(
tp_dealloc.api_func.functype,
tp_dealloc.api_func.get_wrapper(space))
else:
from pypy.module.cpyext.typeobject import subtype_dealloc
return llhelper(
subtype_dealloc.api_func.functype,
subtype_dealloc.api_func.get_wrapper(space))
示例8: setup_string_buffer_procs
def setup_string_buffer_procs(space, pto):
c_buf = lltype.malloc(PyBufferProcs, flavor='raw', zero=True)
c_buf.c_bf_getsegcount = llhelper(str_segcount.api_func.functype,
str_segcount.api_func.get_wrapper(space))
c_buf.c_bf_getreadbuffer = llhelper(str_getreadbuffer.api_func.functype,
str_getreadbuffer.api_func.get_wrapper(space))
c_buf.c_bf_getcharbuffer = llhelper(str_getcharbuffer.api_func.functype,
str_getcharbuffer.api_func.get_wrapper(space))
pto.c_tp_as_buffer = c_buf
pto.c_tp_flags |= Py_TPFLAGS_HAVE_GETCHARBUFFER
示例9: get_tp_function
def get_tp_function(space, typedef):
@cpython_api([], lltype.Signed, error=-1, external=False)
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))
示例10: make_finalizer_funcptr_for_type
def make_finalizer_funcptr_for_type(self, TYPE):
from pypy.rpython.memory.gctransform.support import get_rtti, type_contains_pyobjs
rtti = get_rtti(TYPE)
if rtti is not None and hasattr(rtti._obj, "destructor_funcptr"):
destrptr = rtti._obj.destructor_funcptr
DESTR_ARG = lltype.typeOf(destrptr).TO.ARGS[0]
destrgraph = destrptr._obj.graph
else:
return None, False
assert not type_contains_pyobjs(TYPE), "not implemented"
t = self.llinterp.typer.annotator.translator
light = not FinalizerAnalyzer(t).analyze_light_finalizer(destrgraph)
def ll_finalizer(addr, dummy):
assert dummy == llmemory.NULL
try:
v = llmemory.cast_adr_to_ptr(addr, DESTR_ARG)
self.llinterp.eval_graph(destrgraph, [v], recursive=True)
except llinterp.LLException:
raise RuntimeError("a finalizer raised an exception, shouldn't happen")
return llmemory.NULL
return llhelper(gctypelayout.GCData.FINALIZER_OR_CT, ll_finalizer), light
示例11: test_qsort
def test_qsort(self):
CMPFUNC = lltype.FuncType([rffi.VOIDP, rffi.VOIDP], rffi.INT)
qsort = rffi.llexternal('qsort', [rffi.VOIDP,
rffi.SIZE_T,
rffi.SIZE_T,
lltype.Ptr(CMPFUNC)],
lltype.Void)
lst = [23, 43, 24, 324, 242, 34, 78, 5, 3, 10]
A = lltype.Array(lltype.Signed, hints={'nolength': True})
a = lltype.malloc(A, 10, flavor='raw')
for i in range(10):
a[i] = lst[i]
SIGNEDPTR = lltype.Ptr(lltype.FixedSizeArray(lltype.Signed, 1))
def my_compar(p1, p2):
p1 = rffi.cast(SIGNEDPTR, p1)
p2 = rffi.cast(SIGNEDPTR, p2)
print 'my_compar:', p1[0], p2[0]
return rffi.cast(rffi.INT, cmp(p1[0], p2[0]))
qsort(rffi.cast(rffi.VOIDP, a),
rffi.cast(rffi.SIZE_T, 10),
rffi.cast(rffi.SIZE_T, llmemory.sizeof(lltype.Signed)),
llhelper(lltype.Ptr(CMPFUNC), my_compar))
for i in range(10):
print a[i],
print
lst.sort()
for i in range(10):
assert a[i] == lst[i]
lltype.free(a, flavor='raw')
assert not ALLOCATED # detects memory leaks in the test
示例12: define_custom_trace
def define_custom_trace(cls):
from pypy.rpython.annlowlevel import llhelper
from pypy.rpython.lltypesystem import llmemory
#
S = lltype.GcStruct('S', ('x', llmemory.Address), rtti=True)
offset_of_x = llmemory.offsetof(S, 'x')
def customtrace(obj, prev):
if not prev:
return obj + offset_of_x
else:
return llmemory.NULL
CUSTOMTRACEFUNC = lltype.FuncType([llmemory.Address, llmemory.Address],
llmemory.Address)
customtraceptr = llhelper(lltype.Ptr(CUSTOMTRACEFUNC), customtrace)
lltype.attachRuntimeTypeInfo(S, customtraceptr=customtraceptr)
#
def setup():
s = lltype.nullptr(S)
for i in range(10000):
t = lltype.malloc(S)
t.x = llmemory.cast_ptr_to_adr(s)
s = t
return s
def measure_length(s):
res = 0
while s:
res += 1
s = llmemory.cast_adr_to_ptr(s.x, lltype.Ptr(S))
return res
def f(n):
s1 = setup()
llop.gc__collect(lltype.Void)
return measure_length(s1)
return f
示例13: get_shadowstackref
def get_shadowstackref(gctransformer):
if hasattr(gctransformer, '_SHADOWSTACKREF'):
return gctransformer._SHADOWSTACKREF
SHADOWSTACKREFPTR = lltype.Ptr(lltype.GcForwardReference())
SHADOWSTACKREF = lltype.GcStruct('ShadowStackRef',
('base', llmemory.Address),
('top', llmemory.Address),
('context', llmemory.Address),
#('fullstack', lltype.Bool),
rtti=True)
SHADOWSTACKREFPTR.TO.become(SHADOWSTACKREF)
gc = gctransformer.gcdata.gc
root_iterator = get_root_iterator(gctransformer)
def customtrace(obj, prev):
obj = llmemory.cast_adr_to_ptr(obj, SHADOWSTACKREFPTR)
if not prev:
root_iterator.setcontext(obj.context)
prev = obj.top
return root_iterator.nextleft(gc, obj.base, prev)
CUSTOMTRACEFUNC = lltype.FuncType([llmemory.Address, llmemory.Address],
llmemory.Address)
customtraceptr = llhelper(lltype.Ptr(CUSTOMTRACEFUNC), customtrace)
lltype.attachRuntimeTypeInfo(SHADOWSTACKREF, customtraceptr=customtraceptr)
gctransformer._SHADOWSTACKREF = SHADOWSTACKREF
return SHADOWSTACKREF
示例14: _new_callback
def _new_callback():
# Here, we just closed the stack. Get the stack anchor, store
# it in the gcrootfinder.suspstack.anchor, and create a new
# stacklet with stacklet_new(). If this call fails, then we
# are just returning NULL.
_stack_just_closed()
return _c.new(gcrootfinder.thrd, llhelper(_c.run_fn, _new_runfn),
llmemory.NULL)
示例15: helper_func
def helper_func(self, FUNCPTR, func):
if not self.cpu.translate_support_code:
return llhelper(FUNCPTR, func)
FUNC = get_functype(FUNCPTR)
args_s = [annmodel.lltype_to_annotation(ARG) for ARG in FUNC.ARGS]
s_result = annmodel.lltype_to_annotation(FUNC.RESULT)
graph = self.annhelper.getgraph(func, args_s, s_result)
return self.annhelper.graph2delayed(graph, FUNC)