summaryrefslogtreecommitdiffstats
path: root/Objects/classobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-08-15 17:52:31 (GMT)
committerGuido van Rossum <guido@python.org>2001-08-15 17:52:31 (GMT)
commit23cc2b4991001b79f0b87deef554ee7b66e8bbc4 (patch)
tree3368da08b0062a2217de33439c6d5bf34be5a6bc /Objects/classobject.c
parentb5a136b05d1352faf5f9745a033d9af61bbe74a0 (diff)
downloadcpython-23cc2b4991001b79f0b87deef554ee7b66e8bbc4.zip
cpython-23cc2b4991001b79f0b87deef554ee7b66e8bbc4.tar.gz
cpython-23cc2b4991001b79f0b87deef554ee7b66e8bbc4.tar.bz2
PyMethod_Type: add a tp_descr_get slot function to ensure proper
binding of unbound methods.
Diffstat (limited to 'Objects/classobject.c')
-rw-r--r--Objects/classobject.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c
index 9c01538..255a432 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -2193,6 +2193,14 @@ instancemethod_call(PyObject *func, PyObject *arg, PyObject *kw)
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 @@ PyTypeObject PyMethod_Type = {
(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 */