[pypy-commit] pypy op_malloc_gc: Don't raise MemoryError explicitly; it is not needed, and confuses

arigo noreply at buildbot.pypy.org
Mon Dec 19 07:26:18 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: op_malloc_gc
Changeset: r50694:5d8f68105e9c
Date: 2011-12-19 07:25 +0100
http://bitbucket.org/pypy/pypy/changeset/5d8f68105e9c/

Log:	Don't raise MemoryError explicitly; it is not needed, and confuses
	test_runner:test_memoryerror.

diff --git a/pypy/jit/backend/llsupport/gc.py b/pypy/jit/backend/llsupport/gc.py
--- a/pypy/jit/backend/llsupport/gc.py
+++ b/pypy/jit/backend/llsupport/gc.py
@@ -40,8 +40,8 @@
 
     def generate_function(self, funcname, func, ARGS, RESULT=llmemory.GCREF):
         """Generates a variant of malloc with the given name and the given
-        arguments.  It should raise MemoryError and return NULL if out of
-        memory.
+        arguments.  It should return NULL if out of memory.  If it raises
+        anything, it must be an optional MemoryError.
         """
         FUNCPTR = lltype.Ptr(lltype.FuncType(ARGS, RESULT))
         descr = get_call_descr(self, ARGS, RESULT)
@@ -173,10 +173,7 @@
     def _make_functions(self):
 
         def malloc_fixedsize(size):
-            res = self.malloc_fn_ptr(size)
-            if not res:
-                raise MemoryError
-            return res
+            return self.malloc_fn_ptr(size)
         self.generate_function('malloc_fixedsize', malloc_fixedsize,
                                [lltype.Signed])
 
@@ -184,12 +181,11 @@
             try:
                 totalsize = ovfcheck(basesize + ovfcheck(itemsize * num_elem))
             except OverflowError:
-                raise MemoryError
+                return lltype.nullptr(llmemory.GCREF.TO)
             res = self.malloc_fn_ptr(totalsize)
-            if not res:
-                raise MemoryError
-            arrayptr = rffi.cast(rffi.CArrayPtr(lltype.Signed), res)
-            arrayptr[ofs_length/WORD] = num_elem
+            if res:
+                arrayptr = rffi.cast(rffi.CArrayPtr(lltype.Signed), res)
+                arrayptr[ofs_length/WORD] = num_elem
             return res
         self.generate_function('malloc_array', malloc_array,
                                [lltype.Signed] * 4)


More information about the pypy-commit mailing list