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