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

cfbolz at codespeak.net cfbolz at codespeak.net
Thu Aug 11 18:10:13 CEST 2005


Author: cfbolz
Date: Thu Aug 11 18:10:13 2005
New Revision: 15970

Modified:
   pypy/dist/pypy/rpython/memory/simulator.py
   pypy/dist/pypy/rpython/memory/test/test_simulator.py
Log:
oops, bad idea. the memory simulator used the total size of all memory
allocated to this point as the current memory size. Test + fix.


Modified: pypy/dist/pypy/rpython/memory/simulator.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/simulator.py	(original)
+++ pypy/dist/pypy/rpython/memory/simulator.py	Thu Aug 11 18:10:13 2005
@@ -94,6 +94,7 @@
         self.freememoryaddress = 4 + SIZE_OF_OBJECT_BLOCK
         if ram_size is not None:
             self.size_of_simulated_ram = ram_size
+        self.current_size = 0
 
     def find_block(self, address):
         if address >= self.freememoryaddress:
@@ -115,7 +116,8 @@
         result = self.freememoryaddress
         self.blocks.append(MemoryBlock(result, size))
         self.freememoryaddress += size
-        if self.freememoryaddress > self.size_of_simulated_ram:
+        self.current_size += size
+        if self.current_size + size > self.size_of_simulated_ram:
             raise MemorySimulatorError, "out of memory"
         return result
 
@@ -125,6 +127,7 @@
         block = self.find_block(baseaddress)
         if baseaddress != block.baseaddress:
             raise MemorySimulatorError, "trying to free address not malloc'ed"
+        self.current_size -= block.size
         block.free()
 
     def getstruct(self, fmt, address):

Modified: pypy/dist/pypy/rpython/memory/test/test_simulator.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/test/test_simulator.py	(original)
+++ pypy/dist/pypy/rpython/memory/test/test_simulator.py	Thu Aug 11 18:10:13 2005
@@ -63,9 +63,14 @@
     def test_out_of_memory(self):
         sim = MemorySimulator(1 * 1024 * 1024)
         def f():
-            for i in xrange(10000000):
+            for i in xrange(10000):
                 sim.malloc(4096)
         py.test.raises(MemorySimulatorError, f)
+        sim = MemorySimulator(1 * 1024 * 1024)
+        def g():
+            for i in xrange(10000):
+                sim.free(sim.malloc(4096))
+        g() #does not raise
 
     def test_object_access(self):
         sim = MemorySimulator()



More information about the Pypy-commit mailing list