[pypy-commit] pypy py3k: add a null check to PyMemoryView_FromBuffer. test_FillWithObject seems to
pjenvey
noreply at buildbot.pypy.org
Thu Apr 11 22:37:22 CEST 2013
Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r63247:ea6d963fbdba
Date: 2013-04-11 13:36 -0700
http://bitbucket.org/pypy/pypy/changeset/ea6d963fbdba/
Log: add a null check to PyMemoryView_FromBuffer. test_FillWithObject
seems to require an extra del for correct cleanup
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
@@ -1,3 +1,4 @@
+from pypy.interpreter.error import OperationError
from pypy.module.cpyext.api import cpython_api, Py_buffer
from pypy.module.cpyext.pyobject import PyObject, from_ref
from pypy.module.cpyext.buffer import CBuffer
@@ -14,6 +15,9 @@
The memoryview object then owns the buffer represented by view, which
means you shouldn't try to call PyBuffer_Release() yourself: it
will be done on deallocation of the memoryview object."""
+ if not view.c_buf:
+ msg = "cannot make memory view from a buffer with a NULL data pointer"
+ raise OperationError(space.w_ValueError, space.wrap(msg))
w_obj = from_ref(space, view.c_obj)
buf = CBuffer(space, view.c_buf, view.c_len, w_obj)
return space.wrap(W_MemoryView(space.wrap(buf)))
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
@@ -36,5 +36,20 @@
""")])
result = module.fillinfo()
assert b"hello, world." == result
+ del result
-
+ def test_fill_from_NULL_pointer(self):
+ module = self.import_extension('foo', [
+ ("fillinfo_NULL", "METH_VARARGS",
+ """
+ Py_buffer info;
+ if (PyBuffer_FillInfo(&info, NULL, NULL, 1, 1,
+ PyBUF_FULL_RO) < 0) {
+ return NULL;
+ }
+ return PyMemoryView_FromBuffer(&info);
+ """)])
+ exc = raises(ValueError, module.fillinfo_NULL)
+ expected = ("cannot make memory view from a buffer with a NULL data "
+ "pointer")
+ assert str(exc.value) == expected
More information about the pypy-commit
mailing list