Skip to content

Commit 440632a

Browse files
authored
gh-111178: Fix function signatures in cellobject.c (#125182)
1 parent a5716a3 commit 440632a

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

Objects/cellobject.c

+23-16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "pycore_modsupport.h" // _PyArg_NoKeywords()
66
#include "pycore_object.h"
77

8+
#define _PyCell_CAST(op) _Py_CAST(PyCellObject*, (op))
9+
810
PyObject *
911
PyCell_New(PyObject *obj)
1012
{
@@ -72,8 +74,9 @@ PyCell_Set(PyObject *op, PyObject *value)
7274
}
7375

7476
static void
75-
cell_dealloc(PyCellObject *op)
77+
cell_dealloc(PyObject *self)
7678
{
79+
PyCellObject *op = _PyCell_CAST(self);
7780
_PyObject_GC_UNTRACK(op);
7881
Py_XDECREF(op->ob_ref);
7982
PyObject_GC_Del(op);
@@ -100,51 +103,55 @@ cell_richcompare(PyObject *a, PyObject *b, int op)
100103
}
101104

102105
static PyObject *
103-
cell_repr(PyCellObject *op)
106+
cell_repr(PyObject *self)
104107
{
105-
if (op->ob_ref == NULL)
108+
PyCellObject *op = _PyCell_CAST(self);
109+
if (op->ob_ref == NULL) {
106110
return PyUnicode_FromFormat("<cell at %p: empty>", op);
111+
}
107112

108113
return PyUnicode_FromFormat("<cell at %p: %.80s object at %p>",
109114
op, Py_TYPE(op->ob_ref)->tp_name,
110115
op->ob_ref);
111116
}
112117

113118
static int
114-
cell_traverse(PyCellObject *op, visitproc visit, void *arg)
119+
cell_traverse(PyObject *self, visitproc visit, void *arg)
115120
{
121+
PyCellObject *op = _PyCell_CAST(self);
116122
Py_VISIT(op->ob_ref);
117123
return 0;
118124
}
119125

120126
static int
121-
cell_clear(PyCellObject *op)
127+
cell_clear(PyObject *self)
122128
{
129+
PyCellObject *op = _PyCell_CAST(self);
123130
Py_CLEAR(op->ob_ref);
124131
return 0;
125132
}
126133

127134
static PyObject *
128-
cell_get_contents(PyCellObject *op, void *closure)
135+
cell_get_contents(PyObject *self, void *closure)
129136
{
130-
if (op->ob_ref == NULL)
131-
{
137+
PyCellObject *op = _PyCell_CAST(self);
138+
if (op->ob_ref == NULL) {
132139
PyErr_SetString(PyExc_ValueError, "Cell is empty");
133140
return NULL;
134141
}
135142
return Py_NewRef(op->ob_ref);
136143
}
137144

138145
static int
139-
cell_set_contents(PyCellObject *op, PyObject *obj, void *Py_UNUSED(ignored))
146+
cell_set_contents(PyObject *self, PyObject *obj, void *Py_UNUSED(ignored))
140147
{
148+
PyCellObject *op = _PyCell_CAST(self);
141149
Py_XSETREF(op->ob_ref, Py_XNewRef(obj));
142150
return 0;
143151
}
144152

145153
static PyGetSetDef cell_getsetlist[] = {
146-
{"cell_contents", (getter)cell_get_contents,
147-
(setter)cell_set_contents, NULL},
154+
{"cell_contents", cell_get_contents, cell_set_contents, NULL},
148155
{NULL} /* sentinel */
149156
};
150157

@@ -153,12 +160,12 @@ PyTypeObject PyCell_Type = {
153160
"cell",
154161
sizeof(PyCellObject),
155162
0,
156-
(destructor)cell_dealloc, /* tp_dealloc */
163+
cell_dealloc, /* tp_dealloc */
157164
0, /* tp_vectorcall_offset */
158165
0, /* tp_getattr */
159166
0, /* tp_setattr */
160167
0, /* tp_as_async */
161-
(reprfunc)cell_repr, /* tp_repr */
168+
cell_repr, /* tp_repr */
162169
0, /* tp_as_number */
163170
0, /* tp_as_sequence */
164171
0, /* tp_as_mapping */
@@ -170,8 +177,8 @@ PyTypeObject PyCell_Type = {
170177
0, /* tp_as_buffer */
171178
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
172179
cell_new_doc, /* tp_doc */
173-
(traverseproc)cell_traverse, /* tp_traverse */
174-
(inquiry)cell_clear, /* tp_clear */
180+
cell_traverse, /* tp_traverse */
181+
cell_clear, /* tp_clear */
175182
cell_richcompare, /* tp_richcompare */
176183
0, /* tp_weaklistoffset */
177184
0, /* tp_iter */
@@ -186,6 +193,6 @@ PyTypeObject PyCell_Type = {
186193
0, /* tp_dictoffset */
187194
0, /* tp_init */
188195
0, /* tp_alloc */
189-
(newfunc)cell_new, /* tp_new */
196+
cell_new, /* tp_new */
190197
0, /* tp_free */
191198
};

0 commit comments

Comments
 (0)