Mercurial > cpython-lru_cache-weakref
annotate Objects/funcobject.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 | 4afa7eb4734b |
| children | 527889ae8450 |
| rev | line source |
|---|---|
| 145 | 1 /*********************************************************** |
|
2059
866c81068dbd
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
866c81068dbd
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1848
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 /* Function object implementation */ |
| 26 | |
| 86 | 27 #include "allobjects.h" |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
28 #include "compile.h" |
| 86 | 29 #include "structmember.h" |
| 6 | 30 |
| 31 object * | |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
32 newfuncobject(code, globals) |
|
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
33 object *code; |
| 6 | 34 object *globals; |
| 35 { | |
| 36 funcobject *op = NEWOBJ(funcobject, &Functype); | |
| 37 if (op != NULL) { | |
|
2082
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
38 object *doc; |
|
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
39 object *consts; |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
40 INCREF(code); |
|
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
41 op->func_code = code; |
|
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
42 INCREF(globals); |
| 6 | 43 op->func_globals = globals; |
|
2082
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
44 op->func_name = ((codeobject *)code)->co_name; |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
45 INCREF(op->func_name); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
46 op->func_argcount = -1; /* Unknown */ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
47 op->func_argdefs = NULL; /* No default arguments */ |
|
2082
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
48 consts = ((codeobject *)code)->co_consts; |
|
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
49 if (gettuplesize(consts) >= 1) { |
|
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
50 doc = gettupleitem(consts, 0); |
|
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
51 if (!is_stringobject(doc)) |
|
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
52 doc = None; |
|
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
53 } |
|
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
54 else |
|
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
55 doc = None; |
|
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
56 INCREF(doc); |
|
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
57 op->func_doc = doc; |
| 6 | 58 } |
| 59 return (object *)op; | |
| 60 } | |
| 61 | |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
62 object * |
|
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
63 getfunccode(op) |
| 6 | 64 object *op; |
| 65 { | |
| 66 if (!is_funcobject(op)) { | |
| 27 | 67 err_badcall(); |
| 6 | 68 return NULL; |
| 69 } | |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
70 return ((funcobject *) op) -> func_code; |
| 6 | 71 } |
| 72 | |
| 73 object * | |
| 74 getfuncglobals(op) | |
| 75 object *op; | |
| 76 { | |
| 77 if (!is_funcobject(op)) { | |
| 27 | 78 err_badcall(); |
| 6 | 79 return NULL; |
| 80 } | |
| 81 return ((funcobject *) op) -> func_globals; | |
| 82 } | |
| 83 | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
84 object * |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
85 getfuncargstuff(op, argcount_return) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
86 object *op; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
87 int *argcount_return; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
88 { |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
89 if (!is_funcobject(op)) { |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
90 err_badcall(); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
91 return NULL; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
92 } |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
93 *argcount_return = ((funcobject *) op) -> func_argcount; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
94 return ((funcobject *) op) -> func_argdefs; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
95 } |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
96 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
97 int |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
98 setfuncargstuff(op, argcount, argdefs) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
99 object *op; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
100 int argcount; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
101 object *argdefs; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
102 { |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
103 if (!is_funcobject(op) || |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
104 argdefs != NULL && !is_tupleobject(argdefs)) { |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
105 err_badcall(); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
106 return -1; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
107 } |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
108 if (argdefs == None) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
109 argdefs = NULL; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
110 else if (is_tupleobject(argdefs)) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
111 XINCREF(argdefs); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
112 else { |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
113 err_setstr(SystemError, "non-tuple default args"); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
114 return -1; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
115 } |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
116 ((funcobject *) op) -> func_argcount = argcount; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
117 XDECREF(((funcobject *) op) -> func_argdefs); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
118 ((funcobject *) op) -> func_argdefs = argdefs; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
119 return 0; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
120 } |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
121 |
| 6 | 122 /* Methods */ |
| 123 | |
| 86 | 124 #define OFF(x) offsetof(funcobject, x) |
| 125 | |
| 126 static struct memberlist func_memberlist[] = { | |
|
588
7d24de643fb5
Added READONLY specifier to data members.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
127 {"func_code", T_OBJECT, OFF(func_code), READONLY}, |
|
7d24de643fb5
Added READONLY specifier to data members.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
128 {"func_globals",T_OBJECT, OFF(func_globals), READONLY}, |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
129 {"func_name", T_OBJECT, OFF(func_name), READONLY}, |
|
2105
ea7b2bf0b521
add restrictions in restricted mode
Guido van Rossum <guido@python.org>
parents:
2082
diff
changeset
|
130 {"__name__", T_OBJECT, OFF(func_name), READONLY}, |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
131 {"func_argcount",T_INT, OFF(func_argcount), READONLY}, |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
132 {"func_argdefs",T_OBJECT, OFF(func_argdefs), READONLY}, |
|
2082
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
133 {"func_doc", T_OBJECT, OFF(func_doc)}, |
|
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
134 {"__doc__", T_OBJECT, OFF(func_doc)}, |
| 86 | 135 {NULL} /* Sentinel */ |
| 136 }; | |
| 137 | |
| 138 static object * | |
| 139 func_getattr(op, name) | |
| 140 funcobject *op; | |
| 141 char *name; | |
| 142 { | |
|
2105
ea7b2bf0b521
add restrictions in restricted mode
Guido van Rossum <guido@python.org>
parents:
2082
diff
changeset
|
143 if (name[0] != '_' && getrestricted()) { |
|
ea7b2bf0b521
add restrictions in restricted mode
Guido van Rossum <guido@python.org>
parents:
2082
diff
changeset
|
144 err_setstr(RuntimeError, |
|
ea7b2bf0b521
add restrictions in restricted mode
Guido van Rossum <guido@python.org>
parents:
2082
diff
changeset
|
145 "function attributes not accessible in restricted mode"); |
|
ea7b2bf0b521
add restrictions in restricted mode
Guido van Rossum <guido@python.org>
parents:
2082
diff
changeset
|
146 return NULL; |
|
ea7b2bf0b521
add restrictions in restricted mode
Guido van Rossum <guido@python.org>
parents:
2082
diff
changeset
|
147 } |
| 86 | 148 return getmember((char *)op, func_memberlist, name); |
| 149 } | |
| 150 | |
| 6 | 151 static void |
| 86 | 152 func_dealloc(op) |
| 6 | 153 funcobject *op; |
| 154 { | |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
155 DECREF(op->func_code); |
| 6 | 156 DECREF(op->func_globals); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
157 XDECREF(op->func_argdefs); |
|
2082
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
158 XDECREF(op->func_doc); |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
159 DEL(op); |
| 6 | 160 } |
| 161 | |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
162 static object* |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
163 func_repr(op) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
164 funcobject *op; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
165 { |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
166 char buf[140]; |
|
1415
06570429f062
* import.c (get_module): pass .py filename to parse_file, not .pyc filename!
Guido van Rossum <guido@python.org>
parents:
1399
diff
changeset
|
167 if (op->func_name == None) |
|
06570429f062
* import.c (get_module): pass .py filename to parse_file, not .pyc filename!
Guido van Rossum <guido@python.org>
parents:
1399
diff
changeset
|
168 sprintf(buf, "<anonymous function at %lx>", (long)op); |
|
06570429f062
* import.c (get_module): pass .py filename to parse_file, not .pyc filename!
Guido van Rossum <guido@python.org>
parents:
1399
diff
changeset
|
169 else |
|
06570429f062
* import.c (get_module): pass .py filename to parse_file, not .pyc filename!
Guido van Rossum <guido@python.org>
parents:
1399
diff
changeset
|
170 sprintf(buf, "<function %.100s at %lx>", |
|
06570429f062
* import.c (get_module): pass .py filename to parse_file, not .pyc filename!
Guido van Rossum <guido@python.org>
parents:
1399
diff
changeset
|
171 getstringvalue(op->func_name), |
|
06570429f062
* import.c (get_module): pass .py filename to parse_file, not .pyc filename!
Guido van Rossum <guido@python.org>
parents:
1399
diff
changeset
|
172 (long)op); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
173 return newstringobject(buf); |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
174 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
175 |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
176 static int |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
177 func_compare(f, g) |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
178 funcobject *f, *g; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
179 { |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
180 int c; |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
181 if (f->func_globals != g->func_globals) |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
182 return (f->func_globals < g->func_globals) ? -1 : 1; |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
183 c = f->func_argcount < g->func_argcount; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
184 if (c != 0) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
185 return c < 0 ? -1 : 1; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
186 c = cmpobject(f->func_argdefs, g->func_argdefs); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
187 if (c != 0) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
188 return c; |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
189 return cmpobject(f->func_code, g->func_code); |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
190 } |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
191 |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
192 static long |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
193 func_hash(f) |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
194 funcobject *f; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
195 { |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
196 long h; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
197 h = hashobject(f->func_code); |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
198 if (h == -1) return h; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
199 h = h ^ (long)f->func_globals; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
200 if (h == -1) h = -2; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
201 return h; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
202 } |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
203 |
| 6 | 204 typeobject Functype = { |
| 205 OB_HEAD_INIT(&Typetype) | |
| 206 0, | |
| 207 "function", | |
| 208 sizeof(funcobject), | |
| 209 0, | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
210 (destructor)func_dealloc, /*tp_dealloc*/ |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
211 0, /*tp_print*/ |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
212 (getattrfunc)func_getattr, /*tp_getattr*/ |
| 6 | 213 0, /*tp_setattr*/ |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
214 (cmpfunc)func_compare, /*tp_compare*/ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
215 (reprfunc)func_repr, /*tp_repr*/ |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
216 0, /*tp_as_number*/ |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
217 0, /*tp_as_sequence*/ |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
218 0, /*tp_as_mapping*/ |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
219 (hashfunc)func_hash, /*tp_hash*/ |
| 6 | 220 }; |
