[pypy-svn] r31812 - in pypy/branch/no-zeroing-assumption-3/pypy: annotation rpython rpython/lltypesystem rpython/lltypesystem/test rpython/memory rpython/rctypes rpython/test translator/c translator/c/src translator/c/test translator/stackless

mwh at codespeak.net mwh at codespeak.net
Tue Aug 29 23:08:46 CEST 2006


Author: mwh
Date: Tue Aug 29 23:08:43 2006
New Revision: 31812

Modified:
   pypy/branch/no-zeroing-assumption-3/pypy/annotation/builtin.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/llinterp.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/ll_str.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/llheap.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/llmemory.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/lloperation.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/lltype.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/rclass.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/rdict.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/rlist.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/rstr.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/test/test_llmemory.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/test/test_lltype.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/test/test_picklelltype.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/memory/convertlltype.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/memory/gc.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/memory/gctransform.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/memory/lladdress.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/memory/simulator.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/memory/support.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/objectmodel.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/rbuiltin.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/rctypes/astringbuf.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/rctypes/rarray.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/rctypes/rchar_p.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/rctypes/rmodel.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/rctypes/rstringbuf.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/test/test_llinterp.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/test/test_rdict.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/test/test_rstr.py
   pypy/branch/no-zeroing-assumption-3/pypy/rpython/test/tool.py
   pypy/branch/no-zeroing-assumption-3/pypy/translator/c/database.py
   pypy/branch/no-zeroing-assumption-3/pypy/translator/c/funcgen.py
   pypy/branch/no-zeroing-assumption-3/pypy/translator/c/gc.py
   pypy/branch/no-zeroing-assumption-3/pypy/translator/c/src/mem.h
   pypy/branch/no-zeroing-assumption-3/pypy/translator/c/test/test_lltyped.py
   pypy/branch/no-zeroing-assumption-3/pypy/translator/c/test/test_newgc.py
   pypy/branch/no-zeroing-assumption-3/pypy/translator/stackless/transform.py
Log:
merge forward; this gets me (a) the test_rtagged fixes (b)
rpython.annlowlevel.llhelper


Modified: pypy/branch/no-zeroing-assumption-3/pypy/annotation/builtin.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/annotation/builtin.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/annotation/builtin.py	Tue Aug 29 23:08:43 2006
@@ -388,7 +388,7 @@
 from pypy.annotation.model import SomePtr
 from pypy.rpython.lltypesystem import lltype
 
-def malloc(s_T, s_n=None, s_flavor=None, s_extra_args=None):
+def malloc(s_T, s_n=None, s_flavor=None, s_extra_args=None, s_zero=None):
     assert (s_n is None or s_n.knowntype == int
             or issubclass(s_n.knowntype, pypy.rpython.rarithmetic.base_int))
     assert s_T.is_constant()
@@ -396,6 +396,8 @@
         n = 1
     else:
         n = None
+    if s_zero:
+        assert s_zero.is_constant()
     if s_flavor is None:
         p = lltype.malloc(s_T.const, n)
         r = SomePtr(lltype.typeOf(p))
@@ -566,6 +568,11 @@
     assert isinstance(s_addr, SomeAddress)
     assert not s_addr.is_null
 
+def raw_memclear(s_addr, s_int):
+    assert isinstance(s_addr, SomeAddress)
+    assert not s_addr.is_null
+    assert isinstance(s_int, SomeInteger)
+
 def raw_memcopy(s_addr1, s_addr2, s_int):
     assert isinstance(s_addr1, SomeAddress)
     assert not s_addr1.is_null
@@ -576,6 +583,7 @@
 BUILTIN_ANALYZERS[lladdress.raw_malloc] = raw_malloc
 BUILTIN_ANALYZERS[lladdress.raw_malloc_usage] = raw_malloc_usage
 BUILTIN_ANALYZERS[lladdress.raw_free] = raw_free
+BUILTIN_ANALYZERS[lladdress.raw_memclear] = raw_memclear
 BUILTIN_ANALYZERS[lladdress.raw_memcopy] = raw_memcopy
 
 #_________________________________

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/llinterp.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/llinterp.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/llinterp.py	Tue Aug 29 23:08:43 2006
@@ -544,6 +544,10 @@
         else:
             return self.heap.malloc(obj)
 
+    def op_zero_malloc(self, obj):
+        assert self.llinterpreter.gc is None
+        return self.heap.malloc(obj, zero=True)
+
     def op_malloc_varsize(self, obj, size):
         if self.llinterpreter.gc is not None:
             args = self.llinterpreter.gc.get_arg_malloc(obj, size)
@@ -556,6 +560,10 @@
             except MemoryError:
                 self.make_llexception()
 
+    def op_zero_malloc_varsize(self, obj, size):
+        assert self.llinterpreter.gc is None
+        return self.heap.malloc(obj, size, zero=True)
+
     def op_flavored_malloc(self, flavor, obj):
         assert isinstance(flavor, str)
         if flavor == "stack":
@@ -665,6 +673,10 @@
         checkadr(addr) 
         self.heap.raw_free(addr)
 
+    def op_raw_memclear(self, addr, size):
+        checkadr(addr)
+        self.heap.raw_memclear(addr, size)
+
     def op_raw_memcopy(self, fromaddr, toaddr, size):
         checkadr(fromaddr)
         checkadr(toaddr)

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/ll_str.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/ll_str.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/ll_str.py	Tue Aug 29 23:08:43 2006
@@ -26,6 +26,7 @@
             len += 1
     len += sign
     result = malloc(STR, len)
+    result.hash = 0
     if sign:
         result.chars[0] = '-'
         j = 1
@@ -61,6 +62,7 @@
     if addPrefix:
         len += 2
     result = malloc(STR, len)
+    result.hash = 0
     j = 0
     if sign:
         result.chars[0] = '-'
@@ -78,6 +80,7 @@
     from pypy.rpython.lltypesystem.rstr import STR
     if i == 0:
         result = malloc(STR, 1)
+        result.hash = 0
         result.chars[0] = '0'
         return result
     temp = malloc(CHAR_ARRAY, 25)
@@ -94,6 +97,7 @@
     if addPrefix:
         len += 1
     result = malloc(STR, len)
+    result.hash = 0
     j = 0
     if sign:
         result.chars[0] = '-'

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/llheap.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/llheap.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/llheap.py	Tue Aug 29 23:08:43 2006
@@ -2,5 +2,5 @@
 
 from pypy.rpython.lltypesystem.lltype import pyobjectptr, malloc, free
 from pypy.rpython.lltypesystem.llmemory import raw_malloc, raw_free
-from pypy.rpython.lltypesystem.llmemory import raw_memcopy
+from pypy.rpython.lltypesystem.llmemory import raw_memclear, raw_memcopy
 from pypy.rpython.lltypesystem.llmemory import raw_malloc_usage

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/llmemory.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/llmemory.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/llmemory.py	Tue Aug 29 23:08:43 2006
@@ -56,11 +56,11 @@
         if (isinstance(self.TYPE, lltype.ContainerType)
             and self.TYPE._gckind == 'gc'):
             assert self.repeat == 1
-            p = lltype.malloc(self.TYPE)
+            p = lltype.malloc(self.TYPE, flavor='raw')
             return cast_ptr_to_adr(p)
         else:
             T = lltype.FixedSizeArray(self.TYPE, self.repeat)
-            p = lltype.malloc(T, immortal=True)
+            p = lltype.malloc(T, flavor='raw')
             array_adr = cast_ptr_to_adr(p)
             return array_adr + ArrayItemsOffset(T)
 
@@ -559,6 +559,14 @@
         size = convert_offset_to_int(size)
     return size
 
+def raw_memclear(adr, size):
+    # hack hack hack
+    obj = adr.get()
+    TYPE = lltype.typeOf(obj)
+    fresh = lltype.malloc(TYPE.TO, zero=True, flavor='raw')
+    from pypy.rpython.rctypes.rmodel import reccopy
+    reccopy(fresh, obj)
+
 def raw_memcopy(source, dest, size):
     source = source.get()
     dest = dest.get()

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/lloperation.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/lloperation.py	Tue Aug 29 23:08:43 2006
@@ -290,7 +290,9 @@
     # __________ pointer operations __________
 
     'malloc':               LLOp(canraise=(MemoryError,), canunwindgc=True),
+    'zero_malloc':          LLOp(canraise=(MemoryError,), canunwindgc=True),
     'malloc_varsize':       LLOp(canraise=(MemoryError,), canunwindgc=True),
+    'zero_malloc_varsize':  LLOp(canraise=(MemoryError,), canunwindgc=True),
     'flavored_malloc':      LLOp(canraise=(MemoryError,)),
     'flavored_free':        LLOp(),
     'getfield':             LLOp(sideeffects=False),
@@ -322,6 +324,7 @@
     'raw_malloc':           LLOp(canraise=(MemoryError,)),
     'raw_malloc_usage':     LLOp(sideeffects=False),
     'raw_free':             LLOp(),
+    'raw_memclear':         LLOp(),
     'raw_memcopy':          LLOp(),
     'raw_load':             LLOp(sideeffects=False),
     'raw_store':            LLOp(),

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/lltype.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/lltype.py	Tue Aug 29 23:08:43 2006
@@ -14,6 +14,13 @@
 
 TLS = tlsobject()
 
+class _uninitialized(object):
+    def __init__(self, TYPE):
+        self.TYPE = TYPE
+    def __repr__(self):
+        return '<Uninitialized %r'%(self.TYPE,)
+        
+
 def saferecursive(func, defl):
     def safe(*args):
         try:
@@ -116,6 +123,10 @@
     def _defl(self, parent=None, parentindex=None):
         raise NotImplementedError
 
+    def _allocate(self, initialization, parent=None, parentindex=None):
+        assert initialization in ('raw', 'malloc', 'example')
+        raise NotImplementedError
+
     def _freeze_(self):
         return True
 
@@ -252,15 +263,19 @@
     def _short_name(self):
         return "%s %s" % (self.__class__.__name__, self._name)
 
-    def _defl(self, parent=None, parentindex=None):
-        return _struct(self, parent=parent, parentindex=parentindex)
+##     def _defl(self, parent=None, parentindex=None):
+##         return _struct(self, parent=parent, parentindex=parentindex)
+
+    def _allocate(self, initialization, parent=None, parentindex=None):
+        return _struct(self, initialization=initialization,
+                       parent=parent, parentindex=parentindex)
 
     def _container_example(self):
         if self._arrayfld is None:
             n = None
         else:
             n = 1
-        return _struct(self, n)
+        return _struct(self, n, initialization='example')
 
 class RttiStruct(Struct):
     _runtime_type_info = None
@@ -356,7 +371,7 @@
     _short_name = saferecursive(_short_name, '...')
 
     def _container_example(self):
-        return _array(self, 1)
+        return _array(self, 1, initialization='example')
 
 class GcArray(Array):
     _gckind = 'gc'
@@ -448,6 +463,9 @@
     def _defl(self, parent=None, parentindex=None):
         return _opaque(self, parent=parent, parentindex=parentindex)
 
+    def _allocate(self, initialization, parent=None, parentindex=None):
+        return self._defl(parent=parent, parentindex=parentindex)
+
 RuntimeTypeInfo = OpaqueType("RuntimeTypeInfo")
 
 class GcOpaqueType(OpaqueType):
@@ -468,6 +486,8 @@
         return False
     def _defl(self, parent=None, parentindex=None):
         return _pyobjheader(parent, parentindex)
+    def _allocate(self, initialization, parent=None, parentindex=None):
+        return self._defl(parent=parent, parentindex=parentindex)
 
 PyObject = PyObjectType()
 
@@ -508,10 +528,17 @@
     def _defl(self, parent=None, parentindex=None):
         return self._default
 
+    def _allocate(self, initialization, parent=None, parentindex=None):
+        if self is not Void and initialization != 'example':
+            return _uninitialized(self)
+        else:
+            return self._default
+
     def _is_atomic(self):
         return True
 
-    _example = _defl
+    def _example(self, parent=None, parentindex=None):
+        return self._default
 
 class Number(Primitive):
 
@@ -577,6 +604,14 @@
     def _defl(self, parent=None, parentindex=None):
         return _ptr(self, None)
 
+    def _allocate(self, initialization, parent=None, parentindex=None):
+        if initialization == 'example':
+            return _ptr(self, None)
+        elif initialization == 'malloc' and self._needsgc():
+            return _ptr(self, None)
+        else:
+            return _uninitialized(self)
+
     def _example(self):
         o = self.TO._container_example()
         return _ptr(self, o, solid=True)
@@ -590,6 +625,8 @@
         return val._TYPE
     except AttributeError:
         tp = type(val)
+        if tp is _uninitialized:
+            raise UninitializedMemoryAccess("typeOf uninitialized value")
         if tp is NoneType:
             return Void   # maybe
         if tp is int:
@@ -826,6 +863,9 @@
 class DelayedPointer(Exception):
     pass
 
+class UninitializedMemoryAccess(Exception):
+    pass
+
 class _ptr(object):
     __slots__ = ('_TYPE', '_T', 
                  '_weak', '_solid',
@@ -919,7 +959,7 @@
     def __getattr__(self, field_name): # ! can only return basic or ptr !
         if isinstance(self._T, Struct):
             if field_name in self._T._flds:
-                o = getattr(self._obj, field_name)
+                o = self._obj._getattr(field_name)
                 return _expose(o, self._solid)
         if isinstance(self._T, ContainerType):
             try:
@@ -1197,11 +1237,11 @@
 
     __slots__ = ()
 
-    def __new__(self, TYPE, n=None, parent=None, parentindex=None):
+    def __new__(self, TYPE, n=None, initialization=None, parent=None, parentindex=None):
         my_variety = _struct_variety(TYPE._names)
         return object.__new__(my_variety)
 
-    def __init__(self, TYPE, n=None, parent=None, parentindex=None):
+    def __init__(self, TYPE, n=None, initialization=None, parent=None, parentindex=None):
         _parentable.__init__(self, TYPE)
         if n is not None and TYPE._arrayfld is None:
             raise TypeError("%r is not variable-sized" % (TYPE,))
@@ -1210,9 +1250,9 @@
         first, FIRSTTYPE = TYPE._first_struct()
         for fld, typ in TYPE._flds.items():
             if fld == TYPE._arrayfld:
-                value = _array(typ, n, parent=self, parentindex=fld)
+                value = _array(typ, n, initialization=initialization, parent=self, parentindex=fld)
             else:
-                value = typ._defl(parent=self, parentindex=fld)
+                value = typ._allocate(initialization=initialization, parent=self, parentindex=fld)
             setattr(self, fld, value)
         if parent is not None:
             self._setparentstructure(parent, parentindex)
@@ -1231,7 +1271,7 @@
         for name in names:
             T = self._TYPE._flds[name]
             if isinstance(T, Primitive):
-                reprvalue = repr(getattr(self, name))
+                reprvalue = repr(getattr(self, name, '<uninitialized>'))
             else:
                 reprvalue = '...'
             fields.append('%s=%s' % (name, reprvalue))
@@ -1247,18 +1287,26 @@
 
     __setstate__ = setstate_with_slots
 
-    def getlength(self):              # for FixedSizeArray kind of structs
+    def _getattr(self, field_name, uninitialized_ok=False):
+        r = getattr(self, field_name)
+        if isinstance(r, _uninitialized) and not uninitialized_ok:
+            raise UninitializedMemoryAccess("%r.%s"%(self, field_name))
+        return r
+    
+    # for FixedSizeArray kind of structs:
+    
+    def getlength(self):
         assert isinstance(self._TYPE, FixedSizeArray)
         return self._TYPE.length
 
     def getbounds(self):
         return 0, self.getlength()
 
-    def getitem(self, index):         # for FixedSizeArray kind of structs
+    def getitem(self, index, uninitialized_ok=False):
         assert isinstance(self._TYPE, FixedSizeArray)
-        return getattr(self, 'item%d' % index)
+        return self._getattr('item%d' % index, uninitialized_ok)
 
-    def setitem(self, index, value):  # for FixedSizeArray kind of structs
+    def setitem(self, index, value):
         assert isinstance(self._TYPE, FixedSizeArray)
         setattr(self, 'item%d' % index, value)
 
@@ -1274,13 +1322,13 @@
 
     __slots__ = ('items',)
 
-    def __init__(self, TYPE, n, parent=None, parentindex=None):
+    def __init__(self, TYPE, n, initialization=None, parent=None, parentindex=None):
         if not isinstance(n, int):
             raise TypeError, "array length must be an int"
         if n < 0:
             raise ValueError, "negative array length"
         _parentable.__init__(self, TYPE)
-        self.items = [TYPE.OF._defl(parent=self, parentindex=j)
+        self.items = [TYPE.OF._allocate(initialization=initialization, parent=self, parentindex=j)
                       for j in range(n)]
         if parent is not None:
             self._setparentstructure(parent, parentindex)
@@ -1289,6 +1337,8 @@
         return '<%s>' % (self,)
 
     def _str_item(self, item):
+        if isinstance(item, _uninitialized):
+            return '#'
         if isinstance(self._TYPE.OF, Struct):
             of = self._TYPE.OF
             if self._TYPE._anonym_struct:
@@ -1321,9 +1371,12 @@
             stop += 1
         return 0, stop
 
-    def getitem(self, index):
+    def getitem(self, index, uninitialized_ok=False):
         try:
-            return self.items[index]
+            v = self.items[index]
+            if isinstance(v, _uninitialized) and not uninitialized_ok:
+                raise UninitializedMemoryAccess("%r[%s]"%(self, index))
+            return v
         except IndexError:
             if (self._TYPE._hints.get('isrpystring', False) and
                 index == len(self.items)):
@@ -1506,11 +1559,17 @@
         return "pyobjheader of type %r" % (getattr(self, 'ob_type', '???'),)
 
 
-def malloc(T, n=None, flavor='gc', immortal=False, extra_args=()):
+def malloc(T, n=None, flavor='gc', immortal=False, extra_args=(), zero=False):
+    if zero or immortal or flavor == 'cpy':
+        initialization = 'example'
+    elif flavor == 'raw':
+        initialization = 'raw'
+    else:
+        initialization = 'malloc'
     if isinstance(T, Struct):
-        o = _struct(T, n)
+        o = _struct(T, n, initialization=initialization)
     elif isinstance(T, Array):
-        o = _array(T, n)
+        o = _array(T, n, initialization=initialization)
     else:
         raise TypeError, "malloc for Structs and Arrays only"
     if T._gckind != 'gc' and not immortal and flavor.startswith('gc'):

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/rclass.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/rclass.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/rclass.py	Tue Aug 29 23:08:43 2006
@@ -440,8 +440,9 @@
                         if attrvalue is None:
                             warning("prebuilt instance %r has no attribute %r" % (
                                     value, name))
-                            continue
-                        llattrvalue = r.convert_desc_or_const(attrvalue)
+                            llattrvalue = r.lowleveltype._defl()
+                        else:
+                            llattrvalue = r.convert_desc_or_const(attrvalue)
                     else:
                         llattrvalue = r.convert_const(attrvalue)
                 setattr(result, mangled_name, llattrvalue)
@@ -517,7 +518,10 @@
                 mangled_name, r = self.allinstancefields[fldname]
                 if r.lowleveltype is Void:
                     continue
-                value = self.classdef.classdesc.read_attribute(fldname, None)
+                if fldname == '_hash_cache_':
+                    value = Constant(0, Signed)
+                else:
+                    value = self.classdef.classdesc.read_attribute(fldname, None)
                 if value is not None:
                     cvalue = inputconst(r.lowleveltype,
                                         r.convert_desc_or_const(value))
@@ -568,6 +572,7 @@
         from pypy.rpython.lltypesystem import rstr
         nameLen = len(instance.typeptr.name)
         nameString = malloc(rstr.STR, nameLen-1)
+        nameString.hash = 0
         i = 0
         while i < nameLen - 1:
             nameString.chars[i] = instance.typeptr.name[i]

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/rdict.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/rdict.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/rdict.py	Tue Aug 29 23:08:43 2006
@@ -458,7 +458,7 @@
     new_size = old_size * 2
     while new_size > DICT_INITSIZE and d.num_items < new_size / 4:
         new_size /= 2
-    d.entries = lltype.malloc(lltype.typeOf(old_entries).TO, new_size)
+    d.entries = lltype.malloc(lltype.typeOf(old_entries).TO, new_size, zero=True)
     d.num_items = 0
     d.num_pristine_entries = new_size
     i = 0
@@ -550,8 +550,8 @@
 
 def ll_newdict(DICT):
     d = lltype.malloc(DICT)
-    d.entries = lltype.malloc(DICT.entries.TO, DICT_INITSIZE)
-    #d.num_items = 0    -- defaults
+    d.entries = lltype.malloc(DICT.entries.TO, DICT_INITSIZE, zero=True)
+    d.num_items = 0
     d.num_pristine_entries = DICT_INITSIZE
     return d
 
@@ -561,8 +561,8 @@
     while n < length_estimate:
         n *= 2
     d = lltype.malloc(DICT)
-    d.entries = lltype.malloc(DICT.entries.TO, n)
-    #d.num_items = 0    -- defaults
+    d.entries = lltype.malloc(DICT.entries.TO, n, zero=True)
+    d.num_items = 0
     d.num_pristine_entries = DICT_INITSIZE
     return d
 
@@ -654,7 +654,7 @@
     DICT = lltype.typeOf(dict).TO
     dictsize = len(dict.entries)
     d = lltype.malloc(DICT)
-    d.entries = lltype.malloc(DICT.entries.TO, dictsize)
+    d.entries = lltype.malloc(DICT.entries.TO, dictsize, zero=True)
     d.num_items = dict.num_items
     d.num_pristine_entries = dict.num_pristine_entries
     if hasattr(DICT, 'fnkeyeq'):   d.fnkeyeq   = dict.fnkeyeq
@@ -676,7 +676,7 @@
     if len(d.entries) == d.num_pristine_entries == DICT_INITSIZE:
         return
     DICT = lltype.typeOf(d).TO
-    d.entries = lltype.malloc(DICT.entries.TO, DICT_INITSIZE)
+    d.entries = lltype.malloc(DICT.entries.TO, DICT_INITSIZE, zero=True)
     d.num_items = 0
     d.num_pristine_entries = DICT_INITSIZE
 

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/rlist.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/rlist.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/rlist.py	Tue Aug 29 23:08:43 2006
@@ -277,8 +277,9 @@
     # XXX consider to have a real realloc
     items = l.items
     newitems = malloc(typeOf(l).TO.items.TO, new_allocated)
-    if allocated < new_allocated:
-        p = allocated - 1
+    before_len = l.length
+    if before_len < new_allocated:
+        p = before_len - 1
     else:
         p = new_allocated - 1
     while p >= 0:

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/rstr.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/rstr.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/rstr.py	Tue Aug 29 23:08:43 2006
@@ -1,6 +1,7 @@
 from weakref import WeakValueDictionary
 from pypy.annotation.pairtype import pairtype
 from pypy.rpython.error import TyperError
+from pypy.rpython.objectmodel import malloc_zero_filled
 from pypy.rpython.robject import PyObjRepr, pyobj_repr
 from pypy.rpython.rarithmetic import _hash_string
 from pypy.rpython.rmodel import inputconst, IntegerRepr
@@ -48,6 +49,7 @@
             p = malloc(STR, len(value))
             for i in range(len(value)):
                 p.chars[i] = value[i]
+            p.hash = 0
             self.ll.ll_strhash(p)   # precompute the hash
             CONST_STR_CACHE[value] = p
             return p
@@ -107,7 +109,11 @@
                                  resulttype=pyobj_repr,
                                  _callable= lambda chars, sz: pyobjectptr(''.join(chars)))
 
-
+def mallocstr(length):
+    r = malloc(STR, length)
+    if not malloc_zero_filled:
+        r.hash = 0
+    return r
 
 # ____________________________________________________________
 #
@@ -120,6 +126,7 @@
 
     def ll_char_mul(ch, times):
         newstr = malloc(STR, times)
+        newstr.hash = 0
         j = 0
         while j < times:
             newstr.chars[j] = ch
@@ -134,6 +141,7 @@
 
     def ll_chr2str(ch):
         s = malloc(STR, 1)
+        s.hash = 0
         s.chars[0] = ch
         return s
 
@@ -154,6 +162,7 @@
         len1 = len(s1.chars)
         len2 = len(s2.chars)
         newstr = malloc(STR, len1 + len2)
+        newstr.hash = 0
         j = 0
         while j < len1:
             newstr.chars[j] = s1.chars[j]
@@ -179,6 +188,7 @@
                 rpos -= 1
         r_len = rpos - lpos + 1
         result = malloc(STR, r_len)
+        result.hash = 0
         i = 0
         j = lpos
         while i < r_len:
@@ -194,6 +204,7 @@
             return emptystr
         i = 0
         result = malloc(STR, s_len)
+        result.hash = 0
         while i < s_len:
             ch = s_chars[i]
             if 'a' <= ch <= 'z':
@@ -209,6 +220,7 @@
             return emptystr
         i = 0
         result = malloc(STR, s_len)
+        result.hash = 0
         while i < s_len:
             ch = s_chars[i]
             if 'A' <= ch <= 'Z':
@@ -229,6 +241,7 @@
             itemslen += len(items[i].chars)
             i += 1
         result = malloc(STR, itemslen + s_len * (num_items - 1))
+        result.hash = 0
         res_chars = result.chars
         res_index = 0
         i = 0
@@ -449,6 +462,7 @@
             itemslen += len(items[i].chars)
             i += 1
         result = malloc(STR, itemslen)
+        result.hash = 0
         res_chars = result.chars
         res_index = 0
         i = 0
@@ -466,6 +480,7 @@
     def ll_join_chars(length, chars):
         num_chars = length
         result = malloc(STR, num_chars)
+        result.hash = 0
         res_chars = result.chars
         i = 0
         while i < num_chars:
@@ -476,6 +491,7 @@
     def ll_stringslice_startonly(s1, start):
         len1 = len(s1.chars)
         newstr = malloc(STR, len1 - start)
+        newstr.hash = 0
         j = 0
         while start < len1:
             newstr.chars[j] = s1.chars[start]
@@ -491,6 +507,7 @@
                 return s1
             stop = len(s1.chars)
         newstr = malloc(STR, stop - start)
+        newstr.hash = 0
         j = 0
         while start < stop:
             newstr.chars[j] = s1.chars[start]
@@ -502,6 +519,7 @@
         newlen = len(s1.chars) - 1
         assert newlen >= 0
         newstr = malloc(STR, newlen)
+        newstr.hash = 0
         j = 0
         while j < newlen:
             newstr.chars[j] = s1.chars[j]
@@ -525,6 +543,7 @@
         while j < strlen:
             if chars[j] == c:
                 item = items[resindex] = malloc(STR, j - i)
+                item.hash = 0
                 newchars = item.chars
                 k = i
                 while k < j:
@@ -534,6 +553,7 @@
                 i = j + 1
             j += 1
         item = items[resindex] = malloc(STR, j - i)
+        item.hash = 0
         newchars = item.chars
         k = i
         while k < j:
@@ -546,6 +566,7 @@
     def ll_replace_chr_chr(s, c1, c2):
         length = len(s.chars)
         newstr = malloc(STR, length)
+        newstr.hash = 0
         src = s.chars
         dst = newstr.chars
         j = 0
@@ -618,6 +639,7 @@
         cTEMP = inputconst(Void, TEMP)
         vtemp = hop.genop("malloc_varsize", [cTEMP, size],
                           resulttype=Ptr(TEMP))
+        # XXX hash
         r_tuple = hop.args_r[1]
         v_tuple = hop.args_v[1]
 

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/test/test_llmemory.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/test/test_llmemory.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/test/test_llmemory.py	Tue Aug 29 23:08:43 2006
@@ -252,6 +252,9 @@
     S = lltype.Struct('S', ('x', lltype.Signed), ('y', lltype.Ptr(T)))
     adr = raw_malloc(sizeof(S))
     s = cast_adr_to_ptr(adr, lltype.Ptr(S))
+    py.test.raises(lltype.UninitializedMemoryAccess, "s.x")
+    raw_memclear(adr, sizeof(S))
+    assert s.x == 0
     assert lltype.typeOf(s) == lltype.Ptr(S)
     s.x = 123
     x_adr = adr + offsetof(S, 'x')
@@ -259,6 +262,28 @@
     x_adr.signed[0] = 124
     assert s.x == 124
 
+def test_llinterp_raw_malloc_struct():
+    T = lltype.GcStruct('T', ('z', lltype.Signed))
+    S = lltype.Struct('S', ('x', lltype.Signed), ('y', lltype.Ptr(T)))
+
+    from pypy.rpython.memory import lladdress # GRUMBLE!
+
+    size = sizeof(S)
+
+    def test_read_uninit():
+        adr = lladdress.raw_malloc(size)
+        s = cast_adr_to_ptr(adr, lltype.Ptr(S))
+        return s.x
+    py.test.raises(lltype.UninitializedMemoryAccess, "interpret(test_read_uninit, [])")
+    def test_read_init():
+        adr = lladdress.raw_malloc(size)
+        lladdress.raw_memclear(adr, size)
+        s = cast_adr_to_ptr(adr, lltype.Ptr(S))
+        return s.x
+    res = interpret(test_read_init, [])
+    assert res == 0
+
+
 def test_raw_malloc_signed():
     adr = raw_malloc(sizeof(lltype.Signed))
     p = cast_adr_to_ptr(adr,
@@ -270,6 +295,20 @@
     py.test.raises(IndexError, "adr.signed[-1]")
     py.test.raises(IndexError, "adr.signed[1]")
 
+def test_raw_malloc_access():
+    S = lltype.GcStruct("S", ('x', lltype.Signed))
+    T = lltype.GcStruct("T", ('y', lltype.Signed), ('s', lltype.Ptr(S)))
+    # regular malloc zeros GC pointers
+    p_t = lltype.malloc(T)
+    assert p_t.s == lltype.nullptr(S)
+    # raw malloc does not
+    p_raw_t = lltype.malloc(T, flavor="raw")
+    py.test.raises(lltype.UninitializedMemoryAccess, "p_raw_t.s")
+    # this sort of raw_malloc too
+    p_raw_t = cast_adr_to_ptr(raw_malloc(sizeof(T)), lltype.Ptr(T))
+    py.test.raises(lltype.UninitializedMemoryAccess, "p_raw_t.s")
+    
+
 def test_raw_malloc_signed_bunch():
     adr = raw_malloc(sizeof(lltype.Signed) * 50)
     p = cast_adr_to_ptr(adr,

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/test/test_lltype.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/test/test_lltype.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/test/test_lltype.py	Tue Aug 29 23:08:43 2006
@@ -10,13 +10,12 @@
     s0 = malloc(S0)
     print s0
     assert typeOf(s0) == Ptr(S0)
-    assert s0.a == 0
-    assert s0.b == 0
-    assert typeOf(s0.a) == Signed
+    py.test.raises(UninitializedMemoryAccess, "s0.a")
     s0.a = 1
     s0.b = s0.a
     assert s0.a == 1
     assert s0.b == 1
+    assert typeOf(s0.a) == Signed
     # simple array
     Ar = GcArray(('v', Signed))
     x = malloc(Ar,0)
@@ -26,11 +25,10 @@
     print x
     assert typeOf(x) == Ptr(Ar)
     assert isweak(x[0], Ar.OF)
-    assert typeOf(x[0].v) == Signed
-    assert x[0].v == 0
     x[0].v = 1
     x[1].v = 2
     x[2].v = 3
+    assert typeOf(x[0].v) == Signed
     assert [x[z].v for z in range(3)] == [1, 2, 3]
     #
     def define_list(T):
@@ -94,10 +92,12 @@
     S1 = GcStruct("s1", ('a', Signed), ('rest', Array(('v', Signed))))
     py.test.raises(TypeError, "malloc(S1)")
     s1 = malloc(S1, 4)
+    s1.a = 0
     assert s1.a == 0
     assert isweak(s1.rest, S1.rest)
     assert len(s1.rest) == 4
     assert isweak(s1.rest[0], S1.rest.OF)
+    s1.rest[0].v = 0
     assert typeOf(s1.rest[0].v) == Signed
     assert s1.rest[0].v == 0
     py.test.raises(IndexError, "s1.rest[4]")
@@ -206,7 +206,6 @@
     S1 = GcStruct("s1", ('sub1', S2), ('sub2', S2), ('tail', Array(('e', Signed))))
     p1 = malloc(S1, 1)
     p2 = p1.sub2
-    assert p2.a == 0
     p3 = p1.tail
     p3[0].e = 1
     assert p3[0].e == 1
@@ -220,8 +219,6 @@
     A1 = GcArray(('v', Signed))
     p1 = malloc(A1, 10)
     p1[5].v=3
-    assert p1[0].v == 0
-    assert p1[9].v == 0
     assert p1[5].v == 3
     p1_5 = p1[5]
     del p1
@@ -327,9 +324,7 @@
     As = GcArray(Signed)
     a = malloc(As, 3)
     assert typeOf(a) == Ptr(As)
-    assert a[0] == 0
-    assert a[1] == 0
-    assert a[2] == 0
+    py.test.raises(UninitializedMemoryAccess, "a[0]")
     a[1] = 3
     assert a[1] == 3
     S = GcStruct('s', ('x', Signed))
@@ -398,10 +393,13 @@
     S = GcStruct('s', ('x', Signed))
     attachRuntimeTypeInfo(S)
     s = malloc(S)
+    s.x = 0
     assert runtime_type_info(s) == getRuntimeTypeInfo(S)
     S1 = GcStruct('s1', ('sub', S), ('x', Signed))
     attachRuntimeTypeInfo(S1)
     s1 = malloc(S1)
+    s1.sub.x = 0
+    s1.x = 0
     assert runtime_type_info(s1) == getRuntimeTypeInfo(S1)
     assert runtime_type_info(s1.sub) == getRuntimeTypeInfo(S1)
     assert runtime_type_info(cast_pointer(Ptr(S), s1)) == getRuntimeTypeInfo(S1)

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/test/test_picklelltype.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/test/test_picklelltype.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/test/test_picklelltype.py	Tue Aug 29 23:08:43 2006
@@ -92,6 +92,9 @@
     S1 = GcStruct("s1", ('a', Signed), ('rest', Array(('v', Signed))))
     py.test.raises(TypeError, "malloc(S1)")
     s1 = malloc(S1, 4)
+    s1.a = 0
+    for i in range(4):
+        s1.rest[i].v = 0
     p_s1 = pickle.dumps(s1)
     r_s1 = pickle.loads(p_s1)
     assert r_s1.a == 0
@@ -166,6 +169,8 @@
 def test_best_effort_gced_parent_for_arrays():
     A1 = GcArray(('v', Signed))
     p1 = malloc(A1, 10)
+    for i in range(10):
+        p1[i].v = 0
     p1[5].v = 3
     p1_5 = p1[5]
     r_p1_5 = pickle.loads(pickle.dumps(p1_5))

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/memory/convertlltype.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/memory/convertlltype.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/memory/convertlltype.py	Tue Aug 29 23:08:43 2006
@@ -119,7 +119,9 @@
             if isinstance(FIELD, (lltype.Struct, lltype.Array)):
                 self.convert(getattr(_struct, name), getattr(ptr, name))
             else:
-                setattr(ptr, name, self.convert(getattr(_struct, name)))
+                v = _struct._getattr(name, uninitialized_ok=True)
+                if not isinstance(v, lltype._uninitialized):
+                    setattr(ptr, name, self.convert(v))
         return ptr
 
     def convert_pointer(self, _ptr, inline_to_ptr):

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/memory/gc.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/memory/gc.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/memory/gc.py	Tue Aug 29 23:08:43 2006
@@ -1,4 +1,4 @@
-from pypy.rpython.memory.lladdress import raw_malloc, raw_free, raw_memcopy
+from pypy.rpython.memory.lladdress import raw_malloc, raw_free, raw_memcopy, raw_memclear
 from pypy.rpython.memory.lladdress import NULL, _address, raw_malloc_usage
 from pypy.rpython.memory.support import get_address_linked_list
 from pypy.rpython.memory.gcheader import GCHeaderBuilder
@@ -196,6 +196,33 @@
         #                 '->', llmemory.cast_adr_to_int(result))
         return llmemory.cast_adr_to_ptr(result, llmemory.GCREF)
 
+    def malloc_fixedsize_clear(self, typeid, size, can_collect, has_finalizer=False):
+        if can_collect and self.bytes_malloced > self.bytes_malloced_threshold:
+            self.collect()
+        size_gc_header = self.gcheaderbuilder.size_gc_header
+        try:
+            tot_size = size_gc_header + size
+            usage = raw_malloc_usage(tot_size)
+            bytes_malloced = ovfcheck(self.bytes_malloced+usage)
+            ovfcheck(self.heap_usage + bytes_malloced)
+        except OverflowError:
+            raise memoryError
+        result = raw_malloc(tot_size)
+        raw_memclear(result, tot_size)
+        hdr = llmemory.cast_adr_to_ptr(result, self.HDRPTR)
+        hdr.typeid = typeid << 1
+        if has_finalizer:
+            hdr.next = self.malloced_objects_with_finalizer
+            self.malloced_objects_with_finalizer = hdr
+        else:
+            hdr.next = self.malloced_objects
+            self.malloced_objects = hdr
+        self.bytes_malloced = bytes_malloced
+        result += size_gc_header
+        #llop.debug_print(lltype.Void, 'malloc typeid', typeid,
+        #                 '->', llmemory.cast_adr_to_int(result))
+        return llmemory.cast_adr_to_ptr(result, llmemory.GCREF)
+
     def malloc_varsize(self, typeid, length, size, itemsize, offset_to_length,
                        can_collect, has_finalizer=False):
         if can_collect and self.bytes_malloced > self.bytes_malloced_threshold:
@@ -228,6 +255,38 @@
         #                 '->', llmemory.cast_adr_to_int(result))
         return llmemory.cast_adr_to_ptr(result, llmemory.GCREF)
 
+    def malloc_varsize_clear(self, typeid, length, size, itemsize, offset_to_length,
+                       can_collect, has_finalizer=False):
+        if can_collect and self.bytes_malloced > self.bytes_malloced_threshold:
+            self.collect()
+        size_gc_header = self.gcheaderbuilder.size_gc_header
+        try:
+            fixsize = size_gc_header + size
+            varsize = ovfcheck(itemsize * length)
+            tot_size = ovfcheck(fixsize + varsize)
+            usage = raw_malloc_usage(tot_size)
+            bytes_malloced = ovfcheck(self.bytes_malloced+usage)
+            ovfcheck(self.heap_usage + bytes_malloced)
+        except OverflowError:
+            raise memoryError
+        result = raw_malloc(tot_size)
+        (result + size_gc_header + offset_to_length).signed[0] = length
+        hdr = llmemory.cast_adr_to_ptr(result, self.HDRPTR)
+        hdr.typeid = typeid << 1
+        if has_finalizer:
+            hdr.next = self.malloced_objects_with_finalizer
+            self.malloced_objects_with_finalizer = hdr
+        else:
+            hdr.next = self.malloced_objects
+            self.malloced_objects = hdr
+        self.bytes_malloced = bytes_malloced
+            
+        result += size_gc_header
+        #llop.debug_print(lltype.Void, 'malloc_varsize length', length,
+        #                 'typeid', typeid,
+        #                 '->', llmemory.cast_adr_to_int(result))
+        return llmemory.cast_adr_to_ptr(result, llmemory.GCREF)
+
     def collect(self):
         # 1. mark from the roots, and also the objects that objects-with-del
         #    point to (using the list of malloced_objects_with_finalizer)

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/memory/gctransform.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/memory/gctransform.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/memory/gctransform.py	Tue Aug 29 23:08:43 2006
@@ -20,6 +20,7 @@
 from pypy.rpython.memory.gcheader import GCHeaderBuilder
 from pypy.rpython.annlowlevel import MixLevelHelperAnnotator
 from pypy.rpython.extregistry import ExtRegistryEntry
+from pypy.rpython.rtyper import LowLevelOpList
 import sets, os
 
 def var_ispyobj(var):
@@ -905,10 +906,20 @@
              annmodel.SomeInteger(nonneg=True),
              annmodel.SomeBool(), annmodel.SomeBool()], s_gcref,
             inline = False)
+##         self.malloc_fixedsize_clear_ptr = getfn(
+##             GCClass.malloc_fixedsize_clear.im_func,
+##             [s_gc, annmodel.SomeInteger(nonneg=True),
+##              annmodel.SomeInteger(nonneg=True),
+##              annmodel.SomeBool(), annmodel.SomeBool()], s_gcref,
+##             inline = False)
         self.malloc_varsize_ptr = getfn(
             GCClass.malloc_varsize.im_func,
             [s_gc] + [annmodel.SomeInteger(nonneg=True) for i in range(5)]
             + [annmodel.SomeBool(), annmodel.SomeBool()], s_gcref)
+##         self.malloc_varsize_clear_ptr = getfn(
+##             GCClass.malloc_varsize_clear.im_func,
+##             [s_gc] + [annmodel.SomeInteger(nonneg=True) for i in range(5)]
+##             + [annmodel.SomeBool(), annmodel.SomeBool()], s_gcref)
         self.collect_ptr = getfn(GCClass.collect.im_func,
             [s_gc], annmodel.s_None)
 
@@ -960,6 +971,7 @@
             _alloc_flavor_ = 'raw'
             def setup_root_stack():
                 stackbase = lladdress.raw_malloc(rootstacksize)
+                #lladdress.raw_memclear(stackbase, rootstacksize)
                 gcdata.root_stack_top  = stackbase
                 gcdata.root_stack_base = stackbase
                 i = 0
@@ -1195,26 +1207,40 @@
         info = self.type_info_list[type_id]
         c_size = rmodel.inputconst(lltype.Signed, info["fixedsize"])
         if not op.opname.endswith('_varsize'):
-            args = [self.malloc_fixedsize_ptr, self.c_const_gc, c_type_id,
-                    c_size, c_can_collect]
+            malloc_ptr = self.malloc_fixedsize_ptr
+##             if op.opname.startswith('zero'):
+##                 malloc_ptr = self.malloc_fixedsize_clear_ptr
+##             else:
+##                 malloc_ptr = self.malloc_fixedsize_ptr
+            args = [self.c_const_gc, c_type_id, c_size, c_can_collect]
         else:
             v_length = op.args[-1]
             c_ofstolength = rmodel.inputconst(lltype.Signed, info['ofstolength'])
             c_varitemsize = rmodel.inputconst(lltype.Signed, info['varitemsize'])
-            args = [self.malloc_varsize_ptr, self.c_const_gc, c_type_id,
-                    v_length, c_size, c_varitemsize, c_ofstolength,
-                    c_can_collect]
+            malloc_ptr = self.malloc_varsize_ptr
+##             if op.opname.startswith('zero'):
+##                 p = self.malloc_varsize_clear_ptr
+##             else:
+##                 p = self.malloc_varsize_clear_ptr
+            args = [self.c_const_gc, c_type_id, v_length, c_size,
+                    c_varitemsize, c_ofstolength, c_can_collect]
         c_has_finalizer = rmodel.inputconst(
             lltype.Bool, bool(self.finalizer_funcptr_for_type(TYPE)))
         args.append(c_has_finalizer)
         v = varoftype(llmemory.GCREF)
-        newop = SpaceOperation("direct_call", args, v)
+        newop = SpaceOperation("direct_call", [malloc_ptr] + args, v)
         ops, index = self.protect_roots(newop, livevars, block,
                                         block.operations.index(op))
         ops.append(SpaceOperation("cast_opaque_ptr", [v], op.result))
+        if malloc_ptr == self.malloc_fixedsize_ptr:
+            llops = LowLevelOpList(None)
+            gen_zero_gc_pointers(TYPE, op.result, llops)
+            ops.extend(llops)            
         return ops
 
+    replace_zero_malloc = replace_malloc
     replace_malloc_varsize = replace_malloc
+    replace_zero_malloc_varsize = replace_malloc
     replace_flavored_malloc = replace_malloc
     replace_flavored_malloc_varsize = replace_malloc
 
@@ -1314,6 +1340,21 @@
         offsets.append(0)
     return offsets
 
+def gen_zero_gc_pointers(TYPE, v, llops):
+    assert isinstance(TYPE, lltype.Struct)
+    for name in TYPE._names:
+        FIELD = getattr(TYPE, name)
+        if isinstance(FIELD, lltype.Ptr) and FIELD._needsgc():
+            c_name = Constant(name, lltype.Void)
+            c_null = Constant(lltype.nullptr(FIELD.TO), FIELD)
+            llops.genop('bare_setfield', [v, c_name, c_null])
+        elif isinstance(FIELD, lltype.Struct):
+            c_name = Constant(name, lltype.Void)
+            v1 = llops.genop('getsubstruct', [v, c_name],
+                             resulttype = lltype.Ptr(FIELD))
+            gen_zero_gc_pointers(FIELD, v1, llops)
+
+
 # ____________________________________________________________
 
 

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/memory/lladdress.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/memory/lladdress.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/memory/lladdress.py	Tue Aug 29 23:08:43 2006
@@ -128,6 +128,9 @@
 def raw_free(addr):
     simulator.free(addr.intaddress)
 
+def raw_memclear(addr, size):
+    simulator.memclear(addr.intaddress, size)
+
 def raw_memcopy(addr1, addr2, size):
     simulator.memcopy(addr1.intaddress, addr2.intaddress, size)
 

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/memory/simulator.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/memory/simulator.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/memory/simulator.py	Tue Aug 29 23:08:43 2006
@@ -58,6 +58,9 @@
         other.memory[offset2:offset2+size] = self.memory[offset1:offset1+size]
         other.status[offset2:offset2+size] = self.status[offset1:offset1+size]
 
+    def memclear(self, offset, size):
+        self.setbytes(offset, "\x00" * size)
+
 
 # block which stores functions and PyObects
 class ObjectBlock(object):
@@ -150,6 +153,9 @@
         offset2 = address2 - block2.baseaddress
         block1.memcopy(offset1, block2, offset2, size)
 
+    def memclear(self, offset, size):
+        self.setbytes(offset, "\x00" * size)
+
     def get_py_object(self, address):
         block = self.objectblock
         offset = address - block.baseaddress

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/memory/support.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/memory/support.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/memory/support.py	Tue Aug 29 23:08:43 2006
@@ -16,6 +16,8 @@
                                    llmemory.Address, chunk_size))))
     null_chunk = lltype.nullptr(CHUNK)
 
+##     SIZEOF_CHUNK = llmemory.sizeof(CHUNK)
+
     class FreeList(object):
         _alloc_flavor_ = "raw"
 
@@ -24,7 +26,11 @@
 
         def get(self):
             if not self.free_list:
-                return lltype.malloc(CHUNK, flavor='raw')
+                r = lltype.malloc(CHUNK, flavor="raw")
+##                 from pypy.rpython.memory.lladdress import raw_memclear
+##                 raw_memclear(llmemory.cast_ptr_to_adr(r), SIZEOF_CHUNK)
+                return r
+                
             result = self.free_list
             self.free_list = result.previous
             return result

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/objectmodel.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/objectmodel.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/objectmodel.py	Tue Aug 29 23:08:43 2006
@@ -52,7 +52,7 @@
         from pypy.rpython.lltypesystem import lltype
         return lltype.Signed
     
-malloc_zero_filled = CDefinedIntSymbolic('MALLOC_ZERO_FILLED', default=1)
+malloc_zero_filled = CDefinedIntSymbolic('MALLOC_ZERO_FILLED', default=0)
 
 def instantiate(cls):
     "Create an empty instance of 'cls'."

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/rbuiltin.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/rbuiltin.py	Tue Aug 29 23:08:43 2006
@@ -330,15 +330,19 @@
 BUILTIN_TYPER[object.__init__] = rtype_object__init__
 # annotation of low-level types
 
-def rtype_malloc(hop, i_flavor=None, i_extra_args=None):
+def rtype_malloc(hop, i_flavor=None, i_extra_args=None, i_zero=None):
     assert hop.args_s[0].is_constant()
     vlist = [hop.inputarg(lltype.Void, arg=0)]
     opname = 'malloc'
-    v_flavor, v_extra_args = parse_kwds(hop, (i_flavor, lltype.Void),
-                                             (i_extra_args, None))
+    v_flavor, v_extra_args, v_zero = parse_kwds(hop, (i_flavor, lltype.Void),
+                                                     (i_extra_args, None),
+                                                     (i_zero, None))
     if v_flavor is not None:
         vlist.insert(0, v_flavor)
         opname = 'flavored_' + opname
+    if i_zero is not None:
+        assert i_extra_args is i_flavor is None
+        opname = 'zero_' + opname
     if hop.nb_args == 2:
         vlist.append(hop.inputarg(lltype.Signed, arg=1))
         opname += '_varsize'
@@ -563,9 +567,14 @@
     v_list = hop.inputargs(llmemory.Address, llmemory.Address, lltype.Signed)
     return hop.genop('raw_memcopy', v_list)
 
+def rtype_raw_memclear(hop):
+    v_list = hop.inputargs(llmemory.Address, lltype.Signed)
+    return hop.genop('raw_memclear', v_list)
+
 BUILTIN_TYPER[lladdress.raw_malloc] = rtype_raw_malloc
 BUILTIN_TYPER[lladdress.raw_malloc_usage] = rtype_raw_malloc_usage
 BUILTIN_TYPER[lladdress.raw_free] = rtype_raw_free
+BUILTIN_TYPER[lladdress.raw_memclear] = rtype_raw_memclear
 BUILTIN_TYPER[lladdress.raw_memcopy] = rtype_raw_memcopy
 
 def rtype_offsetof(hop):

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/rctypes/astringbuf.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/rctypes/astringbuf.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/rctypes/astringbuf.py	Tue Aug 29 23:08:43 2006
@@ -34,7 +34,7 @@
         [v_length] = hop.inputargs(lltype.Signed)
         r_stringbuf = hop.r_result
         hop.exception_cannot_occur()
-        return hop.genop("malloc_varsize", [
+        return hop.genop("zero_malloc_varsize", [
             hop.inputconst(lltype.Void, r_stringbuf.lowleveltype.TO),
             v_length,
             ], resulttype=r_stringbuf.lowleveltype,

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/rctypes/rarray.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/rctypes/rarray.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/rctypes/rarray.py	Tue Aug 29 23:08:43 2006
@@ -155,6 +155,7 @@
     p = box.c_data
     length = rchar_p.ll_strnlen(lltype.direct_arrayitems(p), len(p))
     newstr = lltype.malloc(string_repr.lowleveltype.TO, length)
+    newstr.hash = 0
     for i in range(length):
         newstr.chars[i] = p[i]
     return newstr

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/rctypes/rchar_p.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/rctypes/rchar_p.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/rctypes/rchar_p.py	Tue Aug 29 23:08:43 2006
@@ -119,6 +119,7 @@
         return lltype.nullptr(string_repr.lowleveltype.TO)
     length = ll_strlen(p)
     newstr = lltype.malloc(string_repr.lowleveltype.TO, length)
+    newstr.hash = 0
     for i in range(length):
         newstr.chars[i] = p[i]
     return newstr
@@ -135,6 +136,7 @@
         else:
             length = ll_strlen(p)
         newstr = lltype.malloc(string_repr.lowleveltype.TO, length)
+        newstr.hash = 0
         for i in range(length):
             newstr.chars[i] = p[i]
         return newstr

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/rctypes/rmodel.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/rctypes/rmodel.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/rctypes/rmodel.py	Tue Aug 29 23:08:43 2006
@@ -86,14 +86,14 @@
             return self.const_cache[key][0]
         except KeyError:
             self.setup()
-            p = lltype.malloc(self.r_memoryowner.lowleveltype.TO)
+            p = lltype.malloc(self.r_memoryowner.lowleveltype.TO, zero=True)
             self.initialize_const(p, value)
             if self.ownsmemory:
                 result = p
             else:
                 # we must return a non-memory-owning box that keeps the
                 # memory-owning box alive
-                result = lltype.malloc(self.lowleveltype.TO)
+                result = lltype.malloc(self.lowleveltype.TO, zero=True)
                 result.c_data = p.c_data    # initialize c_data pointer
                 result.c_data_owner_keepalive = p
             self.const_cache[key] = result, keepalive
@@ -123,14 +123,14 @@
         if TYPE._is_varsize():
             raise TyperError("allocating array with unknown length")
         c1 = inputconst(lltype.Void, TYPE)
-        return llops.genop("malloc", [c1], resulttype=self.lowleveltype)
+        return llops.genop("zero_malloc", [c1], resulttype=self.lowleveltype)
 
     def allocate_instance_varsize(self, llops, v_length):
         TYPE = self.lowleveltype.TO
         if not TYPE._is_varsize():
             raise TyperError("allocating non-array with a specified length")
         c1 = inputconst(lltype.Void, TYPE)
-        return llops.genop("malloc_varsize", [c1, v_length],
+        return llops.genop("zero_malloc_varsize", [c1, v_length],
                            resulttype=self.lowleveltype)
 
     def allocate_instance_ref(self, llops, v_c_data, v_c_data_owner=None):
@@ -277,8 +277,9 @@
                 subdst = dest[i]
                 reccopy(subsrc, subdst)
             else:
-                llvalue = source[i]
-                dest[i] = llvalue
+                # this is a hack XXX de-hack this
+                llvalue = source._obj.getitem(i, uninitialized_ok=True)
+                dest._obj.setitem(i, llvalue)
     elif isinstance(T, lltype.Struct):
         for name in T._names:
             FIELDTYPE = getattr(T, name)
@@ -287,8 +288,9 @@
                 subdst = getattr(dest,   name)
                 reccopy(subsrc, subdst)
             else:
-                llvalue = getattr(source, name)
-                setattr(dest, name, llvalue)
+                # this is a hack XXX de-hack this
+                llvalue = source._obj._getattr(name, uninitialized_ok=True)
+                setattr(dest._obj, name, llvalue)
     else:
         raise TypeError(T)
 

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/rctypes/rstringbuf.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/rctypes/rstringbuf.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/rctypes/rstringbuf.py	Tue Aug 29 23:08:43 2006
@@ -102,6 +102,7 @@
         start = stop
     newlength = stop - start
     newstr = lltype.malloc(string_repr.lowleveltype.TO, newlength)
+    newstr.hash = 0
     for i in range(newlength):
         newstr.chars[i] = sbuf[start + i]
     return newstr
@@ -122,6 +123,7 @@
     p = box.c_data
     length = len(p)
     newstr = lltype.malloc(string_repr.lowleveltype.TO, length)
+    newstr.hash = 0
     for i in range(length):
         newstr.chars[i] = p[i]
     return newstr

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/test/test_llinterp.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/test/test_llinterp.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/test/test_llinterp.py	Tue Aug 29 23:08:43 2006
@@ -1,4 +1,3 @@
-
 import py
 from pypy.rpython.lltypesystem.lltype import typeOf, pyobjectptr, Ptr, PyObject, Void
 from pypy.rpython.lltypesystem.lloperation import llop

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/test/test_rdict.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/test/test_rdict.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/test/test_rdict.py	Tue Aug 29 23:08:43 2006
@@ -513,6 +513,7 @@
             p = lltype.malloc(rstr.STR, len(value))
             for i in range(len(value)):
                 p.chars[i] = value[i]
+            p.hash = 0
             return rstr.LLHelpers.ll_strhash(p) 
 
         def func(c1, c2): 

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/test/test_rstr.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/test/test_rstr.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/test/test_rstr.py	Tue Aug 29 23:08:43 2006
@@ -600,6 +600,7 @@
         p = malloc(STR, len(s))
         for i in range(len(s)):
             p.chars[i] = s[i]
+        p.hash = 0
         return p
 
     def test_ll_find_rfind(self):

Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/test/tool.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/test/tool.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/test/tool.py	Tue Aug 29 23:08:43 2006
@@ -29,7 +29,11 @@
         return LLSupport.to_rstr(s)
 
     def ll_to_list(self, l):
-        return map(None, l.ll_items())[:l.ll_length()]
+        r = []
+        items = l.ll_items()
+        for i in range(l.ll_length()):
+            r.append(items[i])
+        return r
 
     def get_callable(self, fnptr):
         return fnptr._obj._callable

Modified: pypy/branch/no-zeroing-assumption-3/pypy/translator/c/database.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/translator/c/database.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/translator/c/database.py	Tue Aug 29 23:08:43 2006
@@ -1,7 +1,7 @@
 from pypy.rpython.lltypesystem.lltype import \
      Primitive, Ptr, typeOf, RuntimeTypeInfo, \
      Struct, Array, FuncType, PyObject, Void, \
-     ContainerType, OpaqueType, FixedSizeArray
+     ContainerType, OpaqueType, FixedSizeArray, _uninitialized
 from pypy.rpython.lltypesystem import lltype
 from pypy.rpython.lltypesystem.llmemory import Address
 from pypy.rpython.memory.lladdress import NULL
@@ -282,6 +282,8 @@
 
         def add_dependencies(newdependencies):
             for value in newdependencies:
+                #if isinstance(value, _uninitialized):
+                #    continue
                 if isinstance(typeOf(value), ContainerType):
                     self.getcontainernode(value)
                 else:

Modified: pypy/branch/no-zeroing-assumption-3/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/translator/c/funcgen.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/translator/c/funcgen.py	Tue Aug 29 23:08:43 2006
@@ -500,7 +500,7 @@
                                      self.expr(op.args[0]),
                                      self.expr(op.args[1]))
 
-    def OP_MALLOC(self, op):
+    def OP_ZERO_MALLOC(self, op):
         TYPE = self.lltypemap(op.result).TO
         typename = self.db.gettype(TYPE)
         eresult = self.expr(op.result)
@@ -508,6 +508,16 @@
 
         return self.gcpolicy.zero_malloc(TYPE, esize, eresult)
 
+    def OP_MALLOC(self, op):
+        TYPE = self.lltypemap(op.result).TO
+        typename = self.db.gettype(TYPE)
+        eresult = self.expr(op.result)
+        esize = 'sizeof(%s)' % cdecl(typename, '')
+
+        return self.gcpolicy.malloc(TYPE, esize, eresult)
+
+    OP_ZERO_MALLOC = OP_MALLOC
+    
     def OP_MALLOC_VARSIZE(self, op):
         TYPE = self.lltypemap(op.result).TO
         typename = self.db.gettype(TYPE)
@@ -546,6 +556,8 @@
         result += '\n}'
         return result
 
+    OP_ZERO_MALLOC_VARSIZE = OP_MALLOC_VARSIZE
+    
     def OP_RAW_MALLOC(self, op):
         eresult = self.expr(op.result)
         esize = self.expr(op.args[0])

Modified: pypy/branch/no-zeroing-assumption-3/pypy/translator/c/gc.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/translator/c/gc.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/translator/c/gc.py	Tue Aug 29 23:08:43 2006
@@ -103,6 +103,8 @@
         erestype = cdecl(typename, '*')
         return 'OP_ZERO_MALLOC(%s, %s, %s);' % (esize, eresult, erestype)
 
+    malloc = zero_malloc
+
     def OP_GC_CALL_RTTI_DESTRUCTOR(self, funcgen, op):
         args = [funcgen.expr(v) for v in op.args]
         line = '%s(%s);' % (args[0], ', '.join(args[1:]))
@@ -194,6 +196,8 @@
                        % (eresult, gcinfo.finalizer))
         return result
 
+    malloc = zero_malloc
+
     def gc_libraries(self):
         if sys.platform == 'win32':
             return ['gc_pypy']
@@ -339,11 +343,14 @@
                 TYPE, esize, eresult)
         return result
 
+    malloc = zero_malloc
+
 # to get an idea how it looks like with no refcount/gc at all
 
 class NoneGcPolicy(BoehmGcPolicy):
 
     zero_malloc = RefcountingGcPolicy.zero_malloc.im_func
+    malloc = RefcountingGcPolicy.malloc.im_func
     gc_libraries = RefcountingGcPolicy.gc_libraries.im_func
     gc_startup_code = RefcountingGcPolicy.gc_startup_code.im_func
 
@@ -396,10 +403,9 @@
         return defnode.db.gctransformer.gc_field_values_for(o)
 
     def zero_malloc(self, TYPE, esize, eresult):
-        assert TYPE._gckind == 'gc'   # we don't really support this
-        typename = self.db.gettype(TYPE)
-        erestype = cdecl(typename, '*')
-        return 'OP_ZERO_MALLOC(%s, %s, %s);' % (esize, eresult, erestype)
+        assert False, "a malloc operation in a framework build??"
+
+    malloc = zero_malloc
 
 class StacklessFrameworkGcPolicy(FrameworkGcPolicy):
     transformerclass = gctransform.StacklessFrameworkGCTransformer

Modified: pypy/branch/no-zeroing-assumption-3/pypy/translator/c/src/mem.h
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/translator/c/src/mem.h	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/translator/c/src/mem.h	Tue Aug 29 23:08:43 2006
@@ -2,7 +2,40 @@
 /************************************************************/
  /***  C header subsection: operations on LowLevelTypes    ***/
 
-#define OP_RAW_MALLOC(size,r,restype) OP_ZERO_MALLOC(size, r, restype)
+#define RAW_MALLOC_ZERO_FILLED 1
+
+#if RAW_MALLOC_ZERO_FILLED
+
+#define OP_RAW_MALLOC(size, r, restype)  {				\
+		r = (restype) PyObject_Malloc(size);			\
+		if (r == NULL) {					\
+			FAIL_EXCEPTION(PyExc_MemoryError,		\
+				       "out of memory");		\
+		} 							\
+		else {							\
+			memset((void*)r, 0, size);			\
+			COUNT_MALLOC;					\
+		}							\
+	}
+
+#else
+
+#define OP_RAW_MALLOC(size, r, restype)  {				\
+		r = (restype) PyObject_Malloc(size);			\
+		if (r == NULL) {					\
+			FAIL_EXCEPTION(PyExc_MemoryError,		\
+				       "out of memory");		\
+		} 							\
+		else {							\
+			COUNT_MALLOC;					\
+		}							\
+	}
+
+#endif
+
+#define OP_RAW_FREE(p, r) PyObject_Free(p); COUNT_FREE;
+
+#define OP_RAW_MEMCLEAR(p, size, r) memset((void*)p, 0, size)
 
 #define OP_RAW_MALLOC_USAGE(size, r) r = size
 
@@ -10,14 +43,17 @@
 #define alloca  _alloca
 #endif
 
+#ifdef USING_BOEHM_GC
+#define MALLOC_ZERO_FILLED 1
+#else
 #define MALLOC_ZERO_FILLED 1
+#endif
 
 #define OP_STACK_MALLOC(size,r,restype)                                 \
     r = (restype) alloca(size);                                         \
     if (r == NULL) FAIL_EXCEPTION(PyExc_MemoryError, "out of memory");  \
     memset((void*) r, 0, size);
 
-#define OP_RAW_FREE(x,r)           OP_FREE(x)
 #define OP_RAW_MEMCOPY(x,y,size,r) memcpy(y,x,size);
 
 /************************************************************/
@@ -41,16 +77,20 @@
    other globals, plus one.  This upper bound "approximation" will do... */
 #define REFCOUNT_IMMORTAL  (INT_MAX/2)
 
-#define OP_ZERO_MALLOC(size, r, restype)  {                                      \
-    r = (restype) PyObject_Malloc(size);                                  \
-    if (r == NULL) {FAIL_EXCEPTION(PyExc_MemoryError, "out of memory"); } \
-    else {                                                              \
-        memset((void*) r, 0, size);                                     \
-        COUNT_MALLOC;                                                   \
-    }                                                                   \
-  }
+#if RAW_MALLOC_ZERO_FILLED
+
+#define OP_ZERO_MALLOC OP_RAW_MALLOC
+
+#else
 
-#define OP_FREE(p)	{ PyObject_Free(p); COUNT_FREE; }
+#define OP_ZERO_MALLOC(size, r, restype)  {				\
+		OP_RAW_MALLOC(size, r, restype);			\
+		if (r != NULL) OP_RAW_MEMCLEAR(r, size, /* */);		\
+	}
+
+#endif
+
+#define OP_FREE(p)	OP_RAW_FREE(p, do_not_use)
 
 /*------------------------------------------------------------*/
 #ifndef COUNT_OP_MALLOCS
@@ -106,33 +146,15 @@
 
 #endif /* USING_BOEHM_GC */
 
-/* for no GC */
-#ifdef USING_NO_GC
-
-#undef OP_ZERO_MALLOC
-
-#define OP_ZERO_MALLOC(size, r, restype)  {                                 \
-    r = (restype) malloc(size);                                  \
-    if (r == NULL) { FAIL_EXCEPTION(PyExc_MemoryError, "out of memory"); } \
-    else {                                                                  \
-        memset((void*) r, 0, size);                                         \
-        COUNT_MALLOC;                                                       \
-    }                                                                       \
-  }
-
-#undef PUSH_ALIVE
-#define PUSH_ALIVE(obj)
-
-#endif /* USING_NO_GC */
-
 /************************************************************/
 /* rcpy support */
 
-#define OP_CPY_MALLOC(cpytype, r, restype)  {                            \
-    /* XXX add tp_itemsize later */                             \
-    OP_RAW_MALLOC(((PyTypeObject *)cpytype)->tp_basicsize, r, restype);  \
-    if (r) {                                                    \
-        PyObject_Init((PyObject *)r, (PyTypeObject *)cpytype);  \
-    }                                                           \
-  }
+#define OP_CPY_MALLOC(cpytype, r, restype)  {			\
+	/* XXX add tp_itemsize later */				\
+	OP_RAW_MALLOC(((PyTypeObject *)cpytype)->tp_basicsize, r, restype); \
+	if (r) {						\
+	    OP_RAW_MEMCLEAR(r, ((PyTypeObject *)cpytype)->tp_basicsize, /* */); \
+	    PyObject_Init((PyObject *)r, (PyTypeObject *)cpytype); \
+	}							\
+    }
 #define OP_CPY_FREE(x)   OP_RAW_FREE(x, /*nothing*/)

Modified: pypy/branch/no-zeroing-assumption-3/pypy/translator/c/test/test_lltyped.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/translator/c/test/test_lltyped.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/translator/c/test/test_lltyped.py	Tue Aug 29 23:08:43 2006
@@ -97,7 +97,7 @@
     def test_more_prebuilt_arrays(self):
         A = FixedSizeArray(Struct('s1', ('x', Signed)), 5)
         S = GcStruct('s', ('a1', Ptr(A)), ('a2', A))
-        s = malloc(S)
+        s = malloc(S, zero=True)
         s.a1 = malloc(A, immortal=True)
         s.a1[2].x = 50
         s.a2[2].x = 60
@@ -173,9 +173,9 @@
         assert res == 34
 
     def test_prebuilt_subarrays(self):
-        a1 = malloc(GcArray(Signed), 5)
+        a1 = malloc(GcArray(Signed), 5, zero=True)
         a2 = malloc(FixedSizeArray(Signed, 5), immortal=True)
-        s  = malloc(GcStruct('S', ('x', Signed), ('y', Signed)))
+        s  = malloc(GcStruct('S', ('x', Signed), ('y', Signed)), zero=True)
         a1[3] = 7000
         a2[1] =  600
         s.x   =   50

Modified: pypy/branch/no-zeroing-assumption-3/pypy/translator/c/test/test_newgc.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/translator/c/test/test_newgc.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/translator/c/test/test_newgc.py	Tue Aug 29 23:08:43 2006
@@ -849,6 +849,19 @@
         res = fn()
         assert res == 10
 
+    def test_framework_late_filling_pointers(self):
+        A = lltype.GcStruct('A', ('x', lltype.Signed))
+        B = lltype.GcStruct('B', ('a', lltype.Ptr(A)))
+
+        def f():
+            p = lltype.malloc(B)
+            llop.gc__collect(lltype.Void)
+            p.a = lltype.malloc(A)
+            return p.a.x
+        fn = self.getcompiled(f)
+        # the point is just not to segfault
+        res = fn()
+
 class TestUsingStacklessFramework(TestUsingFramework):
     from pypy.translator.c.gc import StacklessFrameworkGcPolicy as gcpolicy
 

Modified: pypy/branch/no-zeroing-assumption-3/pypy/translator/stackless/transform.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/translator/stackless/transform.py	(original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/translator/stackless/transform.py	Tue Aug 29 23:08:43 2006
@@ -718,7 +718,7 @@
         realrettype = op.result.concretetype
         for i, a in enumerate(noexclink.args):
             if a is op.result:
-                noexclink.args[i] = model.Constant(realrettype._defl(), realrettype)
+                noexclink.args[i] = model.Constant(realrettype._defl(example=True), realrettype)
         block.recloseblock(*((noexclink,) + block.exits[1:]))        
 
     def insert_unwind_handling(self, block, i):



More information about the Pypy-commit mailing list