[pypy-dev] Catching MemoryError in RPython

Niko Matsakis niko at alum.mit.edu
Fri Feb 22 19:54:52 CET 2008

I cannot seem to generate code that catches OOM errors in RPython.  I  
wrote a test like this:

     def test_memoryerror_due_to_oom(self):
         def fn():
                 lst = []
                 for i in range(sys.maxint): lst.append(i)
             except Exception: #MemoryError:
                 return "OK"
         assert self.interpret(fn, []) == "OK"

but the try:/except: seems to have disappeared by the time the JVM  
backend is invoked (it's not in the flow graphs anywhere).  I assume  
that it is getting stripped away by a deadcode pass at some point,  
though I'm not sure where that might be.  I haven't managed to concoct  
code that can fool it into keeping the exception block yet, but I'm  
pretty sure that if I only could, then the JVM backend would handle it  
correctly... :)

If you comment out the test that causes this out of memory condition,  
then test_builtin.py *almost* passes in pypy-jvm.  There are still two  
errors, though.  :)


More information about the Pypy-dev mailing list