[pypy-svn] r28809 - in pypy/dist/pypy/translator/c: . test
pedronis at codespeak.net
pedronis at codespeak.net
Thu Jun 15 14:35:24 CEST 2006
Author: pedronis
Date: Thu Jun 15 14:35:23 2006
New Revision: 28809
Modified:
pypy/dist/pypy/translator/c/funcgen.py
pypy/dist/pypy/translator/c/test/test_boehm.py
Log:
fix crash on out of memory conditions with boehm and malloc_varsize
Modified: pypy/dist/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/dist/pypy/translator/c/funcgen.py (original)
+++ pypy/dist/pypy/translator/c/funcgen.py Thu Jun 15 14:35:23 2006
@@ -547,7 +547,7 @@
# ctypes Arrays have no length field
if not VARPART._hints.get('nolength', False):
- result += '\n%s->%s = %s;' % (eresult, lenfld, elength)
+ result += '\nif(%s) %s->%s = %s;' % (eresult, eresult, lenfld, elength)
return result
def OP_FLAVORED_MALLOC(self, op):
Modified: pypy/dist/pypy/translator/c/test/test_boehm.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_boehm.py (original)
+++ pypy/dist/pypy/translator/c/test/test_boehm.py Thu Jun 15 14:35:23 2006
@@ -156,6 +156,24 @@
# if res is still 0, then we haven't tested anything so fail.
# it might be the test's fault though.
assert res > 0
+
+ def test_memory_error_varsize(self):
+ from pypy.rpython.lltypesystem import lltype
+ N = int(2**31-1)
+ A = lltype.GcArray(lltype.Char)
+ def alloc(n):
+ return lltype.malloc(A, n)
+ def f():
+ try:
+ x = alloc(N)
+ except MemoryError:
+ alloc(10)
+ return 0
+ alloc(10)
+ return 0 # allocation may work on 64 bits machines
+ fn = self.getcompiled(f)
+ res = fn()
+ assert res == 0
class TestUsingExactBoehm(TestUsingBoehm):
More information about the Pypy-commit
mailing list