]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-111178: Fix function signatures in classobject.c (#124943)
authorVictor Stinner <vstinner@python.org>
Fri, 4 Oct 2024 10:00:00 +0000 (12:00 +0200)
committerGitHub <noreply@github.com>
Fri, 4 Oct 2024 10:00:00 +0000 (12:00 +0200)
Objects/classobject.c

index 69a7d5f046e30d021900877e37794d07fda4f811..775894ad5a716641a812afc69b83eecda0e20cdd 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "clinic/classobject.c.h"
 
+#define _PyMethodObject_CAST(op) _Py_CAST(PyMethodObject*, (op))
 #define TP_DESCR_GET(t) ((t)->tp_descr_get)
 
 /*[clinic input]
@@ -166,13 +167,14 @@ static PyMemberDef method_memberlist[] = {
    should only be used for the class, not for instances */
 
 static PyObject *
-method_get_doc(PyMethodObject *im, void *context)
+method_get_doc(PyObject *self, void *context)
 {
+    PyMethodObject *im = _PyMethodObject_CAST(self);
     return PyObject_GetAttr(im->im_func, &_Py_ID(__doc__));
 }
 
 static PyGetSetDef method_getset[] = {
-    {"__doc__", (getter)method_get_doc, NULL, NULL},
+    {"__doc__", method_get_doc, NULL, NULL},
     {0}
 };
 
@@ -235,8 +237,9 @@ method_new_impl(PyTypeObject *type, PyObject *function, PyObject *instance)
 }
 
 static void
-method_dealloc(PyMethodObject *im)
+method_dealloc(PyObject *self)
 {
+    PyMethodObject *im = _PyMethodObject_CAST(self);
     _PyObject_GC_UNTRACK(im);
     if (im->im_weakreflist != NULL)
         PyObject_ClearWeakRefs((PyObject *)im);
@@ -274,8 +277,9 @@ method_richcompare(PyObject *self, PyObject *other, int op)
 }
 
 static PyObject *
-method_repr(PyMethodObject *a)
+method_repr(PyObject *op)
 {
+    PyMethodObject *a = _PyMethodObject_CAST(op);
     PyObject *self = a->im_self;
     PyObject *func = a->im_func;
     PyObject *funcname, *result;
@@ -301,22 +305,26 @@ method_repr(PyMethodObject *a)
 }
 
 static Py_hash_t
-method_hash(PyMethodObject *a)
+method_hash(PyObject *self)
 {
-    Py_hash_t x, y;
-    x = PyObject_GenericHash(a->im_self);
-    y = PyObject_Hash(a->im_func);
-    if (y == -1)
+    PyMethodObject *a = _PyMethodObject_CAST(self);
+    Py_hash_t x = PyObject_GenericHash(a->im_self);
+    Py_hash_t y = PyObject_Hash(a->im_func);
+    if (y == -1) {
         return -1;
+    }
+
     x = x ^ y;
-    if (x == -1)
+    if (x == -1) {
         x = -2;
+    }
     return x;
 }
 
 static int
-method_traverse(PyMethodObject *im, visitproc visit, void *arg)
+method_traverse(PyObject *self, visitproc visit, void *arg)
 {
+    PyMethodObject *im = _PyMethodObject_CAST(self);
     Py_VISIT(im->im_func);
     Py_VISIT(im->im_self);
     return 0;
@@ -333,17 +341,17 @@ PyTypeObject PyMethod_Type = {
     PyVarObject_HEAD_INIT(&PyType_Type, 0)
     .tp_name = "method",
     .tp_basicsize = sizeof(PyMethodObject),
-    .tp_dealloc = (destructor)method_dealloc,
+    .tp_dealloc = method_dealloc,
     .tp_vectorcall_offset = offsetof(PyMethodObject, vectorcall),
-    .tp_repr = (reprfunc)method_repr,
-    .tp_hash = (hashfunc)method_hash,
+    .tp_repr = method_repr,
+    .tp_hash = method_hash,
     .tp_call = PyVectorcall_Call,
     .tp_getattro = method_getattro,
     .tp_setattro = PyObject_GenericSetAttr,
     .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
                 Py_TPFLAGS_HAVE_VECTORCALL,
     .tp_doc = method_new__doc__,
-    .tp_traverse = (traverseproc)method_traverse,
+    .tp_traverse = method_traverse,
     .tp_richcompare = method_richcompare,
     .tp_weaklistoffset = offsetof(PyMethodObject, im_weakreflist),
     .tp_methods = method_methods,
@@ -399,7 +407,7 @@ instancemethod_get_doc(PyObject *self, void *context)
 }
 
 static PyGetSetDef instancemethod_getset[] = {
-    {"__doc__", (getter)instancemethod_get_doc, NULL, NULL},
+    {"__doc__", instancemethod_get_doc, NULL, NULL},
     {0}
 };
 
@@ -537,7 +545,7 @@ PyTypeObject PyInstanceMethod_Type = {
     .tp_name = "instancemethod",
     .tp_basicsize = sizeof(PyInstanceMethodObject),
     .tp_dealloc = instancemethod_dealloc,
-    .tp_repr = (reprfunc)instancemethod_repr,
+    .tp_repr = instancemethod_repr,
     .tp_call = instancemethod_call,
     .tp_getattro = instancemethod_getattro,
     .tp_setattro = PyObject_GenericSetAttr,