def test_framework_opaque(self): A = lltype.GcStruct('A', ('value', lltype.Signed)) O = lltype.GcOpaqueType('test.framework') def gethidden(n): a = lltype.malloc(A) a.value = -n * 7 return lltype.cast_opaque_ptr(lltype.Ptr(O), a) gethidden._dont_inline_ = True def reveal(o): return lltype.cast_opaque_ptr(lltype.Ptr(A), o) def overwrite(a, i): a.value = i overwrite._dont_inline_ = True def f(): o = gethidden(10) llop.gc__collect(lltype.Void) for i in range(1000): # overwrite freed memory overwrite(lltype.malloc(A), i) a = reveal(o) return a.value fn = self.getcompiled(f) res = fn() assert res == -70
def test_opaque(): S = lltype.GcStruct('S', ('x', lltype.Signed), ('y', lltype.Signed)) O = lltype.GcOpaqueType('O') s = lltype.malloc(S) adr = cast_ptr_to_adr(s) o = cast_adr_to_ptr(adr, lltype.Ptr(O)) assert lltype.cast_opaque_ptr(lltype.Ptr(S), o) == s adr2 = cast_ptr_to_adr(o) s2 = cast_adr_to_ptr(adr2, lltype.Ptr(S)) assert s2 == s
def is_true(self, real_object): return bool(real_object) def get_switch(self, real_object): return bound_switch_of_frame_stack_top_controller.box(real_object) def convert(self, obj): assert obj is None return lltype.nullptr(OPAQUE_STATE_HEADER_PTR.TO) frame_stack_top_controller = FrameStackTopController() bound_switch_of_frame_stack_top_controller = BoundSwitchOfFrameStackTopController( ) OPAQUE_STATE_HEADER = lltype.GcOpaqueType("OPAQUE_STATE_HEADER", hints={"render_structure": True}) OPAQUE_STATE_HEADER_PTR = lltype.Ptr(OPAQUE_STATE_HEADER) class FrameStackTopReturningFnEntry(ExtRegistryEntry): def compute_result_annotation(self): from pypy.annotation import model as annmodel return SomeControlledInstance( annmodel.lltype_to_annotation(OPAQUE_STATE_HEADER_PTR), frame_stack_top_controller) class YieldCurrentFrameToCallerFnEntry(FrameStackTopReturningFnEntry): _about_ = yield_current_frame_to_caller def specialize_call(self, hop):
class NullAddressError(Exception): pass class DanglingPointerError(Exception): pass NULL = fakeaddress(None) NULL.intaddress = 0 # this is to make memory.lladdress more happy Address = lltype.Primitive("Address", NULL) # GCREF is similar to Address but it is GC-aware GCREF = lltype.Ptr(lltype.GcOpaqueType('GCREF')) # A placeholder for any type that is a GcArray of pointers. # This can be used in the symbolic offsets above to access such arrays # in a generic way. GCARRAY_OF_PTR = lltype.GcArray(GCREF, hints={'placeholder': True}) gcarrayofptr_lengthoffset = ArrayLengthOffset(GCARRAY_OF_PTR) gcarrayofptr_itemsoffset = ArrayItemsOffset(GCARRAY_OF_PTR) gcarrayofptr_singleitemoffset = ItemOffset(GCARRAY_OF_PTR.OF) def array_type_match(A1, A2): return A1 == A2 or (A2 == GCARRAY_OF_PTR and isinstance( A1, lltype.GcArray) and isinstance(A1.OF, lltype.Ptr) and not A1._hints.get('nolength'))
from pypy.rpython.lltypesystem.llmemory import raw_malloc, raw_free from pypy.rpython.lltypesystem.llmemory import raw_memcopy, raw_memclear from pypy.rpython.lltypesystem.llmemory import NULL, raw_malloc_usage from pypy.rpython.memory.support import DEFAULT_CHUNK_SIZE from pypy.rpython.memory.support import get_address_stack from pypy.rpython.memory.gcheader import GCHeaderBuilder from pypy.rpython.lltypesystem import lltype, llmemory, rffi from pypy.rlib.objectmodel import free_non_gc_object from pypy.rpython.lltypesystem.lloperation import llop from pypy.rlib.rarithmetic import ovfcheck from pypy.rlib.debug import debug_print, debug_start, debug_stop from pypy.rpython.memory.gc.base import GCBase import sys, os X_POOL = lltype.GcOpaqueType('gc.pool') X_POOL_PTR = lltype.Ptr(X_POOL) X_CLONE = lltype.GcStruct('CloneData', ('gcobjectptr', llmemory.GCREF), ('pool', X_POOL_PTR)) X_CLONE_PTR = lltype.Ptr(X_CLONE) FL_WITHHASH = 0x01 FL_CURPOOL = 0x02 memoryError = MemoryError() class MarkSweepGC(GCBase): HDR = lltype.ForwardReference() HDRPTR = lltype.Ptr(HDR) # need to maintain a linked list of malloced objects, since we used the