Guido van Rossum | 50e9fb9 | 2006-08-17 05:42:55 +0000 | [diff] [blame] | 1 | /* Class object implementation (dead now except for methods) */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2 | |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 3 | #include "Python.h" |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 4 | #include "structmember.h" |
Guido van Rossum | 04691fc | 1992-08-12 15:35:34 +0000 | [diff] [blame] | 5 | |
Guido van Rossum | 3cf5b1e | 2006-07-27 21:53:35 +0000 | [diff] [blame] | 6 | #define TP_DESCR_GET(t) ((t)->tp_descr_get) |
Guido van Rossum | 915f0eb | 2001-10-17 20:26:38 +0000 | [diff] [blame] | 7 | |
Christian Heimes | 2202f87 | 2008-02-06 14:31:34 +0000 | [diff] [blame] | 8 | /* Free list for method objects to safe malloc/free overhead |
| 9 | * The im_self element is used to chain the elements. |
| 10 | */ |
| 11 | static PyMethodObject *free_list; |
| 12 | static int numfree = 0; |
| 13 | #ifndef PyMethod_MAXFREELIST |
| 14 | #define PyMethod_MAXFREELIST 256 |
| 15 | #endif |
| 16 | |
Guido van Rossum | b479dc5 | 2001-09-05 22:52:50 +0000 | [diff] [blame] | 17 | PyObject * |
| 18 | PyMethod_Function(PyObject *im) |
| 19 | { |
| 20 | if (!PyMethod_Check(im)) { |
| 21 | PyErr_BadInternalCall(); |
| 22 | return NULL; |
| 23 | } |
| 24 | return ((PyMethodObject *)im)->im_func; |
| 25 | } |
| 26 | |
| 27 | PyObject * |
| 28 | PyMethod_Self(PyObject *im) |
| 29 | { |
| 30 | if (!PyMethod_Check(im)) { |
| 31 | PyErr_BadInternalCall(); |
| 32 | return NULL; |
| 33 | } |
| 34 | return ((PyMethodObject *)im)->im_self; |
| 35 | } |
| 36 | |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 37 | /* Method objects are used for bound instance methods returned by |
| 38 | instancename.methodname. ClassName.methodname returns an ordinary |
| 39 | function. |
Guido van Rossum | 81daa32 | 1993-05-20 14:24:46 +0000 | [diff] [blame] | 40 | */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 41 | |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 42 | PyObject * |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 43 | PyMethod_New(PyObject *func, PyObject *self) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 44 | { |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 45 | register PyMethodObject *im; |
Guido van Rossum | 7859f87 | 1998-07-08 14:58:16 +0000 | [diff] [blame] | 46 | if (!PyCallable_Check(func)) { |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 47 | PyErr_BadInternalCall(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 48 | return NULL; |
| 49 | } |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 50 | if (self == NULL) { |
| 51 | PyErr_BadInternalCall(); |
| 52 | return NULL; |
| 53 | } |
Guido van Rossum | a0d349f | 1997-08-05 02:06:53 +0000 | [diff] [blame] | 54 | im = free_list; |
| 55 | if (im != NULL) { |
| 56 | free_list = (PyMethodObject *)(im->im_self); |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 57 | PyObject_INIT(im, &PyMethod_Type); |
Christian Heimes | 2202f87 | 2008-02-06 14:31:34 +0000 | [diff] [blame] | 58 | numfree--; |
Guido van Rossum | a0d349f | 1997-08-05 02:06:53 +0000 | [diff] [blame] | 59 | } |
| 60 | else { |
Neil Schemenauer | e83c00e | 2001-08-29 23:54:21 +0000 | [diff] [blame] | 61 | im = PyObject_GC_New(PyMethodObject, &PyMethod_Type); |
Guido van Rossum | a0d349f | 1997-08-05 02:06:53 +0000 | [diff] [blame] | 62 | if (im == NULL) |
| 63 | return NULL; |
| 64 | } |
Fred Drake | db81e8d | 2001-03-23 04:19:27 +0000 | [diff] [blame] | 65 | im->im_weakreflist = NULL; |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 66 | Py_INCREF(func); |
Guido van Rossum | e8122f1 | 1991-05-05 20:03:07 +0000 | [diff] [blame] | 67 | im->im_func = func; |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 68 | Py_XINCREF(self); |
Guido van Rossum | e8122f1 | 1991-05-05 20:03:07 +0000 | [diff] [blame] | 69 | im->im_self = self; |
Neil Schemenauer | e83c00e | 2001-08-29 23:54:21 +0000 | [diff] [blame] | 70 | _PyObject_GC_TRACK(im); |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 71 | return (PyObject *)im; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Guido van Rossum | f0b35e1 | 2001-09-18 03:53:24 +0000 | [diff] [blame] | 74 | /* Descriptors for PyMethod attributes */ |
| 75 | |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 76 | /* im_func and im_self are stored in the PyMethod object */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 77 | |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 78 | #define MO_OFF(x) offsetof(PyMethodObject, x) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 79 | |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 80 | static PyMemberDef method_memberlist[] = { |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 81 | {"__func__", T_OBJECT, MO_OFF(im_func), READONLY|RESTRICTED, |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 82 | "the function (or other callable) implementing a method"}, |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 83 | {"__self__", T_OBJECT, MO_OFF(im_self), READONLY|RESTRICTED, |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 84 | "the instance to which a method is bound"}, |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 85 | {NULL} /* Sentinel */ |
| 86 | }; |
| 87 | |
Guido van Rossum | baf0f8f | 2003-11-22 23:55:50 +0000 | [diff] [blame] | 88 | /* Christian Tismer argued convincingly that method attributes should |
| 89 | (nearly) always override function attributes. |
| 90 | The one exception is __doc__; there's a default __doc__ which |
| 91 | should only be used for the class, not for instances */ |
| 92 | |
| 93 | static PyObject * |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 94 | method_get_doc(PyMethodObject *im, void *context) |
Guido van Rossum | baf0f8f | 2003-11-22 23:55:50 +0000 | [diff] [blame] | 95 | { |
| 96 | static PyObject *docstr; |
| 97 | if (docstr == NULL) { |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 98 | docstr= PyUnicode_InternFromString("__doc__"); |
Guido van Rossum | baf0f8f | 2003-11-22 23:55:50 +0000 | [diff] [blame] | 99 | if (docstr == NULL) |
| 100 | return NULL; |
| 101 | } |
| 102 | return PyObject_GetAttr(im->im_func, docstr); |
| 103 | } |
| 104 | |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 105 | static PyGetSetDef method_getset[] = { |
| 106 | {"__doc__", (getter)method_get_doc, NULL, NULL}, |
Guido van Rossum | baf0f8f | 2003-11-22 23:55:50 +0000 | [diff] [blame] | 107 | {0} |
| 108 | }; |
Guido van Rossum | f0b35e1 | 2001-09-18 03:53:24 +0000 | [diff] [blame] | 109 | |
| 110 | static PyObject * |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 111 | method_getattro(PyObject *obj, PyObject *name) |
Guido van Rossum | f0b35e1 | 2001-09-18 03:53:24 +0000 | [diff] [blame] | 112 | { |
| 113 | PyMethodObject *im = (PyMethodObject *)obj; |
| 114 | PyTypeObject *tp = obj->ob_type; |
Guido van Rossum | baf0f8f | 2003-11-22 23:55:50 +0000 | [diff] [blame] | 115 | PyObject *descr = NULL; |
Guido van Rossum | f0b35e1 | 2001-09-18 03:53:24 +0000 | [diff] [blame] | 116 | |
Guido van Rossum | 3cf5b1e | 2006-07-27 21:53:35 +0000 | [diff] [blame] | 117 | { |
Guido van Rossum | 915f0eb | 2001-10-17 20:26:38 +0000 | [diff] [blame] | 118 | if (tp->tp_dict == NULL) { |
| 119 | if (PyType_Ready(tp) < 0) |
| 120 | return NULL; |
| 121 | } |
| 122 | descr = _PyType_Lookup(tp, name); |
Barry Warsaw | d6a9e84 | 2001-01-15 20:40:19 +0000 | [diff] [blame] | 123 | } |
Guido van Rossum | f0b35e1 | 2001-09-18 03:53:24 +0000 | [diff] [blame] | 124 | |
Guido van Rossum | f0b35e1 | 2001-09-18 03:53:24 +0000 | [diff] [blame] | 125 | if (descr != NULL) { |
Guido van Rossum | baf0f8f | 2003-11-22 23:55:50 +0000 | [diff] [blame] | 126 | descrgetfunc f = TP_DESCR_GET(descr->ob_type); |
| 127 | if (f != NULL) |
Guido van Rossum | f0b35e1 | 2001-09-18 03:53:24 +0000 | [diff] [blame] | 128 | return f(descr, obj, (PyObject *)obj->ob_type); |
Guido van Rossum | baf0f8f | 2003-11-22 23:55:50 +0000 | [diff] [blame] | 129 | else { |
| 130 | Py_INCREF(descr); |
| 131 | return descr; |
| 132 | } |
Guido van Rossum | f0b35e1 | 2001-09-18 03:53:24 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Guido van Rossum | baf0f8f | 2003-11-22 23:55:50 +0000 | [diff] [blame] | 135 | return PyObject_GetAttr(im->im_func, name); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 138 | PyDoc_STRVAR(method_doc, |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 139 | "method(function, instance)\n\ |
Guido van Rossum | bea18cc | 2002-06-14 20:41:17 +0000 | [diff] [blame] | 140 | \n\ |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 141 | Create a bound instance method object."); |
Guido van Rossum | bea18cc | 2002-06-14 20:41:17 +0000 | [diff] [blame] | 142 | |
| 143 | static PyObject * |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 144 | method_new(PyTypeObject* type, PyObject* args, PyObject *kw) |
Guido van Rossum | bea18cc | 2002-06-14 20:41:17 +0000 | [diff] [blame] | 145 | { |
| 146 | PyObject *func; |
| 147 | PyObject *self; |
Guido van Rossum | bea18cc | 2002-06-14 20:41:17 +0000 | [diff] [blame] | 148 | |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 149 | if (!_PyArg_NoKeywords("method", kw)) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 150 | return NULL; |
Christian Heimes | 9bbac50 | 2007-12-08 18:27:16 +0000 | [diff] [blame] | 151 | if (!PyArg_UnpackTuple(args, "method", 2, 2, |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 152 | &func, &self)) |
Guido van Rossum | bea18cc | 2002-06-14 20:41:17 +0000 | [diff] [blame] | 153 | return NULL; |
| 154 | if (!PyCallable_Check(func)) { |
| 155 | PyErr_SetString(PyExc_TypeError, |
| 156 | "first argument must be callable"); |
| 157 | return NULL; |
| 158 | } |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 159 | if (self == NULL || self == Py_None) { |
Michael W. Hudson | e2749cb | 2005-03-30 16:32:10 +0000 | [diff] [blame] | 160 | PyErr_SetString(PyExc_TypeError, |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 161 | "self must not be None"); |
Michael W. Hudson | e2749cb | 2005-03-30 16:32:10 +0000 | [diff] [blame] | 162 | return NULL; |
| 163 | } |
| 164 | |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 165 | return PyMethod_New(func, self); |
Guido van Rossum | bea18cc | 2002-06-14 20:41:17 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 168 | static void |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 169 | method_dealloc(register PyMethodObject *im) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 170 | { |
Neil Schemenauer | e83c00e | 2001-08-29 23:54:21 +0000 | [diff] [blame] | 171 | _PyObject_GC_UNTRACK(im); |
Fred Drake | c916f5a | 2001-10-26 17:56:51 +0000 | [diff] [blame] | 172 | if (im->im_weakreflist != NULL) |
| 173 | PyObject_ClearWeakRefs((PyObject *)im); |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 174 | Py_DECREF(im->im_func); |
| 175 | Py_XDECREF(im->im_self); |
Christian Heimes | 2202f87 | 2008-02-06 14:31:34 +0000 | [diff] [blame] | 176 | if (numfree < PyMethod_MAXFREELIST) { |
| 177 | im->im_self = (PyObject *)free_list; |
| 178 | free_list = im; |
| 179 | numfree++; |
| 180 | } |
| 181 | else { |
| 182 | PyObject_GC_Del(im); |
| 183 | } |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 186 | static PyObject * |
| 187 | method_richcompare(PyObject *self, PyObject *other, int op) |
Guido van Rossum | ebc8c51 | 1992-09-03 20:39:51 +0000 | [diff] [blame] | 188 | { |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 189 | PyMethodObject *a, *b; |
| 190 | PyObject *res; |
| 191 | int eq; |
Thomas Wouters | 73e5a5b | 2006-06-08 15:35:45 +0000 | [diff] [blame] | 192 | |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 193 | if ((op != Py_EQ && op != Py_NE) || |
| 194 | !PyMethod_Check(self) || |
| 195 | !PyMethod_Check(other)) |
| 196 | { |
| 197 | Py_INCREF(Py_NotImplemented); |
| 198 | return Py_NotImplemented; |
| 199 | } |
| 200 | a = (PyMethodObject *)self; |
| 201 | b = (PyMethodObject *)other; |
| 202 | eq = PyObject_RichCompareBool(a->im_func, b->im_func, Py_EQ); |
| 203 | if (eq == 1) { |
| 204 | if (a->im_self == NULL || b->im_self == NULL) |
| 205 | eq = a->im_self == b->im_self; |
| 206 | else |
| 207 | eq = PyObject_RichCompareBool(a->im_self, b->im_self, |
| 208 | Py_EQ); |
| 209 | } |
| 210 | if (eq < 0) |
| 211 | return NULL; |
| 212 | if (op == Py_EQ) |
| 213 | res = eq ? Py_True : Py_False; |
Thomas Wouters | 73e5a5b | 2006-06-08 15:35:45 +0000 | [diff] [blame] | 214 | else |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 215 | res = eq ? Py_False : Py_True; |
| 216 | Py_INCREF(res); |
| 217 | return res; |
Guido van Rossum | ebc8c51 | 1992-09-03 20:39:51 +0000 | [diff] [blame] | 218 | } |
| 219 | |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 220 | static PyObject * |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 221 | method_repr(PyMethodObject *a) |
Guido van Rossum | 2583165 | 1993-05-19 14:50:45 +0000 | [diff] [blame] | 222 | { |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 223 | PyObject *self = a->im_self; |
Guido van Rossum | 7859f87 | 1998-07-08 14:58:16 +0000 | [diff] [blame] | 224 | PyObject *func = a->im_func; |
Christian Heimes | 90aa764 | 2007-12-19 02:45:37 +0000 | [diff] [blame] | 225 | PyObject *klass = (PyObject*)Py_TYPE(self); |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 226 | PyObject *funcname = NULL ,*klassname = NULL, *result = NULL; |
Walter Dörwald | d7fb764 | 2007-06-11 16:36:59 +0000 | [diff] [blame] | 227 | char *defname = "?"; |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 228 | |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 229 | if (self == NULL) { |
| 230 | PyErr_BadInternalCall(); |
| 231 | return NULL; |
| 232 | } |
| 233 | |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 234 | funcname = PyObject_GetAttrString(func, "__name__"); |
Guido van Rossum | e7b8ecf | 2002-06-13 21:42:04 +0000 | [diff] [blame] | 235 | if (funcname == NULL) { |
| 236 | if (!PyErr_ExceptionMatches(PyExc_AttributeError)) |
| 237 | return NULL; |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 238 | PyErr_Clear(); |
Guido van Rossum | e7b8ecf | 2002-06-13 21:42:04 +0000 | [diff] [blame] | 239 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 240 | else if (!PyUnicode_Check(funcname)) { |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 241 | Py_DECREF(funcname); |
| 242 | funcname = NULL; |
Guido van Rossum | 7859f87 | 1998-07-08 14:58:16 +0000 | [diff] [blame] | 243 | } |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 244 | |
Guido van Rossum | 4066769 | 2001-08-17 13:59:27 +0000 | [diff] [blame] | 245 | if (klass == NULL) |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 246 | klassname = NULL; |
Guido van Rossum | 4066769 | 2001-08-17 13:59:27 +0000 | [diff] [blame] | 247 | else { |
| 248 | klassname = PyObject_GetAttrString(klass, "__name__"); |
Guido van Rossum | e7b8ecf | 2002-06-13 21:42:04 +0000 | [diff] [blame] | 249 | if (klassname == NULL) { |
| 250 | if (!PyErr_ExceptionMatches(PyExc_AttributeError)) |
| 251 | return NULL; |
Guido van Rossum | 4066769 | 2001-08-17 13:59:27 +0000 | [diff] [blame] | 252 | PyErr_Clear(); |
Guido van Rossum | e7b8ecf | 2002-06-13 21:42:04 +0000 | [diff] [blame] | 253 | } |
Martin v. Löwis | 5b22213 | 2007-06-10 09:51:05 +0000 | [diff] [blame] | 254 | else if (!PyUnicode_Check(klassname)) { |
Guido van Rossum | 4066769 | 2001-08-17 13:59:27 +0000 | [diff] [blame] | 255 | Py_DECREF(klassname); |
| 256 | klassname = NULL; |
| 257 | } |
Guido van Rossum | 7859f87 | 1998-07-08 14:58:16 +0000 | [diff] [blame] | 258 | } |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 259 | |
| 260 | /* XXX Shouldn't use repr()/%R here! */ |
| 261 | result = PyUnicode_FromFormat("<bound method %V.%V of %R>", |
| 262 | klassname, defname, |
| 263 | funcname, defname, self); |
| 264 | |
Guido van Rossum | 42636dc | 1999-10-11 14:03:12 +0000 | [diff] [blame] | 265 | Py_XDECREF(funcname); |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 266 | Py_XDECREF(klassname); |
| 267 | return result; |
Guido van Rossum | 2583165 | 1993-05-19 14:50:45 +0000 | [diff] [blame] | 268 | } |
| 269 | |
Guido van Rossum | 9bfef44 | 1993-03-29 10:43:31 +0000 | [diff] [blame] | 270 | static long |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 271 | method_hash(PyMethodObject *a) |
Guido van Rossum | 9bfef44 | 1993-03-29 10:43:31 +0000 | [diff] [blame] | 272 | { |
| 273 | long x, y; |
Guido van Rossum | 81daa32 | 1993-05-20 14:24:46 +0000 | [diff] [blame] | 274 | if (a->im_self == NULL) |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 275 | x = PyObject_Hash(Py_None); |
Guido van Rossum | 81daa32 | 1993-05-20 14:24:46 +0000 | [diff] [blame] | 276 | else |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 277 | x = PyObject_Hash(a->im_self); |
Guido van Rossum | 9bfef44 | 1993-03-29 10:43:31 +0000 | [diff] [blame] | 278 | if (x == -1) |
| 279 | return -1; |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 280 | y = PyObject_Hash(a->im_func); |
Guido van Rossum | 9bfef44 | 1993-03-29 10:43:31 +0000 | [diff] [blame] | 281 | if (y == -1) |
| 282 | return -1; |
Thomas Wouters | 73e5a5b | 2006-06-08 15:35:45 +0000 | [diff] [blame] | 283 | x = x ^ y; |
| 284 | if (x == -1) |
| 285 | x = -2; |
| 286 | return x; |
Guido van Rossum | 9bfef44 | 1993-03-29 10:43:31 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Jeremy Hylton | 8caad49 | 2000-06-23 14:18:11 +0000 | [diff] [blame] | 289 | static int |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 290 | method_traverse(PyMethodObject *im, visitproc visit, void *arg) |
Jeremy Hylton | 8caad49 | 2000-06-23 14:18:11 +0000 | [diff] [blame] | 291 | { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 292 | Py_VISIT(im->im_func); |
| 293 | Py_VISIT(im->im_self); |
Jeremy Hylton | d22162b | 2000-06-23 17:14:56 +0000 | [diff] [blame] | 294 | return 0; |
Jeremy Hylton | 8caad49 | 2000-06-23 14:18:11 +0000 | [diff] [blame] | 295 | } |
| 296 | |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 297 | static PyObject * |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 298 | method_call(PyObject *func, PyObject *arg, PyObject *kw) |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 299 | { |
| 300 | PyObject *self = PyMethod_GET_SELF(func); |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 301 | PyObject *result; |
| 302 | |
| 303 | func = PyMethod_GET_FUNCTION(func); |
| 304 | if (self == NULL) { |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 305 | PyErr_BadInternalCall(); |
| 306 | return NULL; |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 307 | } |
| 308 | else { |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 309 | Py_ssize_t argcount = PyTuple_Size(arg); |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 310 | PyObject *newarg = PyTuple_New(argcount + 1); |
| 311 | int i; |
| 312 | if (newarg == NULL) |
| 313 | return NULL; |
| 314 | Py_INCREF(self); |
| 315 | PyTuple_SET_ITEM(newarg, 0, self); |
| 316 | for (i = 0; i < argcount; i++) { |
| 317 | PyObject *v = PyTuple_GET_ITEM(arg, i); |
| 318 | Py_XINCREF(v); |
| 319 | PyTuple_SET_ITEM(newarg, i+1, v); |
| 320 | } |
| 321 | arg = newarg; |
| 322 | } |
| 323 | result = PyObject_Call((PyObject *)func, arg, kw); |
| 324 | Py_DECREF(arg); |
| 325 | return result; |
| 326 | } |
| 327 | |
Guido van Rossum | 23cc2b4 | 2001-08-15 17:52:31 +0000 | [diff] [blame] | 328 | static PyObject * |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 329 | method_descr_get(PyObject *meth, PyObject *obj, PyObject *cls) |
Guido van Rossum | 23cc2b4 | 2001-08-15 17:52:31 +0000 | [diff] [blame] | 330 | { |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 331 | /* Don't rebind an already bound method of a class that's not a base |
| 332 | class of cls. */ |
Guido van Rossum | 6bae46d | 2003-02-11 18:43:00 +0000 | [diff] [blame] | 333 | if (PyMethod_GET_SELF(meth) != NULL) { |
| 334 | /* Already bound */ |
Guido van Rossum | 501c7c7 | 2001-08-16 20:41:56 +0000 | [diff] [blame] | 335 | Py_INCREF(meth); |
| 336 | return meth; |
| 337 | } |
Guido van Rossum | 6bae46d | 2003-02-11 18:43:00 +0000 | [diff] [blame] | 338 | /* Bind it to obj */ |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 339 | return PyMethod_New(PyMethod_GET_FUNCTION(meth), obj); |
Guido van Rossum | 23cc2b4 | 2001-08-15 17:52:31 +0000 | [diff] [blame] | 340 | } |
| 341 | |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 342 | PyTypeObject PyMethod_Type = { |
Martin v. Löwis | 9f2e346 | 2007-07-21 17:22:18 +0000 | [diff] [blame] | 343 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 344 | "method", |
Neil Schemenauer | e83c00e | 2001-08-29 23:54:21 +0000 | [diff] [blame] | 345 | sizeof(PyMethodObject), |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 346 | 0, |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 347 | (destructor)method_dealloc, /* tp_dealloc */ |
Guido van Rossum | 8998b4f | 2001-01-17 15:28:20 +0000 | [diff] [blame] | 348 | 0, /* tp_print */ |
| 349 | 0, /* tp_getattr */ |
| 350 | 0, /* tp_setattr */ |
Mark Dickinson | e94c679 | 2009-02-02 20:36:42 +0000 | [diff] [blame^] | 351 | 0, /* tp_reserved */ |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 352 | (reprfunc)method_repr, /* tp_repr */ |
Guido van Rossum | 8998b4f | 2001-01-17 15:28:20 +0000 | [diff] [blame] | 353 | 0, /* tp_as_number */ |
| 354 | 0, /* tp_as_sequence */ |
| 355 | 0, /* tp_as_mapping */ |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 356 | (hashfunc)method_hash, /* tp_hash */ |
| 357 | method_call, /* tp_call */ |
Guido van Rossum | 8998b4f | 2001-01-17 15:28:20 +0000 | [diff] [blame] | 358 | 0, /* tp_str */ |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 359 | method_getattro, /* tp_getattro */ |
Guido van Rossum | f0b35e1 | 2001-09-18 03:53:24 +0000 | [diff] [blame] | 360 | PyObject_GenericSetAttr, /* tp_setattro */ |
Guido van Rossum | 8998b4f | 2001-01-17 15:28:20 +0000 | [diff] [blame] | 361 | 0, /* tp_as_buffer */ |
Guido van Rossum | 3cf5b1e | 2006-07-27 21:53:35 +0000 | [diff] [blame] | 362 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 363 | method_doc, /* tp_doc */ |
| 364 | (traverseproc)method_traverse, /* tp_traverse */ |
Fred Drake | db81e8d | 2001-03-23 04:19:27 +0000 | [diff] [blame] | 365 | 0, /* tp_clear */ |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 366 | method_richcompare, /* tp_richcompare */ |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 367 | offsetof(PyMethodObject, im_weakreflist), /* tp_weaklistoffset */ |
Guido van Rossum | 23cc2b4 | 2001-08-15 17:52:31 +0000 | [diff] [blame] | 368 | 0, /* tp_iter */ |
| 369 | 0, /* tp_iternext */ |
| 370 | 0, /* tp_methods */ |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 371 | method_memberlist, /* tp_members */ |
| 372 | method_getset, /* tp_getset */ |
Guido van Rossum | 23cc2b4 | 2001-08-15 17:52:31 +0000 | [diff] [blame] | 373 | 0, /* tp_base */ |
| 374 | 0, /* tp_dict */ |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 375 | method_descr_get, /* tp_descr_get */ |
Guido van Rossum | 23cc2b4 | 2001-08-15 17:52:31 +0000 | [diff] [blame] | 376 | 0, /* tp_descr_set */ |
| 377 | 0, /* tp_dictoffset */ |
Guido van Rossum | bea18cc | 2002-06-14 20:41:17 +0000 | [diff] [blame] | 378 | 0, /* tp_init */ |
| 379 | 0, /* tp_alloc */ |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 380 | method_new, /* tp_new */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 381 | }; |
Guido van Rossum | a0d349f | 1997-08-05 02:06:53 +0000 | [diff] [blame] | 382 | |
| 383 | /* Clear out the free list */ |
| 384 | |
Christian Heimes | a156e09 | 2008-02-16 07:38:31 +0000 | [diff] [blame] | 385 | int |
| 386 | PyMethod_ClearFreeList(void) |
Guido van Rossum | a0d349f | 1997-08-05 02:06:53 +0000 | [diff] [blame] | 387 | { |
Christian Heimes | a156e09 | 2008-02-16 07:38:31 +0000 | [diff] [blame] | 388 | int freelist_size = numfree; |
| 389 | |
Guido van Rossum | a0d349f | 1997-08-05 02:06:53 +0000 | [diff] [blame] | 390 | while (free_list) { |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 391 | PyMethodObject *im = free_list; |
| 392 | free_list = (PyMethodObject *)(im->im_self); |
Neil Schemenauer | e83c00e | 2001-08-29 23:54:21 +0000 | [diff] [blame] | 393 | PyObject_GC_Del(im); |
Christian Heimes | 2202f87 | 2008-02-06 14:31:34 +0000 | [diff] [blame] | 394 | numfree--; |
Guido van Rossum | a0d349f | 1997-08-05 02:06:53 +0000 | [diff] [blame] | 395 | } |
Christian Heimes | 2202f87 | 2008-02-06 14:31:34 +0000 | [diff] [blame] | 396 | assert(numfree == 0); |
Christian Heimes | a156e09 | 2008-02-16 07:38:31 +0000 | [diff] [blame] | 397 | return freelist_size; |
| 398 | } |
| 399 | |
| 400 | void |
| 401 | PyMethod_Fini(void) |
| 402 | { |
| 403 | (void)PyMethod_ClearFreeList(); |
Guido van Rossum | a0d349f | 1997-08-05 02:06:53 +0000 | [diff] [blame] | 404 | } |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 405 | |
| 406 | /* ------------------------------------------------------------------------ |
| 407 | * instance method |
| 408 | */ |
| 409 | |
| 410 | PyObject * |
| 411 | PyInstanceMethod_New(PyObject *func) { |
| 412 | PyInstanceMethodObject *method; |
| 413 | method = PyObject_GC_New(PyInstanceMethodObject, |
| 414 | &PyInstanceMethod_Type); |
| 415 | if (method == NULL) return NULL; |
| 416 | Py_INCREF(func); |
| 417 | method->func = func; |
| 418 | _PyObject_GC_TRACK(method); |
| 419 | return (PyObject *)method; |
| 420 | } |
| 421 | |
| 422 | PyObject * |
| 423 | PyInstanceMethod_Function(PyObject *im) |
| 424 | { |
| 425 | if (!PyInstanceMethod_Check(im)) { |
| 426 | PyErr_BadInternalCall(); |
| 427 | return NULL; |
| 428 | } |
| 429 | return PyInstanceMethod_GET_FUNCTION(im); |
| 430 | } |
| 431 | |
| 432 | #define IMO_OFF(x) offsetof(PyInstanceMethodObject, x) |
| 433 | |
| 434 | static PyMemberDef instancemethod_memberlist[] = { |
| 435 | {"__func__", T_OBJECT, IMO_OFF(func), READONLY|RESTRICTED, |
| 436 | "the function (or other callable) implementing a method"}, |
| 437 | {NULL} /* Sentinel */ |
| 438 | }; |
| 439 | |
| 440 | static PyObject * |
| 441 | instancemethod_get_doc(PyObject *self, void *context) |
| 442 | { |
| 443 | static PyObject *docstr; |
| 444 | if (docstr == NULL) { |
| 445 | docstr = PyUnicode_InternFromString("__doc__"); |
| 446 | if (docstr == NULL) |
| 447 | return NULL; |
| 448 | } |
| 449 | return PyObject_GetAttr(PyInstanceMethod_GET_FUNCTION(self), docstr); |
| 450 | } |
| 451 | |
| 452 | static PyGetSetDef instancemethod_getset[] = { |
| 453 | {"__doc__", (getter)instancemethod_get_doc, NULL, NULL}, |
| 454 | {0} |
| 455 | }; |
| 456 | |
| 457 | static PyObject * |
| 458 | instancemethod_getattro(PyObject *self, PyObject *name) |
| 459 | { |
| 460 | PyTypeObject *tp = self->ob_type; |
| 461 | PyObject *descr = NULL; |
| 462 | |
| 463 | if (tp->tp_dict == NULL) { |
| 464 | if (PyType_Ready(tp) < 0) |
| 465 | return NULL; |
| 466 | } |
| 467 | descr = _PyType_Lookup(tp, name); |
| 468 | |
| 469 | if (descr != NULL) { |
| 470 | descrgetfunc f = TP_DESCR_GET(descr->ob_type); |
| 471 | if (f != NULL) |
| 472 | return f(descr, self, (PyObject *)self->ob_type); |
| 473 | else { |
| 474 | Py_INCREF(descr); |
| 475 | return descr; |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | return PyObject_GetAttr(PyInstanceMethod_GET_FUNCTION(self), name); |
| 480 | } |
| 481 | |
| 482 | static void |
| 483 | instancemethod_dealloc(PyObject *self) { |
| 484 | _PyObject_GC_UNTRACK(self); |
| 485 | Py_DECREF(PyInstanceMethod_GET_FUNCTION(self)); |
| 486 | PyObject_GC_Del(self); |
| 487 | } |
| 488 | |
| 489 | static int |
| 490 | instancemethod_traverse(PyObject *self, visitproc visit, void *arg) { |
| 491 | Py_VISIT(PyInstanceMethod_GET_FUNCTION(self)); |
| 492 | return 0; |
| 493 | } |
| 494 | |
| 495 | static PyObject * |
| 496 | instancemethod_call(PyObject *self, PyObject *arg, PyObject *kw) |
| 497 | { |
| 498 | return PyObject_Call(PyMethod_GET_FUNCTION(self), arg, kw); |
| 499 | } |
| 500 | |
| 501 | static PyObject * |
| 502 | instancemethod_descr_get(PyObject *descr, PyObject *obj, PyObject *type) { |
| 503 | register PyObject *func = PyInstanceMethod_GET_FUNCTION(descr); |
Georg Brandl | c9b0953 | 2008-05-25 09:24:38 +0000 | [diff] [blame] | 504 | if (obj == NULL) { |
| 505 | Py_INCREF(func); |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 506 | return func; |
Georg Brandl | c9b0953 | 2008-05-25 09:24:38 +0000 | [diff] [blame] | 507 | } |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 508 | else |
| 509 | return PyMethod_New(func, obj); |
| 510 | } |
| 511 | |
| 512 | static PyObject * |
| 513 | instancemethod_richcompare(PyObject *self, PyObject *other, int op) |
| 514 | { |
| 515 | PyInstanceMethodObject *a, *b; |
| 516 | PyObject *res; |
| 517 | int eq; |
| 518 | |
| 519 | if ((op != Py_EQ && op != Py_NE) || |
| 520 | !PyInstanceMethod_Check(self) || |
| 521 | !PyInstanceMethod_Check(other)) |
| 522 | { |
| 523 | Py_INCREF(Py_NotImplemented); |
| 524 | return Py_NotImplemented; |
| 525 | } |
| 526 | a = (PyInstanceMethodObject *)self; |
| 527 | b = (PyInstanceMethodObject *)other; |
| 528 | eq = PyObject_RichCompareBool(a->func, b->func, Py_EQ); |
| 529 | if (eq < 0) |
| 530 | return NULL; |
| 531 | if (op == Py_EQ) |
| 532 | res = eq ? Py_True : Py_False; |
| 533 | else |
| 534 | res = eq ? Py_False : Py_True; |
| 535 | Py_INCREF(res); |
| 536 | return res; |
| 537 | } |
| 538 | |
| 539 | static PyObject * |
| 540 | instancemethod_repr(PyObject *self) |
| 541 | { |
| 542 | PyObject *func = PyInstanceMethod_Function(self); |
| 543 | PyObject *funcname = NULL , *result = NULL; |
| 544 | char *defname = "?"; |
| 545 | |
| 546 | if (func == NULL) { |
| 547 | PyErr_BadInternalCall(); |
| 548 | return NULL; |
| 549 | } |
| 550 | |
| 551 | funcname = PyObject_GetAttrString(func, "__name__"); |
| 552 | if (funcname == NULL) { |
| 553 | if (!PyErr_ExceptionMatches(PyExc_AttributeError)) |
| 554 | return NULL; |
| 555 | PyErr_Clear(); |
| 556 | } |
| 557 | else if (!PyUnicode_Check(funcname)) { |
| 558 | Py_DECREF(funcname); |
| 559 | funcname = NULL; |
| 560 | } |
| 561 | |
| 562 | result = PyUnicode_FromFormat("<instancemethod %V at %p>", |
| 563 | funcname, defname, self); |
| 564 | |
| 565 | Py_XDECREF(funcname); |
| 566 | return result; |
| 567 | } |
| 568 | |
| 569 | /* |
| 570 | static long |
| 571 | instancemethod_hash(PyObject *self) |
| 572 | { |
| 573 | long x, y; |
| 574 | x = (long)self; |
| 575 | y = PyObject_Hash(PyInstanceMethod_GET_FUNCTION(self)); |
| 576 | if (y == -1) |
| 577 | return -1; |
| 578 | x = x ^ y; |
| 579 | if (x == -1) |
| 580 | x = -2; |
| 581 | return x; |
| 582 | } |
| 583 | */ |
| 584 | |
| 585 | PyDoc_STRVAR(instancemethod_doc, |
| 586 | "instancemethod(function)\n\ |
| 587 | \n\ |
| 588 | Bind a function to a class."); |
| 589 | |
| 590 | static PyObject * |
| 591 | instancemethod_new(PyTypeObject* type, PyObject* args, PyObject *kw) |
| 592 | { |
| 593 | PyObject *func; |
| 594 | |
| 595 | if (!_PyArg_NoKeywords("instancemethod", kw)) |
| 596 | return NULL; |
| 597 | if (!PyArg_UnpackTuple(args, "instancemethod", 1, 1, &func)) |
| 598 | return NULL; |
| 599 | if (!PyCallable_Check(func)) { |
| 600 | PyErr_SetString(PyExc_TypeError, |
| 601 | "first argument must be callable"); |
| 602 | return NULL; |
| 603 | } |
| 604 | |
| 605 | return PyInstanceMethod_New(func); |
| 606 | } |
| 607 | |
| 608 | PyTypeObject PyInstanceMethod_Type = { |
| 609 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
| 610 | "instancemethod", /* tp_name */ |
| 611 | sizeof(PyInstanceMethodObject), /* tp_basicsize */ |
| 612 | 0, /* tp_itemsize */ |
| 613 | instancemethod_dealloc, /* tp_dealloc */ |
| 614 | 0, /* tp_print */ |
| 615 | 0, /* tp_getattr */ |
| 616 | 0, /* tp_setattr */ |
Mark Dickinson | e94c679 | 2009-02-02 20:36:42 +0000 | [diff] [blame^] | 617 | 0, /* tp_reserved */ |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 618 | (reprfunc)instancemethod_repr, /* tp_repr */ |
| 619 | 0, /* tp_as_number */ |
| 620 | 0, /* tp_as_sequence */ |
| 621 | 0, /* tp_as_mapping */ |
| 622 | 0, /*(hashfunc)instancemethod_hash, tp_hash */ |
| 623 | instancemethod_call, /* tp_call */ |
| 624 | 0, /* tp_str */ |
| 625 | instancemethod_getattro, /* tp_getattro */ |
| 626 | PyObject_GenericSetAttr, /* tp_setattro */ |
| 627 | 0, /* tp_as_buffer */ |
| 628 | Py_TPFLAGS_DEFAULT |
| 629 | | Py_TPFLAGS_HAVE_GC, /* tp_flags */ |
| 630 | instancemethod_doc, /* tp_doc */ |
| 631 | instancemethod_traverse, /* tp_traverse */ |
| 632 | 0, /* tp_clear */ |
| 633 | instancemethod_richcompare, /* tp_richcompare */ |
| 634 | 0, /* tp_weaklistoffset */ |
| 635 | 0, /* tp_iter */ |
| 636 | 0, /* tp_iternext */ |
| 637 | 0, /* tp_methods */ |
| 638 | instancemethod_memberlist, /* tp_members */ |
| 639 | instancemethod_getset, /* tp_getset */ |
| 640 | 0, /* tp_base */ |
| 641 | 0, /* tp_dict */ |
| 642 | instancemethod_descr_get, /* tp_descr_get */ |
| 643 | 0, /* tp_descr_set */ |
| 644 | 0, /* tp_dictoffset */ |
| 645 | 0, /* tp_init */ |
| 646 | 0, /* tp_alloc */ |
| 647 | instancemethod_new, /* tp_new */ |
| 648 | }; |