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