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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
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
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
4
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
5 All Rights Reserved
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
6
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
8 documentation for any purpose and without fee is hereby granted,
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
9 provided that the above copyright notice appear in all copies and that
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
10 both that copyright notice and this permission notice appear in
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
12 Centrum or CWI not be used in advertising or publicity pertaining to
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
13 distribution of the software without specific, written prior permission.
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
14
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
22
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
23 ******************************************************************/
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
24
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 /* Method object implementation */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 27
diff changeset
27 #include "allobjects.h"
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
28
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 #include "token.h"
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
30
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 typedef struct {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 } methodobject;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
36
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 object *self;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 methodobject *op = NEWOBJ(methodobject, &Methodtype);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 op->m_self = self;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 return (object *)op;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
50
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 method
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 getmethod(op)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 object *op;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 if (!is_methodobject(op)) {
27
82c7bab78bb1 New errors.
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
56 err_badcall();
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 return NULL;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
61
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 object *
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 getself(op)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 object *op;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 if (!is_methodobject(op)) {
27
82c7bab78bb1 New errors.
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
67 err_badcall();
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 return NULL;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 return ((methodobject *)op) -> m_self;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 /* Methods (the standard built-in methods, that is) */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
85
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 static void
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 meth_dealloc(m)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 methodobject *m;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 free((char *)m);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
93
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 meth_repr(m)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 methodobject *m;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 char buf[200];
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 else
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 27
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 return newstringobject(buf);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
173 typeobject Methodtype = {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 OB_HEAD_INIT(&Typetype)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 sizeof(methodobject),
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
185 0, /*tp_as_number*/
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
186 0, /*tp_as_sequence*/
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 };
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 27
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 27
diff changeset
216 /* Find a method in a module's method table.
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 27
diff changeset
217 Usually called from an object's getattr method. */
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 27
diff changeset
218
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 27
diff changeset
219 object *
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 27
diff changeset
220 findmethod(ml, op, name)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 27
diff changeset
221 struct methodlist *ml;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 27
diff changeset
222 object *op;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 27
diff changeset
223 char *name;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 27
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 27
diff changeset
227 for (; ml->ml_name != NULL; ml++) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 27
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 27
diff changeset
230 }
472
1d4b0339b83d Use AttributeError.
Guido van Rossum <guido@python.org>
parents: 395
diff changeset
231 err_setstr(AttributeError, name);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 27
diff changeset
232 return NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 27
diff changeset
233 }