Mercurial > cpython-lru_cache-weakref
annotate Objects/funcobject.c @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | 65d2d8e67da3 |
| children | d1447950fa04 |
| 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 | |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
| 145 | 9 provided that the above copyright notice appear in all copies and that |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
| 145 | 11 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
12 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
13 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
14 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
15 permission. |
| 145 | 16 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
17 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
18 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
19 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
20 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2842
diff
changeset
|
28 PERFORMANCE OF THIS SOFTWARE. |
| 145 | 29 |
| 30 ******************************************************************/ | |
| 31 | |
| 6 | 32 /* Function object implementation */ |
| 33 | |
| 86 | 34 #include "allobjects.h" |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
35 #include "compile.h" |
| 86 | 36 #include "structmember.h" |
| 6 | 37 |
| 38 object * | |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
39 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
|
40 object *code; |
| 6 | 41 object *globals; |
| 42 { | |
| 43 funcobject *op = NEWOBJ(funcobject, &Functype); | |
| 44 if (op != NULL) { | |
|
2082
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
45 object *doc; |
|
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
46 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
|
47 INCREF(code); |
|
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
48 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
|
49 INCREF(globals); |
| 6 | 50 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
|
51 op->func_name = ((codeobject *)code)->co_name; |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
52 INCREF(op->func_name); |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2205
diff
changeset
|
53 op->func_defaults = 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
|
54 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
|
55 if (gettuplesize(consts) >= 1) { |
|
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
56 doc = gettupleitem(consts, 0); |
|
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
57 if (!is_stringobject(doc)) |
|
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
58 doc = None; |
|
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
59 } |
|
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
60 else |
|
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
61 doc = None; |
|
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
62 INCREF(doc); |
|
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
63 op->func_doc = doc; |
| 6 | 64 } |
| 65 return (object *)op; | |
| 66 } | |
| 67 | |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
68 object * |
|
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
69 getfunccode(op) |
| 6 | 70 object *op; |
| 71 { | |
| 72 if (!is_funcobject(op)) { | |
| 27 | 73 err_badcall(); |
| 6 | 74 return NULL; |
| 75 } | |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
76 return ((funcobject *) op) -> func_code; |
| 6 | 77 } |
| 78 | |
| 79 object * | |
| 80 getfuncglobals(op) | |
| 81 object *op; | |
| 82 { | |
| 83 if (!is_funcobject(op)) { | |
| 27 | 84 err_badcall(); |
| 6 | 85 return NULL; |
| 86 } | |
| 87 return ((funcobject *) op) -> func_globals; | |
| 88 } | |
| 89 | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
90 object * |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2205
diff
changeset
|
91 PyFunction_GetDefaults(op) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
92 object *op; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
93 { |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
94 if (!is_funcobject(op)) { |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
95 err_badcall(); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
96 return NULL; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
97 } |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2205
diff
changeset
|
98 return ((funcobject *) op) -> func_defaults; |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
99 } |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
100 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
101 int |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2205
diff
changeset
|
102 PyFunction_SetDefaults(op, defaults) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
103 object *op; |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2205
diff
changeset
|
104 object *defaults; |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
105 { |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2205
diff
changeset
|
106 if (!is_funcobject(op)) { |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
107 err_badcall(); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
108 return -1; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
109 } |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2205
diff
changeset
|
110 if (defaults == None) |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2205
diff
changeset
|
111 defaults = NULL; |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2205
diff
changeset
|
112 else if (is_tupleobject(defaults)) |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2205
diff
changeset
|
113 XINCREF(defaults); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
114 else { |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
115 err_setstr(SystemError, "non-tuple default args"); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
116 return -1; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
117 } |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2205
diff
changeset
|
118 XDECREF(((funcobject *) op) -> func_defaults); |
|
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2205
diff
changeset
|
119 ((funcobject *) op) -> func_defaults = defaults; |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
120 return 0; |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
121 } |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
122 |
| 6 | 123 /* Methods */ |
| 124 | |
| 86 | 125 #define OFF(x) offsetof(funcobject, x) |
| 126 | |
| 127 static struct memberlist func_memberlist[] = { | |
|
588
7d24de643fb5
Added READONLY specifier to data members.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
128 {"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
|
129 {"func_globals",T_OBJECT, OFF(func_globals), READONLY}, |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
130 {"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
|
131 {"__name__", T_OBJECT, OFF(func_name), READONLY}, |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2205
diff
changeset
|
132 {"func_defaults",T_OBJECT, OFF(func_defaults), 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); |
|
2205
527889ae8450
fix leak in func_dealloc (forgot to decref name)
Guido van Rossum <guido@python.org>
parents:
2105
diff
changeset
|
157 DECREF(op->func_name); |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2205
diff
changeset
|
158 XDECREF(op->func_defaults); |
|
2082
4afa7eb4734b
Added __doc__ attribute (alias func_doc), initialized from first
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
159 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
|
160 DEL(op); |
| 6 | 161 } |
| 162 | |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
163 static object* |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
164 func_repr(op) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
165 funcobject *op; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
166 { |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 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
|
173 (long)op); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
174 return newstringobject(buf); |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
175 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
176 |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
177 static int |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
178 func_compare(f, g) |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
179 funcobject *f, *g; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
180 { |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
181 int c; |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
182 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
|
183 return (f->func_globals < g->func_globals) ? -1 : 1; |
|
2842
420874f7d8bd
changes for keyword arguments and fast function call; added abstract.c
Guido van Rossum <guido@python.org>
parents:
2205
diff
changeset
|
184 c = cmpobject(f->func_defaults, g->func_defaults); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
185 if (c != 0) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
186 return c; |
|
1399
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
187 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
|
188 } |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
189 |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
190 static long |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
191 func_hash(f) |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
192 funcobject *f; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
193 { |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
194 long h; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
195 h = hashobject(f->func_code); |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
196 if (h == -1) return h; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
197 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
|
198 if (h == -1) h = -2; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
199 return h; |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
200 } |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
201 |
| 6 | 202 typeobject Functype = { |
| 203 OB_HEAD_INIT(&Typetype) | |
| 204 0, | |
| 205 "function", | |
| 206 sizeof(funcobject), | |
| 207 0, | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
208 (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
|
209 0, /*tp_print*/ |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
210 (getattrfunc)func_getattr, /*tp_getattr*/ |
| 6 | 211 0, /*tp_setattr*/ |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
212 (cmpfunc)func_compare, /*tp_compare*/ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
213 (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
|
214 0, /*tp_as_number*/ |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
215 0, /*tp_as_sequence*/ |
|
cc172ce05561
Added compare operations for functions and code objects.
Guido van Rossum <guido@python.org>
parents:
1288
diff
changeset
|
216 0, /*tp_as_mapping*/ |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1415
diff
changeset
|
217 (hashfunc)func_hash, /*tp_hash*/ |
| 6 | 218 }; |
