diff Objects/classobject.c @ 19280:f10b68eceefc legacy-trunk

PyMethod_Type: add a tp_descr_get slot function to ensure proper binding of unbound methods.
author Guido van Rossum <guido@python.org>
date Wed, 15 Aug 2001 17:52:31 +0000
parents f20727cc3d0f
children 261e28e7fa01
line wrap: on
line diff
--- a/Objects/classobject.c	Wed Aug 15 17:51:17 2001 +0000
+++ b/Objects/classobject.c	Wed Aug 15 17:52:31 2001 +0000
@@ -2193,6 +2193,14 @@
 	return result;
 }
 
+static PyObject *
+instancemethod_descr_get(PyObject *meth, PyObject *obj, PyObject *type)
+{
+	if (obj == Py_None)
+		obj = NULL;
+	return PyMethod_New(PyMethod_GET_FUNCTION(meth), obj, type);
+}
+
 PyTypeObject PyMethod_Type = {
 	PyObject_HEAD_INIT(&PyType_Type)
 	0,
@@ -2219,7 +2227,17 @@
 	(traverseproc)instancemethod_traverse,	/* tp_traverse */
 	0,					/* tp_clear */
 	0,					/* tp_richcompare */
- 	offsetof(PyMethodObject, im_weakreflist) /* tp_weaklistoffset */
+ 	offsetof(PyMethodObject, im_weakreflist), /* tp_weaklistoffset */
+	0,					/* tp_iter */
+	0,					/* tp_iternext */
+	0,					/* tp_methods */
+	0,					/* tp_members */
+	0,					/* tp_getset */
+	0,					/* tp_base */
+	0,					/* tp_dict */
+	instancemethod_descr_get,		/* tp_descr_get */
+	0,					/* tp_descr_set */
+	0,					/* tp_dictoffset */
 };
 
 /* Clear out the free list */