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