8000 gh-111178: Fix function signatures in _testbuffer.c by vstinner · Pull Request #131463 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-111178: Fix function signatures in _testbuffer.c #131463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 50 additions & 36 deletions Modules/_testbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,9 @@ ndarray_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}

static void
ndarray_dealloc(NDArrayObject *self)
ndarray_dealloc(PyObject *op)
{
NDArrayObject *self = (NDArrayObject*)op;
if (self->head) {
if (ND_IS_CONSUMER(self)) {
Py_buffer *base = &self->head->base;
Expand Down Expand Up @@ -1413,8 +1414,9 @@ ndarray_pop(PyObject *self, PyObject *dummy)
/**************************************************************************/

static int
ndarray_getbuf(NDArrayObject *self, Py_buffer *view, int flags)
ndarray_getbuf(PyObject *op, Py_buffer *view, int flags)
{
NDArrayObject *self = (NDArrayObject*)op;
ndbuf_t *ndbuf = self->head;
Py_buffer *base = &ndbuf->base;
int baseflags = ndbuf->flags;
Expand Down Expand Up @@ -1530,8 +1532,9 @@ ndarray_getbuf(NDArrayObject *self, Py_buffer *view, int flags)
}

static void
ndarray_releasebuf(NDArrayObject *self, Py_buffer *view)
ndarray_releasebuf(PyObject *op, Py_buffer *view)
{
NDArrayObject *self = (NDArrayObject*)op;
if (!ND_IS_CONSUMER(self)) {
ndbuf_t *ndbuf = view->internal;
if (--ndbuf->exports == 0 && ndbuf != self->head)
Expand All @@ -1540,8 +1543,8 @@ ndarray_releasebuf(NDArrayObject *self, Py_buffer *view)
}

static PyBufferProcs ndarray_as_buffer = {
(getbufferproc)ndarray_getbuf, /* bf_getbuffer */
(releasebufferproc)ndarray_releasebuf /* bf_releasebuffer */
ndarray_getbuf, /* bf_getbuffer */
ndarray_releasebuf, /* bf_releasebuffer */
};


Expand Down Expand Up @@ -1998,21 +2001,24 @@ ssize_array_as_tuple(Py_ssize_t *array, Py_ssize_t len)
}

static PyObject *
ndarray_get_flags(NDArrayObject *self, void *closure)
ndarray_get_flags(PyObject *op, void *closure)
{
NDArrayObject *self = (NDArrayObject*)op;
return PyLong_FromLong(self->head->flags);
}

static PyObject *
ndarray_get_offset(NDArrayObject *self, void *closure)
ndarray_get_offset(PyObject *op, void *closure)
{
NDArrayObject *self = (NDArrayObject*)op;
ndbuf_t *ndbuf = self->head;
return PyLong_FromSsize_t(ndbuf->offset);
}

static PyObject *
ndarray_get_obj(NDArrayObject *self, void *closure)
ndarray_get_obj(PyObject *op, void *closure)
{
NDArrayObject *self = (NDArrayObject*)op;
Py_buffer *base = &self->head->base;

if (base->obj == NULL) {
Expand All @@ -2022,64 +2028,72 @@ ndarray_get_obj(NDArrayObject *self, void *closure)
}

static PyObject *
ndarray_get_nbytes(NDArrayObject *self, void *closure)
ndarray_get_nbytes(PyObject *op, void *closure)
{
NDArrayObject *self = (NDArrayObject*)op;
Py_buffer *base = &self->head->base;
return PyLong_FromSsize_t(base->len);
}

static PyObject *
ndarray_get_readonly(NDArrayObject *self, void *closure)
ndarray_get_readonly(PyObject *op, void *closure)
{
NDArrayObject *self = (NDArrayObject*)op;
Py_buffer *base = &self->head->base;
return PyBool_FromLong(base->readonly);
}

static PyObject *
ndarray_get_itemsize(NDArrayObject *self, void *closure)
ndarray_get_itemsize(PyObject *op, void *closure)
{
NDArrayObject *self = (NDArrayObject*)op;
Py_buffer *base = &self->head->base;
return PyLong_FromSsize_t(base->itemsize);
}

static PyObject *
ndarray_get_format(NDArrayObject *self, void *closure)
ndarray_get_format(PyObject *op, void *closure)
{
NDArrayObject *self = (NDArrayObject*)op;
Py_buffer *base = &self->head->base;
const char *fmt = base->format ? base->format : "";
return PyUnicode_FromString(fmt);
}

static PyObject *
ndarray_get_ndim(NDArrayObject *self, void *closure)
ndarray_get_ndim(PyObject *op, void *closure)
{
NDArrayObject *self = (NDArrayObject*)op;
Py_buffer *base = &self->head->base;
return PyLong_FromSsize_t(base->ndim);
}

static PyObject *
ndarray_get_shape(NDArrayObject *self, void *closure)
ndarray_get_shape(PyObject *op, void *closure)
{
NDArrayObject *self = (NDArrayObject*)op;
Py_buffer *base = &self->head->base;
return ssize_array_as_tuple(base->shape, base->ndim);
}

static PyObject *
ndarray_get_strides(NDArrayObject *self, void *closure)
ndarray_get_strides(PyObject *op, void *closure)
{
NDArrayObject *self = (NDArrayObject*)op;
Py_buffer *base = &self->head->base;
return ssize_array_as_tuple(base->strides, base->ndim);
}

static PyObject *
ndarray_get_suboffsets(NDArrayObject *self, void *closure)
ndarray_get_suboffsets(PyObject *op, void *closure)
{
NDArrayObject *self = (NDArrayObject*)op;
Py_buffer *base = &self->head->base;
return ssize_array_as_tuple(base->suboffsets, base->ndim);
}

static PyObject *
ndarray_c_contig(PyObject *self, PyObject *dummy)
ndarray_c_contig(PyObject *self, void *dummy)
{
NDArrayObject *nd = (NDArrayObject *)self;
int ret = PyBuffer_IsContiguous(&nd->head->base, 'C');
Expand All @@ -2093,7 +2107,7 @@ ndarray_c_contig(PyObject *self, PyObject *dummy)
}

static PyObject *
ndarray_fortran_contig(PyObject *self, PyObject *dummy)
ndarray_fortran_contig(PyObject *self, void *dummy)
{
NDArrayObject *nd = (NDArrayObject *)self;
int ret = PyBuffer_IsContiguous(&nd->head->base, 'F');
Expand All @@ -2107,7 +2121,7 @@ ndarray_fortran_contig(PyObject *self, PyObject *dummy)
}

static PyObject *
ndarray_contig(PyObject *self, PyObject *dummy)
ndarray_contig(PyObject *self, void *dummy)
{
NDArrayObject *nd = (NDArrayObject *)self;
int ret = PyBuffer_IsContiguous(&nd->head->base, 'A');
Expand All @@ -2124,21 +2138,21 @@ ndarray_contig(PyObject *self, PyObject *dummy)
static PyGetSetDef ndarray_getset [] =
{
/* ndbuf */
{ "flags", (getter)ndarray_get_flags, NULL, NULL, NULL},
{ "offset", (getter)ndarray_get_offset, NULL, NULL, NULL},
{ "flags", ndarray_get_flags, NULL, NULL, NULL},
{ "offset", ndarray_get_offset, NULL, NULL, NULL},
/* ndbuf.base */
{ "obj", (getter)ndarray_get_obj, NULL, NULL, NULL},
{ "nbytes", (getter)ndarray_get_nbytes, NULL, NULL, NULL},
{ "readonly", (getter)ndarray_get_readonly, NULL, NULL, NULL},
{ "itemsize", (getter)ndarray_get_itemsize, NULL, NULL, NULL},
{ "format", (getter)ndarray_get_format, NULL, NULL, NULL},
{ "ndim", (getter)ndarray_get_ndim, NULL, NULL, NULL},
{ "shape", (getter)ndarray_get_shape, NULL, NULL, NULL},
{ "strides", (getter)ndarray_get_strides, NULL, NULL, NULL},
{ "suboffsets", (getter)ndarray_get_suboffsets, NULL, NULL, NULL},
{ "c_contiguous", (getter)ndarray_c_contig, NULL, NULL, NULL},
{ "f_contiguous", (getter)ndarray_fortran_contig, NULL, NULL, NULL},
{ "contiguous", (getter)ndarray_contig, NULL, NULL, NULL},
{ "obj", ndarray_get_obj, NULL, NULL, NULL},
{ "nbytes", ndarray_get_nbytes, NULL, NULL, NULL},
{ "readonly", ndarray_get_readonly, NULL, NULL, NULL},
{ "itemsize", ndarray_get_itemsize, NULL, NULL, NULL},
{ "format", ndarray_get_format, NULL, NULL, NULL},
{ "ndim", ndarray_get_ndim, NULL, NULL, NULL},
{ "shape", ndarray_get_shape, NULL, NULL, NULL},
{ "strides", ndarray_get_strides, NULL, NULL, NULL},
{ "suboffsets", ndarray_get_suboffsets, NULL, NULL, NULL},
{ "c_contiguous", ndarray_c_contig, NULL, NULL, NULL},
{ "f_contiguous", ndarray_fortran_contig, NULL, NULL, NULL},
{ "contiguous", ndarray_contig, NULL, NULL, NULL},
{NULL}
};

Expand Down Expand Up @@ -2623,7 +2637,7 @@ ndarray_hash(PyObject *self)
}


static PyMethodDef ndarray_methods [] =
static PyMethodDef ndarray_methods[] =
{
{ "tolist", ndarray_tolist, METH_NOARGS, NULL },
{ "tobytes", ndarray_tobytes, METH_NOARGS, NULL },
Expand All @@ -2639,7 +2653,7 @@ static PyTypeObject NDArray_Type = {
"ndarray", /* Name of this type */
sizeof(NDArrayObject), /* Basic object size */
0, /* Item size for varobject */
(destructor)ndarray_dealloc, /* tp_dealloc */
ndarray_dealloc, /* tp_dealloc */
0, /* tp_vectorcall_offset */
0, /* tp_getattr */
0, /* tp_setattr */
Expand All @@ -2648,7 +2662,7 @@ static PyTypeObject NDArray_Type = {
0, /* tp_as_number */
&ndarray_as_sequence, /* tp_as_sequence */
&ndarray_as_mapping, /* tp_as_mapping */
(hashfunc)ndarray_hash, /* tp_hash */
ndarray_hash, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
PyObject_GenericGetAttr, /* tp_getattro */
Expand Down
Loading
0