def long_str(lstr): ptr = rffi.get_raw_address_of_string(lstr) for i, c in enumerate(lstr): debug_assert(ptr[i] == c, "failure c") gc.collect() ptr2 = rffi.get_raw_address_of_string(lstr) debug_assert(ptr == ptr2, "ptr != ptr2!!!") return ptr
def use_str(): mystr = b'abc' #debug_assert(rgc.can_move(mystr), "short string cannot move... why?") ptr = rffi.get_raw_address_of_string(mystr) ptr2 = rffi.get_raw_address_of_string(mystr) debug_assert(ptr == ptr2, "ptr != ptr2") debug_assert(ptr[0] == b'a', "notnurseryadr[0] == b'a' is is %s" % ptr[0]) ptr[0] = b'x' # oh no no, in real programs nobody is allowed to modify that debug_assert(mystr[0] == b'a', "mystr[0] != b'a'") debug_assert(ptr[0] == b'x', "notnurseryadr[0] == b'x'") gc.collect() nptr = rffi.get_raw_address_of_string(mystr) debug_assert(nptr == ptr, "second call to mystr must return the same ptr") debug_assert(ptr[0] == b'x', "failure a") debug_assert(nptr[0] == b'x', "failure b") mystr = None
def get_raw_address(self): from rpython.rtyper.lltypesystem import rffi # may still raise ValueError on some GCs return rffi.get_raw_address_of_string(self.value)