[pypy-commit] pypy memoryview-attributes: test, fix for passing flags arg around
mattip
pypy.commits at gmail.com
Sat Aug 20 13:34:46 EDT 2016
Author: Matti Picus <matti.picus at gmail.com>
Branch: memoryview-attributes
Changeset: r86358:8dc76d4c4aa3
Date: 2016-08-21 05:33 +1200
http://bitbucket.org/pypy/pypy/changeset/8dc76d4c4aa3/
Log: test, fix for passing flags arg around
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -208,7 +208,7 @@
def buffer_w(self, space, flags):
w_impl = space.lookup(self, '__buffer__')
if w_impl is not None:
- w_result = space.get_and_call_function(w_impl, self)
+ w_result = space.get_and_call_function(w_impl, self, flags)
if space.isinstance_w(w_result, space.w_buffer):
return w_result.buffer_w(space, flags)
raise BufferInterfaceNotFound
@@ -216,7 +216,8 @@
def readbuf_w(self, space):
w_impl = space.lookup(self, '__buffer__')
if w_impl is not None:
- w_result = space.get_and_call_function(w_impl, self)
+ w_result = space.get_and_call_function(w_impl, self,
+ space.BUF_FULL_RO)
if space.isinstance_w(w_result, space.w_buffer):
return w_result.readbuf_w(space)
raise BufferInterfaceNotFound
@@ -224,7 +225,8 @@
def writebuf_w(self, space):
w_impl = space.lookup(self, '__buffer__')
if w_impl is not None:
- w_result = space.get_and_call_function(w_impl, self)
+ w_result = space.get_and_call_function(w_impl, self,
+ space.BUF_FULL)
if space.isinstance_w(w_result, space.w_buffer):
return w_result.writebuf_w(space)
raise BufferInterfaceNotFound
@@ -232,7 +234,8 @@
def charbuf_w(self, space):
w_impl = space.lookup(self, '__buffer__')
if w_impl is not None:
- w_result = space.get_and_call_function(w_impl, self)
+ w_result = space.get_and_call_function(w_impl, self,
+ space.BUF_FULL_RO)
if space.isinstance_w(w_result, space.w_buffer):
return w_result.charbuf_w(space)
raise BufferInterfaceNotFound
diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py
--- a/pypy/module/cpyext/slotdefs.py
+++ b/pypy/module/cpyext/slotdefs.py
@@ -346,8 +346,13 @@
def wrap_getbuffer(space, w_self, w_args, func):
func_target = rffi.cast(getbufferproc, func)
with lltype.scoped_alloc(Py_buffer) as pybuf:
- # XXX flags are not in w_args?
- flags = rffi.cast(rffi.INT_real,0)
+ _flags = 0
+ if space.len_w(w_args) > 0:
+ _flags = space.listview(w_args)[0]
+ if not isinstance(_flags, int):
+ raise oefmt(space.w_TypeError,
+ "non-int flags passed to getbufferproc")
+ flags = rffi.cast(rffi.INT_real,_flags)
size = generic_cpy_call(space, func_target, w_self, pybuf, flags)
if widen(size) < 0:
space.fromcache(State).check_and_raise_exception(always=True)
@@ -356,7 +361,10 @@
ndim = widen(pybuf.c_ndim)
shape = [pybuf.c_shape[i] for i in range(ndim)]
strides = [pybuf.c_strides[i] for i in range(ndim)]
- format = rffi.charp2str(pybuf.c_format)
+ if pybuf.c_format:
+ format = rffi.charp2str(pybuf.c_format)
+ else:
+ format = 'B'
return space.newbuffer(CPyBuffer(ptr, size, w_self, format=format,
ndim=ndim, shape=shape, strides=strides,
itemsize=pybuf.c_itemsize,
diff --git a/pypy/module/cpyext/test/buffer_test.c b/pypy/module/cpyext/test/buffer_test.c
--- a/pypy/module/cpyext/test/buffer_test.c
+++ b/pypy/module/cpyext/test/buffer_test.c
@@ -106,6 +106,10 @@
PyErr_SetString(PyExc_ValueError, "NULL view in getbuffer");
return -1;
}
+ if (flags == 0) {
+ PyErr_SetString(PyExc_ValueError, "flags == 0 in getbuffer");
+ return -1;
+ }
PyMyArray* self = (PyMyArray*)obj;
view->obj = (PyObject*)self;
More information about the pypy-commit
mailing list