本文整理汇总了Python中pypy.rpython.lltypesystem.lltype.cast_ptr_to_int函数的典型用法代码示例。如果您正苦于以下问题:Python cast_ptr_to_int函数的具体用法?Python cast_ptr_to_int怎么用?Python cast_ptr_to_int使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cast_ptr_to_int函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: f
def f():
s1 = lltype.malloc(S)
llop.keepalive(lltype.Void, s1)
s2 = lltype.malloc(S)
llop.keepalive(lltype.Void, s1)
llop.keepalive(lltype.Void, s2)
return lltype.cast_ptr_to_int(s1) + lltype.cast_ptr_to_int(s2)
示例2: cast_whatever_to_int
def cast_whatever_to_int(T, value):
if isinstance(T, lltype.Ptr):
return lltype.cast_ptr_to_int(value)
elif T is llmemory.Address:
return llmemory.cast_adr_to_int(value)
else:
return lltype.cast_primitive(lltype.Signed, value)
示例3: ll_unboxed_isinstance_const
def ll_unboxed_isinstance_const(obj, minid, maxid, answer_if_unboxed):
if not obj:
return False
if lltype.cast_ptr_to_int(obj) & 1:
return answer_if_unboxed
else:
return ll_issubclass_const(obj.typeptr, minid, maxid)
示例4: ll_str
def ll_str(self, i):
if lltype.cast_ptr_to_int(i) & 1:
from pypy.rpython.lltypesystem import rstr
from pypy.rpython.rint import signed_repr
llstr1 = signed_repr.ll_str(ll_unboxed_to_int(i))
return rstr.ll_strconcat(rstr.unboxed_instance_str_prefix,
rstr.ll_strconcat(llstr1,
rstr.unboxed_instance_str_suffix))
else:
return InstanceRepr.ll_str(self, i)
示例5: ll_inst_hash
def ll_inst_hash(ins):
if not ins:
return 0 # for None
cached = ins.hash_cache
if cached == 0:
# XXX this should ideally be done in a GC-dependent way: we only
# need a hash_cache for moving GCs, and we only need the '~' to
# avoid Boehm keeping the object alive if the value is passed
# around
cached = ins.hash_cache = ~cast_ptr_to_int(ins)
return cached
示例6: tigetstr_llimpl
def tigetstr_llimpl(cap):
check_setup_invoked()
ll_cap = rffi.str2charp(cap)
try:
ll_res = c_tigetstr(ll_cap)
num = lltype.cast_ptr_to_int(ll_res)
if num == 0 or num == -1:
raise interp_curses.TermError()
res = rffi.charp2str(ll_res)
return res
finally:
rffi.free_charp(ll_cap)
示例7: _generalcast
def _generalcast(T, value):
if isinstance(T, lltype.Ptr):
return lltype.cast_pointer(T, value)
elif T == llmemory.Address:
return llmemory.cast_ptr_to_adr(value)
else:
T1 = lltype.typeOf(value)
if T1 is llmemory.Address:
value = llmemory.cast_adr_to_int(value)
elif isinstance(T1, lltype.Ptr):
value = lltype.cast_ptr_to_int(value)
else:
value = value
return lltype.cast_primitive(T, value)
示例8: add_case
def add_case(block, exitcase):
block = from_opaque_object(block)
exitcase = from_opaque_object(exitcase)
assert isinstance(exitcase, flowmodel.Constant)
assert isinstance(block.exitswitch, flowmodel.Variable)
case_link = flowmodel.Link([], None)
exitvalue = exitcase.value
if isinstance(lltype.typeOf(exitvalue), lltype.Ptr):
# XXX hack!
exitvalue = lltype.cast_ptr_to_int(exitvalue)
case_link.exitcase = exitvalue
case_link.llexitcase = exitvalue
if block.exits and block.exits[-1].exitcase == 'default':
exits = block.exits[:-1] + (case_link,) + block.exits[-1:]
else:
exits = block.exits + (case_link,)
block.recloseblock(*exits)
return to_opaque_object(case_link)
示例9: _generalcast
def _generalcast(T, value):
if lltype.typeOf(value) == T:
return value
elif isinstance(T, lltype.Ptr):
return lltype.cast_pointer(T, value)
elif T == llmemory.Address:
return llmemory.cast_ptr_to_adr(value)
elif isinstance(T, ootype.StaticMethod):
fn = value._obj
return ootype._static_meth(T, graph=fn.graph, _callable=fn._callable)
else:
T1 = lltype.typeOf(value)
if T1 is llmemory.Address:
value = llmemory.cast_adr_to_int(value)
elif isinstance(T1, lltype.Ptr):
value = lltype.cast_ptr_to_int(value)
else:
value = value
return lltype.cast_primitive(T, value)
示例10: ll_str
def ll_str(self, i): # doesn't work for non-gc classes!
from pypy.rpython.lltypesystem import rstr
from pypy.rpython.lltypesystem.ll_str import ll_int2hex
from pypy.rlib.rarithmetic import r_uint
if not i:
return rstr.null_str
instance = cast_pointer(OBJECTPTR, i)
uid = r_uint(cast_ptr_to_int(i))
nameLen = len(instance.typeptr.name)
nameString = rstr.mallocstr(nameLen-1)
i = 0
while i < nameLen - 1:
nameString.chars[i] = instance.typeptr.name[i]
i += 1
res = rstr.instance_str_prefix
res = rstr.ll_strconcat(res, nameString)
res = rstr.ll_strconcat(res, rstr.instance_str_infix)
res = rstr.ll_strconcat(res, ll_int2hex(uid, False))
res = rstr.ll_strconcat(res, rstr.instance_str_suffix)
return res
示例11: gc_malloc_fnaddr
def gc_malloc_fnaddr():
"""Returns the address of the Boehm 'malloc' function."""
if we_are_translated():
gc_malloc_ptr = llhelper(GC_MALLOC, gc_malloc)
return lltype.cast_ptr_to_int(gc_malloc_ptr)
else:
# <pedronis> don't do this at home
import threading
if not isinstance(threading.currentThread(), threading._MainThread):
import py
py.test.skip("must run in the main thread")
try:
from ctypes import cast, c_void_p, util
path = util.find_library('gc')
if path is None:
raise ImportError("Boehm (libgc) not found")
boehmlib = ctypes.cdll.LoadLibrary(path)
except ImportError, e:
import py
py.test.skip(str(e))
else:
示例12: test_gcref_casts
def test_gcref_casts(self):
p0 = ctypes.c_void_p(0)
ref0 = ctypes2lltype(llmemory.GCREF, p0)
assert lltype.cast_ptr_to_int(ref0) == 0
assert llmemory.cast_ptr_to_adr(ref0) == llmemory.NULL
NODE = lltype.GcStruct('NODE')
assert lltype.cast_opaque_ptr(lltype.Ptr(NODE), ref0) == lltype.nullptr(NODE)
node = lltype.malloc(NODE)
ref1 = lltype.cast_opaque_ptr(llmemory.GCREF, node)
intval = rffi.cast(lltype.Signed, node)
intval1 = rffi.cast(lltype.Signed, ref1)
assert intval == intval1
ref2 = ctypes2lltype(llmemory.GCREF, intval1)
assert lltype.cast_opaque_ptr(lltype.Ptr(NODE), ref2) == node
示例13: g
def g(p):
return lltype.cast_ptr_to_int(p)
示例14: f
def f(p):
n = lltype.cast_ptr_to_int(p)
return n
示例15: f
def f():
p = lltype.malloc(GCS1)
return lltype.cast_ptr_to_int(p)