[pypy-svn] r44952 - in pypy/branch/emptying-the-malloc-zoo-2/pypy: rpython/lltypesystem rpython/memory rpython/memory/gctransform translator/c/src

mwh at codespeak.net mwh at codespeak.net
Thu Jul 12 14:15:35 CEST 2007


Author: mwh
Date: Thu Jul 12 14:15:34 2007
New Revision: 44952

Modified:
   pypy/branch/emptying-the-malloc-zoo-2/pypy/rpython/lltypesystem/llmemory.py
   pypy/branch/emptying-the-malloc-zoo-2/pypy/rpython/lltypesystem/lloperation.py
   pypy/branch/emptying-the-malloc-zoo-2/pypy/rpython/memory/gc.py
   pypy/branch/emptying-the-malloc-zoo-2/pypy/rpython/memory/gctransform/framework.py
   pypy/branch/emptying-the-malloc-zoo-2/pypy/rpython/memory/gctransform/refcounting.py
   pypy/branch/emptying-the-malloc-zoo-2/pypy/translator/c/src/mem.h
Log:
(pedronis, mwh and his Bazaar T-shirt)
merge changes from emptying-the-malloc-zoo


Modified: pypy/branch/emptying-the-malloc-zoo-2/pypy/rpython/lltypesystem/llmemory.py
==============================================================================
--- pypy/branch/emptying-the-malloc-zoo-2/pypy/rpython/lltypesystem/llmemory.py	(original)
+++ pypy/branch/emptying-the-malloc-zoo-2/pypy/rpython/lltypesystem/llmemory.py	Thu Jul 12 14:15:34 2007
@@ -22,8 +22,8 @@
             return NotImplemented
         return CompositeOffset(self, other)
 
-    def raw_malloc(self, rest, zero):
-        raise NotImplementedError("raw_malloc(%r, %r)" % (self, rest))
+    def _raw_malloc(self, rest, zero):
+        raise NotImplementedError("_raw_malloc(%r, %r)" % (self, rest))
 
     def raw_memcopy(self, srcadr, dstsrc):
         raise NotImplementedError("raw_memcopy(%r)" % (self,))
@@ -67,7 +67,7 @@
         else:
             raise TypeError('got %r, expected %r' % (A, self.TYPE))
 
-    def raw_malloc(self, rest, zero):
+    def _raw_malloc(self, rest, zero):
         assert not rest
         if (isinstance(self.TYPE, lltype.ContainerType)
             and self.TYPE._gckind == 'gc'):
@@ -118,12 +118,12 @@
         else:
             return lltype.direct_fieldptr(struct, self.fldname)
 
-    def raw_malloc(self, rest, parenttype=None, zero=False):
+    def _raw_malloc(self, rest, parenttype=None, zero=False):
         if self.fldname != self.TYPE._arrayfld:
             # for the error msg
-            return AddressOffset.raw_malloc(self, rest, zero=zero)
+            return AddressOffset._raw_malloc(self, rest, zero=zero)
         assert rest
-        return rest[0].raw_malloc(rest[1:], parenttype=parenttype or self.TYPE,
+        return rest[0]._raw_malloc(rest[1:], parenttype=parenttype or self.TYPE,
                                             zero=zero)
 
     def raw_memcopy(self, srcadr, dstadr):
@@ -171,8 +171,8 @@
             ptr = item.ref(ptr)
         return ptr
 
-    def raw_malloc(self, rest, zero):
-        return self.offsets[0].raw_malloc(self.offsets[1:] + rest, zero=zero)
+    def _raw_malloc(self, rest, zero):
+        return self.offsets[0]._raw_malloc(self.offsets[1:] + rest, zero=zero)
 
     def raw_memcopy(self, srcadr, dstadr):
         for o in self.offsets[:-1]:
@@ -198,7 +198,7 @@
         else:
             return lltype.direct_arrayitems(arrayptr)
 
-    def raw_malloc(self, rest, parenttype=None, zero=False):
+    def _raw_malloc(self, rest, parenttype=None, zero=False):
         if rest:
             assert len(rest) == 1
             assert isinstance(rest[0], ItemOffset)
@@ -245,11 +245,11 @@
         gcptr = self.gcheaderbuilder.object_from_header(headerptr)
         return gcptr
 
-    def raw_malloc(self, rest, zero):
+    def _raw_malloc(self, rest, zero):
         assert rest
         if isinstance(rest[0], GCHeaderAntiOffset):
-            return rest[1].raw_malloc(rest[2:], zero=zero)    # just for fun
-        gcobjadr = rest[0].raw_malloc(rest[1:], zero=zero)
+            return rest[1]._raw_malloc(rest[2:], zero=zero)    # just for fun
+        gcobjadr = rest[0]._raw_malloc(rest[1:], zero=zero)
         headerptr = self.gcheaderbuilder.new_header(gcobjadr.ptr)
         return cast_ptr_to_adr(headerptr)
 
@@ -271,10 +271,10 @@
         headerptr = self.gcheaderbuilder.header_of_object(gcptr)
         return headerptr
 
-    def raw_malloc(self, rest, zero):
+    def _raw_malloc(self, rest, zero):
         assert len(rest) >= 2
         assert isinstance(rest[0], GCHeaderOffset)
-        return rest[1].raw_malloc(rest[2:], zero=zero)
+        return rest[1]._raw_malloc(rest[2:], zero=zero)
 
 # ____________________________________________________________
 
@@ -543,7 +543,7 @@
 def raw_malloc(size):
     if not isinstance(size, AddressOffset):
         raise NotImplementedError(size)
-    return size.raw_malloc([], zero=False)
+    return size._raw_malloc([], zero=False)
 
 def raw_free(adr):
     # try to free the whole object if 'adr' is the address of the header
@@ -568,7 +568,7 @@
     if not isinstance(size, AddressOffset):
         raise NotImplementedError(size)
     assert lltype.typeOf(adr) == Address
-    zeroadr = size.raw_malloc([], zero=True)
+    zeroadr = size._raw_malloc([], zero=True)
     size.raw_memcopy(zeroadr, adr)
 
 def raw_memcopy(source, dest, size):
@@ -615,7 +615,7 @@
         self.unitsize = unitsize
         self.n = n
 
-    def raw_malloc(self, rest, zero=False):
+    def _raw_malloc(self, rest, zero=False):
         assert not rest
         arena = _arena(self, zero=zero)
         return arena.getitemaddr(0)

Modified: pypy/branch/emptying-the-malloc-zoo-2/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/branch/emptying-the-malloc-zoo-2/pypy/rpython/lltypesystem/lloperation.py	(original)
+++ pypy/branch/emptying-the-malloc-zoo-2/pypy/rpython/lltypesystem/lloperation.py	Thu Jul 12 14:15:34 2007
@@ -339,7 +339,7 @@
 
     # __________ address operations __________
 
-    'raw_malloc':           LLOp(canraise=(MemoryError,)),
+    'raw_malloc':           LLOp(),
     'raw_malloc_usage':     LLOp(sideeffects=False),
     'raw_free':             LLOp(),
     'raw_memclear':         LLOp(),

Modified: pypy/branch/emptying-the-malloc-zoo-2/pypy/rpython/memory/gc.py
==============================================================================
--- pypy/branch/emptying-the-malloc-zoo-2/pypy/rpython/memory/gc.py	(original)
+++ pypy/branch/emptying-the-malloc-zoo-2/pypy/rpython/memory/gc.py	Thu Jul 12 14:15:34 2007
@@ -4,7 +4,7 @@
 from pypy.rpython.memory.gcheader import GCHeaderBuilder
 from pypy.rpython.memory import lltypesimulation
 from pypy.rpython.lltypesystem import lltype, llmemory
-from pypy.rlib.objectmodel import free_non_gc_object
+from pypy.rlib.objectmodel import free_non_gc_object, debug_assert
 from pypy.rpython.lltypesystem.lloperation import llop
 from pypy.rlib.rarithmetic import ovfcheck
 
@@ -97,7 +97,10 @@
         size = self.fixed_size(typeid)
         if self.is_varsize(typeid):
             size += length * self.varsize_item_sizes(typeid)
-        return raw_malloc(size)
+        result = raw_malloc(size)
+        if not result:
+            raise memoryError
+        return result
          
     def collect(self):
         self.get_roots() #this is there so that the annotator thinks get_roots is a function
@@ -182,6 +185,8 @@
         except OverflowError:
             raise memoryError
         result = raw_malloc(tot_size)
+        if not result:
+            raise memoryError
         hdr = llmemory.cast_adr_to_ptr(result, self.HDRPTR)
         hdr.typeid = typeid << 1
         if has_finalizer:
@@ -208,6 +213,8 @@
         except OverflowError:
             raise memoryError
         result = raw_malloc(tot_size)
+        if not result:
+            raise memoryError
         raw_memclear(result, tot_size)
         hdr = llmemory.cast_adr_to_ptr(result, self.HDRPTR)
         hdr.typeid = typeid << 1
@@ -238,6 +245,8 @@
         except OverflowError:
             raise memoryError
         result = raw_malloc(tot_size)
+        if not result:
+            raise memoryError
         (result + size_gc_header + offset_to_length).signed[0] = length
         hdr = llmemory.cast_adr_to_ptr(result, self.HDRPTR)
         hdr.typeid = typeid << 1
@@ -270,6 +279,8 @@
         except OverflowError:
             raise memoryError
         result = raw_malloc(tot_size)
+        if not result:
+            raise memoryError
         raw_memclear(result, tot_size)        
         (result + size_gc_header + offset_to_length).signed[0] = length
         hdr = llmemory.cast_adr_to_ptr(result, self.HDRPTR)
@@ -942,8 +953,10 @@
 
     def setup(self):
         self.tospace = raw_malloc(self.space_size)
+        debug_assert(bool(self.tospace), "couldn't allocate tospace")
         self.top_of_space = self.tospace + self.space_size
         self.fromspace = raw_malloc(self.space_size)
+        debug_assert(bool(self.fromspace), "couldn't allocate fromspace")
         self.free = self.tospace
 
     def free_memory(self):
@@ -1125,6 +1138,8 @@
         size_gc_header = self.size_gc_header()
         result = raw_malloc(size + size_gc_header)
 ##         print "mallocing %s, size %s at %s" % (typeid, size, result)
+        if not result:
+            raise memoryError
         result.signed[0] = 0 # refcount
         result.signed[1] = typeid
         return result + size_gc_header

Modified: pypy/branch/emptying-the-malloc-zoo-2/pypy/rpython/memory/gctransform/framework.py
==============================================================================
--- pypy/branch/emptying-the-malloc-zoo-2/pypy/rpython/memory/gctransform/framework.py	(original)
+++ pypy/branch/emptying-the-malloc-zoo-2/pypy/rpython/memory/gctransform/framework.py	Thu Jul 12 14:15:34 2007
@@ -6,6 +6,7 @@
 from pypy.rpython.memory import gc, lladdress
 from pypy.rpython.memory.gcheader import GCHeaderBuilder
 from pypy.rlib.rarithmetic import ovfcheck
+from pypy.rlib.objectmodel import debug_assert
 from pypy.translator.backendopt import graphanalyze
 from pypy.annotation import model as annmodel
 from pypy.rpython import annlowlevel
@@ -251,6 +252,7 @@
             _alloc_flavor_ = 'raw'
             def setup_root_stack():
                 stackbase = lladdress.raw_malloc(rootstacksize)
+                debug_assert(bool(stackbase), "could not allocate root stack")
                 lladdress.raw_memclear(stackbase, rootstacksize)
                 gcdata.root_stack_top  = stackbase
                 gcdata.root_stack_base = stackbase

Modified: pypy/branch/emptying-the-malloc-zoo-2/pypy/rpython/memory/gctransform/refcounting.py
==============================================================================
--- pypy/branch/emptying-the-malloc-zoo-2/pypy/rpython/memory/gctransform/refcounting.py	(original)
+++ pypy/branch/emptying-the-malloc-zoo-2/pypy/rpython/memory/gctransform/refcounting.py	Thu Jul 12 14:15:34 2007
@@ -45,7 +45,9 @@
 
         # create incref, etc  graph
 
+        memoryError = MemoryError()
         HDRPTR = lltype.Ptr(self.HDR)
+
         def ll_incref(adr):
             if adr:
                 gcheader = llmemory.cast_adr_to_ptr(adr - gc_header_offset, HDRPTR)
@@ -71,6 +73,8 @@
         def ll_malloc_fixedsize(size):
             size = gc_header_offset + size
             result = lladdress.raw_malloc(size)
+            if not result:
+                raise memoryError
             lladdress.raw_memclear(result, size)
             result += gc_header_offset
             return result
@@ -80,8 +84,10 @@
                 varsize = ovfcheck(itemsize * length)
                 tot_size = ovfcheck(fixsize + varsize)
             except OverflowError:
-                raise MemoryError
+                raise memoryError
             result = lladdress.raw_malloc(tot_size)
+            if not result:
+                raise memoryError
             lladdress.raw_memclear(result, tot_size)
             result += gc_header_offset
             return result

Modified: pypy/branch/emptying-the-malloc-zoo-2/pypy/translator/c/src/mem.h
==============================================================================
--- pypy/branch/emptying-the-malloc-zoo-2/pypy/translator/c/src/mem.h	(original)
+++ pypy/branch/emptying-the-malloc-zoo-2/pypy/translator/c/src/mem.h	Thu Jul 12 14:15:34 2007
@@ -8,11 +8,7 @@
 
 #define OP_RAW_MALLOC(size, r, restype)  {				\
 		r = (restype) PyObject_Malloc(size);			\
-		if (r == NULL) {					\
-			FAIL_EXCEPTION(PyExc_MemoryError,		\
-				       "out of memory");		\
-		} 							\
-		else {							\
+		if (r != NULL) {					\
 			memset((void*)r, 0, size);			\
 			COUNT_MALLOC;					\
 		}							\
@@ -22,13 +18,9 @@
 
 #define OP_RAW_MALLOC(size, r, restype)  {				\
 		r = (restype) PyObject_Malloc(size);			\
-		if (r == NULL) {					\
-			FAIL_EXCEPTION(PyExc_MemoryError,		\
-				       "out of memory");		\
-		} 							\
-		else {							\
+		if (r != NULL) {					\
 			COUNT_MALLOC;					\
-		}							\
+		} 							\
 	}
 
 #endif



More information about the Pypy-commit mailing list