Mercurial > cpython-lru_cache-weakref
annotate Python/bltinmodule.c @ 3365:f8ff28329971 legacy-trunk
properly initialize optional arguments to apply()
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 26 Jan 1996 20:44:30 +0000 |
| parents | 6098aaa8ae7f |
| children | 03c6c18325ea |
| rev | line source |
|---|---|
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
diff
changeset
|
1 /*********************************************************** |
|
2062
d0d0a69b5ca3
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2052
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
d0d0a69b5ca3
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2052
diff
changeset
|
3 The Netherlands. |
|
145
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 "sysmodule.h" | |
| 119 | 32 #include "bltinmodule.h" |
| 86 | 33 #include "import.h" |
| 34 #include "pythonrun.h" | |
| 35 #include "ceval.h" | |
| 36 #include "modsupport.h" | |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
37 #include "compile.h" |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
38 #include "eval.h" |
| 86 | 39 |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
40 /* Forward */ |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
41 static object *filterstring PROTO((object *, object *)); |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
42 static object *filtertuple PROTO((object *, object *)); |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
43 |
| 86 | 44 static object * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
45 builtin___import__(self, args) |
| 86 | 46 object *self; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
47 object *args; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
48 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
49 char *name; |
|
2338
4c2f1452125d
call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents:
2306
diff
changeset
|
50 object *globals = NULL; |
|
4c2f1452125d
call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents:
2306
diff
changeset
|
51 object *locals = NULL; |
|
4c2f1452125d
call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents:
2306
diff
changeset
|
52 object *fromlist = NULL; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
53 |
|
2338
4c2f1452125d
call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents:
2306
diff
changeset
|
54 if (!newgetargs(args, "s|OOO:__import__", |
|
4c2f1452125d
call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents:
2306
diff
changeset
|
55 &name, &globals, &locals, &fromlist)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
56 return NULL; |
|
2198
27557e70a8f0
fix import related leaks
Guido van Rossum <guido@python.org>
parents:
2153
diff
changeset
|
57 return import_module(name); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
58 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
59 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
60 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
61 static object * |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
62 builtin_abs(self, args) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
63 object *self; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
64 object *args; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
65 { |
| 86 | 66 object *v; |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
67 number_methods *nm; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
68 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
69 if (!newgetargs(args, "O:abs", &v)) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
70 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
71 if ((nm = v->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
|
72 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
|
73 return NULL; |
| 86 | 74 } |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
75 return (*nm->nb_absolute)(v); |
| 86 | 76 } |
| 77 | |
| 78 static object * | |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
79 builtin_apply(self, args) |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
80 object *self; |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
81 object *args; |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
82 { |
|
3365
f8ff28329971
properly initialize optional arguments to apply()
Guido van Rossum <guido@python.org>
parents:
3323
diff
changeset
|
83 object *func, *alist = NULL, *kwdict = NULL; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
84 |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2824
diff
changeset
|
85 if (!newgetargs(args, "O|OO:apply", &func, &alist, &kwdict)) |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
86 return NULL; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2824
diff
changeset
|
87 if (alist != NULL && !is_tupleobject(alist)) { |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
88 err_setstr(TypeError, "apply() 2nd argument must be tuple"); |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
89 return NULL; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
90 } |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2824
diff
changeset
|
91 if (kwdict != NULL && !is_dictobject(kwdict)) { |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2824
diff
changeset
|
92 err_setstr(TypeError, |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2824
diff
changeset
|
93 "apply() 3rd argument must be dictionary"); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2824
diff
changeset
|
94 return NULL; |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2824
diff
changeset
|
95 } |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2824
diff
changeset
|
96 return PyEval_CallObjectWithKeywords(func, alist, kwdict); |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
97 } |
|
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
98 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
99 static object * |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
100 builtin_callable(self, args) |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
101 object *self; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
102 object *args; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
103 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
104 object *v; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
105 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
106 if (!newgetargs(args, "O:callable", &v)) |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
107 return NULL; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
108 return newintobject((long)callable(v)); |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
109 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
110 |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
111 static object * |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1387
diff
changeset
|
112 builtin_filter(self, args) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
113 object *self; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
114 object *args; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
115 { |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
116 object *func, *seq, *result; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
117 sequence_methods *sqf; |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
118 int len; |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
119 register int i, j; |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
120 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
121 if (!newgetargs(args, "OO:filter", &func, &seq)) |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
122 return NULL; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
123 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
124 if (is_stringobject(seq)) { |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
125 object *r = filterstring(func, seq); |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
126 return r; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
127 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
128 |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
129 if (is_tupleobject(seq)) { |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
130 object *r = filtertuple(func, seq); |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
131 return r; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
132 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
133 |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
134 if ((sqf = seq->ob_type->tp_as_sequence) == NULL) { |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
135 err_setstr(TypeError, |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1387
diff
changeset
|
136 "argument 2 to filter() must be a sequence type"); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
137 goto Fail_2; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
138 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
139 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
140 if ((len = (*sqf->sq_length)(seq)) < 0) |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
141 goto Fail_2; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
142 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
143 if (is_listobject(seq) && seq->ob_refcnt == 1) { |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
144 INCREF(seq); |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
145 result = seq; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
146 } |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
147 else { |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
148 if ((result = newlistobject(len)) == NULL) |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
149 goto Fail_2; |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
150 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
151 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
152 for (i = j = 0; ; ++i) { |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
153 object *item, *good; |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
154 int ok; |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
155 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
156 if ((item = (*sqf->sq_item)(seq, i)) == NULL) { |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
157 if (i < len) |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
158 goto Fail_1; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
159 if (err_occurred() == IndexError) { |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
160 err_clear(); |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
161 break; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
162 } |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
163 goto Fail_1; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
164 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
165 |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
166 if (func == None) { |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
167 good = item; |
|
2120
84b61fe44573
fix subtle refcount big in filter() -- Tim MacKenzie
Guido van Rossum <guido@python.org>
parents:
2113
diff
changeset
|
168 INCREF(good); |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
169 } |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
170 else { |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
171 object *arg = mkvalue("(O)", item); |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
172 if (arg == NULL) |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
173 goto Fail_1; |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
174 good = call_object(func, arg); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
175 DECREF(arg); |
|
2120
84b61fe44573
fix subtle refcount big in filter() -- Tim MacKenzie
Guido van Rossum <guido@python.org>
parents:
2113
diff
changeset
|
176 if (good == NULL) { |
|
84b61fe44573
fix subtle refcount big in filter() -- Tim MacKenzie
Guido van Rossum <guido@python.org>
parents:
2113
diff
changeset
|
177 DECREF(item); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
178 goto Fail_1; |
|
2120
84b61fe44573
fix subtle refcount big in filter() -- Tim MacKenzie
Guido van Rossum <guido@python.org>
parents:
2113
diff
changeset
|
179 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
180 } |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
181 ok = testbool(good); |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
182 DECREF(good); |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
183 if (ok) { |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
184 if (j < len) { |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
185 if (setlistitem(result, j++, item) < 0) |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
186 goto Fail_1; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
187 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
188 else { |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
189 j++; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
190 if (addlistitem(result, item) < 0) |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
191 goto Fail_1; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
192 } |
|
2120
84b61fe44573
fix subtle refcount big in filter() -- Tim MacKenzie
Guido van Rossum <guido@python.org>
parents:
2113
diff
changeset
|
193 } else { |
|
84b61fe44573
fix subtle refcount big in filter() -- Tim MacKenzie
Guido van Rossum <guido@python.org>
parents:
2113
diff
changeset
|
194 DECREF(item); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
195 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
196 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
197 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
198 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
199 if (j < len && setlistslice(result, j, len, NULL) < 0) |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
200 goto Fail_1; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
201 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
202 return result; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
203 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
204 Fail_1: |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
205 DECREF(result); |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
206 Fail_2: |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
207 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
208 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
209 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
210 static object * |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
211 builtin_chr(self, args) |
| 86 | 212 object *self; |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
213 object *args; |
| 86 | 214 { |
| 215 long x; | |
| 216 char s[1]; | |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
217 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
218 if (!newgetargs(args, "l:chr", &x)) |
| 86 | 219 return NULL; |
| 220 if (x < 0 || x >= 256) { | |
| 463 | 221 err_setstr(ValueError, "chr() arg not in range(256)"); |
| 86 | 222 return NULL; |
| 223 } | |
| 224 s[0] = x; | |
| 225 return newsizedstringobject(s, 1); | |
| 226 } | |
| 227 | |
| 228 static object * | |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
229 builtin_cmp(self, args) |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
230 object *self; |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
231 object *args; |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
232 { |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
233 object *a, *b; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
234 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
235 if (!newgetargs(args, "OO:cmp", &a, &b)) |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
236 return NULL; |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
237 return newintobject((long)cmpobject(a, b)); |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
238 } |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
239 |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
240 static object * |
|
2113
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2106
diff
changeset
|
241 builtin_coerce(self, args) |
|
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2106
diff
changeset
|
242 object *self; |
|
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2106
diff
changeset
|
243 object *args; |
|
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2106
diff
changeset
|
244 { |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
245 object *v, *w; |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
246 object *res; |
|
2113
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2106
diff
changeset
|
247 |
|
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2106
diff
changeset
|
248 if (!newgetargs(args, "OO:coerce", &v, &w)) |
|
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2106
diff
changeset
|
249 return NULL; |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
250 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
|
251 return NULL; |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
252 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
|
253 DECREF(v); |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
254 DECREF(w); |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
255 return res; |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
256 } |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
257 |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
258 static object * |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
259 builtin_compile(self, args) |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
260 object *self; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
261 object *args; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
262 { |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
263 char *str; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
264 char *filename; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
265 char *startstr; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
266 int start; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
267 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
268 if (!newgetargs(args, "sss:compile", &str, &filename, &startstr)) |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
269 return NULL; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
270 if (strcmp(startstr, "exec") == 0) |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
271 start = file_input; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
272 else if (strcmp(startstr, "eval") == 0) |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
273 start = eval_input; |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
274 else if (strcmp(startstr, "single") == 0) |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
275 start = single_input; |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
276 else { |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
277 err_setstr(ValueError, |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
278 "compile() mode must be 'exec' or 'eval' or 'single'"); |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
279 return NULL; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
280 } |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
281 return compile_string(str, filename, start); |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
282 } |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
283 |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
284 #ifndef WITHOUT_COMPLEX |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
285 |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
286 static object * |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
287 builtin_complex(self, args) |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
288 object *self; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
289 object *args; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
290 { |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
291 object *r, *i; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
292 number_methods *nbr, *nbi; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
293 complex cr, ci; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
294 |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
295 i = NULL; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
296 if (!newgetargs(args, "O|O:complex", &r, &i)) |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
297 return NULL; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
298 if ((nbr = r->ob_type->tp_as_number) == NULL || |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
299 nbr->nb_float == NULL || (i != NULL && |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
300 ((nbi = i->ob_type->tp_as_number) == NULL || |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
301 nbi->nb_float == NULL))) { |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
302 err_setstr(TypeError, |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
303 "complex() argument can't be converted to complex"); |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
304 return NULL; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
305 } |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
306 if (is_complexobject(r)) |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
307 cr = ((complexobject*)r)->cval; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
308 else { |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
309 cr.real = getfloatvalue((*nbr->nb_float)(r)); |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
310 cr.imag = 0.; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
311 } |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
312 if (i == NULL) { |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
313 ci.real = 0.; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
314 ci.imag = 0.; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
315 } |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
316 else if (is_complexobject(i)) |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
317 ci = ((complexobject*)i)->cval; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
318 else { |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
319 ci.real = getfloatvalue((*nbi->nb_float)(i)); |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
320 ci.imag = 0.; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
321 } |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
322 cr.real -= ci.imag; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
323 cr.imag += ci.real; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
324 return newcomplexobject(cr); |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
325 } |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
326 |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
327 #endif |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
328 |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
329 static object * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
330 builtin_dir(self, args) |
| 86 | 331 object *self; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
332 object *args; |
| 86 | 333 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
334 object *v = NULL; |
| 86 | 335 object *d; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
336 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
337 if (!newgetargs(args, "|O:dir", &v)) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
338 return NULL; |
| 86 | 339 if (v == NULL) { |
| 340 d = getlocals(); | |
|
385
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
341 INCREF(d); |
| 86 | 342 } |
| 343 else { | |
|
385
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
344 d = getattr(v, "__dict__"); |
|
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
345 if (d == NULL) { |
| 86 | 346 err_setstr(TypeError, |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
347 "dir() argument must have __dict__ attribute"); |
| 86 | 348 return NULL; |
| 349 } | |
|
385
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
350 } |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
351 if (is_dictobject(d)) { |
|
385
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
352 v = getdictkeys(d); |
|
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
353 if (sortlist(v) != 0) { |
|
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
354 DECREF(v); |
|
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
355 v = NULL; |
|
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
356 } |
| 86 | 357 } |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
358 else { |
|
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
359 v = newlistobject(0); |
|
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
360 } |
|
385
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
361 DECREF(d); |
| 86 | 362 return v; |
| 363 } | |
| 364 | |
| 365 static object * | |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
366 do_divmod(v, w) |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
367 object *v, *w; |
| 86 | 368 { |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
369 object *res; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
370 |
|
1914
893412101296
* Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
Guido van Rossum <guido@python.org>
parents:
1856
diff
changeset
|
371 if (is_instanceobject(v) || is_instanceobject(w)) |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
372 return instancebinop(v, w, "__divmod__", "__rdivmod__", |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
373 do_divmod); |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
374 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
|
375 w->ob_type->tp_as_number == NULL) { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
376 err_setstr(TypeError, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
377 "divmod() requires numeric or class instance arguments"); |
| 86 | 378 return NULL; |
| 379 } | |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
380 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
|
381 return NULL; |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
382 res = (*v->ob_type->tp_as_number->nb_divmod)(v, w); |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
383 DECREF(v); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
384 DECREF(w); |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
385 return res; |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
386 } |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
387 |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
388 static object * |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
389 builtin_divmod(self, args) |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
390 object *self; |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
391 object *args; |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
392 { |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
393 object *v, *w; |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
394 |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
395 if (!newgetargs(args, "OO:divmod", &v, &w)) |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
396 return NULL; |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
397 return do_divmod(v, w); |
| 86 | 398 } |
| 399 | |
| 400 static object * | |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
401 builtin_eval(self, args) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
402 object *self; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
403 object *args; |
| 86 | 404 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
405 object *cmd; |
|
2106
2ebb21284f34
fix globals/locals defaults for eval/execfile
Guido van Rossum <guido@python.org>
parents:
2098
diff
changeset
|
406 object *globals = None, *locals = None; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
407 char *str; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
408 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
409 if (!newgetargs(args, "O|O!O!:eval", |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
410 &cmd, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
411 &Mappingtype, &globals, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
412 &Mappingtype, &locals)) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
413 return NULL; |
|
2106
2ebb21284f34
fix globals/locals defaults for eval/execfile
Guido van Rossum <guido@python.org>
parents:
2098
diff
changeset
|
414 if (globals == None) { |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
415 globals = getglobals(); |
|
2106
2ebb21284f34
fix globals/locals defaults for eval/execfile
Guido van Rossum <guido@python.org>
parents:
2098
diff
changeset
|
416 if (locals == None) |
|
2ebb21284f34
fix globals/locals defaults for eval/execfile
Guido van Rossum <guido@python.org>
parents:
2098
diff
changeset
|
417 locals = getlocals(); |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
418 } |
|
2106
2ebb21284f34
fix globals/locals defaults for eval/execfile
Guido van Rossum <guido@python.org>
parents:
2098
diff
changeset
|
419 else if (locals == None) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
420 locals = globals; |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
421 if (dictlookup(globals, "__builtins__") == NULL) { |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
422 if (dictinsert(globals, "__builtins__", getbuiltins()) != 0) |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
423 return NULL; |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
424 } |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
425 if (is_codeobject(cmd)) |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2824
diff
changeset
|
426 return eval_code((codeobject *) cmd, globals, locals); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
427 if (!is_stringobject(cmd)) { |
| 86 | 428 err_setstr(TypeError, |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
429 "eval() argument 1 must be string or code object"); |
| 86 | 430 return NULL; |
| 431 } | |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
432 str = getstringvalue(cmd); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
433 if (strlen(str) != getstringsize(cmd)) { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
434 err_setstr(ValueError, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
435 "embedded '\\0' in string arg"); |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
436 return NULL; |
|
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
437 } |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
438 while (*str == ' ' || *str == '\t') |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
439 str++; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
440 return run_string(str, eval_input, globals, locals); |
| 86 | 441 } |
| 442 | |
| 443 static object * | |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
444 builtin_execfile(self, args) |
| 673 | 445 object *self; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
446 object *args; |
| 673 | 447 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
448 char *filename; |
|
2106
2ebb21284f34
fix globals/locals defaults for eval/execfile
Guido van Rossum <guido@python.org>
parents:
2098
diff
changeset
|
449 object *globals = None, *locals = None; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
450 object *res; |
| 673 | 451 FILE* fp; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
452 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
453 if (!newgetargs(args, "s|O!O!:execfile", |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
454 &filename, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
455 &Mappingtype, &globals, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
456 &Mappingtype, &locals)) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
457 return NULL; |
|
2106
2ebb21284f34
fix globals/locals defaults for eval/execfile
Guido van Rossum <guido@python.org>
parents:
2098
diff
changeset
|
458 if (globals == None) { |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
459 globals = getglobals(); |
|
2106
2ebb21284f34
fix globals/locals defaults for eval/execfile
Guido van Rossum <guido@python.org>
parents:
2098
diff
changeset
|
460 if (locals == None) |
|
2ebb21284f34
fix globals/locals defaults for eval/execfile
Guido van Rossum <guido@python.org>
parents:
2098
diff
changeset
|
461 locals = getlocals(); |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
462 } |
|
2106
2ebb21284f34
fix globals/locals defaults for eval/execfile
Guido van Rossum <guido@python.org>
parents:
2098
diff
changeset
|
463 else if (locals == None) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
464 locals = globals; |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
465 if (dictlookup(globals, "__builtins__") == NULL) { |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
466 if (dictinsert(globals, "__builtins__", getbuiltins()) != 0) |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
467 return NULL; |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
468 } |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
469 BGN_SAVE |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
470 fp = fopen(filename, "r"); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
471 END_SAVE |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
472 if (fp == NULL) { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
473 err_errno(IOError); |
| 673 | 474 return NULL; |
| 475 } | |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
476 res = run_file(fp, filename, file_input, globals, locals); |
| 926 | 477 BGN_SAVE |
| 673 | 478 fclose(fp); |
| 926 | 479 END_SAVE |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
480 return res; |
| 673 | 481 } |
| 482 | |
| 483 static object * | |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
484 builtin_float(self, args) |
| 86 | 485 object *self; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
486 object *args; |
| 86 | 487 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
488 object *v; |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
489 number_methods *nb; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
490 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
491 if (!newgetargs(args, "O:float", &v)) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
492 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
493 if ((nb = v->ob_type->tp_as_number) == NULL || |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
494 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
|
495 err_setstr(TypeError, |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
496 "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
|
497 return NULL; |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
498 } |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
499 return (*nb->nb_float)(v); |
| 86 | 500 } |
| 501 | |
| 502 static object * | |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
503 builtin_getattr(self, args) |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
504 object *self; |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
505 object *args; |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
506 { |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
507 object *v; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
508 object *name; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
509 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
510 if (!newgetargs(args, "OS:getattr", &v, &name)) |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
511 return NULL; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
512 return getattro(v, name); |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
513 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
514 |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
515 static object * |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
516 builtin_globals(self, args) |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
517 object *self; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
518 object *args; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
519 { |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
520 object *d; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
521 |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
522 if (!newgetargs(args, "")) |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
523 return NULL; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
524 d = getglobals(); |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
525 INCREF(d); |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
526 return d; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
527 } |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
528 |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
529 static object * |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
530 builtin_hasattr(self, args) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
531 object *self; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
532 object *args; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
533 { |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
534 object *v; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
535 object *name; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
536 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
537 if (!newgetargs(args, "OS:hasattr", &v, &name)) |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
538 return NULL; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
539 v = getattro(v, name); |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
540 if (v == NULL) { |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
541 err_clear(); |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
542 return newintobject(0L); |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
543 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
544 DECREF(v); |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
545 return newintobject(1L); |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
546 } |
|
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
547 |
|
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
548 static object * |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
549 builtin_id(self, args) |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
550 object *self; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
551 object *args; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
552 { |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
553 object *v; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
554 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
555 if (!newgetargs(args, "O:id", &v)) |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
556 return NULL; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
557 return newintobject((long)v); |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
558 } |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
559 |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
560 static object * |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
561 builtin_map(self, args) |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
562 object *self; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
563 object *args; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
564 { |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
565 typedef struct { |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
566 object *seq; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
567 sequence_methods *sqf; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
568 int len; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
569 } sequence; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
570 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
571 object *func, *result; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
572 sequence *seqs = NULL, *sqp; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
573 int n, len; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
574 register int i, j; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
575 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
576 n = gettuplesize(args); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
577 if (n < 2) { |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
578 err_setstr(TypeError, "map() requires at least two args"); |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
579 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
580 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
581 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
582 func = gettupleitem(args, 0); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
583 n--; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
584 |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
585 if ((seqs = NEW(sequence, n)) == NULL) { |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
586 err_nomem(); |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
587 goto Fail_2; |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
588 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
589 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
590 for (len = 0, i = 0, sqp = seqs; i < n; ++i, ++sqp) { |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
591 int curlen; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
592 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
593 if ((sqp->seq = gettupleitem(args, i + 1)) == NULL) |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
594 goto Fail_2; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
595 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
596 if (! (sqp->sqf = sqp->seq->ob_type->tp_as_sequence)) { |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
597 static char errmsg[] = |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
598 "argument %d to map() must be a sequence object"; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
599 char errbuf[sizeof(errmsg) + 3]; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
600 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
601 sprintf(errbuf, errmsg, i+2); |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
602 err_setstr(TypeError, errbuf); |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
603 goto Fail_2; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
604 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
605 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
606 if ((curlen = sqp->len = (*sqp->sqf->sq_length)(sqp->seq)) < 0) |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
607 goto Fail_2; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
608 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
609 if (curlen > len) |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
610 len = curlen; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
611 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
612 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
613 if ((result = (object *) newlistobject(len)) == NULL) |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
614 goto Fail_2; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
615 |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
616 /* XXX Special case map(None, single_list) could be more efficient */ |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
617 for (i = 0; ; ++i) { |
|
2824
65c7105868f8
rename arglist to alist (conflict with new grammar symbol)
Guido van Rossum <guido@python.org>
parents:
2808
diff
changeset
|
618 object *alist, *item, *value; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
619 int any = 0; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
620 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
621 if (func == None && n == 1) |
|
2824
65c7105868f8
rename arglist to alist (conflict with new grammar symbol)
Guido van Rossum <guido@python.org>
parents:
2808
diff
changeset
|
622 alist = NULL; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
623 else { |
|
2824
65c7105868f8
rename arglist to alist (conflict with new grammar symbol)
Guido van Rossum <guido@python.org>
parents:
2808
diff
changeset
|
624 if ((alist = newtupleobject(n)) == NULL) |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
625 goto Fail_1; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
626 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
627 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
628 for (j = 0, sqp = seqs; j < n; ++j, ++sqp) { |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
629 if (sqp->len < 0) { |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
630 INCREF(None); |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
631 item = None; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
632 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
633 else { |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
634 item = (*sqp->sqf->sq_item)(sqp->seq, i); |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
635 if (item == NULL) { |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
636 if (i < sqp->len) |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
637 goto Fail_0; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
638 if (err_occurred() == IndexError) { |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
639 err_clear(); |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
640 INCREF(None); |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
641 item = None; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
642 sqp->len = -1; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
643 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
644 else { |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
645 goto Fail_0; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
646 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
647 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
648 else |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
649 any = 1; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
650 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
651 } |
|
2824
65c7105868f8
rename arglist to alist (conflict with new grammar symbol)
Guido van Rossum <guido@python.org>
parents:
2808
diff
changeset
|
652 if (!alist) |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
653 break; |
|
2824
65c7105868f8
rename arglist to alist (conflict with new grammar symbol)
Guido van Rossum <guido@python.org>
parents:
2808
diff
changeset
|
654 if (settupleitem(alist, j, item) < 0) { |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
655 DECREF(item); |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
656 goto Fail_0; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
657 } |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
658 continue; |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
659 |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
660 Fail_0: |
|
2824
65c7105868f8
rename arglist to alist (conflict with new grammar symbol)
Guido van Rossum <guido@python.org>
parents:
2808
diff
changeset
|
661 XDECREF(alist); |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
662 goto Fail_1; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
663 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
664 |
|
2824
65c7105868f8
rename arglist to alist (conflict with new grammar symbol)
Guido van Rossum <guido@python.org>
parents:
2808
diff
changeset
|
665 if (!alist) |
|
65c7105868f8
rename arglist to alist (conflict with new grammar symbol)
Guido van Rossum <guido@python.org>
parents:
2808
diff
changeset
|
666 alist = item; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
667 |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
668 if (!any) { |
|
2824
65c7105868f8
rename arglist to alist (conflict with new grammar symbol)
Guido van Rossum <guido@python.org>
parents:
2808
diff
changeset
|
669 DECREF(alist); |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
670 break; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
671 } |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
672 |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
673 if (func == None) |
|
2824
65c7105868f8
rename arglist to alist (conflict with new grammar symbol)
Guido van Rossum <guido@python.org>
parents:
2808
diff
changeset
|
674 value = alist; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
675 else { |
|
2824
65c7105868f8
rename arglist to alist (conflict with new grammar symbol)
Guido van Rossum <guido@python.org>
parents:
2808
diff
changeset
|
676 value = call_object(func, alist); |
|
65c7105868f8
rename arglist to alist (conflict with new grammar symbol)
Guido van Rossum <guido@python.org>
parents:
2808
diff
changeset
|
677 DECREF(alist); |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
678 if (value == NULL) |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
679 goto Fail_1; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
680 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
681 if (i >= len) { |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
682 if (addlistitem(result, value) < 0) |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
683 goto Fail_1; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
684 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
685 else { |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
686 if (setlistitem(result, i, value) < 0) |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
687 goto Fail_1; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
688 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
689 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
690 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
691 DEL(seqs); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
692 return result; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
693 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
694 Fail_1: |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
695 DECREF(result); |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
696 Fail_2: |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
697 if (seqs) DEL(seqs); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
698 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
699 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
700 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
701 static object * |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
702 builtin_setattr(self, args) |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
703 object *self; |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
704 object *args; |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
705 { |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
706 object *v; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
707 object *name; |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
708 object *value; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
709 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
710 if (!newgetargs(args, "OSO:setattr", &v, &name, &value)) |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
711 return NULL; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
712 if (setattro(v, name, value) != 0) |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
713 return NULL; |
|
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
714 INCREF(None); |
|
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
715 return None; |
|
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
716 } |
|
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
717 |
|
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
718 static object * |
| 1843 | 719 builtin_delattr(self, args) |
| 720 object *self; | |
| 721 object *args; | |
| 722 { | |
| 723 object *v; | |
| 724 object *name; | |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
725 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
726 if (!newgetargs(args, "OS:delattr", &v, &name)) |
| 1843 | 727 return NULL; |
| 728 if (setattro(v, name, (object *)NULL) != 0) | |
| 729 return NULL; | |
| 730 INCREF(None); | |
| 731 return None; | |
| 732 } | |
| 733 | |
| 734 static object * | |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
735 builtin_hash(self, args) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
736 object *self; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
737 object *args; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
738 { |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
739 object *v; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
740 long x; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
741 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
742 if (!newgetargs(args, "O:hash", &v)) |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
743 return NULL; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
744 x = hashobject(v); |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
745 if (x == -1) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
746 return NULL; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
747 return newintobject(x); |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
748 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
749 |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
750 static object * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
751 builtin_hex(self, args) |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
752 object *self; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
753 object *args; |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
754 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
755 object *v; |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
756 number_methods *nb; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
757 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
758 if (!newgetargs(args, "O:hex", &v)) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
759 return NULL; |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
760 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
761 if ((nb = v->ob_type->tp_as_number) == NULL || |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
762 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
|
763 err_setstr(TypeError, |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
764 "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
|
765 return NULL; |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
766 } |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
767 return (*nb->nb_hex)(v); |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
768 } |
|
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
769 |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1049
diff
changeset
|
770 static object *builtin_raw_input PROTO((object *, object *)); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1049
diff
changeset
|
771 |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
772 static object * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
773 builtin_input(self, args) |
| 86 | 774 object *self; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
775 object *args; |
| 86 | 776 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
777 object *line; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
778 char *str; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
779 object *res; |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
780 object *globals, *locals; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
781 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
782 line = builtin_raw_input(self, args); |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1049
diff
changeset
|
783 if (line == NULL) |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1049
diff
changeset
|
784 return line; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
785 if (!getargs(line, "s;embedded '\\0' in input line", &str)) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
786 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
787 while (*str == ' ' || *str == '\t') |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
788 str++; |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
789 globals = getglobals(); |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
790 locals = getlocals(); |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
791 if (dictlookup(globals, "__builtins__") == NULL) { |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
792 if (dictinsert(globals, "__builtins__", getbuiltins()) != 0) |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
793 return NULL; |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
794 } |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
795 res = run_string(str, eval_input, globals, locals); |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1049
diff
changeset
|
796 DECREF(line); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
797 return res; |
| 86 | 798 } |
| 799 | |
| 800 static object * | |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
801 builtin_int(self, args) |
| 86 | 802 object *self; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
803 object *args; |
| 86 | 804 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
805 object *v; |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
806 number_methods *nb; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
807 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
808 if (!newgetargs(args, "O:int", &v)) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
809 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
810 if ((nb = v->ob_type->tp_as_number) == NULL || |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
811 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
|
812 err_setstr(TypeError, |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
813 "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
|
814 return NULL; |
| 86 | 815 } |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
816 return (*nb->nb_int)(v); |
| 86 | 817 } |
| 818 | |
| 819 static object * | |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
820 builtin_len(self, args) |
| 86 | 821 object *self; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
822 object *args; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
823 { |
| 86 | 824 object *v; |
| 825 long len; | |
| 826 typeobject *tp; | |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
827 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
828 if (!newgetargs(args, "O:len", &v)) |
| 86 | 829 return NULL; |
| 830 tp = v->ob_type; | |
| 831 if (tp->tp_as_sequence != NULL) { | |
| 832 len = (*tp->tp_as_sequence->sq_length)(v); | |
| 833 } | |
| 834 else if (tp->tp_as_mapping != NULL) { | |
| 835 len = (*tp->tp_as_mapping->mp_length)(v); | |
| 836 } | |
| 837 else { | |
| 838 err_setstr(TypeError, "len() of unsized object"); | |
| 839 return NULL; | |
| 840 } | |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
841 if (len < 0) |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
842 return NULL; |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
843 else |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
844 return newintobject(len); |
| 86 | 845 } |
| 846 | |
| 847 static object * | |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
848 builtin_locals(self, args) |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
849 object *self; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
850 object *args; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
851 { |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
852 object *d; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
853 |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
854 if (!newgetargs(args, "")) |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
855 return NULL; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
856 d = getlocals(); |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
857 INCREF(d); |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
858 return d; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
859 } |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
860 |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
861 static object * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
862 builtin_long(self, args) |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
863 object *self; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
864 object *args; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
865 { |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
866 object *v; |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
867 number_methods *nb; |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
868 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
869 if (!newgetargs(args, "O:long", &v)) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
870 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
871 if ((nb = v->ob_type->tp_as_number) == NULL || |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
872 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
|
873 err_setstr(TypeError, |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
874 "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
|
875 return NULL; |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
876 } |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
877 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
|
878 } |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
879 |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
880 static object * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
881 min_max(args, sign) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
882 object *args; |
| 86 | 883 int sign; |
| 884 { | |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
885 int i; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
886 object *v, *w, *x; |
| 86 | 887 sequence_methods *sq; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
888 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
889 if (gettuplesize(args) > 1) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
890 v = args; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
891 else if (!newgetargs(args, "O:min/max", &v)) |
| 86 | 892 return NULL; |
| 893 sq = v->ob_type->tp_as_sequence; | |
| 894 if (sq == NULL) { | |
| 895 err_setstr(TypeError, "min() or max() of non-sequence"); | |
| 896 return NULL; | |
| 897 } | |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
898 w = NULL; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
899 for (i = 0; ; i++) { |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
900 x = (*sq->sq_item)(v, i); /* Implies INCREF */ |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
901 if (x == NULL) { |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
902 if (err_occurred() == IndexError) { |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
903 err_clear(); |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
904 break; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
905 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
906 XDECREF(w); |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
907 return NULL; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
908 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
909 if (w == NULL) |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
910 w = x; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
911 else { |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
912 if (cmpobject(x, w) * sign > 0) { |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
913 DECREF(w); |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
914 w = x; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
915 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
916 else |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
917 DECREF(x); |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
918 } |
| 86 | 919 } |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
920 if (w == NULL) |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
921 err_setstr(ValueError, "min() or max() of empty sequence"); |
| 86 | 922 return w; |
| 923 } | |
| 924 | |
| 925 static object * | |
| 926 builtin_min(self, v) | |
| 927 object *self; | |
| 928 object *v; | |
| 929 { | |
| 930 return min_max(v, -1); | |
| 931 } | |
| 932 | |
| 933 static object * | |
| 934 builtin_max(self, v) | |
| 935 object *self; | |
| 936 object *v; | |
| 937 { | |
| 938 return min_max(v, 1); | |
| 939 } | |
| 940 | |
| 941 static object * | |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
942 builtin_oct(self, args) |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
943 object *self; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
944 object *args; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
945 { |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
946 object *v; |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
947 number_methods *nb; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
948 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
949 if (!newgetargs(args, "O:oct", &v)) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
950 return NULL; |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
951 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
|
952 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
|
953 err_setstr(TypeError, |
|
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
954 "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
|
955 return NULL; |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
956 } |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
957 return (*nb->nb_oct)(v); |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
958 } |
|
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
959 |
|
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
960 static object * |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
961 builtin_open(self, args) |
| 86 | 962 object *self; |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
963 object *args; |
| 86 | 964 { |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
965 char *name; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
966 char *mode = "r"; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
967 int bufsize = -1; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
968 object *f; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
969 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
970 if (!newgetargs(args, "s|si:open", &name, &mode, &bufsize)) |
| 86 | 971 return NULL; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
972 f = newfileobject(name, mode); |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
973 if (f != NULL) |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
974 setfilebufsize(f, bufsize); |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
975 return f; |
| 86 | 976 } |
| 977 | |
| 978 static object * | |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
979 builtin_ord(self, args) |
| 86 | 980 object *self; |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
981 object *args; |
| 86 | 982 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
983 char c; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
984 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
985 if (!newgetargs(args, "c:ord", &c)) |
| 86 | 986 return NULL; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
987 return newintobject((long)(c & 0xff)); |
| 86 | 988 } |
| 989 | |
| 990 static object * | |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
991 do_pow(v, w) |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
992 object *v, *w; |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
993 { |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
994 object *res; |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
995 if (is_instanceobject(v) || is_instanceobject(w)) |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
996 return instancebinop(v, w, "__pow__", "__rpow__", do_pow); |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
997 if (v->ob_type->tp_as_number == NULL || |
|
1841
23f03ef00361
Python/bltinmodule.c: mods by Andrew Kuchling to implement
Guido van Rossum <guido@python.org>
parents:
1840
diff
changeset
|
998 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
|
999 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
|
1000 return NULL; |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
1001 } |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
1002 if ( |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
1003 #ifndef WITHOUT_COMPLEX |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
1004 !is_complexobject(v) && |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
1005 #endif |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
1006 is_floatobject(w) && getfloatvalue(v) < 0.0) { |
|
2375
51c8824985f8
fix bogus test for negative float
Guido van Rossum <guido@python.org>
parents:
2338
diff
changeset
|
1007 if (!err_occurred()) |
|
51c8824985f8
fix bogus test for negative float
Guido van Rossum <guido@python.org>
parents:
2338
diff
changeset
|
1008 err_setstr(ValueError, "negative number to float power"); |
|
2306
08b457d6b516
test for float to the float power here
Guido van Rossum <guido@python.org>
parents:
2240
diff
changeset
|
1009 return NULL; |
|
08b457d6b516
test for float to the float power here
Guido van Rossum <guido@python.org>
parents:
2240
diff
changeset
|
1010 } |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
1011 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
|
1012 return NULL; |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1013 res = (*v->ob_type->tp_as_number->nb_power)(v, w, None); |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
1014 DECREF(v); |
|
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
1015 DECREF(w); |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1016 return res; |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1017 } |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1018 |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1019 static object * |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1020 builtin_pow(self, args) |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1021 object *self; |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1022 object *args; |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1023 { |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1024 object *v, *w, *z = None, *res; |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1025 object *v1, *z1, *w2, *z2; |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1026 |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1027 if (!newgetargs(args, "OO|O:pow", &v, &w, &z)) |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1028 return NULL; |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1029 if (z == None) |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1030 return do_pow(v, w); |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1031 /* XXX The ternary version doesn't do class instance coercions */ |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1032 if (is_instanceobject(v)) |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1033 return v->ob_type->tp_as_number->nb_power(v, w, z); |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1034 if (v->ob_type->tp_as_number == NULL || |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1035 z->ob_type->tp_as_number == NULL || |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1036 w->ob_type->tp_as_number == NULL) { |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1037 err_setstr(TypeError, "pow() requires numeric arguments"); |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1038 return NULL; |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1039 } |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1040 if (coerce(&v, &w) != 0) |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1041 return NULL; |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1042 res = NULL; |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1043 v1 = v; |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1044 z1 = z; |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1045 if (coerce(&v1, &z1) != 0) |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1046 goto error2; |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1047 w2 = w; |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1048 z2 = z1; |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1049 if (coerce(&w2, &z2) != 0) |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1050 goto error1; |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1051 res = (*v1->ob_type->tp_as_number->nb_power)(v1, w2, z2); |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1052 DECREF(w2); |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1053 DECREF(z2); |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1054 error1: |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1055 DECREF(v1); |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1056 DECREF(z1); |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1057 error2: |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1058 DECREF(v); |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1059 DECREF(w); |
|
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1060 return res; |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
1061 } |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
1062 |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
1063 static object * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1064 builtin_range(self, args) |
| 86 | 1065 object *self; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1066 object *args; |
| 86 | 1067 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1068 long ilow = 0, ihigh = 0, istep = 1; |
| 86 | 1069 int i, n; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1070 object *v; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1071 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1072 if (gettuplesize(args) <= 1) { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1073 if (!newgetargs(args, |
|
2153
e54b8654f938
fix Alpha bug in (x)range; different __builtins__ initialization
Guido van Rossum <guido@python.org>
parents:
2120
diff
changeset
|
1074 "l;range() requires 1-3 int arguments", |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1075 &ihigh)) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1076 return NULL; |
| 86 | 1077 } |
| 1078 else { | |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1079 if (!newgetargs(args, |
|
2153
e54b8654f938
fix Alpha bug in (x)range; different __builtins__ initialization
Guido van Rossum <guido@python.org>
parents:
2120
diff
changeset
|
1080 "ll|l;range() requires 1-3 int arguments", |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1081 &ilow, &ihigh, &istep)) |
| 86 | 1082 return NULL; |
| 1083 } | |
| 1084 if (istep == 0) { | |
| 463 | 1085 err_setstr(ValueError, "zero step for range()"); |
| 86 | 1086 return NULL; |
| 1087 } | |
| 1088 /* XXX ought to check overflow of subtraction */ | |
| 1089 if (istep > 0) | |
| 1090 n = (ihigh - ilow + istep - 1) / istep; | |
| 1091 else | |
| 1092 n = (ihigh - ilow + istep + 1) / istep; | |
| 1093 if (n < 0) | |
| 1094 n = 0; | |
| 1095 v = newlistobject(n); | |
| 1096 if (v == NULL) | |
| 1097 return NULL; | |
| 1098 for (i = 0; i < n; i++) { | |
| 1099 object *w = newintobject(ilow); | |
| 1100 if (w == NULL) { | |
| 1101 DECREF(v); | |
| 1102 return NULL; | |
| 1103 } | |
| 1104 setlistitem(v, i, w); | |
| 1105 ilow += istep; | |
| 1106 } | |
| 1107 return v; | |
| 1108 } | |
| 1109 | |
| 1110 static object * | |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1111 builtin_xrange(self, args) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1112 object *self; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1113 object *args; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1114 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1115 long ilow = 0, ihigh = 0, istep = 1; |
|
2153
e54b8654f938
fix Alpha bug in (x)range; different __builtins__ initialization
Guido van Rossum <guido@python.org>
parents:
2120
diff
changeset
|
1116 long n; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1117 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1118 if (gettuplesize(args) <= 1) { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1119 if (!newgetargs(args, |
|
2153
e54b8654f938
fix Alpha bug in (x)range; different __builtins__ initialization
Guido van Rossum <guido@python.org>
parents:
2120
diff
changeset
|
1120 "l;xrange() requires 1-3 int arguments", |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1121 &ihigh)) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1122 return NULL; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1123 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1124 else { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1125 if (!newgetargs(args, |
|
2153
e54b8654f938
fix Alpha bug in (x)range; different __builtins__ initialization
Guido van Rossum <guido@python.org>
parents:
2120
diff
changeset
|
1126 "ll|l;xrange() requires 1-3 int arguments", |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1127 &ilow, &ihigh, &istep)) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1128 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1129 } |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1130 if (istep == 0) { |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1131 err_setstr(ValueError, "zero step for xrange()"); |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1132 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1133 } |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1134 /* XXX ought to check overflow of subtraction */ |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1135 if (istep > 0) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1136 n = (ihigh - ilow + istep - 1) / istep; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1137 else |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1138 n = (ihigh - ilow + istep + 1) / istep; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1139 if (n < 0) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1140 n = 0; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1141 return newrangeobject(ilow, n, istep, 1); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1142 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1143 |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1144 extern char *my_readline PROTO((char *)); |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1145 |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1146 static object * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1147 builtin_raw_input(self, args) |
| 86 | 1148 object *self; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1149 object *args; |
| 86 | 1150 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1151 object *v = NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1152 object *f; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1153 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1154 if (!newgetargs(args, "|O:[raw_]input", &v)) |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1049
diff
changeset
|
1155 return NULL; |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1156 if (getfilefile(sysget("stdin")) == stdin && |
|
2857
eebbdbee54f9
be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
1157 getfilefile(sysget("stdout")) == stdout && |
|
eebbdbee54f9
be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
1158 isatty(fileno(stdin)) && isatty(fileno(stdout))) { |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1159 object *po; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1160 char *prompt; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1161 char *s; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1162 object *result; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1163 if (v != NULL) { |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1164 po = strobject(v); |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1165 if (po == NULL) |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1166 return NULL; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1167 prompt = getstringvalue(po); |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1168 } |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1169 else { |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1170 po = NULL; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1171 prompt = ""; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1172 } |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1173 s = my_readline(prompt); |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1174 XDECREF(po); |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1175 if (s == NULL) { |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1176 err_set(KeyboardInterrupt); |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1177 return NULL; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1178 } |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1179 if (*s == '\0') { |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1180 err_set(EOFError); |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1181 result = NULL; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1182 } |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1183 else { /* strip trailing '\n' */ |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1184 result = newsizedstringobject(s, strlen(s)-1); |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1185 } |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1186 free(s); |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1187 return result; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1188 } |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
1189 if (v != NULL) { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1190 f = sysget("stdout"); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1191 if (f == NULL) { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1192 err_setstr(RuntimeError, "lost sys.stdout"); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1193 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1194 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1195 flushline(); |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1049
diff
changeset
|
1196 if (writeobject(v, f, PRINT_RAW) != 0) |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
1197 return NULL; |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
1198 } |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1199 f = sysget("stdin"); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1200 if (f == NULL) { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1201 err_setstr(RuntimeError, "lost sys.stdin"); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1202 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1203 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1204 return filegetline(f, -1); |
| 86 | 1205 } |
| 1206 | |
| 1207 static object * | |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1208 builtin_reduce(self, args) |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1209 object *self; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1210 object *args; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1211 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1212 object *seq, *func, *result = NULL; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1213 sequence_methods *sqf; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1214 register int i; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1215 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1216 if (!newgetargs(args, "OO|O:reduce", &func, &seq, &result)) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1217 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1218 if (result != NULL) |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1219 INCREF(result); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1220 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1221 if ((sqf = seq->ob_type->tp_as_sequence) == NULL) { |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1222 err_setstr(TypeError, |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1223 "2nd argument to reduce() must be a sequence object"); |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1224 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1225 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1226 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1227 if ((args = newtupleobject(2)) == NULL) |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1228 goto Fail; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1229 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1230 for (i = 0; ; ++i) { |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1231 object *op2; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1232 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1233 if (args->ob_refcnt > 1) { |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1234 DECREF(args); |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1235 if ((args = newtupleobject(2)) == NULL) |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1236 goto Fail; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1237 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1238 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1239 if ((op2 = (*sqf->sq_item)(seq, i)) == NULL) { |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1240 if (err_occurred() == IndexError) { |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1241 err_clear(); |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1242 break; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1243 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1244 goto Fail; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1245 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1246 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1247 if (result == NULL) |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1248 result = op2; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1249 else { |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1250 settupleitem(args, 0, result); |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1251 settupleitem(args, 1, op2); |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1252 if ((result = call_object(func, args)) == NULL) |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1253 goto Fail; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1254 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1255 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1256 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1257 DECREF(args); |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1258 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1259 if (result == NULL) |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1260 err_setstr(TypeError, |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1261 "reduce of empty sequence with no initial value"); |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1262 |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1263 return result; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1264 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1265 Fail: |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1266 XDECREF(args); |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1267 XDECREF(result); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1268 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1269 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1270 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1271 static object * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1272 builtin_reload(self, args) |
| 86 | 1273 object *self; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1274 object *args; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1275 { |
| 86 | 1276 object *v; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1277 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1278 if (!newgetargs(args, "O:reload", &v)) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1279 return NULL; |
| 86 | 1280 return reload_module(v); |
| 1281 } | |
| 1282 | |
| 1283 static object * | |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1284 builtin_repr(self, args) |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1285 object *self; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1286 object *args; |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1287 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1288 object *v; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1289 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1290 if (!newgetargs(args, "O:repr", &v)) |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1291 return NULL; |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1292 return reprobject(v); |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1293 } |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1294 |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1295 static object * |
|
1215
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1296 builtin_round(self, args) |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1297 object *self; |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1298 object *args; |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1299 { |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1300 extern double floor PROTO((double)); |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1301 extern double ceil PROTO((double)); |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1302 double x; |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1303 double f; |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1304 int ndigits = 0; |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1305 int i; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1306 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1307 if (!newgetargs(args, "d|i:round", &x, &ndigits)) |
|
1215
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1308 return NULL; |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1309 f = 1.0; |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1310 for (i = ndigits; --i >= 0; ) |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1311 f = f*10.0; |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1312 for (i = ndigits; ++i <= 0; ) |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1313 f = f*0.1; |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1314 if (x >= 0.0) |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1315 return newfloatobject(floor(x*f + 0.5) / f); |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1316 else |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1317 return newfloatobject(ceil(x*f - 0.5) / f); |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1318 } |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1319 |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1320 static object * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1321 builtin_str(self, args) |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1322 object *self; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1323 object *args; |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1324 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1325 object *v; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1326 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1327 if (!newgetargs(args, "O:str", &v)) |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1328 return NULL; |
|
1400
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1393
diff
changeset
|
1329 return strobject(v); |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1330 } |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1331 |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1332 static object * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1333 builtin_tuple(self, args) |
|
1842
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1334 object *self; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1335 object *args; |
|
1842
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1336 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1337 object *v; |
|
1842
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1338 sequence_methods *sqf; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1339 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1340 if (!newgetargs(args, "O:tuple", &v)) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1341 return NULL; |
|
1842
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1342 if (is_tupleobject(v)) { |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1343 INCREF(v); |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1344 return v; |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1345 } |
|
1856
1822465a35b8
* Python/getmtime.c: Remove mac specifics (Mac subdirectory has
Guido van Rossum <guido@python.org>
parents:
1843
diff
changeset
|
1346 if (is_listobject(v)) |
|
1822465a35b8
* Python/getmtime.c: Remove mac specifics (Mac subdirectory has
Guido van Rossum <guido@python.org>
parents:
1843
diff
changeset
|
1347 return listtuple(v); |
|
1842
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1348 if (is_stringobject(v)) { |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1349 int n = getstringsize(v); |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1350 object *t = newtupleobject(n); |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1351 if (t != NULL) { |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1352 int i; |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1353 char *p = getstringvalue(v); |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1354 for (i = 0; i < n; i++) { |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1355 object *item = newsizedstringobject(p+i, 1); |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1356 if (item == NULL) { |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1357 DECREF(t); |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1358 t = NULL; |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1359 break; |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1360 } |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1361 settupleitem(t, i, item); |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1362 } |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1363 } |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1364 return t; |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1365 } |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1366 /* Generic sequence object */ |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1367 if ((sqf = v->ob_type->tp_as_sequence) != NULL) { |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1368 int n = (*sqf->sq_length)(v); |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1369 int i; |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1370 object *t; |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1371 if (n < 0) |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1372 return NULL; |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1373 t = newtupleobject(n); |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1374 if (t == NULL) |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1375 return NULL; |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1376 for (i = 0; i < n; i++) { |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1377 object *item = (*sqf->sq_item)(v, i); |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1378 if (item == NULL) { |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1379 DECREF(t); |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1380 t = NULL; |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1381 break; |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1382 } |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1383 settupleitem(t, i, item); |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1384 } |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1385 /* XXX Should support indefinite-length sequences */ |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1386 return t; |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1387 } |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1388 /* None of the above */ |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1389 err_setstr(TypeError, "tuple() argument must be a sequence"); |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1390 return NULL; |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1391 } |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1392 |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1393 static object * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1394 builtin_type(self, args) |
| 86 | 1395 object *self; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1396 object *args; |
| 86 | 1397 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1398 object *v; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1399 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1400 if (!newgetargs(args, "O:type", &v)) |
| 86 | 1401 return NULL; |
| 1402 v = (object *)v->ob_type; | |
| 1403 INCREF(v); | |
| 1404 return v; | |
| 1405 } | |
| 1406 | |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1407 static object * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1408 builtin_vars(self, args) |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1409 object *self; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1410 object *args; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1411 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1412 object *v = NULL; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1413 object *d; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1414 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1415 if (!newgetargs(args, "|O:vars", &v)) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1416 return NULL; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1417 if (v == NULL) { |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1418 d = getlocals(); |
|
2857
eebbdbee54f9
be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
1419 if (d == NULL) { |
|
eebbdbee54f9
be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
1420 if (!err_occurred()) |
|
eebbdbee54f9
be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
1421 err_setstr(SystemError, "no locals!?"); |
|
eebbdbee54f9
be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
1422 } |
|
eebbdbee54f9
be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
1423 else |
|
eebbdbee54f9
be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
1424 INCREF(d); |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1425 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1426 else { |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1427 d = getattr(v, "__dict__"); |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1428 if (d == NULL) { |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1429 err_setstr(TypeError, |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1430 "vars() argument must have __dict__ attribute"); |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1431 return NULL; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1432 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1433 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1434 return d; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1435 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1436 |
| 86 | 1437 static struct methodlist builtin_methods[] = { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1438 {"__import__", builtin___import__, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1439 {"abs", builtin_abs, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1440 {"apply", builtin_apply, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1441 {"callable", builtin_callable, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1442 {"chr", builtin_chr, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1443 {"cmp", builtin_cmp, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1444 {"coerce", builtin_coerce, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1445 {"compile", builtin_compile, 1}, |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
1446 #ifndef WITHOUT_COMPLEX |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
1447 {"complex", builtin_complex, 1}, |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
1448 #endif |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1449 {"delattr", builtin_delattr, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1450 {"dir", builtin_dir, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1451 {"divmod", builtin_divmod, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1452 {"eval", builtin_eval, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1453 {"execfile", builtin_execfile, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1454 {"filter", builtin_filter, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1455 {"float", builtin_float, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1456 {"getattr", builtin_getattr, 1}, |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1457 {"globals", builtin_globals, 1}, |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1458 {"hasattr", builtin_hasattr, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1459 {"hash", builtin_hash, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1460 {"hex", builtin_hex, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1461 {"id", builtin_id, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1462 {"input", builtin_input, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1463 {"int", builtin_int, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1464 {"len", builtin_len, 1}, |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1465 {"locals", builtin_locals, 1}, |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1466 {"long", builtin_long, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1467 {"map", builtin_map, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1468 {"max", builtin_max, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1469 {"min", builtin_min, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1470 {"oct", builtin_oct, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1471 {"open", builtin_open, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1472 {"ord", builtin_ord, 1}, |
| 2002 | 1473 {"pow", builtin_pow, 1}, |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1474 {"range", builtin_range, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1475 {"raw_input", builtin_raw_input, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1476 {"reduce", builtin_reduce, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1477 {"reload", builtin_reload, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1478 {"repr", builtin_repr, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1479 {"round", builtin_round, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1480 {"setattr", builtin_setattr, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1481 {"str", builtin_str, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1482 {"tuple", builtin_tuple, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1483 {"type", builtin_type, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1484 {"vars", builtin_vars, 1}, |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1485 {"xrange", builtin_xrange, 1}, |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
1486 {NULL, NULL}, |
| 86 | 1487 }; |
| 1488 | |
|
2153
e54b8654f938
fix Alpha bug in (x)range; different __builtins__ initialization
Guido van Rossum <guido@python.org>
parents:
2120
diff
changeset
|
1489 static object *builtin_mod; |
| 86 | 1490 static object *builtin_dict; |
| 1491 | |
| 1492 object * | |
|
2153
e54b8654f938
fix Alpha bug in (x)range; different __builtins__ initialization
Guido van Rossum <guido@python.org>
parents:
2120
diff
changeset
|
1493 getbuiltinmod() |
|
e54b8654f938
fix Alpha bug in (x)range; different __builtins__ initialization
Guido van Rossum <guido@python.org>
parents:
2120
diff
changeset
|
1494 { |
|
e54b8654f938
fix Alpha bug in (x)range; different __builtins__ initialization
Guido van Rossum <guido@python.org>
parents:
2120
diff
changeset
|
1495 return builtin_mod; |
|
e54b8654f938
fix Alpha bug in (x)range; different __builtins__ initialization
Guido van Rossum <guido@python.org>
parents:
2120
diff
changeset
|
1496 } |
|
e54b8654f938
fix Alpha bug in (x)range; different __builtins__ initialization
Guido van Rossum <guido@python.org>
parents:
2120
diff
changeset
|
1497 |
|
e54b8654f938
fix Alpha bug in (x)range; different __builtins__ initialization
Guido van Rossum <guido@python.org>
parents:
2120
diff
changeset
|
1498 object * |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
1499 getbuiltindict() |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1500 { |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
1501 return builtin_dict; |
| 86 | 1502 } |
| 1503 | |
| 1504 /* Predefined exceptions */ | |
| 1505 | |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1263
diff
changeset
|
1506 object *AccessError; |
| 495 | 1507 object *AttributeError; |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1263
diff
changeset
|
1508 object *ConflictError; |
| 86 | 1509 object *EOFError; |
| 495 | 1510 object *IOError; |
|
505
095d9cf4e3e6
Sorted exceptions; added ImportError.
Guido van Rossum <guido@python.org>
parents:
495
diff
changeset
|
1511 object *ImportError; |
| 495 | 1512 object *IndexError; |
| 1513 object *KeyError; | |
| 1514 object *KeyboardInterrupt; | |
| 86 | 1515 object *MemoryError; |
| 1516 object *NameError; | |
| 495 | 1517 object *OverflowError; |
| 1518 object *RuntimeError; | |
| 1519 object *SyntaxError; | |
| 86 | 1520 object *SystemError; |
| 545 | 1521 object *SystemExit; |
| 495 | 1522 object *TypeError; |
| 1523 object *ValueError; | |
| 463 | 1524 object *ZeroDivisionError; |
| 1525 | |
| 86 | 1526 static object * |
| 495 | 1527 newstdexception(name) |
| 1528 char *name; | |
| 86 | 1529 { |
| 495 | 1530 object *v = newstringobject(name); |
| 86 | 1531 if (v == NULL || dictinsert(builtin_dict, name, v) != 0) |
| 1532 fatal("no mem for new standard exception"); | |
| 1533 return v; | |
| 1534 } | |
| 1535 | |
| 1536 static void | |
| 1537 initerrors() | |
| 1538 { | |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1263
diff
changeset
|
1539 AccessError = newstdexception("AccessError"); |
|
505
095d9cf4e3e6
Sorted exceptions; added ImportError.
Guido van Rossum <guido@python.org>
parents:
495
diff
changeset
|
1540 AttributeError = newstdexception("AttributeError"); |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1263
diff
changeset
|
1541 ConflictError = newstdexception("ConflictError"); |
| 495 | 1542 EOFError = newstdexception("EOFError"); |
|
505
095d9cf4e3e6
Sorted exceptions; added ImportError.
Guido van Rossum <guido@python.org>
parents:
495
diff
changeset
|
1543 IOError = newstdexception("IOError"); |
|
095d9cf4e3e6
Sorted exceptions; added ImportError.
Guido van Rossum <guido@python.org>
parents:
495
diff
changeset
|
1544 ImportError = newstdexception("ImportError"); |
|
095d9cf4e3e6
Sorted exceptions; added ImportError.
Guido van Rossum <guido@python.org>
parents:
495
diff
changeset
|
1545 IndexError = newstdexception("IndexError"); |
|
095d9cf4e3e6
Sorted exceptions; added ImportError.
Guido van Rossum <guido@python.org>
parents:
495
diff
changeset
|
1546 KeyError = newstdexception("KeyError"); |
|
095d9cf4e3e6
Sorted exceptions; added ImportError.
Guido van Rossum <guido@python.org>
parents:
495
diff
changeset
|
1547 KeyboardInterrupt = newstdexception("KeyboardInterrupt"); |
| 495 | 1548 MemoryError = newstdexception("MemoryError"); |
| 1549 NameError = newstdexception("NameError"); | |
|
505
095d9cf4e3e6
Sorted exceptions; added ImportError.
Guido van Rossum <guido@python.org>
parents:
495
diff
changeset
|
1550 OverflowError = newstdexception("OverflowError"); |
|
095d9cf4e3e6
Sorted exceptions; added ImportError.
Guido van Rossum <guido@python.org>
parents:
495
diff
changeset
|
1551 RuntimeError = newstdexception("RuntimeError"); |
|
095d9cf4e3e6
Sorted exceptions; added ImportError.
Guido van Rossum <guido@python.org>
parents:
495
diff
changeset
|
1552 SyntaxError = newstdexception("SyntaxError"); |
| 495 | 1553 SystemError = newstdexception("SystemError"); |
| 545 | 1554 SystemExit = newstdexception("SystemExit"); |
|
505
095d9cf4e3e6
Sorted exceptions; added ImportError.
Guido van Rossum <guido@python.org>
parents:
495
diff
changeset
|
1555 TypeError = newstdexception("TypeError"); |
|
095d9cf4e3e6
Sorted exceptions; added ImportError.
Guido van Rossum <guido@python.org>
parents:
495
diff
changeset
|
1556 ValueError = newstdexception("ValueError"); |
| 495 | 1557 ZeroDivisionError = newstdexception("ZeroDivisionError"); |
| 86 | 1558 } |
| 1559 | |
| 1560 void | |
| 1561 initbuiltin() | |
| 1562 { | |
|
2153
e54b8654f938
fix Alpha bug in (x)range; different __builtins__ initialization
Guido van Rossum <guido@python.org>
parents:
2120
diff
changeset
|
1563 builtin_mod = initmodule("__builtin__", builtin_methods); |
|
e54b8654f938
fix Alpha bug in (x)range; different __builtins__ initialization
Guido van Rossum <guido@python.org>
parents:
2120
diff
changeset
|
1564 builtin_dict = getmoduledict(builtin_mod); |
| 86 | 1565 INCREF(builtin_dict); |
| 1566 initerrors(); | |
| 1567 (void) dictinsert(builtin_dict, "None", None); | |
| 1568 } | |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
1569 |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1570 |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1387
diff
changeset
|
1571 /* Helper for filter(): filter a tuple through a function */ |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1572 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1573 static object * |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1574 filtertuple(func, tuple) |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1575 object *func; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1576 object *tuple; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1577 { |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1578 object *result; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1579 register int i, j; |
|
1387
f992ac2a38d5
* rangeobject.{c,h}, bltinmodule.c: removed non-essential ops from range
Guido van Rossum <guido@python.org>
parents:
1380
diff
changeset
|
1580 int len = gettuplesize(tuple); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1581 |
|
2890
04e1690fb4d1
avoid resize of 0-length tuple
Guido van Rossum <guido@python.org>
parents:
2857
diff
changeset
|
1582 if (len == 0) { |
|
04e1690fb4d1
avoid resize of 0-length tuple
Guido van Rossum <guido@python.org>
parents:
2857
diff
changeset
|
1583 INCREF(tuple); |
|
04e1690fb4d1
avoid resize of 0-length tuple
Guido van Rossum <guido@python.org>
parents:
2857
diff
changeset
|
1584 return tuple; |
|
04e1690fb4d1
avoid resize of 0-length tuple
Guido van Rossum <guido@python.org>
parents:
2857
diff
changeset
|
1585 } |
|
04e1690fb4d1
avoid resize of 0-length tuple
Guido van Rossum <guido@python.org>
parents:
2857
diff
changeset
|
1586 |
|
1387
f992ac2a38d5
* rangeobject.{c,h}, bltinmodule.c: removed non-essential ops from range
Guido van Rossum <guido@python.org>
parents:
1380
diff
changeset
|
1587 if ((result = newtupleobject(len)) == NULL) |
|
f992ac2a38d5
* rangeobject.{c,h}, bltinmodule.c: removed non-essential ops from range
Guido van Rossum <guido@python.org>
parents:
1380
diff
changeset
|
1588 return NULL; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1589 |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1590 for (i = j = 0; i < len; ++i) { |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1591 object *item, *good; |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1592 int ok; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1593 |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1594 if ((item = gettupleitem(tuple, i)) == NULL) |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1595 goto Fail_1; |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1596 if (func == None) { |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1597 INCREF(item); |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1598 good = item; |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1599 } |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1600 else { |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1601 object *arg = mkvalue("(O)", item); |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1602 if (arg == NULL) |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1603 goto Fail_1; |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1604 good = call_object(func, arg); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1605 DECREF(arg); |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1606 if (good == NULL) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1607 goto Fail_1; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1608 } |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1609 ok = testbool(good); |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1610 DECREF(good); |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1611 if (ok) { |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1612 INCREF(item); |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1613 if (settupleitem(result, j++, item) < 0) |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1614 goto Fail_1; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1615 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1616 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1617 |
|
1380
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1375
diff
changeset
|
1618 if (resizetuple(&result, j, 0) < 0) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1619 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1620 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1621 return result; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1622 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1623 Fail_1: |
|
1387
f992ac2a38d5
* rangeobject.{c,h}, bltinmodule.c: removed non-essential ops from range
Guido van Rossum <guido@python.org>
parents:
1380
diff
changeset
|
1624 DECREF(result); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1625 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1626 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1627 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1628 |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1387
diff
changeset
|
1629 /* Helper for filter(): filter a string through a function */ |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1630 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1631 static object * |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1632 filterstring(func, strobj) |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1633 object *func; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1634 object *strobj; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1635 { |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1636 object *result; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1637 register int i, j; |
|
1387
f992ac2a38d5
* rangeobject.{c,h}, bltinmodule.c: removed non-essential ops from range
Guido van Rossum <guido@python.org>
parents:
1380
diff
changeset
|
1638 int len = getstringsize(strobj); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1639 |
|
1387
f992ac2a38d5
* rangeobject.{c,h}, bltinmodule.c: removed non-essential ops from range
Guido van Rossum <guido@python.org>
parents:
1380
diff
changeset
|
1640 if (func == None) { |
|
f992ac2a38d5
* rangeobject.{c,h}, bltinmodule.c: removed non-essential ops from range
Guido van Rossum <guido@python.org>
parents:
1380
diff
changeset
|
1641 /* No character is ever false -- share input string */ |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1642 INCREF(strobj); |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1643 return strobj; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1644 } |
|
1387
f992ac2a38d5
* rangeobject.{c,h}, bltinmodule.c: removed non-essential ops from range
Guido van Rossum <guido@python.org>
parents:
1380
diff
changeset
|
1645 if ((result = newsizedstringobject(NULL, len)) == NULL) |
|
f992ac2a38d5
* rangeobject.{c,h}, bltinmodule.c: removed non-essential ops from range
Guido van Rossum <guido@python.org>
parents:
1380
diff
changeset
|
1646 return NULL; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1647 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1648 for (i = j = 0; i < len; ++i) { |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1649 object *item, *arg, *good; |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1650 int ok; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1651 |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1652 item = (*strobj->ob_type->tp_as_sequence->sq_item)(strobj, i); |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1653 if (item == NULL) |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1654 goto Fail_1; |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1655 arg = mkvalue("(O)", item); |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1656 DECREF(item); |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1657 if (arg == NULL) |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1658 goto Fail_1; |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1659 good = call_object(func, arg); |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1660 DECREF(arg); |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1661 if (good == NULL) |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1662 goto Fail_1; |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1663 ok = testbool(good); |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1664 DECREF(good); |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1665 if (ok) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1666 GETSTRINGVALUE((stringobject *)result)[j++] = |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1667 GETSTRINGVALUE((stringobject *)item)[0]; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1668 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1669 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1670 if (resizestring(&result, j) < 0) |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1671 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1672 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1673 return result; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1674 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1675 Fail_1: |
|
1387
f992ac2a38d5
* rangeobject.{c,h}, bltinmodule.c: removed non-essential ops from range
Guido van Rossum <guido@python.org>
parents:
1380
diff
changeset
|
1676 DECREF(result); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1677 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1678 } |
