def test_offsetof_nogc(): ARR = lltype.Array(lltype.Signed) offsetx = llmemory.arraylengthoffset(ARR) offsety = llmemory.itemoffsetof(ARR, 0) ARR2 = lltype.GcArray(lltype.Signed) offsetx2 = llmemory.arraylengthoffset(ARR2) offsety2 = llmemory.itemoffsetof(ARR2, 0) def f(): a = lltype.malloc(ARR, 5, flavor='raw') a2 = lltype.malloc(ARR2, 6, flavor='raw') a2[0] = 1 a[0] = 3 adr = llmemory.cast_ptr_to_adr(a) adr2 = llmemory.cast_ptr_to_adr(a2) return ((adr + offsetx).signed[0] * 1000 + (adr + offsety).signed[0] * 100 + (adr2 + offsetx2).signed[0] * 10 + (adr2 + offsety2).signed[0]) fn = compile(f, []) res = fn() assert res == 5361
# the actual frame ('jf_frame', lltype.Array(lltype.Signed)), # note that we keep length field, because it's crucial to have the data # about GCrefs here and not in frame info which might change adtmeths = { 'allocate': jitframe_allocate, 'resolve': jitframe_resolve, }, rtti = True, )) @specialize.memo() def getofs(name): return llmemory.offsetof(JITFRAME, name) GCMAPLENGTHOFS = llmemory.arraylengthoffset(GCMAP) GCMAPBASEOFS = llmemory.itemoffsetof(GCMAP, 0) BASEITEMOFS = llmemory.itemoffsetof(JITFRAME.jf_frame, 0) LENGTHOFS = llmemory.arraylengthoffset(JITFRAME.jf_frame) SIGN_SIZE = llmemory.sizeof(lltype.Signed) UNSIGN_SIZE = llmemory.sizeof(lltype.Unsigned) STACK_DEPTH_OFS = getofs('jf_extra_stack_depth') def jitframe_trace(gc, obj_addr, callback, arg): gc._trace_callback(callback, arg, obj_addr + getofs('jf_descr')) gc._trace_callback(callback, arg, obj_addr + getofs('jf_force_descr')) gc._trace_callback(callback, arg, obj_addr + getofs('jf_savedata')) gc._trace_callback(callback, arg, obj_addr + getofs('jf_guard_exc')) gc._trace_callback(callback, arg, obj_addr + getofs('jf_forward')) if IS_32BIT:
# note that we keep length field, because it's crucial to have the data # about GCrefs here and not in frame info which might change adtmeths={ 'allocate': jitframe_allocate, 'resolve': jitframe_resolve, }, rtti=True, )) @specialize.memo() def getofs(name): return llmemory.offsetof(JITFRAME, name) GCMAPLENGTHOFS = llmemory.arraylengthoffset(GCMAP) GCMAPBASEOFS = llmemory.itemoffsetof(GCMAP, 0) BASEITEMOFS = llmemory.itemoffsetof(JITFRAME.jf_frame, 0) LENGTHOFS = llmemory.arraylengthoffset(JITFRAME.jf_frame) SIGN_SIZE = llmemory.sizeof(lltype.Signed) UNSIGN_SIZE = llmemory.sizeof(lltype.Unsigned) def jitframe_trace(gc, obj_addr, callback, arg): gc._trace_callback(callback, arg, obj_addr + getofs('jf_descr')) gc._trace_callback(callback, arg, obj_addr + getofs('jf_force_descr')) gc._trace_callback(callback, arg, obj_addr + getofs('jf_savedata')) gc._trace_callback(callback, arg, obj_addr + getofs('jf_guard_exc')) gc._trace_callback(callback, arg, obj_addr + getofs('jf_forward')) if IS_32BIT: