def ll_nonmovable_raw_ptr_for_resizable_list(ll_list): """ WARNING: dragons ahead. Return the address of the internal char* buffer of 'll_list', which must be a resizable list of chars. This makes sure that the list items are non-moving, if necessary by first copying the GcArray inside 'll_list.items' outside the GC nursery. The returned 'char *' pointer is guaranteed to be valid until one of these occurs: * 'll_list' gets garbage-collected; or * you do an operation on 'll_list' that changes its size. """ from rpython.rtyper.lltypesystem import lltype, rffi array = ll_list.items if can_move(array): length = ll_list.length new_array = lltype.malloc(lltype.typeOf(ll_list).TO.items.TO, length, nonmovable=True) ll_arraycopy(array, new_array, 0, 0, length) ll_list.items = new_array array = new_array ptr = lltype.direct_arrayitems(array) # ptr is a Ptr(FixedSizeArray(Char, 1)). Cast it to a rffi.CCHARP return rffi.cast(rffi.CCHARP, ptr)
def walk_roots(self, collect_stack_root, collect_static_in_prebuilt_nongc, collect_static_in_prebuilt_gc, is_minor=False): 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')
def writeall_not_sandboxed(fd, buf, length): while length > 0: size = rffi.cast(rffi.SIZE_T, length) count = rffi.cast(lltype.Signed, ll_write_not_sandboxed(fd, buf, size)) if count <= 0: raise IOError length -= count buf = lltype.direct_ptradd(lltype.direct_arrayitems(buf), count) buf = rffi.cast(rffi.CCHARP, buf)
def ref(self, arrayptr): assert array_type_match(lltype.typeOf(arrayptr).TO, self.TYPE) if isinstance(self.TYPE.OF, lltype.ContainerType): # XXX this doesn't support empty arrays # XXX it's also missing 'solid' support, probably o = arrayptr._obj.getitem(0) return o._as_ptr() else: return lltype.direct_arrayitems(arrayptr)
def make_struct_ffitype_e(size, aligment, field_types, track_allocation=True): """Compute the type of a structure. Returns a FFI_STRUCT_P out of which the 'ffistruct' member is a regular FFI_TYPE. """ tpe = lltype.malloc(FFI_STRUCT_P.TO, len(field_types)+1, flavor='raw', track_allocation=track_allocation) tpe.ffistruct.c_type = rffi.cast(rffi.USHORT, FFI_TYPE_STRUCT) tpe.ffistruct.c_size = rffi.cast(rffi.SIZE_T, size) tpe.ffistruct.c_alignment = rffi.cast(rffi.USHORT, aligment) tpe.ffistruct.c_elements = rffi.cast(FFI_TYPE_PP, lltype.direct_arrayitems(tpe.members)) n = 0 while n < len(field_types): tpe.members[n] = field_types[n] n += 1 tpe.members[n] = lltype.nullptr(FFI_TYPE_P.TO) return tpe
def op_direct_arrayitems(obj): checkptr(obj) return lltype.direct_arrayitems(obj)
def direct_arrayitems(s_p): assert isinstance(s_p, SomePtr), "direct_* of non-pointer: %r" % s_p cast_p = lltype.direct_arrayitems(s_p.ll_ptrtype._example()) return SomePtr(ll_ptrtype=lltype.typeOf(cast_p))
def fn(): p1 = lltype.direct_arrayitems(a1) p2 = lltype.direct_ptradd(p1, 6) return p2[0]