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