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" |
Victor Stinner | bcda8f1 | 2018-11-21 22:27:47 +0100 | [diff] [blame] | 4 | #include "pycore_object.h" |
Victor Stinner | 621cebe | 2018-11-12 16:53:38 +0100 | [diff] [blame] | 5 | #include "pycore_pymem.h" |
| 6 | #include "pycore_pystate.h" |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 7 | #include "structmember.h" |
Guido van Rossum | 04691fc | 1992-08-12 15:35:34 +0000 | [diff] [blame] | 8 | |
Guido van Rossum | 3cf5b1e | 2006-07-27 21:53:35 +0000 | [diff] [blame] | 9 | #define TP_DESCR_GET(t) ((t)->tp_descr_get) |
Guido van Rossum | 915f0eb | 2001-10-17 20:26:38 +0000 | [diff] [blame] | 10 | |
Martin v. Löwis | bd928fe | 2011-10-14 10:20:37 +0200 | [diff] [blame] | 11 | _Py_IDENTIFIER(__name__); |
Benjamin Peterson | 48ad7c0 | 2014-08-20 18:41:57 -0500 | [diff] [blame] | 12 | _Py_IDENTIFIER(__qualname__); |
Martin v. Löwis | 1ee1b6f | 2011-10-10 18:11:30 +0200 | [diff] [blame] | 13 | |
Guido van Rossum | b479dc5 | 2001-09-05 22:52:50 +0000 | [diff] [blame] | 14 | PyObject * |
| 15 | PyMethod_Function(PyObject *im) |
| 16 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 17 | if (!PyMethod_Check(im)) { |
| 18 | PyErr_BadInternalCall(); |
| 19 | return NULL; |
| 20 | } |
| 21 | return ((PyMethodObject *)im)->im_func; |
Guido van Rossum | b479dc5 | 2001-09-05 22:52:50 +0000 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | PyObject * |
| 25 | PyMethod_Self(PyObject *im) |
| 26 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 27 | if (!PyMethod_Check(im)) { |
| 28 | PyErr_BadInternalCall(); |
| 29 | return NULL; |
| 30 | } |
| 31 | return ((PyMethodObject *)im)->im_self; |
Guido van Rossum | b479dc5 | 2001-09-05 22:52:50 +0000 | [diff] [blame] | 32 | } |
| 33 | |
Jeroen Demeyer | aacc77f | 2019-05-29 20:31:52 +0200 | [diff] [blame] | 34 | |
| 35 | static PyObject * |
| 36 | method_vectorcall(PyObject *method, PyObject *const *args, |
| 37 | size_t nargsf, PyObject *kwnames) |
| 38 | { |
| 39 | assert(Py_TYPE(method) == &PyMethod_Type); |
| 40 | PyObject *self, *func, *result; |
| 41 | self = PyMethod_GET_SELF(method); |
| 42 | func = PyMethod_GET_FUNCTION(method); |
| 43 | Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); |
| 44 | |
| 45 | if (nargsf & PY_VECTORCALL_ARGUMENTS_OFFSET) { |
| 46 | /* PY_VECTORCALL_ARGUMENTS_OFFSET is set, so we are allowed to mutate the vector */ |
| 47 | PyObject **newargs = (PyObject**)args - 1; |
| 48 | nargs += 1; |
| 49 | PyObject *tmp = newargs[0]; |
| 50 | newargs[0] = self; |
| 51 | result = _PyObject_Vectorcall(func, newargs, nargs, kwnames); |
| 52 | newargs[0] = tmp; |
| 53 | } |
| 54 | else { |
| 55 | Py_ssize_t nkwargs = (kwnames == NULL) ? 0 : PyTuple_GET_SIZE(kwnames); |
Jeroen Demeyer | aacc77f | 2019-05-29 20:31:52 +0200 | [diff] [blame] | 56 | Py_ssize_t totalargs = nargs + nkwargs; |
Jeroen Demeyer | 53c2143 | 2019-07-03 12:54:00 +0200 | [diff] [blame] | 57 | if (totalargs == 0) { |
| 58 | return _PyObject_Vectorcall(func, &self, 1, NULL); |
| 59 | } |
| 60 | |
Jeroen Demeyer | 988e6aa | 2019-06-18 10:56:53 +0200 | [diff] [blame] | 61 | PyObject *newargs_stack[_PY_FASTCALL_SMALL_STACK]; |
Jeroen Demeyer | 53c2143 | 2019-07-03 12:54:00 +0200 | [diff] [blame] | 62 | PyObject **newargs; |
Jeroen Demeyer | 988e6aa | 2019-06-18 10:56:53 +0200 | [diff] [blame] | 63 | if (totalargs <= (Py_ssize_t)Py_ARRAY_LENGTH(newargs_stack) - 1) { |
| 64 | newargs = newargs_stack; |
| 65 | } |
| 66 | else { |
| 67 | newargs = PyMem_Malloc((totalargs+1) * sizeof(PyObject *)); |
| 68 | if (newargs == NULL) { |
| 69 | PyErr_NoMemory(); |
| 70 | return NULL; |
| 71 | } |
Jeroen Demeyer | aacc77f | 2019-05-29 20:31:52 +0200 | [diff] [blame] | 72 | } |
| 73 | /* use borrowed references */ |
| 74 | newargs[0] = self; |
Jeroen Demeyer | 53c2143 | 2019-07-03 12:54:00 +0200 | [diff] [blame] | 75 | /* bpo-37138: since totalargs > 0, it's impossible that args is NULL. |
| 76 | * We need this, since calling memcpy() with a NULL pointer is |
| 77 | * undefined behaviour. */ |
| 78 | assert(args != NULL); |
| 79 | memcpy(newargs + 1, args, totalargs * sizeof(PyObject *)); |
Jeroen Demeyer | aacc77f | 2019-05-29 20:31:52 +0200 | [diff] [blame] | 80 | result = _PyObject_Vectorcall(func, newargs, nargs+1, kwnames); |
Jeroen Demeyer | 988e6aa | 2019-06-18 10:56:53 +0200 | [diff] [blame] | 81 | if (newargs != newargs_stack) { |
| 82 | PyMem_Free(newargs); |
| 83 | } |
Jeroen Demeyer | aacc77f | 2019-05-29 20:31:52 +0200 | [diff] [blame] | 84 | } |
| 85 | return result; |
| 86 | } |
| 87 | |
| 88 | |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 89 | /* Method objects are used for bound instance methods returned by |
| 90 | instancename.methodname. ClassName.methodname returns an ordinary |
| 91 | function. |
Guido van Rossum | 81daa32 | 1993-05-20 14:24:46 +0000 | [diff] [blame] | 92 | */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 93 | |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 94 | PyObject * |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 95 | PyMethod_New(PyObject *func, PyObject *self) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 96 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 97 | if (self == NULL) { |
| 98 | PyErr_BadInternalCall(); |
| 99 | return NULL; |
| 100 | } |
Inada Naoki | 3e54b57 | 2019-07-26 15:05:50 +0900 | [diff] [blame] | 101 | PyMethodObject *im = PyObject_GC_New(PyMethodObject, &PyMethod_Type); |
| 102 | if (im == NULL) { |
| 103 | return NULL; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 104 | } |
| 105 | im->im_weakreflist = NULL; |
| 106 | Py_INCREF(func); |
| 107 | im->im_func = func; |
Hai Shi | c83356c | 2019-06-17 04:19:19 +0800 | [diff] [blame] | 108 | Py_INCREF(self); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 109 | im->im_self = self; |
Jeroen Demeyer | aacc77f | 2019-05-29 20:31:52 +0200 | [diff] [blame] | 110 | im->vectorcall = method_vectorcall; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 111 | _PyObject_GC_TRACK(im); |
| 112 | return (PyObject *)im; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Antoine Pitrou | c9dc4a2 | 2013-11-23 18:59:12 +0100 | [diff] [blame] | 115 | static PyObject * |
Siddhesh Poyarekar | 55edd0c | 2018-04-30 00:29:33 +0530 | [diff] [blame] | 116 | method_reduce(PyMethodObject *im, PyObject *Py_UNUSED(ignored)) |
Antoine Pitrou | c9dc4a2 | 2013-11-23 18:59:12 +0100 | [diff] [blame] | 117 | { |
| 118 | PyObject *self = PyMethod_GET_SELF(im); |
| 119 | PyObject *func = PyMethod_GET_FUNCTION(im); |
Antoine Pitrou | c9dc4a2 | 2013-11-23 18:59:12 +0100 | [diff] [blame] | 120 | PyObject *funcname; |
| 121 | _Py_IDENTIFIER(getattr); |
| 122 | |
| 123 | funcname = _PyObject_GetAttrId(func, &PyId___name__); |
| 124 | if (funcname == NULL) { |
| 125 | return NULL; |
| 126 | } |
Serhiy Storchaka | bb86bf4 | 2018-12-11 08:28:18 +0200 | [diff] [blame] | 127 | return Py_BuildValue("N(ON)", _PyEval_GetBuiltinId(&PyId_getattr), |
| 128 | self, funcname); |
Antoine Pitrou | c9dc4a2 | 2013-11-23 18:59:12 +0100 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | static PyMethodDef method_methods[] = { |
| 132 | {"__reduce__", (PyCFunction)method_reduce, METH_NOARGS, NULL}, |
| 133 | {NULL, NULL} |
| 134 | }; |
| 135 | |
Guido van Rossum | f0b35e1 | 2001-09-18 03:53:24 +0000 | [diff] [blame] | 136 | /* Descriptors for PyMethod attributes */ |
| 137 | |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 138 | /* im_func and im_self are stored in the PyMethod object */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 139 | |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 140 | #define MO_OFF(x) offsetof(PyMethodObject, x) |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 141 | |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 142 | static PyMemberDef method_memberlist[] = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 143 | {"__func__", T_OBJECT, MO_OFF(im_func), READONLY|RESTRICTED, |
| 144 | "the function (or other callable) implementing a method"}, |
| 145 | {"__self__", T_OBJECT, MO_OFF(im_self), READONLY|RESTRICTED, |
| 146 | "the instance to which a method is bound"}, |
| 147 | {NULL} /* Sentinel */ |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 148 | }; |
| 149 | |
Guido van Rossum | baf0f8f | 2003-11-22 23:55:50 +0000 | [diff] [blame] | 150 | /* Christian Tismer argued convincingly that method attributes should |
| 151 | (nearly) always override function attributes. |
| 152 | The one exception is __doc__; there's a default __doc__ which |
| 153 | should only be used for the class, not for instances */ |
| 154 | |
| 155 | static PyObject * |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 156 | method_get_doc(PyMethodObject *im, void *context) |
Guido van Rossum | baf0f8f | 2003-11-22 23:55:50 +0000 | [diff] [blame] | 157 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 158 | static PyObject *docstr; |
| 159 | if (docstr == NULL) { |
| 160 | docstr= PyUnicode_InternFromString("__doc__"); |
| 161 | if (docstr == NULL) |
| 162 | return NULL; |
| 163 | } |
| 164 | return PyObject_GetAttr(im->im_func, docstr); |
Guido van Rossum | baf0f8f | 2003-11-22 23:55:50 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 167 | static PyGetSetDef method_getset[] = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 168 | {"__doc__", (getter)method_get_doc, NULL, NULL}, |
| 169 | {0} |
Guido van Rossum | baf0f8f | 2003-11-22 23:55:50 +0000 | [diff] [blame] | 170 | }; |
Guido van Rossum | f0b35e1 | 2001-09-18 03:53:24 +0000 | [diff] [blame] | 171 | |
| 172 | static PyObject * |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 173 | method_getattro(PyObject *obj, PyObject *name) |
Guido van Rossum | f0b35e1 | 2001-09-18 03:53:24 +0000 | [diff] [blame] | 174 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 175 | PyMethodObject *im = (PyMethodObject *)obj; |
| 176 | PyTypeObject *tp = obj->ob_type; |
| 177 | PyObject *descr = NULL; |
Guido van Rossum | f0b35e1 | 2001-09-18 03:53:24 +0000 | [diff] [blame] | 178 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 179 | { |
| 180 | if (tp->tp_dict == NULL) { |
| 181 | if (PyType_Ready(tp) < 0) |
| 182 | return NULL; |
| 183 | } |
| 184 | descr = _PyType_Lookup(tp, name); |
| 185 | } |
Guido van Rossum | f0b35e1 | 2001-09-18 03:53:24 +0000 | [diff] [blame] | 186 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 187 | if (descr != NULL) { |
| 188 | descrgetfunc f = TP_DESCR_GET(descr->ob_type); |
| 189 | if (f != NULL) |
| 190 | return f(descr, obj, (PyObject *)obj->ob_type); |
| 191 | else { |
| 192 | Py_INCREF(descr); |
| 193 | return descr; |
| 194 | } |
| 195 | } |
Guido van Rossum | f0b35e1 | 2001-09-18 03:53:24 +0000 | [diff] [blame] | 196 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 197 | return PyObject_GetAttr(im->im_func, name); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 200 | PyDoc_STRVAR(method_doc, |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 201 | "method(function, instance)\n\ |
Guido van Rossum | bea18cc | 2002-06-14 20:41:17 +0000 | [diff] [blame] | 202 | \n\ |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 203 | Create a bound instance method object."); |
Guido van Rossum | bea18cc | 2002-06-14 20:41:17 +0000 | [diff] [blame] | 204 | |
| 205 | static PyObject * |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 206 | method_new(PyTypeObject* type, PyObject* args, PyObject *kw) |
Guido van Rossum | bea18cc | 2002-06-14 20:41:17 +0000 | [diff] [blame] | 207 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 208 | PyObject *func; |
| 209 | PyObject *self; |
Guido van Rossum | bea18cc | 2002-06-14 20:41:17 +0000 | [diff] [blame] | 210 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 211 | if (!_PyArg_NoKeywords("method", kw)) |
| 212 | return NULL; |
| 213 | if (!PyArg_UnpackTuple(args, "method", 2, 2, |
| 214 | &func, &self)) |
| 215 | return NULL; |
| 216 | if (!PyCallable_Check(func)) { |
| 217 | PyErr_SetString(PyExc_TypeError, |
| 218 | "first argument must be callable"); |
| 219 | return NULL; |
| 220 | } |
| 221 | if (self == NULL || self == Py_None) { |
| 222 | PyErr_SetString(PyExc_TypeError, |
| 223 | "self must not be None"); |
| 224 | return NULL; |
| 225 | } |
Michael W. Hudson | e2749cb | 2005-03-30 16:32:10 +0000 | [diff] [blame] | 226 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 227 | return PyMethod_New(func, self); |
Guido van Rossum | bea18cc | 2002-06-14 20:41:17 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 230 | static void |
Antoine Pitrou | 9ed5f27 | 2013-08-13 20:18:52 +0200 | [diff] [blame] | 231 | method_dealloc(PyMethodObject *im) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 232 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 233 | _PyObject_GC_UNTRACK(im); |
| 234 | if (im->im_weakreflist != NULL) |
| 235 | PyObject_ClearWeakRefs((PyObject *)im); |
| 236 | Py_DECREF(im->im_func); |
| 237 | Py_XDECREF(im->im_self); |
Inada Naoki | 3e54b57 | 2019-07-26 15:05:50 +0900 | [diff] [blame] | 238 | PyObject_GC_Del(im); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 239 | } |
| 240 | |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 241 | static PyObject * |
| 242 | method_richcompare(PyObject *self, PyObject *other, int op) |
Guido van Rossum | ebc8c51 | 1992-09-03 20:39:51 +0000 | [diff] [blame] | 243 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 244 | PyMethodObject *a, *b; |
| 245 | PyObject *res; |
| 246 | int eq; |
Thomas Wouters | 73e5a5b | 2006-06-08 15:35:45 +0000 | [diff] [blame] | 247 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 248 | if ((op != Py_EQ && op != Py_NE) || |
| 249 | !PyMethod_Check(self) || |
| 250 | !PyMethod_Check(other)) |
| 251 | { |
Brian Curtin | dfc80e3 | 2011-08-10 20:28:54 -0500 | [diff] [blame] | 252 | Py_RETURN_NOTIMPLEMENTED; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 253 | } |
| 254 | a = (PyMethodObject *)self; |
| 255 | b = (PyMethodObject *)other; |
| 256 | eq = PyObject_RichCompareBool(a->im_func, b->im_func, Py_EQ); |
| 257 | if (eq == 1) { |
Serhiy Storchaka | ac20e0f | 2018-07-31 09:18:24 +0300 | [diff] [blame] | 258 | eq = (a->im_self == b->im_self); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 259 | } |
Serhiy Storchaka | ac20e0f | 2018-07-31 09:18:24 +0300 | [diff] [blame] | 260 | else if (eq < 0) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 261 | return NULL; |
| 262 | if (op == Py_EQ) |
| 263 | res = eq ? Py_True : Py_False; |
| 264 | else |
| 265 | res = eq ? Py_False : Py_True; |
| 266 | Py_INCREF(res); |
| 267 | return res; |
Guido van Rossum | ebc8c51 | 1992-09-03 20:39:51 +0000 | [diff] [blame] | 268 | } |
| 269 | |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 270 | static PyObject * |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 271 | method_repr(PyMethodObject *a) |
Guido van Rossum | 2583165 | 1993-05-19 14:50:45 +0000 | [diff] [blame] | 272 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 273 | PyObject *self = a->im_self; |
| 274 | PyObject *func = a->im_func; |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 275 | PyObject *funcname, *result; |
Benjamin Peterson | 48ad7c0 | 2014-08-20 18:41:57 -0500 | [diff] [blame] | 276 | const char *defname = "?"; |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 277 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 278 | if (_PyObject_LookupAttrId(func, &PyId___qualname__, &funcname) < 0 || |
| 279 | (funcname == NULL && |
| 280 | _PyObject_LookupAttrId(func, &PyId___name__, &funcname) < 0)) |
| 281 | { |
| 282 | return NULL; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 283 | } |
Serhiy Storchaka | 009b811 | 2015-03-18 21:53:15 +0200 | [diff] [blame] | 284 | |
Benjamin Peterson | 48ad7c0 | 2014-08-20 18:41:57 -0500 | [diff] [blame] | 285 | if (funcname != NULL && !PyUnicode_Check(funcname)) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 286 | Py_DECREF(funcname); |
| 287 | funcname = NULL; |
| 288 | } |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 289 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 290 | /* XXX Shouldn't use repr()/%R here! */ |
Benjamin Peterson | 48ad7c0 | 2014-08-20 18:41:57 -0500 | [diff] [blame] | 291 | result = PyUnicode_FromFormat("<bound method %V of %R>", |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 292 | funcname, defname, self); |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 293 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 294 | Py_XDECREF(funcname); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 295 | return result; |
Guido van Rossum | 2583165 | 1993-05-19 14:50:45 +0000 | [diff] [blame] | 296 | } |
| 297 | |
Benjamin Peterson | 8f67d08 | 2010-10-17 20:54:53 +0000 | [diff] [blame] | 298 | static Py_hash_t |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 299 | method_hash(PyMethodObject *a) |
Guido van Rossum | 9bfef44 | 1993-03-29 10:43:31 +0000 | [diff] [blame] | 300 | { |
Benjamin Peterson | 8f67d08 | 2010-10-17 20:54:53 +0000 | [diff] [blame] | 301 | Py_hash_t x, y; |
Martijn Pieters | b727239 | 2019-03-05 05:19:34 +0000 | [diff] [blame] | 302 | x = _Py_HashPointer(a->im_self); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 303 | y = PyObject_Hash(a->im_func); |
| 304 | if (y == -1) |
| 305 | return -1; |
| 306 | x = x ^ y; |
| 307 | if (x == -1) |
| 308 | x = -2; |
| 309 | return x; |
Guido van Rossum | 9bfef44 | 1993-03-29 10:43:31 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Jeremy Hylton | 8caad49 | 2000-06-23 14:18:11 +0000 | [diff] [blame] | 312 | static int |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 313 | method_traverse(PyMethodObject *im, visitproc visit, void *arg) |
Jeremy Hylton | 8caad49 | 2000-06-23 14:18:11 +0000 | [diff] [blame] | 314 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 315 | Py_VISIT(im->im_func); |
| 316 | Py_VISIT(im->im_self); |
| 317 | return 0; |
Jeremy Hylton | 8caad49 | 2000-06-23 14:18:11 +0000 | [diff] [blame] | 318 | } |
| 319 | |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 320 | static PyObject * |
Guido van Rossum | 47b9ff6 | 2006-08-24 00:41:19 +0000 | [diff] [blame] | 321 | method_descr_get(PyObject *meth, PyObject *obj, PyObject *cls) |
Guido van Rossum | 23cc2b4 | 2001-08-15 17:52:31 +0000 | [diff] [blame] | 322 | { |
Martijn Pieters | b727239 | 2019-03-05 05:19:34 +0000 | [diff] [blame] | 323 | Py_INCREF(meth); |
| 324 | return meth; |
Guido van Rossum | 23cc2b4 | 2001-08-15 17:52:31 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 327 | PyTypeObject PyMethod_Type = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 328 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
| 329 | "method", |
| 330 | sizeof(PyMethodObject), |
| 331 | 0, |
| 332 | (destructor)method_dealloc, /* tp_dealloc */ |
Jeroen Demeyer | aacc77f | 2019-05-29 20:31:52 +0200 | [diff] [blame] | 333 | offsetof(PyMethodObject, vectorcall), /* tp_vectorcall_offset */ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 334 | 0, /* tp_getattr */ |
| 335 | 0, /* tp_setattr */ |
Jeroen Demeyer | 530f506 | 2019-05-31 04:13:39 +0200 | [diff] [blame] | 336 | 0, /* tp_as_async */ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 337 | (reprfunc)method_repr, /* tp_repr */ |
| 338 | 0, /* tp_as_number */ |
| 339 | 0, /* tp_as_sequence */ |
| 340 | 0, /* tp_as_mapping */ |
| 341 | (hashfunc)method_hash, /* tp_hash */ |
Jeroen Demeyer | c78fe32 | 2019-06-18 10:50:28 +0200 | [diff] [blame] | 342 | PyVectorcall_Call, /* tp_call */ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 343 | 0, /* tp_str */ |
| 344 | method_getattro, /* tp_getattro */ |
| 345 | PyObject_GenericSetAttr, /* tp_setattro */ |
| 346 | 0, /* tp_as_buffer */ |
Jeroen Demeyer | aacc77f | 2019-05-29 20:31:52 +0200 | [diff] [blame] | 347 | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | |
| 348 | _Py_TPFLAGS_HAVE_VECTORCALL, /* tp_flags */ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 349 | method_doc, /* tp_doc */ |
| 350 | (traverseproc)method_traverse, /* tp_traverse */ |
| 351 | 0, /* tp_clear */ |
| 352 | method_richcompare, /* tp_richcompare */ |
| 353 | offsetof(PyMethodObject, im_weakreflist), /* tp_weaklistoffset */ |
| 354 | 0, /* tp_iter */ |
| 355 | 0, /* tp_iternext */ |
Antoine Pitrou | c9dc4a2 | 2013-11-23 18:59:12 +0100 | [diff] [blame] | 356 | method_methods, /* tp_methods */ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 357 | method_memberlist, /* tp_members */ |
| 358 | method_getset, /* tp_getset */ |
| 359 | 0, /* tp_base */ |
| 360 | 0, /* tp_dict */ |
| 361 | method_descr_get, /* tp_descr_get */ |
| 362 | 0, /* tp_descr_set */ |
| 363 | 0, /* tp_dictoffset */ |
| 364 | 0, /* tp_init */ |
| 365 | 0, /* tp_alloc */ |
| 366 | method_new, /* tp_new */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 367 | }; |
Guido van Rossum | a0d349f | 1997-08-05 02:06:53 +0000 | [diff] [blame] | 368 | |
| 369 | /* Clear out the free list */ |
| 370 | |
Christian Heimes | a156e09 | 2008-02-16 07:38:31 +0000 | [diff] [blame] | 371 | int |
| 372 | PyMethod_ClearFreeList(void) |
Guido van Rossum | a0d349f | 1997-08-05 02:06:53 +0000 | [diff] [blame] | 373 | { |
Inada Naoki | 3e54b57 | 2019-07-26 15:05:50 +0900 | [diff] [blame] | 374 | return 0; |
Christian Heimes | a156e09 | 2008-02-16 07:38:31 +0000 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | void |
Victor Stinner | bed4817 | 2019-08-27 00:12:32 +0200 | [diff] [blame] | 378 | _PyMethod_Fini(void) |
Christian Heimes | a156e09 | 2008-02-16 07:38:31 +0000 | [diff] [blame] | 379 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 380 | (void)PyMethod_ClearFreeList(); |
Guido van Rossum | a0d349f | 1997-08-05 02:06:53 +0000 | [diff] [blame] | 381 | } |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 382 | |
| 383 | /* ------------------------------------------------------------------------ |
| 384 | * instance method |
| 385 | */ |
| 386 | |
| 387 | PyObject * |
| 388 | PyInstanceMethod_New(PyObject *func) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 389 | PyInstanceMethodObject *method; |
| 390 | method = PyObject_GC_New(PyInstanceMethodObject, |
| 391 | &PyInstanceMethod_Type); |
| 392 | if (method == NULL) return NULL; |
| 393 | Py_INCREF(func); |
| 394 | method->func = func; |
| 395 | _PyObject_GC_TRACK(method); |
| 396 | return (PyObject *)method; |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | PyObject * |
| 400 | PyInstanceMethod_Function(PyObject *im) |
| 401 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 402 | if (!PyInstanceMethod_Check(im)) { |
| 403 | PyErr_BadInternalCall(); |
| 404 | return NULL; |
| 405 | } |
| 406 | return PyInstanceMethod_GET_FUNCTION(im); |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | #define IMO_OFF(x) offsetof(PyInstanceMethodObject, x) |
| 410 | |
| 411 | static PyMemberDef instancemethod_memberlist[] = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 412 | {"__func__", T_OBJECT, IMO_OFF(func), READONLY|RESTRICTED, |
| 413 | "the function (or other callable) implementing a method"}, |
| 414 | {NULL} /* Sentinel */ |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 415 | }; |
| 416 | |
| 417 | static PyObject * |
| 418 | instancemethod_get_doc(PyObject *self, void *context) |
| 419 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 420 | static PyObject *docstr; |
| 421 | if (docstr == NULL) { |
| 422 | docstr = PyUnicode_InternFromString("__doc__"); |
| 423 | if (docstr == NULL) |
| 424 | return NULL; |
| 425 | } |
| 426 | return PyObject_GetAttr(PyInstanceMethod_GET_FUNCTION(self), docstr); |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | static PyGetSetDef instancemethod_getset[] = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 430 | {"__doc__", (getter)instancemethod_get_doc, NULL, NULL}, |
| 431 | {0} |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 432 | }; |
| 433 | |
| 434 | static PyObject * |
| 435 | instancemethod_getattro(PyObject *self, PyObject *name) |
| 436 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 437 | PyTypeObject *tp = self->ob_type; |
| 438 | PyObject *descr = NULL; |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 439 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 440 | if (tp->tp_dict == NULL) { |
| 441 | if (PyType_Ready(tp) < 0) |
| 442 | return NULL; |
| 443 | } |
| 444 | descr = _PyType_Lookup(tp, name); |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 445 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 446 | if (descr != NULL) { |
| 447 | descrgetfunc f = TP_DESCR_GET(descr->ob_type); |
| 448 | if (f != NULL) |
| 449 | return f(descr, self, (PyObject *)self->ob_type); |
| 450 | else { |
| 451 | Py_INCREF(descr); |
| 452 | return descr; |
| 453 | } |
| 454 | } |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 455 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 456 | return PyObject_GetAttr(PyInstanceMethod_GET_FUNCTION(self), name); |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | static void |
| 460 | instancemethod_dealloc(PyObject *self) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 461 | _PyObject_GC_UNTRACK(self); |
| 462 | Py_DECREF(PyInstanceMethod_GET_FUNCTION(self)); |
| 463 | PyObject_GC_Del(self); |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | static int |
| 467 | instancemethod_traverse(PyObject *self, visitproc visit, void *arg) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 468 | Py_VISIT(PyInstanceMethod_GET_FUNCTION(self)); |
| 469 | return 0; |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | static PyObject * |
| 473 | instancemethod_call(PyObject *self, PyObject *arg, PyObject *kw) |
| 474 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 475 | return PyObject_Call(PyMethod_GET_FUNCTION(self), arg, kw); |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | static PyObject * |
| 479 | instancemethod_descr_get(PyObject *descr, PyObject *obj, PyObject *type) { |
Antoine Pitrou | 9ed5f27 | 2013-08-13 20:18:52 +0200 | [diff] [blame] | 480 | PyObject *func = PyInstanceMethod_GET_FUNCTION(descr); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 481 | if (obj == NULL) { |
| 482 | Py_INCREF(func); |
| 483 | return func; |
| 484 | } |
| 485 | else |
| 486 | return PyMethod_New(func, obj); |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | static PyObject * |
| 490 | instancemethod_richcompare(PyObject *self, PyObject *other, int op) |
| 491 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 492 | PyInstanceMethodObject *a, *b; |
| 493 | PyObject *res; |
| 494 | int eq; |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 495 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 496 | if ((op != Py_EQ && op != Py_NE) || |
| 497 | !PyInstanceMethod_Check(self) || |
| 498 | !PyInstanceMethod_Check(other)) |
| 499 | { |
Brian Curtin | dfc80e3 | 2011-08-10 20:28:54 -0500 | [diff] [blame] | 500 | Py_RETURN_NOTIMPLEMENTED; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 501 | } |
| 502 | a = (PyInstanceMethodObject *)self; |
| 503 | b = (PyInstanceMethodObject *)other; |
| 504 | eq = PyObject_RichCompareBool(a->func, b->func, Py_EQ); |
| 505 | if (eq < 0) |
| 506 | return NULL; |
| 507 | if (op == Py_EQ) |
| 508 | res = eq ? Py_True : Py_False; |
| 509 | else |
| 510 | res = eq ? Py_False : Py_True; |
| 511 | Py_INCREF(res); |
| 512 | return res; |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | static PyObject * |
| 516 | instancemethod_repr(PyObject *self) |
| 517 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 518 | PyObject *func = PyInstanceMethod_Function(self); |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 519 | PyObject *funcname, *result; |
Serhiy Storchaka | e2f92de | 2017-11-11 13:06:26 +0200 | [diff] [blame] | 520 | const char *defname = "?"; |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 521 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 522 | if (func == NULL) { |
| 523 | PyErr_BadInternalCall(); |
| 524 | return NULL; |
| 525 | } |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 526 | |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 527 | if (_PyObject_LookupAttrId(func, &PyId___name__, &funcname) < 0) { |
| 528 | return NULL; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 529 | } |
Serhiy Storchaka | f320be7 | 2018-01-25 10:49:40 +0200 | [diff] [blame] | 530 | if (funcname != NULL && !PyUnicode_Check(funcname)) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 531 | Py_DECREF(funcname); |
| 532 | funcname = NULL; |
| 533 | } |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 534 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 535 | result = PyUnicode_FromFormat("<instancemethod %V at %p>", |
| 536 | funcname, defname, self); |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 537 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 538 | Py_XDECREF(funcname); |
| 539 | return result; |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | /* |
| 543 | static long |
| 544 | instancemethod_hash(PyObject *self) |
| 545 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 546 | long x, y; |
| 547 | x = (long)self; |
| 548 | y = PyObject_Hash(PyInstanceMethod_GET_FUNCTION(self)); |
| 549 | if (y == -1) |
| 550 | return -1; |
| 551 | x = x ^ y; |
| 552 | if (x == -1) |
| 553 | x = -2; |
| 554 | return x; |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 555 | } |
| 556 | */ |
| 557 | |
| 558 | PyDoc_STRVAR(instancemethod_doc, |
| 559 | "instancemethod(function)\n\ |
| 560 | \n\ |
| 561 | Bind a function to a class."); |
| 562 | |
| 563 | static PyObject * |
| 564 | instancemethod_new(PyTypeObject* type, PyObject* args, PyObject *kw) |
| 565 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 566 | PyObject *func; |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 567 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 568 | if (!_PyArg_NoKeywords("instancemethod", kw)) |
| 569 | return NULL; |
| 570 | if (!PyArg_UnpackTuple(args, "instancemethod", 1, 1, &func)) |
| 571 | return NULL; |
| 572 | if (!PyCallable_Check(func)) { |
| 573 | PyErr_SetString(PyExc_TypeError, |
| 574 | "first argument must be callable"); |
| 575 | return NULL; |
| 576 | } |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 577 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 578 | return PyInstanceMethod_New(func); |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | PyTypeObject PyInstanceMethod_Type = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 582 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
| 583 | "instancemethod", /* tp_name */ |
| 584 | sizeof(PyInstanceMethodObject), /* tp_basicsize */ |
| 585 | 0, /* tp_itemsize */ |
| 586 | instancemethod_dealloc, /* tp_dealloc */ |
Jeroen Demeyer | 530f506 | 2019-05-31 04:13:39 +0200 | [diff] [blame] | 587 | 0, /* tp_vectorcall_offset */ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 588 | 0, /* tp_getattr */ |
| 589 | 0, /* tp_setattr */ |
Jeroen Demeyer | 530f506 | 2019-05-31 04:13:39 +0200 | [diff] [blame] | 590 | 0, /* tp_as_async */ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 591 | (reprfunc)instancemethod_repr, /* tp_repr */ |
| 592 | 0, /* tp_as_number */ |
| 593 | 0, /* tp_as_sequence */ |
| 594 | 0, /* tp_as_mapping */ |
| 595 | 0, /*(hashfunc)instancemethod_hash, tp_hash */ |
| 596 | instancemethod_call, /* tp_call */ |
| 597 | 0, /* tp_str */ |
| 598 | instancemethod_getattro, /* tp_getattro */ |
| 599 | PyObject_GenericSetAttr, /* tp_setattro */ |
| 600 | 0, /* tp_as_buffer */ |
| 601 | Py_TPFLAGS_DEFAULT |
| 602 | | Py_TPFLAGS_HAVE_GC, /* tp_flags */ |
| 603 | instancemethod_doc, /* tp_doc */ |
| 604 | instancemethod_traverse, /* tp_traverse */ |
| 605 | 0, /* tp_clear */ |
| 606 | instancemethod_richcompare, /* tp_richcompare */ |
| 607 | 0, /* tp_weaklistoffset */ |
| 608 | 0, /* tp_iter */ |
| 609 | 0, /* tp_iternext */ |
| 610 | 0, /* tp_methods */ |
| 611 | instancemethod_memberlist, /* tp_members */ |
| 612 | instancemethod_getset, /* tp_getset */ |
| 613 | 0, /* tp_base */ |
| 614 | 0, /* tp_dict */ |
| 615 | instancemethod_descr_get, /* tp_descr_get */ |
| 616 | 0, /* tp_descr_set */ |
| 617 | 0, /* tp_dictoffset */ |
| 618 | 0, /* tp_init */ |
| 619 | 0, /* tp_alloc */ |
| 620 | instancemethod_new, /* tp_new */ |
Christian Heimes | a3534a6 | 2007-12-11 19:56:40 +0000 | [diff] [blame] | 621 | }; |