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

cfbolz at codespeak.net cfbolz at codespeak.net
Thu Aug 11 20:25:57 CEST 2005


Author: cfbolz
Date: Thu Aug 11 20:25:56 2005
New Revision: 15974

Modified:
   pypy/dist/pypy/rpython/memory/lladdress.py
   pypy/dist/pypy/rpython/memory/test/test_address.py
Log:
raise an error when trying to access NULL pointer

Modified: pypy/dist/pypy/rpython/memory/lladdress.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/lladdress.py	(original)
+++ pypy/dist/pypy/rpython/memory/lladdress.py	Thu Aug 11 20:25:56 2005
@@ -1,5 +1,5 @@
 import struct
-from pypy.rpython.memory.simulator import MemorySimulator
+from pypy.rpython.memory.simulator import MemorySimulator, MemorySimulatorError
 from pypy.rpython.rarithmetic import r_uint
 
 
@@ -44,6 +44,8 @@
 
 class _accessor(object):
     def __init__(self, addr):
+        if addr == NULL:
+            raise MemorySimulatorError("trying to access NULL pointer")
         self.intaddress = addr.intaddress
     def __getitem__(self, offset):
         result = simulator.getstruct(self.format,

Modified: pypy/dist/pypy/rpython/memory/test/test_address.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/test/test_address.py	(original)
+++ pypy/dist/pypy/rpython/memory/test/test_address.py	Thu Aug 11 20:25:56 2005
@@ -190,6 +190,7 @@
         assert addr.unsigned[0] == sys.maxint * 2 + 1
         addr.address[0] = addr
         assert addr.address[0] == addr
+        py.test.raises(MemorySimulatorError, "NULL.signed[0]")
 
     def test_pointer_arithmetic(self):
         addr = raw_malloc(100)



More information about the Pypy-commit mailing list