Author: Matti Picus <matti.pi...@gmail.com>
Branch: buffer-interface2
Changeset: r87584:b07f8d1cf5cc
Date: 2016-10-04 22:15 +0300
http://bitbucket.org/pypy/pypy/changeset/b07f8d1cf5cc/

Log:    test, fix for UserWarning - make_ref is called only after
        fill_Py_buffer succeeds

diff --git a/pypy/module/cpyext/memoryobject.py 
b/pypy/module/cpyext/memoryobject.py
--- a/pypy/module/cpyext/memoryobject.py
+++ b/pypy/module/cpyext/memoryobject.py
@@ -34,8 +34,9 @@
         view.c_buf = rffi.cast(rffi.VOIDP, buf.get_raw_address())
     except ValueError:
         raise BufferError("could not create buffer from object")
+    ret = fill_Py_buffer(space, buf, view)
     view.c_obj = make_ref(space, w_obj)
-    return fill_Py_buffer(space, buf, view)
+    return ret
 
 def fill_Py_buffer(space, buf, view):
     # c_buf, c_obj have been filled in
@@ -149,6 +150,7 @@
     if ndim >= Py_MAX_NDIMS:
         # XXX warn?
         return view
+    fill_Py_buffer(space, w_obj.buf, view)
     try:
         view.c_buf = rffi.cast(rffi.VOIDP, w_obj.buf.get_raw_address())
         view.c_obj = make_ref(space, w_obj)
@@ -160,6 +162,5 @@
         view.c_buf = rffi.cast(rffi.VOIDP, rffi.str2charp(space.str_w(w_s), 
track_allocation=False))
         rffi.setintfield(view, 'c_readonly', 1)
         isstr = True
-    fill_Py_buffer(space, w_obj.buf, view)
     return view
 
diff --git a/pypy/module/cpyext/test/test_memoryobject.py 
b/pypy/module/cpyext/test/test_memoryobject.py
--- a/pypy/module/cpyext/test/test_memoryobject.py
+++ b/pypy/module/cpyext/test/test_memoryobject.py
@@ -47,6 +47,8 @@
 
     @pytest.mark.skipif(only_pypy, reason='pypy only test')
     def test_buffer_info(self):
+        import warnings
+        warnings.filterwarnings("error")
         try:
             from _numpypy import multiarray as np
         except ImportError:
@@ -60,3 +62,24 @@
         arr = np.zeros((10, 1), order='C')
         shape, strides = get_buffer_info(arr, ['C_CONTIGUOUS'])
         assert strides[-1] == 8
+        dt1 = np.dtype(
+             [('a', 'b'), ('b', 'i'), 
+              ('sub0', np.dtype('b,i')), 
+              ('sub1', np.dtype('b,i')), 
+              ('sub2', np.dtype('b,i')), 
+              ('sub3', np.dtype('b,i')), 
+              ('sub4', np.dtype('b,i')), 
+              ('sub5', np.dtype('b,i')), 
+              ('sub6', np.dtype('b,i')), 
+              ('sub7', np.dtype('b,i')), 
+              ('c', 'i')],
+             )
+        x = np.arange(dt1.itemsize, dtype='int8').view(dt1)
+        # pytest can catch warnings from v2.8 and up, we ship 2.5
+        try:
+            y = get_buffer_info(x, ['SIMPLE'])
+        except UserWarning as e:
+            pass
+        else:
+            assert False ,"PyPy-specific UserWarning not raised" \
+                          " on too long format string"
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to