Skip to content

Commit 2c2ad4f

Browse files
authored
gh-111178: Fix function signatures in classobject.c (#124943)
1 parent aace0dc commit 2c2ad4f

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

Objects/classobject.c

+25-17
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "clinic/classobject.c.h"
1212

13+
#define _PyMethodObject_CAST(op) _Py_CAST(PyMethodObject*, (op))
1314
#define TP_DESCR_GET(t) ((t)->tp_descr_get)
1415

1516
/*[clinic input]
@@ -166,13 +167,14 @@ static PyMemberDef method_memberlist[] = {
166167
should only be used for the class, not for instances */
167168

168169
static PyObject *
169-
method_get_doc(PyMethodObject *im, void *context)
170+
method_get_doc(PyObject *self, void *context)
170171
{
172+
PyMethodObject *im = _PyMethodObject_CAST(self);
171173
return PyObject_GetAttr(im->im_func, &_Py_ID(__doc__));
172174
}
173175

174176
static PyGetSetDef method_getset[] = {
175-
{"__doc__", (getter)method_get_doc, NULL, NULL},
177+
{"__doc__", method_get_doc, NULL, NULL},
176178
{0}
177179
};
178180

@@ -235,8 +237,9 @@ method_new_impl(PyTypeObject *type, PyObject *function, PyObject *instance)
235237
}
236238

237239
static void
238-
method_dealloc(PyMethodObject *im)
240+
method_dealloc(PyObject *self)
239241
{
242+
PyMethodObject *im = _PyMethodObject_CAST(self);
240243
_PyObject_GC_UNTRACK(im);
241244
if (im->im_weakreflist != NULL)
242245
PyObject_ClearWeakRefs((PyObject *)im);
@@ -274,8 +277,9 @@ method_richcompare(PyObject *self, PyObject *other, int op)
274277
}
275278

276279
static PyObject *
277-
method_repr(PyMethodObject *a)
280+
method_repr(PyObject *op)
278281
{
282+
PyMethodObject *a = _PyMethodObject_CAST(op);
279283
PyObject *self = a->im_self;
280284
PyObject *func = a->im_func;
281285
PyObject *funcname, *result;
@@ -301,22 +305,26 @@ method_repr(PyMethodObject *a)
301305
}
302306

303307
static Py_hash_t
304-
method_hash(PyMethodObject *a)
308+
method_hash(PyObject *self)
305309
{
306-
Py_hash_t x, y;
307-
x = PyObject_GenericHash(a->im_self);
308-
y = PyObject_Hash(a->im_func);
309-
if (y == -1)
310+
PyMethodObject *a = _PyMethodObject_CAST(self);
311+
Py_hash_t x = PyObject_GenericHash(a->im_self);
312+
Py_hash_t y = PyObject_Hash(a->im_func);
313+
if (y == -1) {
310314
return -1;
315+
}
316+
311317
x = x ^ y;
312-
if (x == -1)
318+
if (x == -1) {
313319
x = -2;
320+
}
314321
return x;
315322
}
316323

317324
static int
318-
method_traverse(PyMethodObject *im, visitproc visit, void *arg)
325+
method_traverse(PyObject *self, visitproc visit, void *arg)
319326
{
327+
PyMethodObject *im = _PyMethodObject_CAST(self);
320328
Py_VISIT(im->im_func);
321329
Py_VISIT(im->im_self);
322330
return 0;
@@ -333,17 +341,17 @@ PyTypeObject PyMethod_Type = {
333341
PyVarObject_HEAD_INIT(&PyType_Type, 0)
334342
.tp_name = "method",
335343
.tp_basicsize = sizeof(PyMethodObject),
336-
.tp_dealloc = (destructor)method_dealloc,
344+
.tp_dealloc = method_dealloc,
337345
.tp_vectorcall_offset = offsetof(PyMethodObject, vectorcall),
338-
.tp_repr = (reprfunc)method_repr,
339-
.tp_hash = (hashfunc)method_hash,
346+
.tp_repr = method_repr,
347+
.tp_hash = method_hash,
340348
.tp_call = PyVectorcall_Call,
341349
.tp_getattro = method_getattro,
342350
.tp_setattro = PyObject_GenericSetAttr,
343351
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
344352
Py_TPFLAGS_HAVE_VECTORCALL,
345353
.tp_doc = method_new__doc__,
346-
.tp_traverse = (traverseproc)method_traverse,
354+
.tp_traverse = method_traverse,
347355
.tp_richcompare = method_richcompare,
348356
.tp_weaklistoffset = offsetof(PyMethodObject, im_weakreflist),
349357
.tp_methods = method_methods,
@@ -399,7 +407,7 @@ instancemethod_get_doc(PyObject *self, void *context)
399407
}
400408

401409
static PyGetSetDef instancemethod_getset[] = {
402-
{"__doc__", (getter)instancemethod_get_doc, NULL, NULL},
410+
{"__doc__", instancemethod_get_doc, NULL, NULL},
403411
{0}
404412
};
405413

@@ -537,7 +545,7 @@ PyTypeObject PyInstanceMethod_Type = {
537545
.tp_name = "instancemethod",
538546
.tp_basicsize = sizeof(PyInstanceMethodObject),
539547
.tp_dealloc = instancemethod_dealloc,
540-
.tp_repr = (reprfunc)instancemethod_repr,
548+
.tp_repr = instancemethod_repr,
541549
.tp_call = instancemethod_call,
542550
.tp_getattro = instancemethod_getattro,
543551
.tp_setattro = PyObject_GenericSetAttr,

0 commit comments

Comments
 (0)