Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | 6610ad9 | 1995-01-04 19:07:38 +0000 | [diff] [blame] | 2 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 3 | The Netherlands. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 4 | |
| 5 | All Rights Reserved |
| 6 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 9 | provided that the above copyright notice appear in all copies and that |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 10 | both that copyright notice and this permission notice appear in |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 11 | supporting documentation, and that the names of Stichting Mathematisch |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 12 | Centrum or CWI or Corporation for National Research Initiatives or |
| 13 | CNRI not be used in advertising or publicity pertaining to |
| 14 | distribution of the software without specific, written prior |
| 15 | permission. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 16 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 17 | While CWI is the initial source for this software, a modified version |
| 18 | is made available by the Corporation for National Research Initiatives |
| 19 | (CNRI) at the Internet address ftp://ftp.python.org. |
| 20 | |
| 21 | STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
| 22 | REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
| 23 | MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
| 24 | CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
| 25 | DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 26 | PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 27 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 28 | PERFORMANCE OF THIS SOFTWARE. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 29 | |
| 30 | ******************************************************************/ |
| 31 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 32 | /* Method object implementation */ |
| 33 | |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 34 | #include "Python.h" |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 35 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 36 | #include "token.h" |
| 37 | |
| 38 | typedef struct { |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 39 | PyObject_HEAD |
| 40 | PyMethodDef *m_ml; |
| 41 | PyObject *m_self; |
| 42 | } PyCFunctionObject; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 43 | |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 44 | PyObject * |
| 45 | PyCFunction_New(ml, self) |
| 46 | PyMethodDef *ml; |
| 47 | PyObject *self; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 48 | { |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 49 | PyCFunctionObject *op = PyObject_NEW(PyCFunctionObject, |
| 50 | &PyCFunction_Type); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 51 | if (op != NULL) { |
Guido van Rossum | cab650d | 1995-01-07 12:34:58 +0000 | [diff] [blame] | 52 | op->m_ml = ml; |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 53 | Py_XINCREF(self); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 54 | op->m_self = self; |
| 55 | } |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 56 | return (PyObject *)op; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 59 | PyCFunction |
| 60 | PyCFunction_GetFunction(op) |
| 61 | PyObject *op; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 62 | { |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 63 | if (!PyCFunction_Check(op)) { |
| 64 | PyErr_BadInternalCall(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 65 | return NULL; |
| 66 | } |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 67 | return ((PyCFunctionObject *)op) -> m_ml -> ml_meth; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 70 | PyObject * |
| 71 | PyCFunction_GetSelf(op) |
| 72 | PyObject *op; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 73 | { |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 74 | if (!PyCFunction_Check(op)) { |
| 75 | PyErr_BadInternalCall(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 76 | return NULL; |
| 77 | } |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 78 | return ((PyCFunctionObject *)op) -> m_self; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Guido van Rossum | c060229 | 1991-12-16 13:07:24 +0000 | [diff] [blame] | 81 | int |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 82 | PyCFunction_GetFlags(op) |
| 83 | PyObject *op; |
Guido van Rossum | c060229 | 1991-12-16 13:07:24 +0000 | [diff] [blame] | 84 | { |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 85 | if (!PyCFunction_Check(op)) { |
| 86 | PyErr_BadInternalCall(); |
Guido van Rossum | c060229 | 1991-12-16 13:07:24 +0000 | [diff] [blame] | 87 | return -1; |
| 88 | } |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 89 | return ((PyCFunctionObject *)op) -> m_ml -> ml_flags; |
Guido van Rossum | c060229 | 1991-12-16 13:07:24 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 92 | /* Methods (the standard built-in methods, that is) */ |
| 93 | |
| 94 | static void |
| 95 | meth_dealloc(m) |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 96 | PyCFunctionObject *m; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 97 | { |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 98 | Py_XDECREF(m->m_self); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 99 | free((char *)m); |
| 100 | } |
| 101 | |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 102 | static PyObject * |
Guido van Rossum | cab650d | 1995-01-07 12:34:58 +0000 | [diff] [blame] | 103 | meth_getattr(m, name) |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 104 | PyCFunctionObject *m; |
Guido van Rossum | cab650d | 1995-01-07 12:34:58 +0000 | [diff] [blame] | 105 | char *name; |
| 106 | { |
| 107 | if (strcmp(name, "__name__") == 0) { |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 108 | return PyString_FromString(m->m_ml->ml_name); |
Guido van Rossum | cab650d | 1995-01-07 12:34:58 +0000 | [diff] [blame] | 109 | } |
| 110 | if (strcmp(name, "__doc__") == 0) { |
| 111 | char *doc = m->m_ml->ml_doc; |
| 112 | if (doc != NULL) |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 113 | return PyString_FromString(doc); |
| 114 | Py_INCREF(Py_None); |
| 115 | return Py_None; |
Guido van Rossum | cab650d | 1995-01-07 12:34:58 +0000 | [diff] [blame] | 116 | } |
| 117 | if (strcmp(name, "__self__") == 0) { |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 118 | PyObject *self; |
| 119 | if (PyEval_GetRestricted()) { |
| 120 | PyErr_SetString(PyExc_RuntimeError, |
Guido van Rossum | 10393b1 | 1995-01-10 10:39:49 +0000 | [diff] [blame] | 121 | "method.__self__ not accessible in restricted mode"); |
| 122 | return NULL; |
| 123 | } |
| 124 | self = m->m_self; |
Guido van Rossum | cab650d | 1995-01-07 12:34:58 +0000 | [diff] [blame] | 125 | if (self == NULL) |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 126 | self = Py_None; |
| 127 | Py_INCREF(self); |
Guido van Rossum | cab650d | 1995-01-07 12:34:58 +0000 | [diff] [blame] | 128 | return self; |
| 129 | } |
| 130 | if (strcmp(name, "__members__") == 0) { |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 131 | return Py_BuildValue("[sss]", |
| 132 | "__doc__", "__name__", "__self__"); |
Guido van Rossum | cab650d | 1995-01-07 12:34:58 +0000 | [diff] [blame] | 133 | } |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 134 | PyErr_SetString(PyExc_AttributeError, name); |
Guido van Rossum | cab650d | 1995-01-07 12:34:58 +0000 | [diff] [blame] | 135 | return NULL; |
| 136 | } |
| 137 | |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 138 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 139 | meth_repr(m) |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 140 | PyCFunctionObject *m; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 141 | { |
| 142 | char buf[200]; |
| 143 | if (m->m_self == NULL) |
Guido van Rossum | cab650d | 1995-01-07 12:34:58 +0000 | [diff] [blame] | 144 | sprintf(buf, "<built-in function %.80s>", m->m_ml->ml_name); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 145 | else |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 146 | sprintf(buf, |
Guido van Rossum | b3f7258 | 1993-05-21 19:56:10 +0000 | [diff] [blame] | 147 | "<built-in method %.80s of %.80s object at %lx>", |
Guido van Rossum | cab650d | 1995-01-07 12:34:58 +0000 | [diff] [blame] | 148 | m->m_ml->ml_name, m->m_self->ob_type->tp_name, |
Guido van Rossum | 9bfef44 | 1993-03-29 10:43:31 +0000 | [diff] [blame] | 149 | (long)m->m_self); |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 150 | return PyString_FromString(buf); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 151 | } |
| 152 | |
Guido van Rossum | 9bfef44 | 1993-03-29 10:43:31 +0000 | [diff] [blame] | 153 | static int |
| 154 | meth_compare(a, b) |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 155 | PyCFunctionObject *a, *b; |
Guido van Rossum | 9bfef44 | 1993-03-29 10:43:31 +0000 | [diff] [blame] | 156 | { |
| 157 | if (a->m_self != b->m_self) |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 158 | return PyObject_Compare(a->m_self, b->m_self); |
Guido van Rossum | cab650d | 1995-01-07 12:34:58 +0000 | [diff] [blame] | 159 | if (a->m_ml->ml_meth == b->m_ml->ml_meth) |
Guido van Rossum | 9bfef44 | 1993-03-29 10:43:31 +0000 | [diff] [blame] | 160 | return 0; |
Guido van Rossum | cab650d | 1995-01-07 12:34:58 +0000 | [diff] [blame] | 161 | if (strcmp(a->m_ml->ml_name, b->m_ml->ml_name) < 0) |
Guido van Rossum | 9bfef44 | 1993-03-29 10:43:31 +0000 | [diff] [blame] | 162 | return -1; |
| 163 | else |
| 164 | return 1; |
| 165 | } |
| 166 | |
| 167 | static long |
| 168 | meth_hash(a) |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 169 | PyCFunctionObject *a; |
Guido van Rossum | 9bfef44 | 1993-03-29 10:43:31 +0000 | [diff] [blame] | 170 | { |
Guido van Rossum | d7047b3 | 1995-01-02 19:07:15 +0000 | [diff] [blame] | 171 | long x; |
Guido van Rossum | 9bfef44 | 1993-03-29 10:43:31 +0000 | [diff] [blame] | 172 | if (a->m_self == NULL) |
| 173 | x = 0; |
| 174 | else { |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 175 | x = PyObject_Hash(a->m_self); |
Guido van Rossum | 9bfef44 | 1993-03-29 10:43:31 +0000 | [diff] [blame] | 176 | if (x == -1) |
| 177 | return -1; |
| 178 | } |
Guido van Rossum | cab650d | 1995-01-07 12:34:58 +0000 | [diff] [blame] | 179 | return x ^ (long) a->m_ml->ml_meth; |
Guido van Rossum | 9bfef44 | 1993-03-29 10:43:31 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 182 | PyTypeObject PyCFunction_Type = { |
| 183 | PyObject_HEAD_INIT(&PyType_Type) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 184 | 0, |
Guido van Rossum | 7066dd7 | 1992-09-17 17:54:56 +0000 | [diff] [blame] | 185 | "builtin_function_or_method", |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 186 | sizeof(PyCFunctionObject), |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 187 | 0, |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 188 | (destructor)meth_dealloc, /*tp_dealloc*/ |
Guido van Rossum | 7066dd7 | 1992-09-17 17:54:56 +0000 | [diff] [blame] | 189 | 0, /*tp_print*/ |
Guido van Rossum | cab650d | 1995-01-07 12:34:58 +0000 | [diff] [blame] | 190 | (getattrfunc)meth_getattr, /*tp_getattr*/ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 191 | 0, /*tp_setattr*/ |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 192 | (cmpfunc)meth_compare, /*tp_compare*/ |
| 193 | (reprfunc)meth_repr, /*tp_repr*/ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 194 | 0, /*tp_as_number*/ |
| 195 | 0, /*tp_as_sequence*/ |
| 196 | 0, /*tp_as_mapping*/ |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 197 | (hashfunc)meth_hash, /*tp_hash*/ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 198 | }; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 199 | |
Guido van Rossum | 6978503 | 1995-01-26 22:58:48 +0000 | [diff] [blame] | 200 | /* List all methods in a chain -- helper for findmethodinchain */ |
Guido van Rossum | e9c430f | 1991-10-20 20:21:15 +0000 | [diff] [blame] | 201 | |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 202 | static PyObject * |
Guido van Rossum | 6978503 | 1995-01-26 22:58:48 +0000 | [diff] [blame] | 203 | listmethodchain(chain) |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 204 | PyMethodChain *chain; |
Guido van Rossum | e9c430f | 1991-10-20 20:21:15 +0000 | [diff] [blame] | 205 | { |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 206 | PyMethodChain *c; |
| 207 | PyMethodDef *ml; |
Guido van Rossum | e9c430f | 1991-10-20 20:21:15 +0000 | [diff] [blame] | 208 | int i, n; |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 209 | PyObject *v; |
Guido van Rossum | 6978503 | 1995-01-26 22:58:48 +0000 | [diff] [blame] | 210 | |
| 211 | n = 0; |
| 212 | for (c = chain; c != NULL; c = c->link) { |
| 213 | for (ml = c->methods; ml->ml_name != NULL; ml++) |
| 214 | n++; |
| 215 | } |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 216 | v = PyList_New(n); |
Guido van Rossum | 6978503 | 1995-01-26 22:58:48 +0000 | [diff] [blame] | 217 | if (v == NULL) |
| 218 | return NULL; |
| 219 | i = 0; |
| 220 | for (c = chain; c != NULL; c = c->link) { |
| 221 | for (ml = c->methods; ml->ml_name != NULL; ml++) { |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 222 | PyList_SetItem(v, i, PyString_FromString(ml->ml_name)); |
Guido van Rossum | 6978503 | 1995-01-26 22:58:48 +0000 | [diff] [blame] | 223 | i++; |
Guido van Rossum | e9c430f | 1991-10-20 20:21:15 +0000 | [diff] [blame] | 224 | } |
| 225 | } |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 226 | if (PyErr_Occurred()) { |
| 227 | Py_DECREF(v); |
Guido van Rossum | 6978503 | 1995-01-26 22:58:48 +0000 | [diff] [blame] | 228 | return NULL; |
| 229 | } |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 230 | PyList_Sort(v); |
Guido van Rossum | e9c430f | 1991-10-20 20:21:15 +0000 | [diff] [blame] | 231 | return v; |
| 232 | } |
| 233 | |
Guido van Rossum | 6978503 | 1995-01-26 22:58:48 +0000 | [diff] [blame] | 234 | /* Find a method in a method chain */ |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 235 | |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 236 | PyObject * |
| 237 | Py_FindMethodInChain(chain, self, name) |
| 238 | PyMethodChain *chain; |
| 239 | PyObject *self; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 240 | char *name; |
| 241 | { |
Guido van Rossum | e9c430f | 1991-10-20 20:21:15 +0000 | [diff] [blame] | 242 | if (strcmp(name, "__methods__") == 0) |
Guido van Rossum | 6978503 | 1995-01-26 22:58:48 +0000 | [diff] [blame] | 243 | return listmethodchain(chain); |
| 244 | while (chain != NULL) { |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 245 | PyMethodDef *ml = chain->methods; |
Guido van Rossum | 6978503 | 1995-01-26 22:58:48 +0000 | [diff] [blame] | 246 | for (; ml->ml_name != NULL; ml++) { |
| 247 | if (name[0] == ml->ml_name[0] && |
| 248 | strcmp(name+1, ml->ml_name+1) == 0) |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 249 | return PyCFunction_New(ml, self); |
Guido van Rossum | 6978503 | 1995-01-26 22:58:48 +0000 | [diff] [blame] | 250 | } |
| 251 | chain = chain->link; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 252 | } |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 253 | PyErr_SetString(PyExc_AttributeError, name); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 254 | return NULL; |
| 255 | } |
Guido van Rossum | 6978503 | 1995-01-26 22:58:48 +0000 | [diff] [blame] | 256 | |
| 257 | /* Find a method in a single method list */ |
| 258 | |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 259 | PyObject * |
| 260 | Py_FindMethod(methods, self, name) |
| 261 | PyMethodDef *methods; |
| 262 | PyObject *self; |
Guido van Rossum | 6978503 | 1995-01-26 22:58:48 +0000 | [diff] [blame] | 263 | char *name; |
| 264 | { |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 265 | PyMethodChain chain; |
Guido van Rossum | 6978503 | 1995-01-26 22:58:48 +0000 | [diff] [blame] | 266 | chain.methods = methods; |
| 267 | chain.link = NULL; |
Guido van Rossum | c0b618a | 1997-05-02 03:12:38 +0000 | [diff] [blame] | 268 | return Py_FindMethodInChain(&chain, self, name); |
Guido van Rossum | 6978503 | 1995-01-26 22:58:48 +0000 | [diff] [blame] | 269 | } |