Skip to content

Commit

Permalink
gh-111178: Fix function signatures in cellobject.c (#125182)
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner authored Oct 9, 2024
1 parent a5716a3 commit 440632a
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions Objects/cellobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "pycore_modsupport.h" // _PyArg_NoKeywords()
#include "pycore_object.h"

#define _PyCell_CAST(op) _Py_CAST(PyCellObject*, (op))

PyObject *
PyCell_New(PyObject *obj)
{
Expand Down Expand Up @@ -72,8 +74,9 @@ PyCell_Set(PyObject *op, PyObject *value)
}

static void
cell_dealloc(PyCellObject *op)
cell_dealloc(PyObject *self)
{
PyCellObject *op = _PyCell_CAST(self);
_PyObject_GC_UNTRACK(op);
Py_XDECREF(op->ob_ref);
PyObject_GC_Del(op);
Expand All @@ -100,51 +103,55 @@ cell_richcompare(PyObject *a, PyObject *b, int op)
}

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: %.80s object at %p>",
op, Py_TYPE(op->ob_ref)->tp_name,
op->ob_ref);
}

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);
return 0;
}

static int
cell_clear(PyCellObject *op)
cell_clear(PyObject *self)
{
PyCellObject *op = _PyCell_CAST(self);
Py_CLEAR(op->ob_ref);
return 0;
}

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");
return NULL;
}
return Py_NewRef(op->ob_ref);
}

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));
return 0;
}

static PyGetSetDef cell_getsetlist[] = {
{"cell_contents", (getter)cell_get_contents,
(setter)cell_set_contents, NULL},
{"cell_contents", cell_get_contents, cell_set_contents, NULL},
{NULL} /* sentinel */
};

Expand All @@ -153,12 +160,12 @@ PyTypeObject PyCell_Type = {
"cell",
sizeof(PyCellObject),
0,
(destructor)cell_dealloc, /* tp_dealloc */
cell_dealloc, /* tp_dealloc */
0, /* tp_vectorcall_offset */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_as_async */
(reprfunc)cell_repr, /* tp_repr */
cell_repr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
Expand All @@ -170,8 +177,8 @@ PyTypeObject PyCell_Type = {
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
cell_new_doc, /* tp_doc */
(traverseproc)cell_traverse, /* tp_traverse */
(inquiry)cell_clear, /* tp_clear */
cell_traverse, /* tp_traverse */
cell_clear, /* tp_clear */
cell_richcompare, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
Expand All @@ -186,6 +193,6 @@ PyTypeObject PyCell_Type = {
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
(newfunc)cell_new, /* tp_new */
cell_new, /* tp_new */
0, /* tp_free */
};

0 comments on commit 440632a

Please sign in to comment.