Skip to content
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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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