[pypy-svn] r18548 - in pypy/dist/pypy/rpython: . test

arigo at codespeak.net arigo at codespeak.net
Fri Oct 14 16:22:12 CEST 2005


Author: arigo
Date: Fri Oct 14 16:22:09 2005
New Revision: 18548

Modified:
   pypy/dist/pypy/rpython/llinterp.py
   pypy/dist/pypy/rpython/test/test_rlist.py
Log:
Check for MemoryErrors in malloc_varsize, for tests that allocate e.g. lists
of impossibly large sizes



Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py	(original)
+++ pypy/dist/pypy/rpython/llinterp.py	Fri Oct 14 16:22:09 2005
@@ -324,7 +324,10 @@
             result = self.op_direct_call(malloc, *args)
             return self.llinterpreter.gc.adjust_result_malloc(result, obj, size)
         else:
-            return self.llt.malloc(obj, size)
+            try:
+                return self.llt.malloc(obj, size)
+            except MemoryError, e:
+                self.make_llexception(e)
 
     def op_flavored_malloc(self, flavor, obj):
         assert isinstance(flavor, str)

Modified: pypy/dist/pypy/rpython/test/test_rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rlist.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rlist.py	Fri Oct 14 16:22:09 2005
@@ -1,3 +1,4 @@
+import sys
 from pypy.translator.translator import Translator
 from pypy.rpython.lltype import *
 from pypy.rpython.rtyper import RPythonTyper
@@ -500,3 +501,14 @@
     assert res == 2
     res = interpret(fn, [6])
     assert res == 100
+
+def test_memoryerror():
+    def fn(i):
+        lst = [0] * i
+        lst[i-1] = 5
+        return lst[0]
+    res = interpret(fn, [1])
+    assert res == 5
+    res = interpret(fn, [2])
+    assert res == 0
+    interpret_raises(MemoryError, fn, [sys.maxint])



More information about the Pypy-commit mailing list