Commit b871347b authored by Matti Picus's avatar Matti Picus
Browse files

add test that passes -A fails untranslated, bf_get* slots are NULL in subclass

--HG--
branch : buffer-interface2
parent 0497d086d9c5
......@@ -2394,14 +2394,29 @@ static PyTypeObject PyArrayIter_Type = {
(iternextfunc)arrayiter_next, /* tp_iternext */
0, /* tp_methods */
};
static PyObject *
readbuffer_as_string(PyObject *self, PyObject *args)
{
PyObject *obj;
const void *ptr;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "O", &obj)) {
return NULL;
}
if (PyObject_AsReadBuffer(obj, &ptr, &size) < 0)
return NULL;
return PyString_FromStringAndSize((char*)ptr, size);
}
/*********************** Install Module **************************/
/* No functions in array module. */
static PyMethodDef a_methods[] = {
{"_reconstruct", (PyCFunction)_reconstruct, METH_VARARGS, NULL},
{"switch_multiply", (PyCFunction)switch_multiply, METH_NOARGS, NULL},
{"readbuffer_as_string", (PyCFunction)readbuffer_as_string, METH_VARARGS, NULL},
{NULL, NULL, 0, NULL} /* Sentinel */
};
......
......@@ -89,6 +89,7 @@ class AppTestArrayModule(AppTestCpythonExtensionBase):
assert res == [2, 4, 6]
def test_subclass(self):
import struct
module = self.import_module(name='array')
class Sub(module.array):
pass
......@@ -97,3 +98,5 @@ class AppTestArrayModule(AppTestCpythonExtensionBase):
res = [1, 2, 3] * arr
assert res == [1, 2, 3, 1, 2, 3]
val = module.readbuffer_as_string(arr)
assert val == struct.pack('i', 2)
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