[pypy-svn] r24217 - in pypy/dist/pypy: rpython/memory translator/c/test
mwh at codespeak.net
mwh at codespeak.net
Fri Mar 10 13:27:27 CET 2006
Author: mwh
Date: Fri Mar 10 13:27:26 2006
New Revision: 24217
Modified:
pypy/dist/pypy/rpython/memory/gc.py
pypy/dist/pypy/translator/c/test/test_newgc.py
Log:
raise MemoryError if the length * item_size calculation overflows.
this doesn't tackle the issue of raw_malloc actually returning NULL, but I'm
running on a linux box with lots of swap, that's not actually going to happen,
right? (quiet there at the back!)
Modified: pypy/dist/pypy/rpython/memory/gc.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gc.py (original)
+++ pypy/dist/pypy/rpython/memory/gc.py Fri Mar 10 13:27:26 2006
@@ -4,6 +4,7 @@
from pypy.rpython.memory import lltypesimulation
from pypy.rpython.lltypesystem import lltype, llmemory
from pypy.rpython.objectmodel import free_non_gc_object
+from pypy.rpython import rarithmetic
import sys
@@ -123,7 +124,11 @@
self.collect()
size = self.fixed_size(typeid)
if self.is_varsize(typeid):
- size += length * self.varsize_item_sizes(typeid)
+ try:
+ varsize = rarithmetic.ovfcheck(length * self.varsize_item_sizes(typeid))
+ except OverflowError:
+ raise MemoryError
+ size += varsize
size_gc_header = self.size_gc_header()
result = raw_malloc(size + size_gc_header)
## print "mallocing %s, size %s at %s" % (typeid, size, result)
Modified: pypy/dist/pypy/translator/c/test/test_newgc.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_newgc.py (original)
+++ pypy/dist/pypy/translator/c/test/test_newgc.py Fri Mar 10 13:27:26 2006
@@ -295,3 +295,9 @@
assert res == 44
+ def test_framework_malloc_failure(self):
+ def f():
+ a = [1] * (sys.maxint//2)
+ return len(a) + a[0]
+ fn = self.getcompiled(f)
+ py.test.raises(MemoryError, fn)
More information about the Pypy-commit
mailing list