def _more(self): chunk = rffi.cast(CLOSURES, alloc(CHUNK)) count = CHUNK//rffi.sizeof(FFI_CLOSUREP.TO) for i in range(count): rffi.cast(rffi.VOIDPP, chunk)[0] = self.free_list self.free_list = rffi.cast(rffi.VOIDP, chunk) chunk = rffi.ptradd(chunk, 1)
def test_alloc_free(): map_size = 65536 data = alloc(map_size) for i in range(0, map_size, 171): data[i] = chr(i & 0xff) for i in range(0, map_size, 171): assert data[i] == chr(i & 0xff) free(data, map_size)
def detect_sse2(): data = alloc(4096) pos = 0 for c in ("\xB8\x01\x00\x00\x00" # MOV EAX, 1 "\x53" # PUSH EBX "\x0F\xA2" # CPUID "\x5B" # POP EBX "\x92" # XCHG EAX, EDX "\xC3"): # RET data[pos] = c pos += 1 fnptr = rffi.cast(lltype.Ptr(lltype.FuncType([], lltype.Signed)), data) code = fnptr() free(data, 4096) return bool(code & (1<<25)) and bool(code & (1<<26))
def detect_sse2(): data = alloc(4096) pos = 0 for c in ("\xB8\x01\x00\x00\x00" # MOV EAX, 1 "\x53" # PUSH EBX "\x0F\xA2" # CPUID "\x5B" # POP EBX "\x92" # XCHG EAX, EDX "\xC3"): # RET data[pos] = c pos += 1 fnptr = rffi.cast(lltype.Ptr(lltype.FuncType([], lltype.Signed)), data) code = fnptr() free(data, 4096) return bool(code & (1 << 25)) and bool(code & (1 << 26))
def _allocate_large_block(self, minsize): # Compute 'size' from 'minsize': it must be rounded up to # 'large_alloc_size'. Additionally, we use the following line # to limit how many mmap() requests the OS will see in total: minsize = max(minsize, intmask(self.total_memory_allocated >> 4)) size = minsize + self.large_alloc_size - 1 size = (size // self.large_alloc_size) * self.large_alloc_size data = rmmap.alloc(size) if not we_are_translated(): if self._allocated is None: self._allocated = [] self._allocated.append((data, size)) if sys.maxint > 2147483647: # Hack to make sure that mcs are not within 32-bits of one # another for testing purposes rmmap.hint.pos += 0x80000000 - size self.total_memory_allocated += r_uint(size) data = rffi.cast(lltype.Signed, data) return self._add_free_block(data, data + size)
def __init__(self, map_size): data = alloc(map_size) self._init(data, map_size)
def entry_point(argv): one = alloc(1024) free(one, 1024) return 0