Mercurial > cpython-lru_cache-weakref
annotate Python/bltinmodule.c @ 1049:2ed511171809 legacy-trunk
Made builtins int(), long(), float(), oct() and hex() more generic.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Sat, 12 Sep 1992 11:09:23 +0000 |
| parents | 7b37b5e71493 |
| children | 2c0432fcc270 |
| rev | line source |
|---|---|
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
diff
changeset
|
1 /*********************************************************** |
|
795
0cd197947d81
Copyright for 1992 added
Guido van Rossum <guido@python.org>
parents:
748
diff
changeset
|
2 Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The |
|
145
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 "ceval.h" | |
| 37 #include "modsupport.h" | |
| 38 | |
| 39 static object * | |
| 40 builtin_abs(self, v) | |
| 41 object *self; | |
| 42 object *v; | |
| 43 { | |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
44 number_methods *nm; |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
45 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
|
46 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
|
47 return NULL; |
| 86 | 48 } |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
49 return (*nm->nb_absolute)(v); |
| 86 | 50 } |
| 51 | |
| 52 static object * | |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
53 builtin_apply(self, args) |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
54 object *self; |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
55 object *args; |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
56 { |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
57 object *func, *arglist; |
|
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
58 if (!getargs(args, "(OO)", &func, &arglist)) |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
59 return NULL; |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
60 return call_object(func, arglist); |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
61 } |
|
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
62 |
|
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
63 static object * |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
64 builtin_chr(self, args) |
| 86 | 65 object *self; |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
66 object *args; |
| 86 | 67 { |
| 68 long x; | |
| 69 char s[1]; | |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
70 if (!getargs(args, "l", &x)) |
| 86 | 71 return NULL; |
| 72 if (x < 0 || x >= 256) { | |
| 463 | 73 err_setstr(ValueError, "chr() arg not in range(256)"); |
| 86 | 74 return NULL; |
| 75 } | |
| 76 s[0] = x; | |
| 77 return newsizedstringobject(s, 1); | |
| 78 } | |
| 79 | |
| 80 static object * | |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
81 builtin_coerce(self, args) |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
82 object *self; |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
83 object *args; |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
84 { |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
85 object *v, *w; |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
86 object *res; |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
87 |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
88 if (!getargs(args, "(OO)", &v, &w)) |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
89 return NULL; |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
90 if (coerce(&v, &w) < 0) |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
91 return NULL; |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
92 res = mkvalue("(OO)", v, w); |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
93 DECREF(v); |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
94 DECREF(w); |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
95 return res; |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
96 } |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
97 |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
98 static object * |
| 86 | 99 builtin_dir(self, v) |
| 100 object *self; | |
| 101 object *v; | |
| 102 { | |
| 103 object *d; | |
| 104 if (v == NULL) { | |
| 105 d = getlocals(); | |
|
385
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
106 INCREF(d); |
| 86 | 107 } |
| 108 else { | |
|
385
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
109 d = getattr(v, "__dict__"); |
|
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
110 if (d == NULL) { |
| 86 | 111 err_setstr(TypeError, |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
112 "dir() argument must have __dict__ attribute"); |
| 86 | 113 return NULL; |
| 114 } | |
|
385
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
115 } |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
116 if (is_dictobject(d)) { |
|
385
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
117 v = getdictkeys(d); |
|
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
118 if (sortlist(v) != 0) { |
|
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
119 DECREF(v); |
|
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
120 v = NULL; |
|
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
121 } |
| 86 | 122 } |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
123 else { |
|
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
124 v = newlistobject(0); |
|
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
125 } |
|
385
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
126 DECREF(d); |
| 86 | 127 return v; |
| 128 } | |
| 129 | |
| 130 static object * | |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
131 builtin_divmod(self, args) |
| 86 | 132 object *self; |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
133 object *args; |
| 86 | 134 { |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
135 object *v, *w, *x; |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
136 if (!getargs(args, "(OO)", &v, &w)) |
| 86 | 137 return NULL; |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
138 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
|
139 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
|
140 err_setstr(TypeError, "divmod() requires numeric arguments"); |
| 86 | 141 return NULL; |
| 142 } | |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
143 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
|
144 return NULL; |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
145 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
|
146 DECREF(v); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
147 DECREF(w); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
148 return x; |
| 86 | 149 } |
| 150 | |
| 151 static object * | |
| 152 exec_eval(v, start) | |
| 153 object *v; | |
| 154 int start; | |
| 155 { | |
| 156 object *str = NULL, *globals = NULL, *locals = NULL; | |
|
694
5c18d6c57827
Skip leading whitespace of eval() string argument.
Guido van Rossum <guido@python.org>
parents:
673
diff
changeset
|
157 char *s; |
| 86 | 158 int n; |
| 159 if (v != NULL) { | |
| 160 if (is_stringobject(v)) | |
| 161 str = v; | |
| 162 else if (is_tupleobject(v) && | |
| 163 ((n = gettuplesize(v)) == 2 || n == 3)) { | |
| 164 str = gettupleitem(v, 0); | |
| 165 globals = gettupleitem(v, 1); | |
| 166 if (n == 3) | |
| 167 locals = gettupleitem(v, 2); | |
| 168 } | |
| 169 } | |
| 170 if (str == NULL || !is_stringobject(str) || | |
| 171 globals != NULL && !is_dictobject(globals) || | |
| 172 locals != NULL && !is_dictobject(locals)) { | |
| 173 err_setstr(TypeError, | |
| 174 "exec/eval arguments must be string[,dict[,dict]]"); | |
| 175 return NULL; | |
| 176 } | |
|
694
5c18d6c57827
Skip leading whitespace of eval() string argument.
Guido van Rossum <guido@python.org>
parents:
673
diff
changeset
|
177 s = getstringvalue(str); |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
178 if (strlen(s) != getstringsize(str)) { |
|
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
179 err_setstr(ValueError, "embedded '\\0' in string arg"); |
|
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
180 return NULL; |
|
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
181 } |
|
694
5c18d6c57827
Skip leading whitespace of eval() string argument.
Guido van Rossum <guido@python.org>
parents:
673
diff
changeset
|
182 if (start == eval_input) { |
|
5c18d6c57827
Skip leading whitespace of eval() string argument.
Guido van Rossum <guido@python.org>
parents:
673
diff
changeset
|
183 while (*s == ' ' || *s == '\t') |
|
5c18d6c57827
Skip leading whitespace of eval() string argument.
Guido van Rossum <guido@python.org>
parents:
673
diff
changeset
|
184 s++; |
|
5c18d6c57827
Skip leading whitespace of eval() string argument.
Guido van Rossum <guido@python.org>
parents:
673
diff
changeset
|
185 } |
|
5c18d6c57827
Skip leading whitespace of eval() string argument.
Guido van Rossum <guido@python.org>
parents:
673
diff
changeset
|
186 return run_string(s, start, globals, locals); |
| 86 | 187 } |
| 188 | |
| 189 static object * | |
| 190 builtin_eval(self, v) | |
| 191 object *self; | |
| 192 object *v; | |
| 193 { | |
| 194 return exec_eval(v, eval_input); | |
| 195 } | |
| 196 | |
| 197 static object * | |
| 198 builtin_exec(self, v) | |
| 199 object *self; | |
| 200 object *v; | |
| 201 { | |
| 202 return exec_eval(v, file_input); | |
| 203 } | |
| 204 | |
| 205 static object * | |
| 673 | 206 builtin_execfile(self, v) |
| 207 object *self; | |
| 208 object *v; | |
| 209 { | |
| 210 object *str = NULL, *globals = NULL, *locals = NULL, *w; | |
| 211 FILE* fp; | |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
212 char *s; |
| 673 | 213 int n; |
| 214 if (v != NULL) { | |
| 215 if (is_stringobject(v)) | |
| 216 str = v; | |
| 217 else if (is_tupleobject(v) && | |
| 218 ((n = gettuplesize(v)) == 2 || n == 3)) { | |
| 219 str = gettupleitem(v, 0); | |
| 220 globals = gettupleitem(v, 1); | |
| 221 if (n == 3) | |
| 222 locals = gettupleitem(v, 2); | |
| 223 } | |
| 224 } | |
| 225 if (str == NULL || !is_stringobject(str) || | |
| 226 globals != NULL && !is_dictobject(globals) || | |
| 227 locals != NULL && !is_dictobject(locals)) { | |
| 228 err_setstr(TypeError, | |
| 229 "execfile arguments must be filename[,dict[,dict]]"); | |
| 230 return NULL; | |
| 231 } | |
|
972
7b37b5e71493
fix *serious* (new) bug in evalfile: forgot to initialize s!!!
Guido van Rossum <guido@python.org>
parents:
959
diff
changeset
|
232 s = getstringvalue(str); |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
233 if (strlen(s) != getstringsize(str)) { |
|
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
234 err_setstr(ValueError, "embedded '\\0' in string arg"); |
|
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
235 return NULL; |
|
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
236 } |
| 926 | 237 BGN_SAVE |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
238 fp = fopen(s, "r"); |
| 926 | 239 END_SAVE |
| 673 | 240 if (fp == NULL) { |
| 241 err_setstr(IOError, "execfile cannot open the file argument"); | |
| 242 return NULL; | |
| 243 } | |
| 244 w = run_file(fp, getstringvalue(str), file_input, globals, locals); | |
| 926 | 245 BGN_SAVE |
| 673 | 246 fclose(fp); |
| 926 | 247 END_SAVE |
| 673 | 248 return w; |
| 249 } | |
| 250 | |
| 251 static object * | |
| 86 | 252 builtin_float(self, v) |
| 253 object *self; | |
| 254 object *v; | |
| 255 { | |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
256 number_methods *nb; |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
257 |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
258 if (v == NULL || (nb = v->ob_type->tp_as_number) == NULL || |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
259 nb->nb_float == NULL) { |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
260 err_setstr(TypeError, |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
261 "float() argument can't be converted to float"); |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
262 return NULL; |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
263 } |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
264 return (*nb->nb_float)(v); |
| 86 | 265 } |
| 266 | |
| 267 static object * | |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
268 builtin_getattr(self, args) |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
269 object *self; |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
270 object *args; |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
271 { |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
272 object *v; |
|
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
273 char *name; |
|
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
274 if (!getargs(args, "(Os)", &v, &name)) |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
275 return NULL; |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
276 return getattr(v, name); |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
277 } |
|
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
278 |
|
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
279 static object * |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
280 builtin_setattr(self, args) |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
281 object *self; |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
282 object *args; |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
283 { |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
284 object *v; |
|
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
285 char *name; |
|
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
286 object *value; |
|
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
287 if (!getargs(args, "(OsO)", &v, &name, &value)) |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
288 return NULL; |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
289 if (setattr(v, name, value) != 0) |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
290 return NULL; |
|
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
291 INCREF(None); |
|
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
292 return None; |
|
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
293 } |
|
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
294 |
|
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
295 static object * |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
296 builtin_hex(self, v) |
|
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
297 object *self; |
|
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
298 object *v; |
|
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
299 { |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
300 number_methods *nb; |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
301 |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
302 if (v == NULL || (nb = v->ob_type->tp_as_number) == NULL || |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
303 nb->nb_hex == NULL) { |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
304 err_setstr(TypeError, |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
305 "hex() argument can't be converted to hex"); |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
306 return NULL; |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
307 } |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
308 return (*nb->nb_hex)(v); |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
309 } |
|
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
310 |
|
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
311 static object * |
| 86 | 312 builtin_input(self, v) |
| 313 object *self; | |
| 314 object *v; | |
| 315 { | |
| 316 FILE *in = sysgetfile("stdin", stdin); | |
| 317 FILE *out = sysgetfile("stdout", stdout); | |
|
702
f53dcb9a04d6
Strip leading whitespace from input().
Guido van Rossum <guido@python.org>
parents:
694
diff
changeset
|
318 int c; |
| 86 | 319 object *m, *d; |
| 320 flushline(); | |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
321 if (v != NULL) { |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
322 if (printobject(v, out, PRINT_RAW) != 0) |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
323 return NULL; |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
324 } |
| 86 | 325 m = add_module("__main__"); |
| 326 d = getmoduledict(m); | |
| 926 | 327 BGN_SAVE |
|
702
f53dcb9a04d6
Strip leading whitespace from input().
Guido van Rossum <guido@python.org>
parents:
694
diff
changeset
|
328 while ((c = getc(in)) != EOF && (c == ' ' || c == '\t')) |
|
f53dcb9a04d6
Strip leading whitespace from input().
Guido van Rossum <guido@python.org>
parents:
694
diff
changeset
|
329 ; |
|
f53dcb9a04d6
Strip leading whitespace from input().
Guido van Rossum <guido@python.org>
parents:
694
diff
changeset
|
330 ungetc(c, in); |
| 926 | 331 END_SAVE |
| 86 | 332 return run_file(in, "<stdin>", expr_input, d, d); |
| 333 } | |
| 334 | |
| 335 static object * | |
| 336 builtin_int(self, v) | |
| 337 object *self; | |
| 338 object *v; | |
| 339 { | |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
340 number_methods *nb; |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
341 |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
342 if (v == NULL || (nb = v->ob_type->tp_as_number) == NULL || |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
343 nb->nb_int == NULL) { |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
344 err_setstr(TypeError, |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
345 "int() argument can't be converted to int"); |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
346 return NULL; |
| 86 | 347 } |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
348 return (*nb->nb_int)(v); |
| 86 | 349 } |
| 350 | |
| 351 static object * | |
| 352 builtin_len(self, v) | |
| 353 object *self; | |
| 354 object *v; | |
| 355 { | |
| 356 long len; | |
| 357 typeobject *tp; | |
| 358 if (v == NULL) { | |
| 359 err_setstr(TypeError, "len() without argument"); | |
| 360 return NULL; | |
| 361 } | |
| 362 tp = v->ob_type; | |
| 363 if (tp->tp_as_sequence != NULL) { | |
| 364 len = (*tp->tp_as_sequence->sq_length)(v); | |
| 365 } | |
| 366 else if (tp->tp_as_mapping != NULL) { | |
| 367 len = (*tp->tp_as_mapping->mp_length)(v); | |
| 368 } | |
| 369 else { | |
| 370 err_setstr(TypeError, "len() of unsized object"); | |
| 371 return NULL; | |
| 372 } | |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
373 if (len < 0) |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
374 return NULL; |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
375 else |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
376 return newintobject(len); |
| 86 | 377 } |
| 378 | |
| 379 static object * | |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
380 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
|
381 object *self; |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
382 object *v; |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
383 { |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
384 number_methods *nb; |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
385 |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
386 if (v == NULL || (nb = v->ob_type->tp_as_number) == NULL || |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
387 nb->nb_long == NULL) { |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
388 err_setstr(TypeError, |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
389 "long() argument can't be converted to long"); |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
390 return NULL; |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
391 } |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
392 return (*nb->nb_long)(v); |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
393 } |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
394 |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
395 static object * |
| 86 | 396 min_max(v, sign) |
| 397 object *v; | |
| 398 int sign; | |
| 399 { | |
| 400 int i, n, cmp; | |
| 401 object *w, *x; | |
| 402 sequence_methods *sq; | |
| 403 if (v == NULL) { | |
| 404 err_setstr(TypeError, "min() or max() without argument"); | |
| 405 return NULL; | |
| 406 } | |
| 407 sq = v->ob_type->tp_as_sequence; | |
| 408 if (sq == NULL) { | |
| 409 err_setstr(TypeError, "min() or max() of non-sequence"); | |
| 410 return NULL; | |
| 411 } | |
| 412 n = (*sq->sq_length)(v); | |
| 413 if (n == 0) { | |
| 463 | 414 err_setstr(ValueError, "min() or max() of empty sequence"); |
| 86 | 415 return NULL; |
| 416 } | |
| 417 w = (*sq->sq_item)(v, 0); /* Implies INCREF */ | |
| 418 for (i = 1; i < n; i++) { | |
| 419 x = (*sq->sq_item)(v, i); /* Implies INCREF */ | |
| 420 cmp = cmpobject(x, w); | |
| 421 if (cmp * sign > 0) { | |
| 422 DECREF(w); | |
| 423 w = x; | |
| 424 } | |
| 425 else | |
| 426 DECREF(x); | |
| 427 } | |
| 428 return w; | |
| 429 } | |
| 430 | |
| 431 static object * | |
| 432 builtin_min(self, v) | |
| 433 object *self; | |
| 434 object *v; | |
| 435 { | |
| 436 return min_max(v, -1); | |
| 437 } | |
| 438 | |
| 439 static object * | |
| 440 builtin_max(self, v) | |
| 441 object *self; | |
| 442 object *v; | |
| 443 { | |
| 444 return min_max(v, 1); | |
| 445 } | |
| 446 | |
| 447 static object * | |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
448 builtin_oct(self, v) |
|
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
449 object *self; |
|
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
450 object *v; |
|
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
451 { |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
452 number_methods *nb; |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
453 |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
454 if (v == NULL || (nb = v->ob_type->tp_as_number) == NULL || |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
455 nb->nb_oct == NULL) { |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
456 err_setstr(TypeError, |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
457 "oct() argument can't be converted to oct"); |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
458 return NULL; |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
459 } |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
460 return (*nb->nb_oct)(v); |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
461 } |
|
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
462 |
|
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
463 static object * |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
464 builtin_open(self, args) |
| 86 | 465 object *self; |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
466 object *args; |
| 86 | 467 { |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
468 char *name, *mode; |
|
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
469 if (!getargs(args, "(ss)", &name, &mode)) |
| 86 | 470 return NULL; |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
471 return newfileobject(name, mode); |
| 86 | 472 } |
| 473 | |
| 474 static object * | |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
475 builtin_ord(self, args) |
| 86 | 476 object *self; |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
477 object *args; |
| 86 | 478 { |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
479 char *s; |
|
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
480 int len; |
|
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
481 if (!getargs(args, "s#", &s, &len)) |
| 86 | 482 return NULL; |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
483 if (len != 1) { |
| 463 | 484 err_setstr(ValueError, "ord() arg must have length 1"); |
| 86 | 485 return NULL; |
| 486 } | |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
487 return newintobject((long)(s[0] & 0xff)); |
| 86 | 488 } |
| 489 | |
| 490 static object * | |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
491 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
|
492 object *self; |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
493 object *args; |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
494 { |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
495 object *v, *w, *x; |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
496 if (!getargs(args, "(OO)", &v, &w)) |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
497 return NULL; |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
498 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
|
499 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
|
500 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
|
501 return NULL; |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
502 } |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
503 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
|
504 return NULL; |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
505 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
|
506 DECREF(v); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
507 DECREF(w); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
508 return x; |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
509 } |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
510 |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
511 static object * |
| 86 | 512 builtin_range(self, v) |
| 513 object *self; | |
| 514 object *v; | |
| 515 { | |
| 516 static char *errmsg = "range() requires 1-3 int arguments"; | |
| 517 int i, n; | |
| 518 long ilow, ihigh, istep; | |
| 519 if (v != NULL && is_intobject(v)) { | |
| 520 ilow = 0; ihigh = getintvalue(v); istep = 1; | |
| 521 } | |
| 522 else if (v == NULL || !is_tupleobject(v)) { | |
| 523 err_setstr(TypeError, errmsg); | |
| 524 return NULL; | |
| 525 } | |
| 526 else { | |
| 527 n = gettuplesize(v); | |
| 528 if (n < 1 || n > 3) { | |
| 529 err_setstr(TypeError, errmsg); | |
| 530 return NULL; | |
| 531 } | |
| 532 for (i = 0; i < n; i++) { | |
| 533 if (!is_intobject(gettupleitem(v, i))) { | |
| 534 err_setstr(TypeError, errmsg); | |
| 535 return NULL; | |
| 536 } | |
| 537 } | |
| 538 if (n == 3) { | |
| 539 istep = getintvalue(gettupleitem(v, 2)); | |
| 540 --n; | |
| 541 } | |
| 542 else | |
| 543 istep = 1; | |
| 544 ihigh = getintvalue(gettupleitem(v, --n)); | |
| 545 if (n > 0) | |
| 546 ilow = getintvalue(gettupleitem(v, 0)); | |
| 547 else | |
| 548 ilow = 0; | |
| 549 } | |
| 550 if (istep == 0) { | |
| 463 | 551 err_setstr(ValueError, "zero step for range()"); |
| 86 | 552 return NULL; |
| 553 } | |
| 554 /* XXX ought to check overflow of subtraction */ | |
| 555 if (istep > 0) | |
| 556 n = (ihigh - ilow + istep - 1) / istep; | |
| 557 else | |
| 558 n = (ihigh - ilow + istep + 1) / istep; | |
| 559 if (n < 0) | |
| 560 n = 0; | |
| 561 v = newlistobject(n); | |
| 562 if (v == NULL) | |
| 563 return NULL; | |
| 564 for (i = 0; i < n; i++) { | |
| 565 object *w = newintobject(ilow); | |
| 566 if (w == NULL) { | |
| 567 DECREF(v); | |
| 568 return NULL; | |
| 569 } | |
| 570 setlistitem(v, i, w); | |
| 571 ilow += istep; | |
| 572 } | |
| 573 return v; | |
| 574 } | |
| 575 | |
| 576 static object * | |
| 577 builtin_raw_input(self, v) | |
| 578 object *self; | |
| 579 object *v; | |
| 580 { | |
| 581 FILE *out = sysgetfile("stdout", stdout); | |
| 582 flushline(); | |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
583 if (v != NULL) { |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
584 if (printobject(v, out, PRINT_RAW) != 0) |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
585 return NULL; |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
586 } |
|
182
59ffb6d4b34c
Use fileobject's filegetline() to implement unlimited raw_input().
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
587 return filegetline(sysget("stdin"), -1); |
| 86 | 588 } |
| 589 | |
| 590 static object * | |
| 591 builtin_reload(self, v) | |
| 592 object *self; | |
| 593 object *v; | |
| 594 { | |
| 595 return reload_module(v); | |
| 596 } | |
| 597 | |
| 598 static object * | |
| 599 builtin_type(self, v) | |
| 600 object *self; | |
| 601 object *v; | |
| 602 { | |
| 603 if (v == NULL) { | |
| 604 err_setstr(TypeError, "type() requres an argument"); | |
| 605 return NULL; | |
| 606 } | |
| 607 v = (object *)v->ob_type; | |
| 608 INCREF(v); | |
| 609 return v; | |
| 610 } | |
| 611 | |
| 612 static struct methodlist builtin_methods[] = { | |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
613 {"abs", builtin_abs}, |
|
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
614 {"apply", builtin_apply}, |
|
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
615 {"chr", builtin_chr}, |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
616 {"coerce", builtin_coerce}, |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
617 {"dir", builtin_dir}, |
|
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
618 {"divmod", builtin_divmod}, |
|
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
619 {"eval", builtin_eval}, |
|
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
620 {"exec", builtin_exec}, |
| 673 | 621 {"execfile", builtin_execfile}, |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
622 {"float", builtin_float}, |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
623 {"getattr", builtin_getattr}, |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
624 {"hex", builtin_hex}, |
|
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
625 {"input", builtin_input}, |
|
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
626 {"int", builtin_int}, |
|
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
627 {"len", builtin_len}, |
|
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
628 {"long", builtin_long}, |
|
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
629 {"max", builtin_max}, |
|
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
630 {"min", builtin_min}, |
|
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
631 {"oct", builtin_oct}, |
|
662
aaff650d7e13
Get rid of comment about open().
Guido van Rossum <guido@python.org>
parents:
644
diff
changeset
|
632 {"open", builtin_open}, |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
633 {"ord", builtin_ord}, |
|
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
634 {"pow", builtin_pow}, |
|
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
635 {"range", builtin_range}, |
|
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
636 {"raw_input", builtin_raw_input}, |
|
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
637 {"reload", builtin_reload}, |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
638 {"setattr", builtin_setattr}, |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
639 {"type", builtin_type}, |
|
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
640 {NULL, NULL}, |
| 86 | 641 }; |
| 642 | |
| 643 static object *builtin_dict; | |
| 644 | |
| 645 object * | |
| 646 getbuiltin(name) | |
|
332
be3052a77b7f
Change getbuiltin interface to get the name as an object;
Guido van Rossum <guido@python.org>
parents:
301
diff
changeset
|
647 object *name; |
| 86 | 648 { |
|
332
be3052a77b7f
Change getbuiltin interface to get the name as an object;
Guido van Rossum <guido@python.org>
parents:
301
diff
changeset
|
649 return dict2lookup(builtin_dict, name); |
| 86 | 650 } |
| 651 | |
| 652 /* Predefined exceptions */ | |
| 653 | |
| 495 | 654 object *AttributeError; |
| 86 | 655 object *EOFError; |
| 495 | 656 object *IOError; |
|
505
095d9cf4e3e6
Sorted exceptions; added ImportError.
Guido van Rossum <guido@python.org>
parents:
495
diff
changeset
|
657 object *ImportError; |
| 495 | 658 object *IndexError; |
| 659 object *KeyError; | |
| 660 object *KeyboardInterrupt; | |
| 86 | 661 object *MemoryError; |
| 662 object *NameError; | |
| 495 | 663 object *OverflowError; |
| 664 object *RuntimeError; | |
| 665 object *SyntaxError; | |
| 86 | 666 object *SystemError; |
| 545 | 667 object *SystemExit; |
| 495 | 668 object *TypeError; |
| 669 object *ValueError; | |
| 463 | 670 object *ZeroDivisionError; |
| 671 | |
| 86 | 672 static object * |
| 495 | 673 newstdexception(name) |
| 674 char *name; | |
| 86 | 675 { |
| 495 | 676 object *v = newstringobject(name); |
| 86 | 677 if (v == NULL || dictinsert(builtin_dict, name, v) != 0) |
| 678 fatal("no mem for new standard exception"); | |
| 679 return v; | |
| 680 } | |
| 681 | |
| 682 static void | |
| 683 initerrors() | |
| 684 { | |
|
505
095d9cf4e3e6
Sorted exceptions; added ImportError.
Guido van Rossum <guido@python.org>
parents:
495
diff
changeset
|
685 AttributeError = newstdexception("AttributeError"); |
| 495 | 686 EOFError = newstdexception("EOFError"); |
|
505
095d9cf4e3e6
Sorted exceptions; added ImportError.
Guido van Rossum <guido@python.org>
parents:
495
diff
changeset
|
687 IOError = newstdexception("IOError"); |
|
095d9cf4e3e6
Sorted exceptions; added ImportError.
Guido van Rossum <guido@python.org>
parents:
495
diff
changeset
|
688 ImportError = newstdexception("ImportError"); |
|
095d9cf4e3e6
Sorted exceptions; added ImportError.
Guido van Rossum <guido@python.org>
parents:
495
diff
changeset
|
689 IndexError = newstdexception("IndexError"); |
|
095d9cf4e3e6
Sorted exceptions; added ImportError.
Guido van Rossum <guido@python.org>
parents:
495
diff
changeset
|
690 KeyError = newstdexception("KeyError"); |
|
095d9cf4e3e6
Sorted exceptions; added ImportError.
Guido van Rossum <guido@python.org>
parents:
495
diff
changeset
|
691 KeyboardInterrupt = newstdexception("KeyboardInterrupt"); |
| 495 | 692 MemoryError = newstdexception("MemoryError"); |
| 693 NameError = newstdexception("NameError"); | |
|
505
095d9cf4e3e6
Sorted exceptions; added ImportError.
Guido van Rossum <guido@python.org>
parents:
495
diff
changeset
|
694 OverflowError = newstdexception("OverflowError"); |
|
095d9cf4e3e6
Sorted exceptions; added ImportError.
Guido van Rossum <guido@python.org>
parents:
495
diff
changeset
|
695 RuntimeError = newstdexception("RuntimeError"); |
|
095d9cf4e3e6
Sorted exceptions; added ImportError.
Guido van Rossum <guido@python.org>
parents:
495
diff
changeset
|
696 SyntaxError = newstdexception("SyntaxError"); |
| 495 | 697 SystemError = newstdexception("SystemError"); |
| 545 | 698 SystemExit = newstdexception("SystemExit"); |
|
505
095d9cf4e3e6
Sorted exceptions; added ImportError.
Guido van Rossum <guido@python.org>
parents:
495
diff
changeset
|
699 TypeError = newstdexception("TypeError"); |
|
095d9cf4e3e6
Sorted exceptions; added ImportError.
Guido van Rossum <guido@python.org>
parents:
495
diff
changeset
|
700 ValueError = newstdexception("ValueError"); |
| 495 | 701 ZeroDivisionError = newstdexception("ZeroDivisionError"); |
| 86 | 702 } |
| 703 | |
| 704 void | |
| 705 initbuiltin() | |
| 706 { | |
| 707 object *m; | |
| 708 m = initmodule("builtin", builtin_methods); | |
| 709 builtin_dict = getmoduledict(m); | |
| 710 INCREF(builtin_dict); | |
| 711 initerrors(); | |
| 712 (void) dictinsert(builtin_dict, "None", None); | |
| 713 } | |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
714 |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
715 /* 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
|
716 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
|
717 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
|
718 (and then no reference count is incremented). |
|
955
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
944
diff
changeset
|
719 */ |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
720 |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
721 int |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
722 coerce(pv, pw) |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
723 object **pv, **pw; |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
724 { |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
725 register object *v = *pv; |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
726 register object *w = *pw; |
|
955
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
944
diff
changeset
|
727 int res; |
|
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
944
diff
changeset
|
728 |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
729 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
|
730 INCREF(v); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
731 INCREF(w); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
732 return 0; |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
733 } |
|
955
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
944
diff
changeset
|
734 if (v->ob_type->tp_as_number && v->ob_type->tp_as_number->nb_coerce) { |
|
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
944
diff
changeset
|
735 res = (*v->ob_type->tp_as_number->nb_coerce)(pv, pw); |
|
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
944
diff
changeset
|
736 if (res <= 0) |
|
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
944
diff
changeset
|
737 return res; |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
738 } |
|
955
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
944
diff
changeset
|
739 if (w->ob_type->tp_as_number && w->ob_type->tp_as_number->nb_coerce) { |
|
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
944
diff
changeset
|
740 res = (*w->ob_type->tp_as_number->nb_coerce)(pw, pv); |
|
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
944
diff
changeset
|
741 if (res <= 0) |
|
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
944
diff
changeset
|
742 return res; |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
743 } |
|
955
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
944
diff
changeset
|
744 err_setstr(TypeError, "number coercion failed"); |
|
03de67080c95
* classobject.[ch], {float,long,int}object.c, bltinmodule.c:
Guido van Rossum <guido@python.org>
parents:
944
diff
changeset
|
745 return -1; |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
746 } |
