#include "clinic/classobject.c.h"
+#define _PyMethodObject_CAST(op) _Py_CAST(PyMethodObject*, (op))
#define TP_DESCR_GET(t) ((t)->tp_descr_get)
/*[clinic input]
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}
};
}
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);
}
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;
}
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;
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,
}
static PyGetSetDef instancemethod_getset[] = {
- {"__doc__", (getter)instancemethod_get_doc, NULL, NULL},
+ {"__doc__", instancemethod_get_doc, NULL, NULL},
{0}
};
.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,