Mercurial > cpython-lru_cache-weakref
annotate Python/bltinmodule.c @ 388:31d509e94271 legacy-trunk
Comment out 'abort()' call.
Changed comparison operators.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Sun, 20 Oct 1991 20:12:38 +0000 |
| parents | 039aee6cbd78 |
| children | 9cd38d1ac391 |
| rev | line source |
|---|---|
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
diff
changeset
|
1 /*********************************************************** |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
diff
changeset
|
2 Copyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
diff
changeset
|
3 Netherlands. |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
diff
changeset
|
4 |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
diff
changeset
|
5 All Rights Reserved |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
diff
changeset
|
6 |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
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:
139
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
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:
139
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
diff
changeset
|
11 supporting documentation, and that the names of Stichting Mathematisch |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
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:
139
diff
changeset
|
13 distribution of the software without specific, written prior permission. |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
diff
changeset
|
14 |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
diff
changeset
|
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
diff
changeset
|
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
diff
changeset
|
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
diff
changeset
|
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
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:
139
diff
changeset
|
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
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:
139
diff
changeset
|
22 |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
diff
changeset
|
23 ******************************************************************/ |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
diff
changeset
|
24 |
| 86 | 25 /* Built-in functions */ |
| 26 | |
| 27 #include "allobjects.h" | |
| 28 | |
| 29 #include "node.h" | |
| 30 #include "graminit.h" | |
| 31 #include "errcode.h" | |
| 32 #include "sysmodule.h" | |
| 119 | 33 #include "bltinmodule.h" |
| 86 | 34 #include "import.h" |
| 35 #include "pythonrun.h" | |
| 36 #include "compile.h" /* For ceval.h */ | |
| 37 #include "ceval.h" | |
| 38 #include "modsupport.h" | |
| 39 | |
| 40 static object * | |
| 41 builtin_abs(self, v) | |
| 42 object *self; | |
| 43 object *v; | |
| 44 { | |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
45 number_methods *nm; |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
46 if (v == NULL || (nm = v->ob_type->tp_as_number) == NULL) { |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
47 err_setstr(TypeError, "abs() requires numeric argument"); |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
48 return NULL; |
| 86 | 49 } |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
50 return (*nm->nb_absolute)(v); |
| 86 | 51 } |
| 52 | |
| 53 static object * | |
| 54 builtin_chr(self, v) | |
| 55 object *self; | |
| 56 object *v; | |
| 57 { | |
| 58 long x; | |
| 59 char s[1]; | |
| 60 if (v == NULL || !is_intobject(v)) { | |
| 61 err_setstr(TypeError, "chr() must have int argument"); | |
| 62 return NULL; | |
| 63 } | |
| 64 x = getintvalue(v); | |
| 65 if (x < 0 || x >= 256) { | |
| 66 err_setstr(RuntimeError, "chr() arg not in range(256)"); | |
| 67 return NULL; | |
| 68 } | |
| 69 s[0] = x; | |
| 70 return newsizedstringobject(s, 1); | |
| 71 } | |
| 72 | |
| 73 static object * | |
| 74 builtin_dir(self, v) | |
| 75 object *self; | |
| 76 object *v; | |
| 77 { | |
| 78 object *d; | |
| 79 if (v == NULL) { | |
| 80 d = getlocals(); | |
|
385
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
81 INCREF(d); |
| 86 | 82 } |
| 83 else { | |
|
385
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
84 d = getattr(v, "__dict__"); |
|
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
85 if (d == NULL) { |
| 86 | 86 err_setstr(TypeError, |
|
385
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
87 "dir() argument has no variable attributes"); |
| 86 | 88 return NULL; |
| 89 } | |
|
385
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
90 } |
|
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
91 if (!is_dictobject(d)) { /* Assume it is None */ |
|
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
92 v = newlistobject(0); |
| 86 | 93 } |
|
385
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
94 else { |
|
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
95 v = getdictkeys(d); |
|
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
96 if (sortlist(v) != 0) { |
|
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
97 DECREF(v); |
|
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
98 v = NULL; |
|
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
99 } |
| 86 | 100 } |
|
385
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
101 DECREF(d); |
| 86 | 102 return v; |
| 103 } | |
| 104 | |
| 105 static object * | |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
106 builtin_divmod(self, args) |
| 86 | 107 object *self; |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
108 object *args; |
| 86 | 109 { |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
110 object *v, *w, *x; |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
111 if (args == NULL || !is_tupleobject(args) || gettuplesize(args) != 2) { |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
112 err_setstr(TypeError, "divmod() requires 2 arguments"); |
| 86 | 113 return NULL; |
| 114 } | |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
115 v = gettupleitem(args, 0); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
116 w = gettupleitem(args, 1); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
117 if (v->ob_type->tp_as_number == NULL || |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
118 w->ob_type->tp_as_number == NULL) { |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
119 err_setstr(TypeError, "divmod() requires numeric arguments"); |
| 86 | 120 return NULL; |
| 121 } | |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
122 if (coerce(&v, &w) != 0) |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
123 return NULL; |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
124 x = (*v->ob_type->tp_as_number->nb_divmod)(v, w); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
125 DECREF(v); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
126 DECREF(w); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
127 return x; |
| 86 | 128 } |
| 129 | |
| 130 static object * | |
| 131 exec_eval(v, start) | |
| 132 object *v; | |
| 133 int start; | |
| 134 { | |
| 135 object *str = NULL, *globals = NULL, *locals = NULL; | |
| 136 int n; | |
| 137 if (v != NULL) { | |
| 138 if (is_stringobject(v)) | |
| 139 str = v; | |
| 140 else if (is_tupleobject(v) && | |
| 141 ((n = gettuplesize(v)) == 2 || n == 3)) { | |
| 142 str = gettupleitem(v, 0); | |
| 143 globals = gettupleitem(v, 1); | |
| 144 if (n == 3) | |
| 145 locals = gettupleitem(v, 2); | |
| 146 } | |
| 147 } | |
| 148 if (str == NULL || !is_stringobject(str) || | |
| 149 globals != NULL && !is_dictobject(globals) || | |
| 150 locals != NULL && !is_dictobject(locals)) { | |
| 151 err_setstr(TypeError, | |
| 152 "exec/eval arguments must be string[,dict[,dict]]"); | |
| 153 return NULL; | |
| 154 } | |
| 155 return run_string(getstringvalue(str), start, globals, locals); | |
| 156 } | |
| 157 | |
| 158 static object * | |
| 159 builtin_eval(self, v) | |
| 160 object *self; | |
| 161 object *v; | |
| 162 { | |
| 163 return exec_eval(v, eval_input); | |
| 164 } | |
| 165 | |
| 166 static object * | |
| 167 builtin_exec(self, v) | |
| 168 object *self; | |
| 169 object *v; | |
| 170 { | |
| 171 return exec_eval(v, file_input); | |
| 172 } | |
| 173 | |
| 174 static object * | |
| 175 builtin_float(self, v) | |
| 176 object *self; | |
| 177 object *v; | |
| 178 { | |
| 179 if (v == NULL) { | |
| 180 /* */ | |
| 181 } | |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
182 else if (is_intobject(v)) { |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
183 long x = getintvalue(v); |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
184 return newfloatobject((double)x); |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
185 } |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
186 else if (is_longobject(v)) { |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
187 return newfloatobject(dgetlongvalue(v)); |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
188 } |
| 86 | 189 else if (is_floatobject(v)) { |
| 190 INCREF(v); | |
| 191 return v; | |
| 192 } | |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
193 err_setstr(TypeError, "float() argument must be int, long or float"); |
| 86 | 194 return NULL; |
| 195 } | |
| 196 | |
| 197 static object * | |
| 198 builtin_input(self, v) | |
| 199 object *self; | |
| 200 object *v; | |
| 201 { | |
| 202 FILE *in = sysgetfile("stdin", stdin); | |
| 203 FILE *out = sysgetfile("stdout", stdout); | |
| 204 node *n; | |
| 205 int err; | |
| 206 object *m, *d; | |
| 207 flushline(); | |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
208 if (v != NULL) { |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
209 if (printobject(v, out, PRINT_RAW) != 0) |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
210 return NULL; |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
211 } |
| 86 | 212 m = add_module("__main__"); |
| 213 d = getmoduledict(m); | |
| 214 return run_file(in, "<stdin>", expr_input, d, d); | |
| 215 } | |
| 216 | |
| 217 static object * | |
| 218 builtin_int(self, v) | |
| 219 object *self; | |
| 220 object *v; | |
| 221 { | |
| 222 if (v == NULL) { | |
| 223 /* */ | |
| 224 } | |
| 225 else if (is_intobject(v)) { | |
| 226 INCREF(v); | |
| 227 return v; | |
| 228 } | |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
229 else if (is_longobject(v)) { |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
230 long x; |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
231 x = getlongvalue(v); |
|
253
d4e532ee6f3d
Fix conversion of double to long; stylistic changes.
Guido van Rossum <guido@python.org>
parents:
223
diff
changeset
|
232 if (err_occurred()) |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
233 return NULL; |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
234 return newintobject(x); |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
235 } |
| 86 | 236 else if (is_floatobject(v)) { |
| 237 double x = getfloatvalue(v); | |
|
253
d4e532ee6f3d
Fix conversion of double to long; stylistic changes.
Guido van Rossum <guido@python.org>
parents:
223
diff
changeset
|
238 /* XXX should check for overflow */ |
| 86 | 239 return newintobject((long)x); |
| 240 } | |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
241 err_setstr(TypeError, "int() argument must be int, long or float"); |
| 86 | 242 return NULL; |
| 243 } | |
| 244 | |
| 245 static object * | |
| 246 builtin_len(self, v) | |
| 247 object *self; | |
| 248 object *v; | |
| 249 { | |
| 250 long len; | |
| 251 typeobject *tp; | |
| 252 if (v == NULL) { | |
| 253 err_setstr(TypeError, "len() without argument"); | |
| 254 return NULL; | |
| 255 } | |
| 256 tp = v->ob_type; | |
| 257 if (tp->tp_as_sequence != NULL) { | |
| 258 len = (*tp->tp_as_sequence->sq_length)(v); | |
| 259 } | |
| 260 else if (tp->tp_as_mapping != NULL) { | |
| 261 len = (*tp->tp_as_mapping->mp_length)(v); | |
| 262 } | |
| 263 else { | |
| 264 err_setstr(TypeError, "len() of unsized object"); | |
| 265 return NULL; | |
| 266 } | |
| 267 return newintobject(len); | |
| 268 } | |
| 269 | |
| 270 static object * | |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
271 builtin_long(self, v) |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
272 object *self; |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
273 object *v; |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
274 { |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
275 if (v == NULL) { |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
276 /* */ |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
277 } |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
278 else if (is_intobject(v)) { |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
279 return newlongobject(getintvalue(v)); |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
280 } |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
281 else if (is_longobject(v)) { |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
282 INCREF(v); |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
283 return v; |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
284 } |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
285 else if (is_floatobject(v)) { |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
286 double x = getfloatvalue(v); |
|
253
d4e532ee6f3d
Fix conversion of double to long; stylistic changes.
Guido van Rossum <guido@python.org>
parents:
223
diff
changeset
|
287 return dnewlongobject(x); |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
288 } |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
289 err_setstr(TypeError, "long() argument must be int, long or float"); |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
290 return NULL; |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
291 } |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
292 |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
293 static object * |
| 86 | 294 min_max(v, sign) |
| 295 object *v; | |
| 296 int sign; | |
| 297 { | |
| 298 int i, n, cmp; | |
| 299 object *w, *x; | |
| 300 sequence_methods *sq; | |
| 301 if (v == NULL) { | |
| 302 err_setstr(TypeError, "min() or max() without argument"); | |
| 303 return NULL; | |
| 304 } | |
| 305 sq = v->ob_type->tp_as_sequence; | |
| 306 if (sq == NULL) { | |
| 307 err_setstr(TypeError, "min() or max() of non-sequence"); | |
| 308 return NULL; | |
| 309 } | |
| 310 n = (*sq->sq_length)(v); | |
| 311 if (n == 0) { | |
| 312 err_setstr(RuntimeError, "min() or max() of empty sequence"); | |
| 313 return NULL; | |
| 314 } | |
| 315 w = (*sq->sq_item)(v, 0); /* Implies INCREF */ | |
| 316 for (i = 1; i < n; i++) { | |
| 317 x = (*sq->sq_item)(v, i); /* Implies INCREF */ | |
| 318 cmp = cmpobject(x, w); | |
| 319 if (cmp * sign > 0) { | |
| 320 DECREF(w); | |
| 321 w = x; | |
| 322 } | |
| 323 else | |
| 324 DECREF(x); | |
| 325 } | |
| 326 return w; | |
| 327 } | |
| 328 | |
| 329 static object * | |
| 330 builtin_min(self, v) | |
| 331 object *self; | |
| 332 object *v; | |
| 333 { | |
| 334 return min_max(v, -1); | |
| 335 } | |
| 336 | |
| 337 static object * | |
| 338 builtin_max(self, v) | |
| 339 object *self; | |
| 340 object *v; | |
| 341 { | |
| 342 return min_max(v, 1); | |
| 343 } | |
| 344 | |
| 345 static object * | |
| 346 builtin_open(self, v) | |
| 347 object *self; | |
| 348 object *v; | |
| 349 { | |
| 350 object *name, *mode; | |
| 351 if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 2 || | |
| 352 !is_stringobject(name = gettupleitem(v, 0)) || | |
| 353 !is_stringobject(mode = gettupleitem(v, 1))) { | |
| 354 err_setstr(TypeError, "open() requires 2 string arguments"); | |
| 355 return NULL; | |
| 356 } | |
| 357 v = newfileobject(getstringvalue(name), getstringvalue(mode)); | |
| 358 return v; | |
| 359 } | |
| 360 | |
| 361 static object * | |
| 362 builtin_ord(self, v) | |
| 363 object *self; | |
| 364 object *v; | |
| 365 { | |
| 366 if (v == NULL || !is_stringobject(v)) { | |
| 367 err_setstr(TypeError, "ord() must have string argument"); | |
| 368 return NULL; | |
| 369 } | |
| 370 if (getstringsize(v) != 1) { | |
| 371 err_setstr(RuntimeError, "ord() arg must have length 1"); | |
| 372 return NULL; | |
| 373 } | |
| 374 return newintobject((long)(getstringvalue(v)[0] & 0xff)); | |
| 375 } | |
| 376 | |
| 377 static object * | |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
378 builtin_pow(self, args) |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
379 object *self; |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
380 object *args; |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
381 { |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
382 object *v, *w, *x; |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
383 if (args == NULL || !is_tupleobject(args) || gettuplesize(args) != 2) { |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
384 err_setstr(TypeError, "pow() requires 2 arguments"); |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
385 return NULL; |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
386 } |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
387 v = gettupleitem(args, 0); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
388 w = gettupleitem(args, 1); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
389 if (v->ob_type->tp_as_number == NULL || |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
390 w->ob_type->tp_as_number == NULL) { |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
391 err_setstr(TypeError, "pow() requires numeric arguments"); |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
392 return NULL; |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
393 } |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
394 if (coerce(&v, &w) != 0) |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
395 return NULL; |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
396 x = (*v->ob_type->tp_as_number->nb_power)(v, w); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
397 DECREF(v); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
398 DECREF(w); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
399 return x; |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
400 } |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
401 |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
402 static object * |
| 86 | 403 builtin_range(self, v) |
| 404 object *self; | |
| 405 object *v; | |
| 406 { | |
| 407 static char *errmsg = "range() requires 1-3 int arguments"; | |
| 408 int i, n; | |
| 409 long ilow, ihigh, istep; | |
| 410 if (v != NULL && is_intobject(v)) { | |
| 411 ilow = 0; ihigh = getintvalue(v); istep = 1; | |
| 412 } | |
| 413 else if (v == NULL || !is_tupleobject(v)) { | |
| 414 err_setstr(TypeError, errmsg); | |
| 415 return NULL; | |
| 416 } | |
| 417 else { | |
| 418 n = gettuplesize(v); | |
| 419 if (n < 1 || n > 3) { | |
| 420 err_setstr(TypeError, errmsg); | |
| 421 return NULL; | |
| 422 } | |
| 423 for (i = 0; i < n; i++) { | |
| 424 if (!is_intobject(gettupleitem(v, i))) { | |
| 425 err_setstr(TypeError, errmsg); | |
| 426 return NULL; | |
| 427 } | |
| 428 } | |
| 429 if (n == 3) { | |
| 430 istep = getintvalue(gettupleitem(v, 2)); | |
| 431 --n; | |
| 432 } | |
| 433 else | |
| 434 istep = 1; | |
| 435 ihigh = getintvalue(gettupleitem(v, --n)); | |
| 436 if (n > 0) | |
| 437 ilow = getintvalue(gettupleitem(v, 0)); | |
| 438 else | |
| 439 ilow = 0; | |
| 440 } | |
| 441 if (istep == 0) { | |
| 442 err_setstr(RuntimeError, "zero step for range()"); | |
| 443 return NULL; | |
| 444 } | |
| 445 /* XXX ought to check overflow of subtraction */ | |
| 446 if (istep > 0) | |
| 447 n = (ihigh - ilow + istep - 1) / istep; | |
| 448 else | |
| 449 n = (ihigh - ilow + istep + 1) / istep; | |
| 450 if (n < 0) | |
| 451 n = 0; | |
| 452 v = newlistobject(n); | |
| 453 if (v == NULL) | |
| 454 return NULL; | |
| 455 for (i = 0; i < n; i++) { | |
| 456 object *w = newintobject(ilow); | |
| 457 if (w == NULL) { | |
| 458 DECREF(v); | |
| 459 return NULL; | |
| 460 } | |
| 461 setlistitem(v, i, w); | |
| 462 ilow += istep; | |
| 463 } | |
| 464 return v; | |
| 465 } | |
| 466 | |
| 467 static object * | |
| 468 builtin_raw_input(self, v) | |
| 469 object *self; | |
| 470 object *v; | |
| 471 { | |
| 472 FILE *out = sysgetfile("stdout", stdout); | |
| 473 flushline(); | |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
474 if (v != NULL) { |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
475 if (printobject(v, out, PRINT_RAW) != 0) |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
476 return NULL; |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
477 } |
|
182
59ffb6d4b34c
Use fileobject's filegetline() to implement unlimited raw_input().
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
478 return filegetline(sysget("stdin"), -1); |
| 86 | 479 } |
| 480 | |
| 481 static object * | |
| 482 builtin_reload(self, v) | |
| 483 object *self; | |
| 484 object *v; | |
| 485 { | |
| 486 return reload_module(v); | |
| 487 } | |
| 488 | |
| 489 static object * | |
| 490 builtin_type(self, v) | |
| 491 object *self; | |
| 492 object *v; | |
| 493 { | |
| 494 if (v == NULL) { | |
| 495 err_setstr(TypeError, "type() requres an argument"); | |
| 496 return NULL; | |
| 497 } | |
| 498 v = (object *)v->ob_type; | |
| 499 INCREF(v); | |
| 500 return v; | |
| 501 } | |
| 502 | |
| 503 static struct methodlist builtin_methods[] = { | |
| 504 {"abs", builtin_abs}, | |
| 505 {"chr", builtin_chr}, | |
| 506 {"dir", builtin_dir}, | |
| 507 {"divmod", builtin_divmod}, | |
| 508 {"eval", builtin_eval}, | |
| 509 {"exec", builtin_exec}, | |
| 510 {"float", builtin_float}, | |
| 511 {"input", builtin_input}, | |
| 512 {"int", builtin_int}, | |
| 513 {"len", builtin_len}, | |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
514 {"long", builtin_long}, |
|
139
c294a8caebb9
Reversed min and max (to alphabetical order).
Guido van Rossum <guido@python.org>
parents:
119
diff
changeset
|
515 {"max", builtin_max}, |
| 86 | 516 {"min", builtin_min}, |
| 517 {"open", builtin_open}, /* XXX move to OS module */ | |
| 518 {"ord", builtin_ord}, | |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
519 {"pow", builtin_pow}, |
| 86 | 520 {"range", builtin_range}, |
| 521 {"raw_input", builtin_raw_input}, | |
| 522 {"reload", builtin_reload}, | |
| 523 {"type", builtin_type}, | |
| 524 {NULL, NULL}, | |
| 525 }; | |
| 526 | |
| 527 static object *builtin_dict; | |
| 528 | |
| 529 object * | |
| 530 getbuiltin(name) | |
|
332
be3052a77b7f
Change getbuiltin interface to get the name as an object;
Guido van Rossum <guido@python.org>
parents:
301
diff
changeset
|
531 object *name; |
| 86 | 532 { |
|
332
be3052a77b7f
Change getbuiltin interface to get the name as an object;
Guido van Rossum <guido@python.org>
parents:
301
diff
changeset
|
533 return dict2lookup(builtin_dict, name); |
| 86 | 534 } |
| 535 | |
| 536 /* Predefined exceptions */ | |
| 537 | |
| 538 object *RuntimeError; | |
| 539 object *EOFError; | |
| 540 object *TypeError; | |
| 541 object *MemoryError; | |
| 542 object *NameError; | |
| 543 object *SystemError; | |
| 544 object *KeyboardInterrupt; | |
| 545 | |
| 546 static object * | |
| 547 newstdexception(name, message) | |
| 548 char *name, *message; | |
| 549 { | |
| 550 object *v = newstringobject(message); | |
| 551 if (v == NULL || dictinsert(builtin_dict, name, v) != 0) | |
| 552 fatal("no mem for new standard exception"); | |
| 553 return v; | |
| 554 } | |
| 555 | |
| 556 static void | |
| 557 initerrors() | |
| 558 { | |
| 559 RuntimeError = newstdexception("RuntimeError", "run-time error"); | |
| 560 EOFError = newstdexception("EOFError", "end-of-file read"); | |
| 561 TypeError = newstdexception("TypeError", "type error"); | |
| 562 MemoryError = newstdexception("MemoryError", "out of memory"); | |
| 563 NameError = newstdexception("NameError", "undefined name"); | |
| 564 SystemError = newstdexception("SystemError", "system error"); | |
| 565 KeyboardInterrupt = | |
| 566 newstdexception("KeyboardInterrupt", "keyboard interrupt"); | |
| 567 } | |
| 568 | |
| 569 void | |
| 570 initbuiltin() | |
| 571 { | |
| 572 object *m; | |
| 573 m = initmodule("builtin", builtin_methods); | |
| 574 builtin_dict = getmoduledict(m); | |
| 575 INCREF(builtin_dict); | |
| 576 initerrors(); | |
| 577 (void) dictinsert(builtin_dict, "None", None); | |
| 578 } | |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
579 |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
580 /* Coerce two numeric types to the "larger" one. |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
581 Increment the reference count on each argument. |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
582 Return -1 and raise an exception if no coercion is possible |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
583 (and then no reference count is incremented). |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
584 XXX This should be distributed over the various numeric types, |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
585 XXX but for now I don't see how to implement that. |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
586 XXX So, for now, if you add a new numeric type, |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
587 XXX you must add to this function as well. */ |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
588 |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
589 int |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
590 coerce(pv, pw) |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
591 object **pv, **pw; |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
592 { |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
593 register object *v = *pv; |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
594 register object *w = *pw; |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
595 if (v->ob_type == w->ob_type) { |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
596 INCREF(v); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
597 INCREF(w); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
598 return 0; |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
599 } |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
600 if (v->ob_type->tp_as_number == NULL || |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
601 w->ob_type->tp_as_number == NULL) { |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
602 err_setstr(TypeError, "mixing number and non-number"); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
603 return -1; |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
604 } |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
605 if (is_floatobject(v) || is_floatobject(w)) { |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
606 v = builtin_float((object *)0, v); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
607 w = builtin_float((object *)0, w); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
608 } |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
609 else if (is_longobject(v) || is_longobject(w)) { |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
610 v = builtin_long((object *)0, v); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
611 w = builtin_long((object *)0, w); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
612 } |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
613 else { |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
614 err_setstr(TypeError, "can't coerce numeric types?!?!?"); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
615 return -1; |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
616 } |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
617 if (v == NULL || w == NULL) { |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
618 XDECREF(v); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
619 XDECREF(w); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
620 return -1; |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
621 } |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
622 *pv = v; |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
623 *pw = w; |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
624 return 0; |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
625 } |
