[Python-3000-checkins] r64676 - in python/branches/py3k: Include/methodobject.h Objects/methodobject.c

amaury.forgeotdarc python-3000-checkins at python.org
Wed Jul 2 23:47:18 CEST 2008


Author: amaury.forgeotdarc
Date: Wed Jul  2 23:47:18 2008
New Revision: 64676

Log:
Oops, forgot that there are modules outside the win32 world.


Modified:
   python/branches/py3k/Include/methodobject.h
   python/branches/py3k/Objects/methodobject.c

Modified: python/branches/py3k/Include/methodobject.h
==============================================================================
--- python/branches/py3k/Include/methodobject.h	(original)
+++ python/branches/py3k/Include/methodobject.h	Wed Jul  2 23:47:18 2008
@@ -43,6 +43,8 @@
 };
 typedef struct PyMethodDef PyMethodDef;
 
+PyAPI_FUNC(PyObject *) Py_FindMethod(PyMethodDef[], PyObject *, const char *);
+
 #define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL)
 PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *, 
 					 PyObject *);
@@ -68,6 +70,14 @@
 
 #define METH_COEXIST   0x0040
 
+typedef struct PyMethodChain {
+    PyMethodDef *methods;		/* Methods of this type */
+    struct PyMethodChain *link;	/* NULL or base type */
+} PyMethodChain;
+
+PyAPI_FUNC(PyObject *) Py_FindMethodInChain(PyMethodChain *, PyObject *,
+                                            const char *);
+
 typedef struct {
     PyObject_HEAD
     PyMethodDef *m_ml; /* Description of the C function to call */

Modified: python/branches/py3k/Objects/methodobject.c
==============================================================================
--- python/branches/py3k/Objects/methodobject.c	(original)
+++ python/branches/py3k/Objects/methodobject.c	Wed Jul  2 23:47:18 2008
@@ -280,6 +280,43 @@
 	0,					/* tp_dict */
 };
 
+/* Find a method in a method chain */
+
+PyObject *
+Py_FindMethodInChain(PyMethodChain *chain, PyObject *self, const char *name)
+{
+	if (name[0] == '_' && name[1] == '_') {
+		if (strcmp(name, "__doc__") == 0) {
+			const char *doc = self->ob_type->tp_doc;
+			if (doc != NULL)
+				return PyUnicode_FromString(doc);
+		}
+	}
+	while (chain != NULL) {
+		PyMethodDef *ml = chain->methods;
+		for (; ml->ml_name != NULL; ml++) {
+			if (name[0] == ml->ml_name[0] &&
+			    strcmp(name+1, ml->ml_name+1) == 0)
+				/* XXX */
+				return PyCFunction_New(ml, self);
+		}
+		chain = chain->link;
+	}
+	PyErr_SetString(PyExc_AttributeError, name);
+	return NULL;
+}
+
+/* Find a method in a single method list */
+
+PyObject *
+Py_FindMethod(PyMethodDef *methods, PyObject *self, const char *name)
+{
+	PyMethodChain chain;
+	chain.methods = methods;
+	chain.link = NULL;
+	return Py_FindMethodInChain(&chain, self, name);
+}
+
 /* Clear out the free list */
 
 int


More information about the Python-3000-checkins mailing list