Skip to content

Commit 55b69e7

Browse files
committed
Oops, forgot that there are modules outside the win32 world.
1 parent ba4105c commit 55b69e7

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

‎Include/methodobject.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ struct PyMethodDef {
4343
};
4444
typedef struct PyMethodDef PyMethodDef;
4545

46+
PyAPI_FUNC(PyObject *) Py_FindMethod(PyMethodDef[], PyObject *, const char *);
47+
4648
#define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL)
4749
PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *,
4850
PyObject *);
@@ -68,6 +70,14 @@ PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *,
6870

6971
#define METH_COEXIST 0x0040
7072

73+
typedef struct PyMethodChain {
74+
PyMethodDef *methods; /* Methods of this type */
75+
struct PyMethodChain *link; /* NULL or base type */
76+
} PyMethodChain;
77+
78+
PyAPI_FUNC(PyObject *) Py_FindMethodInChain(PyMethodChain *, PyObject *,
79+
const char *);
80+
7181
typedef struct {
7282
PyObject_HEAD
7383
PyMethodDef *m_ml; /* Description of the C function to call */

‎Objects/methodobject.c‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,43 @@ PyTypeObject PyCFunction_Type = {
280280
0, /* tp_dict */
281281
};
282282

283+
/* Find a method in a method chain */
284+
285+
PyObject *
286+
Py_FindMethodInChain(PyMethodChain *chain, PyObject *self, const char *name)
287+
{
288+
if (name[0] == '_' && name[1] == '_') {
289+
if (strcmp(name, "__doc__") == 0) {
290+
const char *doc = self->ob_type->tp_doc;
291+
if (doc != NULL)
292+
return PyUnicode_FromString(doc);
293+
}
294+
}
295+
while (chain != NULL) {
296+
PyMethodDef *ml = chain->methods;
297+
for (; ml->ml_name != NULL; ml++) {
298+
if (name[0] == ml->ml_name[0] &&
299+
strcmp(name+1, ml->ml_name+1) == 0)
300+
/* XXX */
301+
return PyCFunction_New(ml, self);
302+
}
303+
chain = chain->link;
304+
}
305+
PyErr_SetString(PyExc_AttributeError, name);
306+
return NULL;
307+
}
308+
309+
/* Find a method in a single method list */
310+
311+
PyObject *
312+
Py_FindMethod(PyMethodDef *methods, PyObject *self, const char *name)
313+
{
314+
PyMethodChain chain;
315+
chain.methods = methods;
316+
chain.link = NULL;
317+
return Py_FindMethodInChain(&chain, self, name);
318+
}
319+
283320
/* Clear out the free list */
284321

285322
int

0 commit comments

Comments
 (0)