本文整理汇总了Python中pypy.rpython.lltypesystem.rffi.ptradd函数的典型用法代码示例。如果您正苦于以下问题:Python ptradd函数的具体用法?Python ptradd怎么用?Python ptradd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ptradd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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
示例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
示例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")
示例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")
示例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
示例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')
示例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
示例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
示例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)
示例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)
示例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
示例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]
示例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