[pypy-svn] r51725 - in pypy/branch/unified-rtti/pypy/rpython/memory: . gctransform
arigo at codespeak.net
arigo at codespeak.net
Thu Feb 21 15:47:46 CET 2008
Author: arigo
Date: Thu Feb 21 15:47:44 2008
New Revision: 51725
Modified:
pypy/branch/unified-rtti/pypy/rpython/memory/gcheader.py
pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/refcounting.py
Log:
Forgot to set hdr.typeptr on prebuilt objects.
Add the ll_assert() that caught this bug.
Modified: pypy/branch/unified-rtti/pypy/rpython/memory/gcheader.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/rpython/memory/gcheader.py (original)
+++ pypy/branch/unified-rtti/pypy/rpython/memory/gcheader.py Thu Feb 21 15:47:44 2008
@@ -1,5 +1,6 @@
import weakref
from pypy.rpython.lltypesystem import lltype, llmemory
+from pypy.rlib.debug import ll_assert
# this is global because a header cannot be a header of more than one GcObj
@@ -62,6 +63,7 @@
def cast_rtti_to_typeinfo(self, rttiptr):
# this is RPython
+ ll_assert(bool(rttiptr), "NULL rtti pointer")
addr = llmemory.cast_ptr_to_adr(rttiptr)
addr += self.size_gc_typeinfo
return llmemory.cast_adr_to_ptr(addr, lltype.Ptr(self.TYPEINFO))
Modified: pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/refcounting.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/refcounting.py (original)
+++ pypy/branch/unified-rtti/pypy/rpython/memory/gctransform/refcounting.py Thu Feb 21 15:47:44 2008
@@ -8,6 +8,7 @@
from pypy.rpython import rmodel
from pypy.rpython.memory.gcheader import GCHeaderBuilder
from pypy.rlib.rarithmetic import ovfcheck
+from pypy.rlib.debug import ll_assert
from pypy.rpython.rbuiltin import gen_cast
import sys
@@ -69,9 +70,16 @@
rtti = gcheader.typeptr
typeinfo = gchdrbuilder.cast_rtti_to_typeinfo(rtti)
typeinfo.dealloc(adr)
+
def ll_no_pointer_dealloc(adr):
llmemory.raw_free(adr)
+ def ll_gc_runtime_type_info(adr):
+ gcheader = llmemory.cast_adr_to_ptr(adr - gc_header_offset, HDRPTR)
+ rtti = gcheader.typeptr
+ ll_assert(bool(rtti), "NULL rtti pointer")
+ return rtti
+
mh = mallocHelpers()
mh.allocate = llmemory.raw_malloc
def ll_malloc_fixedsize(size):
@@ -112,6 +120,8 @@
ll_decref, [llmemory.Address], lltype.Void)
self.no_pointer_dealloc_ptr = self.inittime_helper(
ll_no_pointer_dealloc, [llmemory.Address], lltype.Void)
+ self.gc_runtime_type_info_ptr = self.inittime_helper(
+ ll_gc_runtime_type_info, [llmemory.Address], RTTIPTR)
self.malloc_fixedsize_ptr = self.inittime_helper(
ll_malloc_fixedsize_rtti, [lltype.Signed, RTTIPTR],
llmemory.Address)
@@ -176,21 +186,14 @@
return v_raw
def gct_gc_runtime_type_info(self, hop):
- # generate inline code equivalent to:
- # gcheader = llmemory.cast_adr_to_ptr(adr - gc_header_offset, HDRPTR)
- # return gcheader.typeptr
[v_ptr] = hop.spaceop.args
v_adr = hop.genop("cast_ptr_to_adr", [v_ptr],
resulttype=llmemory.Address)
- c_gc_header_offset = rmodel.inputconst(lltype.Signed,
- self.gcheaderbuilder.size_gc_header)
- v_adr = hop.genop("adr_sub", [v_adr, c_gc_header_offset],
- resulttype=llmemory.Address)
- v_hdr = hop.genop("cast_adr_to_ptr", [v_adr],
- resulttype=lltype.Ptr(self.HDR))
- c_typeptr = rmodel.inputconst(lltype.Void, "typeptr")
- hop.genop("getfield", [v_hdr, c_typeptr],
- resultvar=hop.spaceop.result)
+ v_result = hop.spaceop.result
+ assert v_result.concretetype == RTTIPTR
+ hop.genop("direct_call",
+ [self.gc_runtime_type_info_ptr, v_adr],
+ resultvar = v_result)
def consider_constant(self, TYPE, value):
if value is not lltype.top_container(value):
@@ -200,6 +203,7 @@
if not self.gcheaderbuilder.get_header(p):
hdr = self.gcheaderbuilder.new_header(p)
hdr.refcount = sys.maxint // 2
+ hdr.typeptr = lltype.getRuntimeTypeInfo(TYPE, self.rtticache)
def static_deallocation_funcptr_for_type(self, TYPE):
"""The 'static deallocator' for a type is the function that can
More information about the Pypy-commit
mailing list