本文整理汇总了Python中pypy.rpython.lltypesystem.rffi.ptradd函数的典型用法代码示例。如果您正苦于以下问题:Python ptradd函数的具体用法?Python ptradd怎么用?Python ptradd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ptradd函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _base_do_setfield
def _base_do_setfield(self, gcref, vbox, fielddescr):
ofs, size, ptr, float = self.unpack_fielddescr(fielddescr)
#
if ptr:
assert lltype.typeOf(gcref) is not lltype.Signed, (
"can't handle write barriers for setfield_raw")
ptr = vbox.getref_base()
self.gc_ll_descr.do_write_barrier(gcref, ptr)
# --- start of GC unsafe code (no GC operation!) ---
field = rffi.ptradd(rffi.cast(rffi.CCHARP, gcref), ofs)
field = rffi.cast(rffi.CArrayPtr(lltype.Signed), field)
field[0] = self.cast_gcref_to_int(ptr)
# --- end of GC unsafe code ---
return
#
if float:
fval = vbox.getfloat()
# --- start of GC unsafe code (no GC operation!) ---
field = rffi.ptradd(rffi.cast(rffi.CCHARP, gcref), ofs)
field = rffi.cast(rffi.CArrayPtr(lltype.Float), field)
field[0] = fval
# --- end of GC unsafe code ---
return
#
val = vbox.getint()
for TYPE, itemsize in unroll_basic_sizes:
if size == itemsize:
# --- start of GC unsafe code (no GC operation!) ---
field = rffi.ptradd(rffi.cast(rffi.CCHARP, gcref), ofs)
field = rffi.cast(rffi.CArrayPtr(TYPE), field)
field[0] = rffi.cast(TYPE, val)
# --- end of GC unsafe code ---
return
else:
raise NotImplementedError("size = %d" % size)
开发者ID:enyst,项目名称:plexnet,代码行数:35,代码来源:llmodel.py
示例2: do_setarrayitem_gc
def do_setarrayitem_gc(self, arraybox, indexbox, vbox, arraydescr):
itemindex = indexbox.getint()
gcref = arraybox.getref_base()
ofs, size, ptr, float = self.unpack_arraydescr(arraydescr)
#
if ptr:
vboxptr = vbox.getref_base()
self.gc_ll_descr.do_write_barrier(gcref, vboxptr)
# --- start of GC unsafe code (no GC operation!) ---
items = rffi.ptradd(rffi.cast(rffi.CCHARP, gcref), ofs)
items = rffi.cast(rffi.CArrayPtr(lltype.Signed), items)
items[itemindex] = self.cast_gcref_to_int(vboxptr)
# --- end of GC unsafe code ---
return
#
if float:
fval = vbox.getfloat()
# --- start of GC unsafe code (no GC operation!) ---
items = rffi.ptradd(rffi.cast(rffi.CCHARP, gcref), ofs)
items = rffi.cast(rffi.CArrayPtr(lltype.Float), items)
items[itemindex] = fval
# --- end of GC unsafe code ---
return
#
val = vbox.getint()
for TYPE, itemsize in unroll_basic_sizes:
if size == itemsize:
# --- start of GC unsafe code (no GC operation!) ---
items = rffi.ptradd(rffi.cast(rffi.CCHARP, gcref), ofs)
items = rffi.cast(rffi.CArrayPtr(TYPE), items)
items[itemindex] = rffi.cast(TYPE, val)
# --- end of GC unsafe code ---
return
else:
raise NotImplementedError("size = %d" % size)
开发者ID:enyst,项目名称:plexnet,代码行数:35,代码来源:llmodel.py
示例3: array_getitem
def array_getitem(ffitype, width, addr, index, offset):
for TYPE, ffitype2 in clibffi.ffitype_map:
if ffitype is ffitype2:
addr = rffi.ptradd(addr, index * width)
addr = rffi.ptradd(addr, offset)
return rffi.cast(rffi.CArrayPtr(TYPE), addr)[0]
assert False
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:libffi.py
示例4: get_indices
def get_indices(w_start, w_stop, w_step, length):
w_slice = space.newslice(w_start, w_stop, w_step)
values = lltype.malloc(Py_ssize_tP.TO, 3, flavor='raw')
res = api.PySlice_GetIndices(w_slice, 100, values,
rffi.ptradd(values, 1),
rffi.ptradd(values, 2))
assert res == 0
rv = values[0], values[1], values[2]
lltype.free(values, flavor='raw')
return rv
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:11,代码来源:test_sliceobject.py
示例5: set_pixel
def set_pixel(image, x, y, pixel):
"""Return the pixel value at (x, y)
NOTE: The surface must be locked before calling this!
"""
bpp = rffi.getintfield(image.c_format, 'c_BytesPerPixel')
pitch = rffi.getintfield(image, 'c_pitch')
# Here p is the address to the pixel we want to retrieve
p = rffi.ptradd(image.c_pixels, y * pitch + x * bpp)
if bpp == 1:
p[0] = rffi.cast(rffi.UCHAR,pixel)
elif bpp == 2:
p = rffi.cast(RSDL.Uint16P, p)
p[0] = rffi.cast(RSDL.Uint16,pixel)
elif bpp == 3:
if RSDL.BYTEORDER == RSDL.BIG_ENDIAN:
p[0] = rffi.cast(rffi.UCHAR,(pixel >> 16) & 0xFF)
p[1] = rffi.cast(rffi.UCHAR,(pixel >> 8 ) & 0xFF)
p[2] = rffi.cast(rffi.UCHAR,pixel & 0xFF)
else:
p[0] = rffi.cast(rffi.UCHAR,pixel & 0xFF)
p[1] = rffi.cast(rffi.UCHAR,(pixel >> 8 ) & 0xFF)
p[2] = rffi.cast(rffi.UCHAR,(pixel >> 16) & 0xFF)
elif bpp == 4:
p = rffi.cast(RSDL.Uint32P, p)
p[0] = rffi.cast(RSDL.Uint32, pixel)
else:
raise ValueError("bad BytesPerPixel")
开发者ID:ParitoshThapliyal59,项目名称:pypy,代码行数:27,代码来源:RSDL_helper.py
示例6: get_pixel
def get_pixel(image, x, y):
"""Return the pixel value at (x, y)
NOTE: The surface must be locked before calling this!
"""
bpp = rffi.getintfield(image.c_format, 'c_BytesPerPixel')
pitch = rffi.getintfield(image, 'c_pitch')
# Here p is the address to the pixel we want to retrieve
p = rffi.ptradd(image.c_pixels, y * pitch + x * bpp)
if bpp == 1:
return rffi.cast(RSDL.Uint32, p[0])
elif bpp == 2:
p = rffi.cast(RSDL.Uint16P, p)
return rffi.cast(RSDL.Uint32, p[0])
elif bpp == 3:
p0 = rffi.cast(lltype.Signed, p[0])
p1 = rffi.cast(lltype.Signed, p[1])
p2 = rffi.cast(lltype.Signed, p[2])
if RSDL.BYTEORDER == RSDL.BIG_ENDIAN:
result = p0 << 16 | p1 << 8 | p2
else:
result = p0 | p1 << 8 | p2 << 16
return rffi.cast(RSDL.Uint32, result)
elif bpp == 4:
p = rffi.cast(RSDL.Uint32P, p)
return p[0]
else:
raise ValueError("bad BytesPerPixel")
开发者ID:ParitoshThapliyal59,项目名称:pypy,代码行数:27,代码来源:RSDL_helper.py
示例7: get_rgb
def get_rgb(color, format):
rgb = lltype.malloc(rffi.CArray(RSDL.Uint8), 3, flavor='raw')
try:
RSDL.GetRGB(color,
format,
rffi.ptradd(rgb, 0),
rffi.ptradd(rgb, 1),
rffi.ptradd(rgb, 2))
r = rffi.cast(lltype.Signed, rgb[0])
g = rffi.cast(lltype.Signed, rgb[1])
b = rffi.cast(lltype.Signed, rgb[2])
result = r, g, b
finally:
lltype.free(rgb, flavor='raw')
return result
开发者ID:ParitoshThapliyal59,项目名称:pypy,代码行数:16,代码来源:RSDL_helper.py
示例8: test_freelist
def test_freelist(self):
S = lltype.Struct('S', ('x', lltype.Signed), ('y', lltype.Signed))
SP = lltype.Ptr(S)
chunk = lltype.malloc(rffi.CArrayPtr(S).TO, 10, flavor='raw')
assert lltype.typeOf(chunk) == rffi.CArrayPtr(S)
free_list = lltype.nullptr(rffi.VOIDP.TO)
# build list
current = chunk
for i in range(10):
rffi.cast(rffi.VOIDPP, current)[0] = free_list
free_list = rffi.cast(rffi.VOIDP, current)
current = rffi.ptradd(current, 1)
# get one
p = free_list
free_list = rffi.cast(rffi.VOIDPP, p)[0]
rffi.cast(SP, p).x = 0
# get two
p = free_list
free_list = rffi.cast(rffi.VOIDPP, p)[0]
rffi.cast(SP, p).x = 0
# get three
p = free_list
free_list = rffi.cast(rffi.VOIDPP, p)[0]
rffi.cast(SP, p).x = 0
lltype.free(chunk, flavor='raw')
开发者ID:ieure,项目名称:pypy,代码行数:25,代码来源:test_ll2ctypes.py
示例9: test_cdll_life_time
def test_cdll_life_time(self):
from pypy.translator.tool.cbuild import ExternalCompilationInfo
from pypy.translator.platform import platform
from pypy.tool.udir import udir
c_file = udir.ensure("test_libffi", dir=1).join("xlib.c")
c_file.write(
py.code.Source(
"""
long fun(long i) {
return i + 42;
}
"""
)
)
eci = ExternalCompilationInfo(export_symbols=["fun"])
lib_name = str(platform.compile([c_file], eci, "x", standalone=False))
lib = CDLL(lib_name)
slong = cast_type_to_ffitype(rffi.LONG)
fun = lib.getrawpointer("fun", [slong], slong)
del lib # already delete here
buffer = lltype.malloc(rffi.LONGP.TO, 2, flavor="raw")
buffer[0] = 200
buffer[1] = -1
fun.call([rffi.cast(rffi.VOIDP, buffer)], rffi.cast(rffi.VOIDP, rffi.ptradd(buffer, 1)))
assert buffer[1] == 242
lltype.free(buffer, flavor="raw")
del fun
assert not ALLOCATED
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:33,代码来源:test_clibffi.py
示例10: test_rawfuncptr
def test_rawfuncptr(self):
libm = self.get_libm()
pow = libm.getrawpointer("pow", [ffi_type_double, ffi_type_double], ffi_type_double)
buffer = lltype.malloc(rffi.DOUBLEP.TO, 3, flavor="raw")
buffer[0] = 2.0
buffer[1] = 3.0
buffer[2] = 43.5
pow.call(
[rffi.cast(rffi.VOIDP, buffer), rffi.cast(rffi.VOIDP, rffi.ptradd(buffer, 1))],
rffi.cast(rffi.VOIDP, rffi.ptradd(buffer, 2)),
)
assert buffer[2] == 8.0
lltype.free(buffer, flavor="raw")
del pow
del libm
assert not ALLOCATED
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:16,代码来源:test_clibffi.py
示例11: do_getarrayitem_gc
def do_getarrayitem_gc(self, arraybox, indexbox, arraydescr):
itemindex = indexbox.getint()
gcref = arraybox.getref_base()
ofs, size, ptr, float = self.unpack_arraydescr(arraydescr)
# --- start of GC unsafe code (no GC operation!) ---
items = rffi.ptradd(rffi.cast(rffi.CCHARP, gcref), ofs)
#
if ptr:
items = rffi.cast(rffi.CArrayPtr(lltype.Signed), items)
pval = self._cast_int_to_gcref(items[itemindex])
# --- end of GC unsafe code ---
return BoxPtr(pval)
#
if float:
items = rffi.cast(rffi.CArrayPtr(lltype.Float), items)
fval = items[itemindex]
# --- end of GC unsafe code ---
return BoxFloat(fval)
#
for TYPE, itemsize in unroll_basic_sizes:
if size == itemsize:
items = rffi.cast(rffi.CArrayPtr(TYPE), items)
val = items[itemindex]
# --- end of GC unsafe code ---
return BoxInt(rffi.cast(lltype.Signed, val))
else:
raise NotImplementedError("size = %d" % size)
开发者ID:enyst,项目名称:plexnet,代码行数:27,代码来源:llmodel.py
示例12: bh_setarrayitem_gc_r
def bh_setarrayitem_gc_r(self, arraydescr, gcref, itemindex, newvalue):
ofs = self.unpack_arraydescr(arraydescr)
self.gc_ll_descr.do_write_barrier(gcref, newvalue)
# --- start of GC unsafe code (no GC operation!) ---
items = rffi.ptradd(rffi.cast(rffi.CCHARP, gcref), ofs)
items = rffi.cast(rffi.CArrayPtr(lltype.Signed), items)
items[itemindex] = self.cast_gcref_to_int(newvalue)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:7,代码来源:llmodel.py
示例13: _base_do_getfield_f
def _base_do_getfield_f(self, struct, fielddescr):
ofs = self.unpack_fielddescr(fielddescr)
# --- start of GC unsafe code (no GC operation!) ---
fieldptr = rffi.ptradd(rffi.cast(rffi.CCHARP, struct), ofs)
fval = rffi.cast(rffi.CArrayPtr(longlong.FLOATSTORAGE), fieldptr)[0]
# --- end of GC unsafe code ---
return fval
开发者ID:gorakhargosh,项目名称:pypy,代码行数:7,代码来源:llmodel.py
示例14: _struct_getfield
def _struct_getfield(TYPE, addr, offset):
"""
Read the field of type TYPE at addr+offset.
addr is of type rffi.VOIDP, offset is an int.
"""
addr = rffi.ptradd(addr, offset)
PTR_FIELD = lltype.Ptr(rffi.CArray(TYPE))
return rffi.cast(PTR_FIELD, addr)[0]
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:8,代码来源:libffi.py
示例15: _struct_setfield
def _struct_setfield(TYPE, addr, offset, value):
"""
Write the field of type TYPE at addr+offset.
addr is of type rffi.VOIDP, offset is an int.
"""
addr = rffi.ptradd(addr, offset)
PTR_FIELD = lltype.Ptr(rffi.CArray(TYPE))
rffi.cast(PTR_FIELD, addr)[0] = value
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:8,代码来源:libffi.py
示例16: get_struct
def get_struct(self, w_ffitype, w_structdescr):
assert isinstance(w_structdescr, W__StructDescr)
rawmem = rffi.cast(rffi.CCHARP, self.rawmem)
innermem = rffi.cast(rffi.VOIDP, rffi.ptradd(rawmem, self.offset))
# we return a reference to the inner struct, not a copy
# autofree=False because it's still owned by the parent struct
return W__StructInstance(w_structdescr, allocate=False, autofree=False,
rawmem=innermem)
开发者ID:MichaelBlume,项目名称:pypy,代码行数:8,代码来源:interp_struct.py
示例17: _base_do_getfield_r
def _base_do_getfield_r(self, struct, fielddescr):
ofs = self.unpack_fielddescr(fielddescr)
# --- start of GC unsafe code (no GC operation!) ---
fieldptr = rffi.ptradd(rffi.cast(rffi.CCHARP, struct), ofs)
pval = rffi.cast(rffi.CArrayPtr(lltype.Signed), fieldptr)[0]
pval = self._cast_int_to_gcref(pval)
# --- end of GC unsafe code ---
return pval
开发者ID:gorakhargosh,项目名称:pypy,代码行数:8,代码来源:llmodel.py
示例18: bh_getarrayitem_gc_f
def bh_getarrayitem_gc_f(self, arraydescr, gcref, itemindex):
ofs = self.unpack_arraydescr(arraydescr)
# --- start of GC unsafe code (no GC operation!) ---
items = rffi.ptradd(rffi.cast(rffi.CCHARP, gcref), ofs)
items = rffi.cast(rffi.CArrayPtr(longlong.FLOATSTORAGE), items)
fval = items[itemindex]
# --- end of GC unsafe code ---
return fval
开发者ID:gorakhargosh,项目名称:pypy,代码行数:8,代码来源:llmodel.py
示例19: bh_getarrayitem_gc_r
def bh_getarrayitem_gc_r(self, arraydescr, gcref, itemindex):
ofs = self.unpack_arraydescr(arraydescr)
# --- start of GC unsafe code (no GC operation!) ---
items = rffi.ptradd(rffi.cast(rffi.CCHARP, gcref), ofs)
items = rffi.cast(rffi.CArrayPtr(lltype.Signed), items)
pval = self._cast_int_to_gcref(items[itemindex])
# --- end of GC unsafe code ---
return pval
开发者ID:gorakhargosh,项目名称:pypy,代码行数:8,代码来源:llmodel.py
示例20: mk_mod
def mk_mod(vm, bc, mod_off):
mod_size = read_word(bc, mod_off + BC_MOD_SIZE)
assert mod_off >= 0 and mod_size >= 0
mod_bc = rffi.ptradd(bc, mod_off)
name = _extract_sstr(mod_bc, BC_MOD_NAME, BC_MOD_NAME_SIZE)
id_ = _extract_sstr(mod_bc, BC_MOD_ID, BC_MOD_ID_SIZE)
src_path = _extract_sstr(mod_bc, BC_MOD_SRC_PATH, BC_MOD_SRC_PATH_SIZE)
imps = []
j = read_word(mod_bc, BC_MOD_IMPORTS)
for k in range(read_word(mod_bc, BC_MOD_NUM_IMPORTS)):
assert j > 0
imp_size = read_word(mod_bc, j)
assert imp_size > 0
j += INTSIZE
imps.append(rffi.charpsize2str(rffi.ptradd(mod_bc, j), imp_size))
j += align(imp_size)
j += INTSIZE + align(read_word(mod_bc, j))
num_vars = read_word(mod_bc, BC_MOD_NUM_TL_VARS_MAP)
tlvars_map = {}
j = read_word(mod_bc, BC_MOD_TL_VARS_MAP)
for k in range(num_vars):
assert j > 0
var_num = read_word(mod_bc, j)
j += INTSIZE
tlvar_size = read_word(mod_bc, j)
assert tlvar_size > 0
j += INTSIZE
n = rffi.charpsize2str(rffi.ptradd(mod_bc, j), tlvar_size)
tlvars_map[n] = var_num
j += align(tlvar_size)
num_consts = read_word(mod_bc, BC_MOD_NUM_CONSTANTS)
mod = Builtins.new_bc_con_module(vm, mod_bc, name, id_, src_path, imps, tlvars_map, num_consts)
init_func_off = read_word(mod_bc, BC_MOD_INSTRUCTIONS)
pc = BC_PC(mod, init_func_off)
max_stack_size = 512 # XXX!
mod.init_func = Builtins.Con_Func(vm, Builtins.Con_String(vm, "$$init$$"), False, pc, \
max_stack_size, 0, num_vars, mod, None)
return mod
开发者ID:cfbolz,项目名称:converge,代码行数:45,代码来源:Bytecode.py
注:本文中的pypy.rpython.lltypesystem.rffi.ptradd函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论