本文整理汇总了Python中pypy.rpython.lltypesystem.lltype.free函数的典型用法代码示例。如果您正苦于以下问题:Python free函数的具体用法?Python free怎么用?Python free使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了free函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: 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')
开发者ID:ParitoshThapliyal59,项目名称:pypy,代码行数:31,代码来源:test_video.py
示例2: _free_buffers
def _free_buffers(self, ll_result, ll_args):
if ll_result:
self._free_buffer_maybe(rffi.cast(rffi.VOIDP, ll_result), self.restype)
for i in range(len(self.argtypes)):
argtype = self.argtypes[i]
self._free_buffer_maybe(ll_args[i], argtype)
lltype.free(ll_args, flavor='raw')
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:libffi.py
示例3: test_blit_rect
def test_blit_rect(self):
surface = RSDL.CreateRGBSurface(0, 150, 50, 32,
r_uint(0x000000FF),
r_uint(0x0000FF00),
r_uint(0x00FF0000),
r_uint(0xFF000000))
fmt = surface.c_format
color = RSDL.MapRGB(fmt, 255, 0, 0)
RSDL.FillRect(surface, lltype.nullptr(RSDL.Rect), color)
paintrect = RSDL_helper.mallocrect(75, 0, 150, 50)
dstrect = lltype.malloc(RSDL.Rect, flavor='raw')
try:
color = RSDL.MapRGB(fmt, 255, 128, 0)
RSDL.FillRect(surface, paintrect, color)
rffi.setintfield(dstrect, 'c_x', 10)
rffi.setintfield(dstrect, 'c_y', 10)
rffi.setintfield(dstrect, 'c_w', 150)
rffi.setintfield(dstrect, 'c_h', 50)
RSDL.BlitSurface(surface, lltype.nullptr(RSDL.Rect), self.screen, dstrect)
RSDL.Flip(self.screen)
finally:
lltype.free(dstrect, flavor='raw')
lltype.free(paintrect, flavor='raw')
RSDL.FreeSurface(surface)
self.check("Half Red/Orange rectangle(150px * 50px) at the top left, 10 pixels from the border")
开发者ID:ParitoshThapliyal59,项目名称:pypy,代码行数:27,代码来源:test_video.py
示例4: test_byval_argument
def test_byval_argument(self):
"""
struct Point {
long x;
long y;
};
long sum_point(struct Point p) {
return p.x + p.y;
}
"""
libfoo = CDLL(self.libfoo_name)
ffi_point_struct = make_struct_ffitype_e(0, 0, [types.slong, types.slong])
ffi_point = ffi_point_struct.ffistruct
sum_point = (libfoo, 'sum_point', [ffi_point], types.slong)
#
ARRAY = rffi.CArray(rffi.LONG)
buf = lltype.malloc(ARRAY, 2, flavor='raw')
buf[0] = 30
buf[1] = 12
adr = rffi.cast(rffi.VOIDP, buf)
res = self.call(sum_point, [('arg_raw', adr)], rffi.LONG,
jitif=["byval"])
assert res == 42
# check that we still have the ownership on the buffer
assert buf[0] == 30
assert buf[1] == 12
lltype.free(buf, flavor='raw')
lltype.free(ffi_point_struct, flavor='raw')
开发者ID:gorakhargosh,项目名称:pypy,代码行数:29,代码来源:test_libffi.py
示例5: test_cstruct_to_ll
def test_cstruct_to_ll():
S = lltype.Struct('S', ('x', lltype.Signed), ('y', lltype.Signed))
s = lltype.malloc(S, flavor='raw')
s2 = lltype.malloc(S, flavor='raw')
s.x = 123
sc = lltype2ctypes(s)
t = ctypes2lltype(lltype.Ptr(S), sc)
assert lltype.typeOf(t) == lltype.Ptr(S)
assert s == t
assert not (s != t)
assert t == s
assert not (t != s)
assert t != lltype.nullptr(S)
assert not (t == lltype.nullptr(S))
assert lltype.nullptr(S) != t
assert not (lltype.nullptr(S) == t)
assert t != s2
assert not (t == s2)
assert s2 != t
assert not (s2 == t)
assert t.x == 123
t.x += 1
assert s.x == 124
s.x += 1
assert t.x == 125
lltype.free(s, flavor='raw')
lltype.free(s2, flavor='raw')
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:27,代码来源:test_ll2ctypes.py
示例6: walk_roots
def walk_roots(self, collect_stack_root,
collect_static_in_prebuilt_nongc,
collect_static_in_prebuilt_gc):
gc = self.tester.gc
layoutbuilder = self.tester.layoutbuilder
if collect_static_in_prebuilt_gc:
for addrofaddr in layoutbuilder.addresses_of_static_ptrs:
if addrofaddr.address[0]:
collect_static_in_prebuilt_gc(gc, addrofaddr)
if collect_static_in_prebuilt_nongc:
for addrofaddr in layoutbuilder.addresses_of_static_ptrs_in_nongc:
if addrofaddr.address[0]:
collect_static_in_prebuilt_nongc(gc, addrofaddr)
if collect_stack_root:
stackroots = self.tester.stackroots
a = lltype.malloc(ADDR_ARRAY, len(stackroots), flavor='raw')
for i in range(len(a)):
a[i] = llmemory.cast_ptr_to_adr(stackroots[i])
a_base = lltype.direct_arrayitems(a)
for i in range(len(a)):
ai = lltype.direct_ptradd(a_base, i)
collect_stack_root(gc, llmemory.cast_ptr_to_adr(ai))
for i in range(len(a)):
PTRTYPE = lltype.typeOf(stackroots[i])
stackroots[i] = llmemory.cast_adr_to_ptr(a[i], PTRTYPE)
lltype.free(a, flavor='raw')
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:26,代码来源:test_direct.py
示例7: test
def test(encoded, endian, realendian=None):
encoded_charp = rffi.str2charp(encoded)
strict_charp = rffi.str2charp("strict")
if endian is not None:
if endian < 0:
value = -1
elif endian > 0:
value = 1
else:
value = 0
pendian = lltype.malloc(rffi.INTP.TO, 1, flavor='raw')
pendian[0] = rffi.cast(rffi.INT, value)
else:
pendian = None
w_ustr = api.PyUnicode_DecodeUTF16(encoded_charp, len(encoded), strict_charp, pendian)
assert space.eq_w(space.call_method(w_ustr, 'encode', space.wrap('ascii')),
space.wrap("abcd"))
rffi.free_charp(encoded_charp)
rffi.free_charp(strict_charp)
if pendian:
if realendian is not None:
assert rffi.cast(rffi.INT, realendian) == pendian[0]
lltype.free(pendian, flavor='raw')
开发者ID:ieure,项目名称:pypy,代码行数:25,代码来源:test_unicodeobject.py
示例8: __init__
def __init__(self, space, environment, context, retrieveError):
self.context = context
if retrieveError:
if environment.errorHandle:
handle = environment.errorHandle
handleType = roci.OCI_HTYPE_ERROR
else:
handle = environment.handle
handleType = roci.OCI_HTYPE_ENV
codeptr = lltype.malloc(rffi.CArray(roci.sb4), 1, flavor='raw')
BUFSIZE = 1024
textbuf, text = rffi.alloc_buffer(BUFSIZE)
try:
status = roci.OCIErrorGet(
handle, 1, lltype.nullptr(roci.oratext.TO), codeptr,
textbuf, BUFSIZE, handleType)
if status != roci.OCI_SUCCESS:
raise OperationError(
get(space).w_InternalError,
space.wrap("No Oracle error?"))
self.code = codeptr[0]
self.w_message = config.w_string(space, textbuf)
finally:
lltype.free(codeptr, flavor='raw')
rffi.keep_buffer_alive_until_here(textbuf, text)
if config.WITH_UNICODE:
# XXX remove double zeros at the end
pass
开发者ID:alkorzt,项目名称:pypy,代码行数:32,代码来源:interp_error.py
示例9: inflateEnd
def inflateEnd(stream):
"""
Free the resources associated with the inflate stream.
Note that this may raise RZlibError.
"""
_inflateEnd(stream)
lltype.free(stream, flavor='raw')
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:rzlib.py
示例10: llimpl_FormatError
def llimpl_FormatError(code):
"Return a message corresponding to the given Windows error code."
buf = lltype.malloc(rffi.CCHARPP.TO, 1, flavor='raw')
try:
msglen = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
None,
rffi.cast(DWORD, code),
DEFAULT_LANGUAGE,
rffi.cast(rffi.CCHARP, buf),
0, None)
if msglen <= 2: # includes the case msglen < 0
return fake_FormatError(code)
# FormatMessage always appends \r\n.
buflen = intmask(msglen - 2)
assert buflen > 0
result = rffi.charpsize2str(buf[0], buflen)
LocalFree(rffi.cast(rffi.VOIDP, buf[0]))
finally:
lltype.free(buf, flavor='raw')
return result
开发者ID:ParitoshThapliyal59,项目名称:pypy,代码行数:26,代码来源:rwin32.py
示例11: test_raw_memclear_on_empty_array
def test_raw_memclear_on_empty_array():
py.test.skip("Fails")
A = lltype.FixedSizeArray(lltype.Signed, 0)
a = lltype.malloc(A, flavor='raw')
src = cast_ptr_to_adr(a) + itemoffsetof(A, 0)
raw_memclear(src, sizeof(lltype.Signed) * 0)
lltype.free(a, flavor="raw")
开发者ID:ieure,项目名称:pypy,代码行数:7,代码来源:test_llmemory.py
示例12: test_forced_ptr_cast
def test_forced_ptr_cast(self):
import array
A = lltype.Array(lltype.Signed, hints={'nolength': True})
B = lltype.Array(lltype.Char, hints={'nolength': True})
a = lltype.malloc(A, 10, flavor='raw')
for i in range(10):
a[i] = i*i
b = rffi.cast(lltype.Ptr(B), a)
checker = array.array('l')
for i in range(10):
checker.append(i*i)
expected = checker.tostring()
for i in range(len(expected)):
assert b[i] == expected[i]
c = rffi.cast(rffi.VOIDP, a)
addr = lltype2ctypes(c)
#assert addr == ctypes.addressof(a._obj._ctypes_storage)
d = ctypes2lltype(rffi.VOIDP, addr)
assert lltype.typeOf(d) == rffi.VOIDP
assert c == d
e = rffi.cast(lltype.Ptr(A), d)
for i in range(10):
assert e[i] == i*i
c = lltype.nullptr(rffi.VOIDP.TO)
addr = rffi.cast(lltype.Signed, c)
assert addr == 0
lltype.free(a, flavor='raw')
assert not ALLOCATED # detects memory leaks in the test
开发者ID:antoine1fr,项目名称:pygirl,代码行数:34,代码来源:test_ll2ctypes.py
示例13: get_darwin_sysctl_signed
def get_darwin_sysctl_signed(sysctl_name):
rval_p = lltype.malloc(rffi.LONGLONGP.TO, 1, flavor='raw')
try:
len_p = lltype.malloc(rffi.SIZE_TP.TO, 1, flavor='raw')
try:
size = rffi.sizeof(rffi.LONGLONG)
rval_p[0] = rffi.cast(rffi.LONGLONG, 0)
len_p[0] = rffi.cast(rffi.SIZE_T, size)
# XXX a hack for llhelper not being robust-enough
result = sysctlbyname(sysctl_name,
rffi.cast(rffi.VOIDP, rval_p),
len_p,
lltype.nullptr(rffi.VOIDP.TO),
rffi.cast(rffi.SIZE_T, 0))
rval = 0
if (rffi.cast(lltype.Signed, result) == 0 and
rffi.cast(lltype.Signed, len_p[0]) == size):
rval = rffi.cast(lltype.Signed, rval_p[0])
if rffi.cast(rffi.LONGLONG, rval) != rval_p[0]:
rval = 0 # overflow!
return rval
finally:
lltype.free(len_p, flavor='raw')
finally:
lltype.free(rval_p, flavor='raw')
开发者ID:ieure,项目名称:pypy,代码行数:25,代码来源:env.py
示例14: 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
开发者ID:antoine1fr,项目名称:pygirl,代码行数:35,代码来源:test_ll2ctypes.py
示例15: test_uninitialized2ctypes
def test_uninitialized2ctypes(self):
# for now, uninitialized fields are filled with 0xDD in the ctypes data
def checkobj(o, size):
p = ctypes.cast(ctypes.c_void_p(ctypes.addressof(o)),
ctypes.POINTER(ctypes.c_ubyte*size))
for i in range(size):
assert p.contents[i] == 0xDD
def checkval(v, fmt):
res = struct.pack(fmt, v)
assert res == "\xDD" * len(res)
checkval(uninitialized2ctypes(rffi.CHAR), 'B')
checkval(uninitialized2ctypes(rffi.SHORT), 'h')
checkval(uninitialized2ctypes(rffi.INT), 'i')
checkval(uninitialized2ctypes(rffi.UINT), 'I')
checkval(uninitialized2ctypes(rffi.LONGLONG), 'q')
checkval(uninitialized2ctypes(rffi.DOUBLE), 'd')
checkobj(uninitialized2ctypes(rffi.INTP),
ctypes.sizeof(ctypes.c_void_p))
checkobj(uninitialized2ctypes(rffi.CCHARP),
ctypes.sizeof(ctypes.c_void_p))
S = lltype.Struct('S', ('x', lltype.Signed), ('y', lltype.Signed))
s = lltype.malloc(S, flavor='raw')
sc = lltype2ctypes(s)
checkval(sc.contents.x, 'l')
checkval(sc.contents.y, 'l')
lltype.free(s, flavor='raw')
assert not ALLOCATED # detects memory leaks in the test
开发者ID:antoine1fr,项目名称:pygirl,代码行数:30,代码来源:test_ll2ctypes.py
示例16: test_carray_to_ll
def test_carray_to_ll():
A = lltype.Array(lltype.Signed, hints={'nolength': True})
a = lltype.malloc(A, 10, flavor='raw')
a2 = lltype.malloc(A, 10, flavor='raw')
a[0] = 100
a[1] = 101
a[2] = 110
ac = lltype2ctypes(a)
b = ctypes2lltype(lltype.Ptr(A), ac)
assert lltype.typeOf(b) == lltype.Ptr(A)
assert b == a
assert not (b != a)
assert a == b
assert not (a != b)
assert b != lltype.nullptr(A)
assert not (b == lltype.nullptr(A))
assert lltype.nullptr(A) != b
assert not (lltype.nullptr(A) == b)
assert b != a2
assert not (b == a2)
assert a2 != b
assert not (a2 == b)
assert b[2] == 110
b[2] *= 2
assert a[2] == 220
a[2] *= 3
assert b[2] == 660
lltype.free(a, flavor='raw')
lltype.free(a2, flavor='raw')
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:29,代码来源:test_ll2ctypes.py
示例17: test_arrayofstruct
def test_arrayofstruct(self):
S1 = lltype.Struct('S1', ('x', lltype.Signed))
A = lltype.Array(S1, hints={'nolength': True})
a = lltype.malloc(A, 5, flavor='raw')
a[0].x = 100
a[1].x = 101
a[2].x = 102
a[3].x = 103
a[4].x = 104
ac = lltype2ctypes(a, normalize=False)
assert ac.contents.items[0].x == 100
assert ac.contents.items[2].x == 102
ac.contents.items[3].x += 500
assert a[3].x == 603
a[4].x += 600
assert ac.contents.items[4].x == 704
a1 = ctypes2lltype(lltype.Ptr(A), ac)
assert a1 == a
assert a1[2].x == 102
aitem1 = ctypes2lltype(lltype.Ptr(S1),
ctypes.pointer(ac.contents.items[1]))
assert aitem1.x == 101
assert aitem1 == a1[1]
lltype.free(a, flavor='raw')
assert not ALLOCATED # detects memory leaks in the test
开发者ID:antoine1fr,项目名称:pygirl,代码行数:25,代码来源:test_ll2ctypes.py
示例18: 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')
开发者ID:ParitoshThapliyal59,项目名称:pypy,代码行数:32,代码来源:test_video.py
示例19: test_addr_raw_packet
def test_addr_raw_packet():
if not hasattr(rsocket._c, 'sockaddr_ll'):
py.test.skip("posix specific test")
c_addr_ll = lltype.malloc(rsocket._c.sockaddr_ll, flavor='raw')
addrlen = rffi.sizeof(rsocket._c.sockaddr_ll)
c_addr = rffi.cast(lltype.Ptr(rsocket._c.sockaddr), c_addr_ll)
rffi.setintfield(c_addr_ll, 'c_sll_ifindex', 1)
rffi.setintfield(c_addr_ll, 'c_sll_protocol', 8)
rffi.setintfield(c_addr_ll, 'c_sll_pkttype', 13)
rffi.setintfield(c_addr_ll, 'c_sll_hatype', 0)
rffi.setintfield(c_addr_ll, 'c_sll_halen', 3)
c_addr_ll.c_sll_addr[0] = 'a'
c_addr_ll.c_sll_addr[1] = 'b'
c_addr_ll.c_sll_addr[2] = 'c'
rffi.setintfield(c_addr, 'c_sa_family', socket.AF_PACKET)
# fd needs to be somehow valid
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
fd = s.fileno()
w_obj = rsocket.make_address(c_addr, addrlen).as_object(fd, space)
lltype.free(c_addr_ll, flavor='raw')
assert space.is_true(space.eq(w_obj, space.newtuple([
space.wrap('lo'),
space.wrap(socket.ntohs(8)),
space.wrap(13),
space.wrap(False),
space.wrap("abc"),
])))
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:27,代码来源:test_sock_app.py
示例20: 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')
开发者ID:ParitoshThapliyal59,项目名称:pypy,代码行数:27,代码来源:test_video.py
注:本文中的pypy.rpython.lltypesystem.lltype.free函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论