[pypy-svn] r51532 - in pypy/dist/pypy/module/_rawffi: . test

fijal at codespeak.net fijal at codespeak.net
Fri Feb 15 14:48:47 CET 2008


Author: fijal
Date: Fri Feb 15 14:48:46 2008
New Revision: 51532

Modified:
   pypy/dist/pypy/module/_rawffi/array.py
   pypy/dist/pypy/module/_rawffi/test/test__rawffi.py
Log:
introduce segfault_exception for array as well


Modified: pypy/dist/pypy/module/_rawffi/array.py
==============================================================================
--- pypy/dist/pypy/module/_rawffi/array.py	(original)
+++ pypy/dist/pypy/module/_rawffi/array.py	Fri Feb 15 14:48:46 2008
@@ -115,6 +115,8 @@
     # XXX don't allow negative indexes, nor slices
 
     def setitem(self, space, num, w_value):
+        if not self.ll_buffer:
+            raise segfault_exception(space, "setting element of freed array")
         if num >= self.length or num < 0:
             raise OperationError(space.w_IndexError, space.w_None)
         unwrap_value(space, push_elem, self.ll_buffer, num, self.shape.itemtp,
@@ -122,6 +124,8 @@
     setitem.unwrap_spec = ['self', ObjSpace, int, W_Root]
 
     def getitem(self, space, num):
+        if not self.ll_buffer:
+            raise segfault_exception(space, "accessing elements of freed array")
         if num >= self.length or num < 0:
             raise OperationError(space.w_IndexError, space.w_None)
         return wrap_value(space, get_elem, self.ll_buffer, num,

Modified: pypy/dist/pypy/module/_rawffi/test/test__rawffi.py
==============================================================================
--- pypy/dist/pypy/module/_rawffi/test/test__rawffi.py	(original)
+++ pypy/dist/pypy/module/_rawffi/test/test__rawffi.py	Fri Feb 15 14:48:46 2008
@@ -587,3 +587,19 @@
         raises(ValueError, lib.getprimitive, 'z', 'ddddddd')
         raises(ValueError, lib.getprimitive, 'zzz', 'static_int')
 
+    def test_segfault_exception(self):
+        import _rawffi
+        S = _rawffi.Structure([('x', 'i')])
+        s = S()
+        s.x = 3
+        s.free()
+        raises(_rawffi.SegfaultException, s.__getattr__, 'x')
+        raises(_rawffi.SegfaultException, s.__setattr__, 'x', 3)
+        A = _rawffi.Array('c')
+        a = A(13)
+        a.free()
+        raises(_rawffi.SegfaultException, a.__getitem__, 3)
+        raises(_rawffi.SegfaultException, a.__setitem__, 3, 3)
+        
+        
+        



More information about the Pypy-commit mailing list