Mercurial > cpython-lru_cache-weakref
annotate Objects/methodobject.c @ 2105:ea7b2bf0b521 legacy-trunk
add restrictions in restricted mode
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 10 Jan 1995 10:39:49 +0000 |
| parents | f2d267edbfd6 |
| children | d091b246a3a7 |
| rev | line source |
|---|---|
| 145 | 1 /*********************************************************** |
|
2059
866c81068dbd
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2053
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
866c81068dbd
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2053
diff
changeset
|
3 The Netherlands. |
| 145 | 4 |
| 5 All Rights Reserved | |
| 6 | |
| 7 Permission to use, copy, modify, and distribute this software and its | |
| 8 documentation for any purpose and without fee is hereby granted, | |
| 9 provided that the above copyright notice appear in all copies and that | |
| 10 both that copyright notice and this permission notice appear in | |
| 11 supporting documentation, and that the names of Stichting Mathematisch | |
| 12 Centrum or CWI not be used in advertising or publicity pertaining to | |
| 13 distribution of the software without specific, written prior permission. | |
| 14 | |
| 15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO | |
| 16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
| 17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE | |
| 18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
| 19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
| 20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | |
| 21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
| 22 | |
| 23 ******************************************************************/ | |
| 24 | |
| 6 | 25 /* Method object implementation */ |
| 26 | |
| 86 | 27 #include "allobjects.h" |
| 6 | 28 |
| 29 #include "token.h" | |
| 30 | |
| 31 typedef struct { | |
| 32 OB_HEAD | |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
33 struct methodlist *m_ml; |
|
488
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
34 object *m_self; |
| 6 | 35 } methodobject; |
| 36 | |
| 37 object * | |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
38 newmethodobject(ml, self) |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
39 struct methodlist *ml; |
| 6 | 40 object *self; |
| 41 { | |
| 42 methodobject *op = NEWOBJ(methodobject, &Methodtype); | |
| 43 if (op != NULL) { | |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
44 op->m_ml = ml; |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
45 XINCREF(self); |
| 6 | 46 op->m_self = self; |
| 47 } | |
| 48 return (object *)op; | |
| 49 } | |
| 50 | |
| 51 method | |
| 52 getmethod(op) | |
| 53 object *op; | |
| 54 { | |
| 55 if (!is_methodobject(op)) { | |
| 27 | 56 err_badcall(); |
| 6 | 57 return NULL; |
| 58 } | |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
59 return ((methodobject *)op) -> m_ml -> ml_meth; |
| 6 | 60 } |
| 61 | |
| 62 object * | |
| 63 getself(op) | |
| 64 object *op; | |
| 65 { | |
| 66 if (!is_methodobject(op)) { | |
| 27 | 67 err_badcall(); |
| 6 | 68 return NULL; |
| 69 } | |
| 70 return ((methodobject *)op) -> m_self; | |
| 71 } | |
| 72 | |
|
488
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
73 int |
|
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
74 getvarargs(op) |
|
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
75 object *op; |
|
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
76 { |
|
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
77 if (!is_methodobject(op)) { |
|
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
78 err_badcall(); |
|
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
79 return -1; |
|
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
80 } |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
81 return ((methodobject *)op) -> m_ml -> ml_flags & METH_VARARGS; |
|
488
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
82 } |
|
90f35fcf8ea0
Add "varargs" attribute.
Guido van Rossum <guido@python.org>
parents:
472
diff
changeset
|
83 |
| 6 | 84 /* Methods (the standard built-in methods, that is) */ |
| 85 | |
| 86 static void | |
| 87 meth_dealloc(m) | |
| 88 methodobject *m; | |
| 89 { | |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
90 XDECREF(m->m_self); |
| 6 | 91 free((char *)m); |
| 92 } | |
| 93 | |
| 94 static object * | |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
95 meth_getattr(m, name) |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
96 methodobject *m; |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
97 char *name; |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
98 { |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
99 if (strcmp(name, "__name__") == 0) { |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
100 return newstringobject(m->m_ml->ml_name); |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
101 } |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
102 if (strcmp(name, "__doc__") == 0) { |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
103 char *doc = m->m_ml->ml_doc; |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
104 if (doc != NULL) |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
105 return newstringobject(doc); |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
106 INCREF(None); |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
107 return None; |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
108 } |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
109 if (strcmp(name, "__self__") == 0) { |
|
2105
ea7b2bf0b521
add restrictions in restricted mode
Guido van Rossum <guido@python.org>
parents:
2083
diff
changeset
|
110 object *self; |
|
ea7b2bf0b521
add restrictions in restricted mode
Guido van Rossum <guido@python.org>
parents:
2083
diff
changeset
|
111 if (getrestricted()) { |
|
ea7b2bf0b521
add restrictions in restricted mode
Guido van Rossum <guido@python.org>
parents:
2083
diff
changeset
|
112 err_setstr(RuntimeError, |
|
ea7b2bf0b521
add restrictions in restricted mode
Guido van Rossum <guido@python.org>
parents:
2083
diff
changeset
|
113 "method.__self__ not accessible in restricted mode"); |
|
ea7b2bf0b521
add restrictions in restricted mode
Guido van Rossum <guido@python.org>
parents:
2083
diff
changeset
|
114 return NULL; |
|
ea7b2bf0b521
add restrictions in restricted mode
Guido van Rossum <guido@python.org>
parents:
2083
diff
changeset
|
115 } |
|
ea7b2bf0b521
add restrictions in restricted mode
Guido van Rossum <guido@python.org>
parents:
2083
diff
changeset
|
116 self = m->m_self; |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
117 if (self == NULL) |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
118 self = None; |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
119 INCREF(self); |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
120 return self; |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
121 } |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
122 if (strcmp(name, "__members__") == 0) { |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
123 return mkvalue("[sss]", "__doc__", "__name__", "__self__"); |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
124 } |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
125 err_setstr(AttributeError, name); |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
126 return NULL; |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
127 } |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
128 |
|
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
129 static object * |
| 6 | 130 meth_repr(m) |
| 131 methodobject *m; | |
| 132 { | |
| 133 char buf[200]; | |
| 134 if (m->m_self == NULL) | |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
135 sprintf(buf, "<built-in function %.80s>", m->m_ml->ml_name); |
| 6 | 136 else |
| 86 | 137 sprintf(buf, |
|
1290
7971fecbf28e
* Lots of small changes related to access.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
138 "<built-in method %.80s of %.80s object at %lx>", |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
139 m->m_ml->ml_name, m->m_self->ob_type->tp_name, |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
140 (long)m->m_self); |
| 6 | 141 return newstringobject(buf); |
| 142 } | |
| 143 | |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
144 static int |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
145 meth_compare(a, b) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
146 methodobject *a, *b; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
147 { |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
148 if (a->m_self != b->m_self) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
149 return cmpobject(a->m_self, b->m_self); |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
150 if (a->m_ml->ml_meth == b->m_ml->ml_meth) |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
151 return 0; |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
152 if (strcmp(a->m_ml->ml_name, b->m_ml->ml_name) < 0) |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
153 return -1; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
154 else |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
155 return 1; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
156 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
157 |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
158 static long |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
159 meth_hash(a) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
160 methodobject *a; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
161 { |
|
2053
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
162 long x; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
163 if (a->m_self == NULL) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
164 x = 0; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
165 else { |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
166 x = hashobject(a->m_self); |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
167 if (x == -1) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
168 return -1; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
169 } |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
170 return x ^ (long) a->m_ml->ml_meth; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
171 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
172 |
| 6 | 173 typeobject Methodtype = { |
| 174 OB_HEAD_INIT(&Typetype) | |
| 175 0, | |
|
1051
f54e64c8b9b7
* Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
176 "builtin_function_or_method", |
| 6 | 177 sizeof(methodobject), |
| 178 0, | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
179 (destructor)meth_dealloc, /*tp_dealloc*/ |
|
1051
f54e64c8b9b7
* Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
180 0, /*tp_print*/ |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
181 (getattrfunc)meth_getattr, /*tp_getattr*/ |
| 6 | 182 0, /*tp_setattr*/ |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
183 (cmpfunc)meth_compare, /*tp_compare*/ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
184 (reprfunc)meth_repr, /*tp_repr*/ |
| 6 | 185 0, /*tp_as_number*/ |
| 186 0, /*tp_as_sequence*/ | |
| 187 0, /*tp_as_mapping*/ | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
188 (hashfunc)meth_hash, /*tp_hash*/ |
| 6 | 189 }; |
| 86 | 190 |
|
1391
7c3245c18677
* ceval.c, longobject.c, methodobject.c, listnode.c, arraymodule.c,
Guido van Rossum <guido@python.org>
parents:
1290
diff
changeset
|
191 static object *listmethods PROTO((struct methodlist *)); /* Forward */ |
|
395
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
192 |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
193 static object * |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
194 listmethods(ml) |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
195 struct methodlist *ml; |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
196 { |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
197 int i, n; |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
198 object *v; |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
199 for (n = 0; ml[n].ml_name != NULL; n++) |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
200 ; |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
201 v = newlistobject(n); |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
202 if (v != NULL) { |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
203 for (i = 0; i < n; i++) |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
204 setlistitem(v, i, newstringobject(ml[i].ml_name)); |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
205 if (err_occurred()) { |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
206 DECREF(v); |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
207 v = NULL; |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
208 } |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
209 else { |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
210 sortlist(v); |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
211 } |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
212 } |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
213 return v; |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
214 } |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
215 |
| 86 | 216 /* Find a method in a module's method table. |
| 217 Usually called from an object's getattr method. */ | |
| 218 | |
| 219 object * | |
| 220 findmethod(ml, op, name) | |
| 221 struct methodlist *ml; | |
| 222 object *op; | |
| 223 char *name; | |
| 224 { | |
|
395
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
225 if (strcmp(name, "__methods__") == 0) |
|
659b8dbf695c
Implemented __methods__ attribute
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
226 return listmethods(ml); |
| 86 | 227 for (; ml->ml_name != NULL; ml++) { |
| 228 if (strcmp(name, ml->ml_name) == 0) | |
|
2083
f2d267edbfd6
* Objects/methodobject.c: changed drastically, the object now
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
229 return newmethodobject(ml, op); |
| 86 | 230 } |
| 472 | 231 err_setstr(AttributeError, name); |
| 86 | 232 return NULL; |
| 233 } |
