Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-111178: Fix function signatures in classobject.c #124943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions Objects/classobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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}
};

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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}
};

Expand Down Expand Up @@ -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,
Expand Down
Loading