Skip to content

Commit cc79e3c

Browse files
committed
Add PyMethod_Function(), PyMethod_Self(), PyMethod_Class() back.
While not even documented, they were clearly part of the C API, there's no great difficulty to support them, and it has the cool effect of not requiring any changes to ExtensionClass.c.
1 parent 25b2583 commit cc79e3c

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

Include/classobject.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ extern DL_IMPORT(PyObject *) PyInstance_New(PyObject *, PyObject *,
4747
extern DL_IMPORT(PyObject *) PyInstance_NewRaw(PyObject *, PyObject *);
4848
extern DL_IMPORT(PyObject *) PyMethod_New(PyObject *, PyObject *, PyObject *);
4949

50+
extern DL_IMPORT(PyObject *) PyMethod_Function(PyObject *);
51+
extern DL_IMPORT(PyObject *) PyMethod_Self(PyObject *);
52+
extern DL_IMPORT(PyObject *) PyMethod_Class(PyObject *);
53+
5054
/* Macros for direct access to these values. Type checks are *not*
5155
done, so use with care. */
5256
#define PyMethod_GET_FUNCTION(meth) \

Objects/classobject.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,36 @@ PyClass_New(PyObject *bases, PyObject *dict, PyObject *name)
106106
return (PyObject *) op;
107107
}
108108

109+
PyObject *
110+
PyMethod_Function(PyObject *im)
111+
{
112+
if (!PyMethod_Check(im)) {
113+
PyErr_BadInternalCall();
114+
return NULL;
115+
}
116+
return ((PyMethodObject *)im)->im_func;
117+
}
118+
119+
PyObject *
120+
PyMethod_Self(PyObject *im)
121+
{
122+
if (!PyMethod_Check(im)) {
123+
PyErr_BadInternalCall();
124+
return NULL;
125+
}
126+
return ((PyMethodObject *)im)->im_self;
127+
}
128+
129+
PyObject *
130+
PyMethod_Class(PyObject *im)
131+
{
132+
if (!PyMethod_Check(im)) {
133+
PyErr_BadInternalCall();
134+
return NULL;
135+
}
136+
return ((PyMethodObject *)im)->im_class;
137+
}
138+
109139
static PyObject *
110140
class_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
111141
{

0 commit comments

Comments
 (0)