gh-111178: Fix function signatures in cellobject.c (#125182)

This commit is contained in:
Victor Stinner 2024-10-09 16:13:55 +02:00 committed by GitHub
parent a5716a3091
commit 440632adb2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 23 additions and 16 deletions

View File

@ -5,6 +5,8 @@
#include "pycore_modsupport.h" // _PyArg_NoKeywords() #include "pycore_modsupport.h" // _PyArg_NoKeywords()
#include "pycore_object.h" #include "pycore_object.h"
#define _PyCell_CAST(op) _Py_CAST(PyCellObject*, (op))
PyObject * PyObject *
PyCell_New(PyObject *obj) PyCell_New(PyObject *obj)
{ {
@ -72,8 +74,9 @@ PyCell_Set(PyObject *op, PyObject *value)
} }
static void static void
cell_dealloc(PyCellObject *op) cell_dealloc(PyObject *self)
{ {
PyCellObject *op = _PyCell_CAST(self);
_PyObject_GC_UNTRACK(op); _PyObject_GC_UNTRACK(op);
Py_XDECREF(op->ob_ref); Py_XDECREF(op->ob_ref);
PyObject_GC_Del(op); PyObject_GC_Del(op);
@ -100,10 +103,12 @@ cell_richcompare(PyObject *a, PyObject *b, int op)
} }
static PyObject * static PyObject *
cell_repr(PyCellObject *op) cell_repr(PyObject *self)
{ {
if (op->ob_ref == NULL) PyCellObject *op = _PyCell_CAST(self);
if (op->ob_ref == NULL) {
return PyUnicode_FromFormat("<cell at %p: empty>", op); return PyUnicode_FromFormat("<cell at %p: empty>", op);
}
return PyUnicode_FromFormat("<cell at %p: %.80s object at %p>", return PyUnicode_FromFormat("<cell at %p: %.80s object at %p>",
op, Py_TYPE(op->ob_ref)->tp_name, op, Py_TYPE(op->ob_ref)->tp_name,
@ -111,24 +116,26 @@ cell_repr(PyCellObject *op)
} }
static int static int
cell_traverse(PyCellObject *op, visitproc visit, void *arg) cell_traverse(PyObject *self, visitproc visit, void *arg)
{ {
PyCellObject *op = _PyCell_CAST(self);
Py_VISIT(op->ob_ref); Py_VISIT(op->ob_ref);
return 0; return 0;
} }
static int static int
cell_clear(PyCellObject *op) cell_clear(PyObject *self)
{ {
PyCellObject *op = _PyCell_CAST(self);
Py_CLEAR(op->ob_ref); Py_CLEAR(op->ob_ref);
return 0; return 0;
} }
static PyObject * static PyObject *
cell_get_contents(PyCellObject *op, void *closure) cell_get_contents(PyObject *self, void *closure)
{ {
if (op->ob_ref == NULL) PyCellObject *op = _PyCell_CAST(self);
{ if (op->ob_ref == NULL) {
PyErr_SetString(PyExc_ValueError, "Cell is empty"); PyErr_SetString(PyExc_ValueError, "Cell is empty");
return NULL; return NULL;
} }
@ -136,15 +143,15 @@ cell_get_contents(PyCellObject *op, void *closure)
} }
static int static int
cell_set_contents(PyCellObject *op, PyObject *obj, void *Py_UNUSED(ignored)) cell_set_contents(PyObject *self, PyObject *obj, void *Py_UNUSED(ignored))
{ {
PyCellObject *op = _PyCell_CAST(self);
Py_XSETREF(op->ob_ref, Py_XNewRef(obj)); Py_XSETREF(op->ob_ref, Py_XNewRef(obj));
return 0; return 0;
} }
static PyGetSetDef cell_getsetlist[] = { static PyGetSetDef cell_getsetlist[] = {
{"cell_contents", (getter)cell_get_contents, {"cell_contents", cell_get_contents, cell_set_contents, NULL},
(setter)cell_set_contents, NULL},
{NULL} /* sentinel */ {NULL} /* sentinel */
}; };
@ -153,12 +160,12 @@ PyTypeObject PyCell_Type = {
"cell", "cell",
sizeof(PyCellObject), sizeof(PyCellObject),
0, 0,
(destructor)cell_dealloc, /* tp_dealloc */ cell_dealloc, /* tp_dealloc */
0, /* tp_vectorcall_offset */ 0, /* tp_vectorcall_offset */
0, /* tp_getattr */ 0, /* tp_getattr */
0, /* tp_setattr */ 0, /* tp_setattr */
0, /* tp_as_async */ 0, /* tp_as_async */
(reprfunc)cell_repr, /* tp_repr */ cell_repr, /* tp_repr */
0, /* tp_as_number */ 0, /* tp_as_number */
0, /* tp_as_sequence */ 0, /* tp_as_sequence */
0, /* tp_as_mapping */ 0, /* tp_as_mapping */
@ -170,8 +177,8 @@ PyTypeObject PyCell_Type = {
0, /* tp_as_buffer */ 0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
cell_new_doc, /* tp_doc */ cell_new_doc, /* tp_doc */
(traverseproc)cell_traverse, /* tp_traverse */ cell_traverse, /* tp_traverse */
(inquiry)cell_clear, /* tp_clear */ cell_clear, /* tp_clear */
cell_richcompare, /* tp_richcompare */ cell_richcompare, /* tp_richcompare */
0, /* tp_weaklistoffset */ 0, /* tp_weaklistoffset */
0, /* tp_iter */ 0, /* tp_iter */
@ -186,6 +193,6 @@ PyTypeObject PyCell_Type = {
0, /* tp_dictoffset */ 0, /* tp_dictoffset */
0, /* tp_init */ 0, /* tp_init */
0, /* tp_alloc */ 0, /* tp_alloc */
(newfunc)cell_new, /* tp_new */ cell_new, /* tp_new */
0, /* tp_free */ 0, /* tp_free */
}; };