Commit 3634f68c authored by Matti Picus's avatar Matti Picus
Browse files

test, fix for passing flags arg around

--HG--
branch : memoryview-attributes
parent 33ec1bbbd5b9
......@@ -208,7 +208,7 @@ class W_Root(object):
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 @@ class W_Root(object):
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 @@ class W_Root(object):
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 @@ class W_Root(object):
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
......
......@@ -346,8 +346,13 @@ def wrap_getreadbuffer(space, w_self, w_args, func):
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 @@ def wrap_getbuffer(space, w_self, w_args, func):
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,
......
......@@ -106,6 +106,10 @@ PyMyArray_getbuffer(PyObject *obj, Py_buffer *view, int flags)
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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment