Author: Devin Jeanpierre <[email protected]>
Branch: cpyext-old-buffers
Changeset: r84522:96591f8ad166
Date: 2016-05-19 18:46 -0700
http://bitbucket.org/pypy/pypy/changeset/96591f8ad166/

Log:    Add a test that actually writes to a writable mmap, showing that it
        works.

diff --git a/pypy/module/cpyext/test/test_abstract.py 
b/pypy/module/cpyext/test/test_abstract.py
--- a/pypy/module/cpyext/test/test_abstract.py
+++ b/pypy/module/cpyext/test/test_abstract.py
@@ -34,6 +34,18 @@
                      return NULL;
                  return PyString_FromStringAndSize((char*)ptr, size);
              """),
+            ("zero_out_writebuffer", "METH_O",
+             """
+                 void *ptr;
+                 Py_ssize_t size;
+                 if (PyObject_AsWriteBuffer(args, &ptr, &size) < 0)
+                     return NULL;
+                 Py_ssize_t i;
+                 for (i = 0; i < size; i++) {
+                     ((char*)ptr)[i] = 0;
+                 }
+                 Py_RETURN_NONE;
+             """),
             ])
 
     def test_string(self):
@@ -71,6 +83,13 @@
         assert s == buffer_support.charbuffer_as_string(mm)
 
         s = '\0' * 3
+        buffer_support.zero_out_writebuffer(mm)
+        assert s == ''.join(mm)
+        assert s == buffer_support.readbuffer_as_string(mm)
+        assert s == buffer_support.writebuffer_as_string(mm)
+        assert s == buffer_support.charbuffer_as_string(mm)
+
+        s = '\0' * 3
         ro_mm = mmap.mmap(-1, 3, access=mmap.ACCESS_READ)
         assert buffer_support.check_readbuffer(ro_mm)
         assert s == buffer_support.readbuffer_as_string(ro_mm)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to