本文整理汇总了Python中pypy.rpython.lltypesystem.rffi.getintfield函数的典型用法代码示例。如果您正苦于以下问题:Python getintfield函数的具体用法?Python getintfield怎么用?Python getintfield使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getintfield函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_load_image
def test_load_image():
for filename in ["demo.jpg", "demo.png"]:
image = RIMG.Load(os.path.join(autopath.this_dir, filename))
assert image
assert rffi.getintfield(image, 'c_w') == 17
assert rffi.getintfield(image, 'c_h') == 23
RSDL.FreeSurface(image)
示例2: 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")
示例3: test_keypresses
def test_keypresses(self):
if not self.is_interactive:
py.test.skip("interactive test only")
RSDL.EnableUNICODE(1)
print
print "Keys pressed in the Pygame window should be printed below."
print " Use Escape to quit."
event = lltype.malloc(RSDL.Event, flavor='raw')
try:
while True:
ok = RSDL.WaitEvent(event)
assert rffi.cast(lltype.Signed, ok) == 1
c_type = rffi.getintfield(event, 'c_type')
if c_type == RSDL.KEYDOWN:
p = rffi.cast(RSDL.KeyboardEventPtr, event)
if rffi.getintfield(p.c_keysym, 'c_sym') == RSDL.K_ESCAPE:
print 'Escape key'
break
char = rffi.getintfield(p.c_keysym, 'c_unicode')
if char != 0:
print 'Key:', unichr(char).encode('utf-8')
else:
print 'Some special key'
else:
print '(event of type %d)' % c_type
finally:
lltype.free(event, flavor='raw')
示例4: 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")
示例5: test_mousemove
def test_mousemove(self):
if not self.is_interactive:
py.test.skip("interactive test only")
print
print "Move the Mouse up and down:"
print " Use Escape to quit."
event = lltype.malloc(RSDL.Event, flavor="raw")
directions = [False]*4
try:
while True:
ok = RSDL.WaitEvent(event)
assert rffi.cast(lltype.Signed, ok) == 1
c_type = rffi.getintfield(event, "c_type")
if c_type == RSDL.MOUSEMOTION:
m = rffi.cast(RSDL.MouseMotionEventPtr, event)
assert rffi.getintfield(m, "c_x") >= 0
assert rffi.getintfield(m, "c_y") >= 0
print rffi.getintfield(m, "c_xrel")
directions[0] |= rffi.getintfield(m, "c_xrel")>0
directions[1] |= rffi.getintfield(m, "c_xrel")<0
directions[2] |= rffi.getintfield(m, "c_yrel")>0
directions[3] |= rffi.getintfield(m, "c_yrel")<0
if False not in directions:
break
elif c_type == RSDL.KEYUP:
p = rffi.cast(RSDL.KeyboardEventPtr, event)
if rffi.getintfield(p.c_keysym, 'c_sym') == RSDL.K_ESCAPE:
print " test manually aborted"
py.test.fail(" mousemovement test aborted")
break
finally:
lltype.free(event, flavor='raw')
示例6: test_poll
def test_poll(self):
if not self.is_interactive:
py.test.skip("interactive test only")
import time, sys
RSDL.EnableUNICODE(1)
print
print "Keys pressed in the Pygame window give a dot."
print " Wait 3 seconds to quit."
timeout = time.time() + 3
event = lltype.malloc(RSDL.Event, flavor='raw')
try:
while True:
# busy polling
ok = RSDL.PollEvent(event)
ok = rffi.cast(lltype.Signed, ok)
assert ok >= 0
if ok > 0:
c_type = rffi.getintfield(event, 'c_type')
if c_type == RSDL.KEYDOWN:
sys.stderr.write('.')
p = rffi.cast(RSDL.KeyboardEventPtr, event)
if rffi.getintfield(p.c_keysym, 'c_sym') == RSDL.K_ESCAPE:
print 'Escape key'
break
timeout = time.time() + 3
else:
if time.time() > timeout:
break
time.sleep(0.05)
finally:
lltype.free(event, flavor='raw')
示例7: test_surface_basic
def test_surface_basic():
assert RSDL.Init(RSDL.INIT_VIDEO) >= 0
surface = RSDL.CreateRGBSurface(0, 150, 50, 32,
r_uint(0x000000FF),
r_uint(0x0000FF00),
r_uint(0x00FF0000),
r_uint(0xFF000000))
assert surface
assert rffi.getintfield(surface, 'c_w') == 150
assert rffi.getintfield(surface, 'c_h') == 50
RSDL.FreeSurface(surface)
RSDL.Quit()
示例8: flush
def flush(self):
if not self.running:
raise OperationError(self.space.w_ValueError,
self.space.wrap("this object was already flushed"))
self.running = False
out_bufsize = SMALLCHUNK
out_buf = lltype.malloc(rffi.CCHARP.TO, out_bufsize, flavor='raw',
zero=True)
try:
self.bzs.c_next_out = out_buf
rffi.setintfield(self.bzs, 'c_avail_out', out_bufsize)
total_out = _bzs_total_out(self.bzs)
temp = []
while True:
bzerror = BZ2_bzCompress(self.bzs, BZ_FINISH)
if bzerror == BZ_STREAM_END:
break
elif bzerror != BZ_FINISH_OK:
_catch_bz2_error(self.space, bzerror)
if rffi.getintfield(self.bzs, 'c_avail_out') == 0:
data = "".join([out_buf[i] for i in range(_bzs_total_out(self.bzs))])
temp.append(data)
out_bufsize = _new_buffer_size(out_bufsize)
out_buf = lltype.malloc(rffi.CCHARP.TO, out_bufsize,
flavor='raw', zero=True)
self.bzs.c_next_out = out_buf
rffi.setintfield(self.bzs, 'c_avail_out', out_bufsize)
if rffi.getintfield(self.bzs, 'c_avail_out'):
size = _bzs_total_out(self.bzs) - total_out
res = "".join([out_buf[i] for i in range(size)])
else:
total_out = _bzs_total_out(self.bzs)
res = "".join([out_buf[i] for i in range(total_out)])
if not temp:
return self.space.wrap(res)
else:
temp.append(res)
return self.space.wrap("".join(temp))
finally:
lltype.free(out_buf, flavor='raw')
示例9: gethost_common
def gethost_common(hostname, hostent, addr=None):
if not hostent:
raise HSocketError(hostname)
family = rffi.getintfield(hostent, 'c_h_addrtype')
if addr is not None and addr.family != family:
raise CSocketError(_c.EAFNOSUPPORT)
h_aliases = hostent.c_h_aliases
if h_aliases: # h_aliases can be NULL, according to SF #1511317
aliases = rffi.charpp2liststr(h_aliases)
else:
aliases = []
address_list = []
h_addr_list = hostent.c_h_addr_list
i = 0
paddr = h_addr_list[0]
while paddr:
if family == AF_INET:
p = rffi.cast(lltype.Ptr(_c.in_addr), paddr)
addr = INETAddress.from_in_addr(p)
elif AF_INET6 is not None and family == AF_INET6:
p = rffi.cast(lltype.Ptr(_c.in6_addr), paddr)
addr = INET6Address.from_in6_addr(p)
else:
raise RSocketError("unknown address family")
address_list.append(addr)
i += 1
paddr = h_addr_list[i]
return (rffi.charp2str(hostent.c_h_name), aliases, address_list)
示例10: _tm_to_tuple
def _tm_to_tuple(space, t):
time_tuple = [
space.wrap(rffi.getintfield(t, 'c_tm_year') + 1900),
space.wrap(rffi.getintfield(t, 'c_tm_mon') + 1), # want january == 1
space.wrap(rffi.getintfield(t, 'c_tm_mday')),
space.wrap(rffi.getintfield(t, 'c_tm_hour')),
space.wrap(rffi.getintfield(t, 'c_tm_min')),
space.wrap(rffi.getintfield(t, 'c_tm_sec')),
space.wrap((rffi.getintfield(t, 'c_tm_wday') + 6) % 7), # want monday == 0
space.wrap(rffi.getintfield(t, 'c_tm_yday') + 1), # want january, 1 == 1
space.wrap(rffi.getintfield(t, 'c_tm_isdst'))]
w_struct_time = _get_module_object(space, 'struct_time')
w_time_tuple = space.newtuple(time_tuple)
return space.call_function(w_struct_time, w_time_tuple)
示例11: test_mousebutton_wheel
def test_mousebutton_wheel(self):
if not self.is_interactive:
py.test.skip("interactive test only")
print
print "Press the given MouseButtons:"
print " Use Escape to pass tests."
event_tests = [("left button", RSDL.BUTTON_LEFT),
("middle button", RSDL.BUTTON_MIDDLE),
("right button", RSDL.BUTTON_RIGHT),
("scroll up", RSDL.BUTTON_WHEELUP),
("scroll down", RSDL.BUTTON_WHEELDOWN)]
test_success = []
event = lltype.malloc(RSDL.Event, flavor='raw')
try:
for button_test in event_tests:
print " press %s:" % button_test[0]
while True:
ok = RSDL.WaitEvent(event)
assert rffi.cast(lltype.Signed, ok) == 1
c_type = rffi.getintfield(event, 'c_type')
if c_type == RSDL.MOUSEBUTTONDOWN:
pass
elif c_type == RSDL.MOUSEBUTTONUP:
b = rffi.cast(RSDL.MouseButtonEventPtr, event)
if rffi.getintfield(b, 'c_button') == button_test[1]:
test_success.append(True)
break
elif c_type == RSDL.KEYUP:
p = rffi.cast(RSDL.KeyboardEventPtr, event)
if rffi.getintfield(p.c_keysym, 'c_sym') == RSDL.K_ESCAPE:
test_success.append(False)
print " manually aborted"
break
#break
if False in test_success:
py.test.fail("")
finally:
lltype.free(event, flavor='raw')
示例12: flush
def flush(self):
if not self.running:
raise OperationError(self.space.w_ValueError, self.space.wrap("this object was already flushed"))
self.running = False
with OutBuffer(self.bzs) as out:
while True:
bzerror = BZ2_bzCompress(self.bzs, BZ_FINISH)
if bzerror == BZ_STREAM_END:
break
elif bzerror != BZ_FINISH_OK:
_catch_bz2_error(self.space, bzerror)
if rffi.getintfield(self.bzs, "c_avail_out") == 0:
out.prepare_next_chunk()
res = out.make_result_string()
return self.space.wrap(res)
示例13: _get_interior_descr
def _get_interior_descr(self, ffitype, width, offset):
kind = libffi.types.getkind(ffitype)
is_pointer = is_float = is_signed = False
if ffitype is libffi.types.pointer:
is_pointer = True
elif kind == 'i':
is_signed = True
elif kind == 'f' or kind == 'I' or kind == 'U':
# longlongs are treated as floats, see
# e.g. llsupport/descr.py:getDescrClass
is_float = True
elif kind == 'u' or kind == 's':
# they're all False
pass
else:
raise NotImplementedError("unsupported ffitype or kind: %s" % kind)
#
fieldsize = rffi.getintfield(ffitype, 'c_size')
return self.optimizer.cpu.interiorfielddescrof_dynamic(
offset, width, fieldsize, is_pointer, is_float, is_signed
)
示例14: getaddrinfo
def getaddrinfo(host, port_or_service,
family=AF_UNSPEC, socktype=0, proto=0, flags=0,
address_to_fill=None):
# port_or_service is a string, not an int (but try str(port_number)).
assert port_or_service is None or isinstance(port_or_service, str)
hints = lltype.malloc(_c.addrinfo, flavor='raw', zero=True)
rffi.setintfield(hints, 'c_ai_family', family)
rffi.setintfield(hints, 'c_ai_socktype', socktype)
rffi.setintfield(hints, 'c_ai_protocol', proto)
rffi.setintfield(hints, 'c_ai_flags' , flags)
# XXX need to lock around getaddrinfo() calls?
p_res = lltype.malloc(rffi.CArray(_c.addrinfo_ptr), 1, flavor='raw')
error = intmask(_c.getaddrinfo(host, port_or_service, hints, p_res))
res = p_res[0]
lltype.free(p_res, flavor='raw')
lltype.free(hints, flavor='raw')
if error:
raise GAIError(error)
try:
result = []
info = res
while info:
addr = make_address(info.c_ai_addr,
rffi.getintfield(info, 'c_ai_addrlen'),
address_to_fill)
if info.c_ai_canonname:
canonname = rffi.charp2str(info.c_ai_canonname)
else:
canonname = ""
result.append((rffi.cast(lltype.Signed, info.c_ai_family),
rffi.cast(lltype.Signed, info.c_ai_socktype),
rffi.cast(lltype.Signed, info.c_ai_protocol),
canonname,
addr))
info = info.c_ai_next
address_to_fill = None # don't fill the same address repeatedly
finally:
_c.freeaddrinfo(res)
return result
示例15: test_image_pixels
def test_image_pixels():
for filename in ["demo.jpg", "demo.png"]:
image = RIMG.Load(os.path.join(autopath.this_dir, filename))
assert image
assert rffi.getintfield(image.c_format, 'c_BytesPerPixel') in (3, 4)
RSDL.LockSurface(image)
result = {}
try:
rgb = lltype.malloc(rffi.CArray(RSDL.Uint8), 3, flavor='raw')
try:
for y in range(23):
for x in range(y % 13, 17, 13):
color = RSDL_helper.get_pixel(image, x, y)
RSDL.GetRGB(color,
image.c_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[x, y] = r, g, b
finally:
lltype.free(rgb, flavor='raw')
finally:
RSDL.UnlockSurface(image)
RSDL.FreeSurface(image)
for x, y in result:
f = (x*17 + y*23) / float(17*17+23*23)
expected_r = int(255.0 * (1.0-f))
expected_g = 0
expected_b = int(255.0 * f)
r, g, b = result[x, y]
assert abs(r-expected_r) < 10
assert abs(g-expected_g) < 10
assert abs(b-expected_b) < 10