Mercurial > cpython-lru_cache-weakref
annotate Python/bltinmodule.c @ 9979:489ef7f64041 legacy-trunk
builtin_complex(): Nailed memory leak. This one's in the instance
test for classes with a __complex__() method. The attribute is pulled
out of the instance with PyObject_GetAttr() but this transfers
ownership and the function object was never DECREF'd.
| author | Barry Warsaw <barry@python.org> |
|---|---|
| date | Wed, 27 Jan 1999 23:13:59 +0000 |
| parents | 5e9ef9d8575b |
| children | dcbe72a0b392 |
| 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 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4416
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4416
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
|
145
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 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4416
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
diff
changeset
|
11 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4416
diff
changeset
|
12 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4416
diff
changeset
|
13 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4416
diff
changeset
|
14 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4416
diff
changeset
|
15 permission. |
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
diff
changeset
|
16 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4416
diff
changeset
|
17 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4416
diff
changeset
|
18 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4416
diff
changeset
|
19 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4416
diff
changeset
|
20 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4416
diff
changeset
|
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4416
diff
changeset
|
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4416
diff
changeset
|
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4416
diff
changeset
|
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4416
diff
changeset
|
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4416
diff
changeset
|
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4416
diff
changeset
|
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4416
diff
changeset
|
28 PERFORMANCE OF THIS SOFTWARE. |
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
diff
changeset
|
29 |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
diff
changeset
|
30 ******************************************************************/ |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
139
diff
changeset
|
31 |
| 86 | 32 /* Built-in functions */ |
| 33 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
34 #include "Python.h" |
| 86 | 35 |
| 36 #include "node.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 |
|
3962
f08d7f368ebf
Include mymath.h instead of declaring prototypes for math functions.
Guido van Rossum <guido@python.org>
parents:
3862
diff
changeset
|
40 #include "mymath.h" |
|
f08d7f368ebf
Include mymath.h instead of declaring prototypes for math functions.
Guido van Rossum <guido@python.org>
parents:
3862
diff
changeset
|
41 |
|
5317
c72c7e1930b3
Keep gcc -Wall and Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents:
5223
diff
changeset
|
42 #include <ctype.h> |
|
c72c7e1930b3
Keep gcc -Wall and Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents:
5223
diff
changeset
|
43 |
|
4655
c75a2f2dc220
Add unistd.h to make gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4595
diff
changeset
|
44 #ifdef HAVE_UNISTD_H |
|
c75a2f2dc220
Add unistd.h to make gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4595
diff
changeset
|
45 #include <unistd.h> |
|
c75a2f2dc220
Add unistd.h to make gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4595
diff
changeset
|
46 #endif |
|
c75a2f2dc220
Add unistd.h to make gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4595
diff
changeset
|
47 |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
48 /* Forward */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
49 static PyObject *filterstring Py_PROTO((PyObject *, PyObject *)); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
50 static PyObject *filtertuple Py_PROTO((PyObject *, PyObject *)); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
51 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
52 static PyObject * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
53 builtin___import__(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
54 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
55 PyObject *args; |
|
2052
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 char *name; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
58 PyObject *globals = NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
59 PyObject *locals = NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
60 PyObject *fromlist = NULL; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
61 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
62 if (!PyArg_ParseTuple(args, "s|OOO:__import__", |
|
2338
4c2f1452125d
call __import__() with 4 args instead of 1
Guido van Rossum <guido@python.org>
parents:
2306
diff
changeset
|
63 &name, &globals, &locals, &fromlist)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
64 return NULL; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6198
diff
changeset
|
65 return PyImport_ImportModuleEx(name, globals, locals, fromlist); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
66 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
67 |
| 8561 | 68 static char import_doc[] = |
| 69 "__import__(name, globals, locals, fromlist) -> module\n\ | |
| 70 \n\ | |
| 71 Import a module. The globals are only used to determine the context;\n\ | |
| 72 they are not modified. The locals are currently unused. The fromlist\n\ | |
| 73 should be a list of names to emulate ``from name import ...'', or an\n\ | |
| 74 empty list to emulate ``import name''.\n\ | |
| 75 When importing a module from a package, note that __import__('A.B', ...)\n\ | |
| 76 returns package A when fromlist is empty, but its submodule B when\n\ | |
| 77 fromlist is not empty."; | |
| 78 | |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
79 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
80 static PyObject * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
81 builtin_abs(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
82 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
83 PyObject *args; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
84 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
85 PyObject *v; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
86 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
87 if (!PyArg_ParseTuple(args, "O:abs", &v)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
88 return NULL; |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
89 return PyNumber_Absolute(v); |
| 86 | 90 } |
| 91 | |
| 8561 | 92 static char abs_doc[] = |
| 93 "abs(number) -> number\n\ | |
| 94 \n\ | |
| 95 Return the absolute value of the argument."; | |
| 96 | |
| 97 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
98 static PyObject * |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
99 builtin_apply(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
100 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
101 PyObject *args; |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
102 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
103 PyObject *func, *alist = NULL, *kwdict = NULL; |
|
9188
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
104 PyObject *t = NULL, *retval = NULL; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
105 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
106 if (!PyArg_ParseTuple(args, "O|OO:apply", &func, &alist, &kwdict)) |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
107 return NULL; |
|
9188
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
108 if (alist != NULL) { |
|
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
109 if (!PyTuple_Check(alist)) { |
|
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
110 if (!PySequence_Check(alist)) { |
|
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
111 PyErr_SetString(PyExc_TypeError, |
|
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
112 "apply() 2nd argument must be a sequence"); |
|
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
113 return NULL; |
|
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
114 } |
|
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
115 t = PySequence_Tuple(alist); |
|
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
116 if (t == NULL) |
|
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
117 return NULL; |
|
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
118 alist = t; |
|
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
119 } |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
120 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
121 if (kwdict != NULL && !PyDict_Check(kwdict)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
122 PyErr_SetString(PyExc_TypeError, |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2824
diff
changeset
|
123 "apply() 3rd argument must be dictionary"); |
|
9188
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
124 goto finally; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2824
diff
changeset
|
125 } |
|
9188
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
126 retval = PyEval_CallObjectWithKeywords(func, alist, kwdict); |
|
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
127 finally: |
|
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
128 Py_XDECREF(t); |
|
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
129 return retval; |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
130 } |
|
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
131 |
| 8561 | 132 static char apply_doc[] = |
| 133 "apply(function, args[, kwargs]) -> value\n\ | |
| 134 \n\ | |
| 135 Call a function with positional arguments taken from the tuple args,\n\ | |
| 136 and keyword arguments taken from the optional dictionary kwargs."; | |
| 137 | |
| 138 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
139 static PyObject * |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
140 builtin_callable(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
141 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
142 PyObject *args; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
143 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
144 PyObject *v; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
145 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
146 if (!PyArg_ParseTuple(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
|
147 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
148 return PyInt_FromLong((long)PyCallable_Check(v)); |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
149 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
150 |
| 8561 | 151 static char callable_doc[] = |
| 152 "callable(object) -> Boolean\n\ | |
| 153 \n\ | |
| 154 Return whether the object is callable (i.e., some kind of function).\n\ | |
| 155 Note that classes are callable, as are instances with a __call__() method."; | |
| 156 | |
| 157 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
158 static PyObject * |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1387
diff
changeset
|
159 builtin_filter(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
160 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
161 PyObject *args; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
162 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
163 PyObject *func, *seq, *result; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
164 PySequenceMethods *sqf; |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
165 int len; |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
166 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
|
167 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
168 if (!PyArg_ParseTuple(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
|
169 return NULL; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
170 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
171 if (PyString_Check(seq)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
172 PyObject *r = filterstring(func, seq); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
173 return r; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
174 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
175 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
176 if (PyTuple_Check(seq)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
177 PyObject *r = filtertuple(func, seq); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
178 return r; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
179 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
180 |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
181 sqf = seq->ob_type->tp_as_sequence; |
|
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
182 if (sqf == NULL || sqf->sq_length == NULL || sqf->sq_item == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
183 PyErr_SetString(PyExc_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
|
184 "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
|
185 goto Fail_2; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
186 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
187 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
188 if ((len = (*sqf->sq_length)(seq)) < 0) |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
189 goto Fail_2; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
190 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
191 if (PyList_Check(seq) && seq->ob_refcnt == 1) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
192 Py_INCREF(seq); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
193 result = seq; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
194 } |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
195 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
196 if ((result = PyList_New(len)) == NULL) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
197 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
|
198 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
199 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
200 for (i = j = 0; ; ++i) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
201 PyObject *item, *good; |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
202 int ok; |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
203 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
204 if ((item = (*sqf->sq_item)(seq, i)) == NULL) { |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
205 if (PyErr_ExceptionMatches(PyExc_IndexError)) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
206 PyErr_Clear(); |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
207 break; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
208 } |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
209 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
|
210 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
211 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
212 if (func == Py_None) { |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
213 good = item; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
214 Py_INCREF(good); |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
215 } |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
216 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
217 PyObject *arg = Py_BuildValue("(O)", item); |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
218 if (arg == NULL) |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
219 goto Fail_1; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
220 good = PyEval_CallObject(func, arg); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
221 Py_DECREF(arg); |
|
2120
84b61fe44573
fix subtle refcount big in filter() -- Tim MacKenzie
Guido van Rossum <guido@python.org>
parents:
2113
diff
changeset
|
222 if (good == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
223 Py_DECREF(item); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
224 goto Fail_1; |
|
2120
84b61fe44573
fix subtle refcount big in filter() -- Tim MacKenzie
Guido van Rossum <guido@python.org>
parents:
2113
diff
changeset
|
225 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
226 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
227 ok = PyObject_IsTrue(good); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
228 Py_DECREF(good); |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
229 if (ok) { |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
230 if (j < len) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
231 if (PyList_SetItem(result, j++, item) < 0) |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
232 goto Fail_1; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
233 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
234 else { |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
235 j++; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
236 if (PyList_Append(result, item) < 0) |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
237 goto Fail_1; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
238 } |
|
2120
84b61fe44573
fix subtle refcount big in filter() -- Tim MacKenzie
Guido van Rossum <guido@python.org>
parents:
2113
diff
changeset
|
239 } else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
240 Py_DECREF(item); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
241 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
242 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
243 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
244 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
245 if (j < len && PyList_SetSlice(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
|
246 goto Fail_1; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
247 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
248 return result; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
249 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
250 Fail_1: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
251 Py_DECREF(result); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
252 Fail_2: |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
253 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
254 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
255 |
| 8561 | 256 static char filter_doc[] = |
| 257 "filter(function, sequence) -> list\n\ | |
| 258 \n\ | |
| 259 Return a list containing those items of sequence for which function(item)\n\ | |
| 260 is true. If function is None, return a list of items that are true."; | |
| 261 | |
| 262 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
263 static PyObject * |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
264 builtin_chr(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
265 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
266 PyObject *args; |
| 86 | 267 { |
| 268 long x; | |
| 269 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
|
270 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
271 if (!PyArg_ParseTuple(args, "l:chr", &x)) |
| 86 | 272 return NULL; |
| 273 if (x < 0 || x >= 256) { | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
274 PyErr_SetString(PyExc_ValueError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
275 "chr() arg not in range(256)"); |
| 86 | 276 return NULL; |
| 277 } | |
|
5317
c72c7e1930b3
Keep gcc -Wall and Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents:
5223
diff
changeset
|
278 s[0] = (char)x; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
279 return PyString_FromStringAndSize(s, 1); |
| 86 | 280 } |
| 281 | |
| 8561 | 282 static char chr_doc[] = |
| 283 "chr(i) -> character\n\ | |
| 284 \n\ | |
| 285 Return a string of one character with ordinal i; 0 <= i < 256."; | |
| 286 | |
| 287 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
288 static PyObject * |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
289 builtin_cmp(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
290 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
291 PyObject *args; |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
292 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
293 PyObject *a, *b; |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
294 int c; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
295 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
296 if (!PyArg_ParseTuple(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
|
297 return NULL; |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
298 if (PyObject_Cmp(a, b, &c) < 0) |
|
5610
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5471
diff
changeset
|
299 return NULL; |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
300 return PyInt_FromLong((long)c); |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
301 } |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
302 |
| 8561 | 303 static char cmp_doc[] = |
| 304 "cmp(x, y) -> integer\n\ | |
| 305 \n\ | |
| 306 Return negative if x<y, zero if x==y, positive if x>y."; | |
| 307 | |
| 308 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
309 static PyObject * |
|
2113
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2106
diff
changeset
|
310 builtin_coerce(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
311 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
312 PyObject *args; |
|
2113
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2106
diff
changeset
|
313 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
314 PyObject *v, *w; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
315 PyObject *res; |
|
2113
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2106
diff
changeset
|
316 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
317 if (!PyArg_ParseTuple(args, "OO:coerce", &v, &w)) |
|
2113
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2106
diff
changeset
|
318 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
319 if (PyNumber_Coerce(&v, &w) < 0) |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
320 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
321 res = Py_BuildValue("(OO)", v, w); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
322 Py_DECREF(v); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
323 Py_DECREF(w); |
|
944
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
324 return res; |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
325 } |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
326 |
| 8561 | 327 static char coerce_doc[] = |
| 328 "coerce(x, y) -> None or (x1, y1)\n\ | |
| 329 \n\ | |
| 330 When x and y can be coerced to values of the same type, return a tuple\n\ | |
| 331 containing the coerced values. When they can't be coerced, return None."; | |
| 332 | |
| 333 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
334 static PyObject * |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
335 builtin_compile(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
336 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
337 PyObject *args; |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
338 { |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
339 char *str; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
340 char *filename; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
341 char *startstr; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
342 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
|
343 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
344 if (!PyArg_ParseTuple(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
|
345 return NULL; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
346 if (strcmp(startstr, "exec") == 0) |
|
5438
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5421
diff
changeset
|
347 start = Py_file_input; |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
348 else if (strcmp(startstr, "eval") == 0) |
|
5438
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5421
diff
changeset
|
349 start = Py_eval_input; |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
350 else if (strcmp(startstr, "single") == 0) |
|
5438
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5421
diff
changeset
|
351 start = Py_single_input; |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
352 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
353 PyErr_SetString(PyExc_ValueError, |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
354 "compile() mode must be 'exec' or 'eval' or 'single'"); |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
355 return NULL; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
356 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
357 return Py_CompileString(str, filename, start); |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
358 } |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
359 |
| 8561 | 360 static char compile_doc[] = |
| 361 "compile(source, filename, mode) -> code object\n\ | |
| 362 \n\ | |
| 363 Compile the source string (a Python module, statement or expression)\n\ | |
| 364 into a code object that can be executed by the exec statement or eval().\n\ | |
| 365 The filename will be used for run-time error messages.\n\ | |
| 366 The mode must be 'exec' to compile a module, 'single' to compile a\n\ | |
| 367 single (interactive) statement, or 'eval' to compile an expression."; | |
| 368 | |
| 369 | |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
370 #ifndef WITHOUT_COMPLEX |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
371 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
372 static PyObject * |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
373 builtin_complex(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
374 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
375 PyObject *args; |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
376 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
377 PyObject *r, *i, *tmp; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
378 PyNumberMethods *nbr, *nbi = NULL; |
|
3766
516490c8192c
Py_complex; and WITHOUT_COMPLEX added to getargs.c
Guido van Rossum <guido@python.org>
parents:
3587
diff
changeset
|
379 Py_complex cr, ci; |
|
5223
bc8832b52b50
1. Add string conversions to int(), long(), float(). (Not to complex()!)
Guido van Rossum <guido@python.org>
parents:
5182
diff
changeset
|
380 int own_r = 0; |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
381 |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
382 i = NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
383 if (!PyArg_ParseTuple(args, "O|O:complex", &r, &i)) |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
384 return NULL; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
385 if ((nbr = r->ob_type->tp_as_number) == NULL || |
|
5223
bc8832b52b50
1. Add string conversions to int(), long(), float(). (Not to complex()!)
Guido van Rossum <guido@python.org>
parents:
5182
diff
changeset
|
386 nbr->nb_float == NULL || |
|
bc8832b52b50
1. Add string conversions to int(), long(), float(). (Not to complex()!)
Guido van Rossum <guido@python.org>
parents:
5182
diff
changeset
|
387 (i != NULL && |
|
bc8832b52b50
1. Add string conversions to int(), long(), float(). (Not to complex()!)
Guido van Rossum <guido@python.org>
parents:
5182
diff
changeset
|
388 ((nbi = i->ob_type->tp_as_number) == NULL || |
|
bc8832b52b50
1. Add string conversions to int(), long(), float(). (Not to complex()!)
Guido van Rossum <guido@python.org>
parents:
5182
diff
changeset
|
389 nbi->nb_float == NULL))) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
390 PyErr_SetString(PyExc_TypeError, |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
391 "complex() argument can't be converted to complex"); |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
392 return NULL; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
393 } |
|
4595
f8f3da3fdaed
Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
394 /* XXX Hack to support classes with __complex__ method */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
395 if (PyInstance_Check(r)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
396 static PyObject *complexstr; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
397 PyObject *f; |
|
4595
f8f3da3fdaed
Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
398 if (complexstr == NULL) { |
|
5010
f0cf8d275fbc
Intern the string "__complex__".
Guido van Rossum <guido@python.org>
parents:
4655
diff
changeset
|
399 complexstr = PyString_InternFromString("__complex__"); |
|
4595
f8f3da3fdaed
Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
400 if (complexstr == NULL) |
|
f8f3da3fdaed
Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
401 return NULL; |
|
f8f3da3fdaed
Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
402 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
403 f = PyObject_GetAttr(r, complexstr); |
|
4595
f8f3da3fdaed
Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
404 if (f == NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
405 PyErr_Clear(); |
|
4595
f8f3da3fdaed
Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
406 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
407 PyObject *args = Py_BuildValue("()"); |
|
4595
f8f3da3fdaed
Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
408 if (args == NULL) |
|
f8f3da3fdaed
Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
409 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
410 r = PyEval_CallObject(f, args); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
411 Py_DECREF(args); |
|
9979
489ef7f64041
builtin_complex(): Nailed memory leak. This one's in the instance
Barry Warsaw <barry@python.org>
parents:
9849
diff
changeset
|
412 Py_DECREF(f); |
|
4595
f8f3da3fdaed
Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
413 if (r == NULL) |
|
f8f3da3fdaed
Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
414 return NULL; |
|
5223
bc8832b52b50
1. Add string conversions to int(), long(), float(). (Not to complex()!)
Guido van Rossum <guido@python.org>
parents:
5182
diff
changeset
|
415 own_r = 1; |
|
4595
f8f3da3fdaed
Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
416 } |
|
f8f3da3fdaed
Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
417 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
418 if (PyComplex_Check(r)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
419 cr = ((PyComplexObject*)r)->cval; |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
7678
diff
changeset
|
420 if (own_r) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
421 Py_DECREF(r); |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
7678
diff
changeset
|
422 } |
|
5223
bc8832b52b50
1. Add string conversions to int(), long(), float(). (Not to complex()!)
Guido van Rossum <guido@python.org>
parents:
5182
diff
changeset
|
423 } |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
424 else { |
|
3962
f08d7f368ebf
Include mymath.h instead of declaring prototypes for math functions.
Guido van Rossum <guido@python.org>
parents:
3862
diff
changeset
|
425 tmp = (*nbr->nb_float)(r); |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
7678
diff
changeset
|
426 if (own_r) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
427 Py_DECREF(r); |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
7678
diff
changeset
|
428 } |
|
3962
f08d7f368ebf
Include mymath.h instead of declaring prototypes for math functions.
Guido van Rossum <guido@python.org>
parents:
3862
diff
changeset
|
429 if (tmp == NULL) |
|
f08d7f368ebf
Include mymath.h instead of declaring prototypes for math functions.
Guido van Rossum <guido@python.org>
parents:
3862
diff
changeset
|
430 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
431 cr.real = PyFloat_AsDouble(tmp); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
432 Py_DECREF(tmp); |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
433 cr.imag = 0.; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
434 } |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
435 if (i == NULL) { |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
436 ci.real = 0.; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
437 ci.imag = 0.; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
438 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
439 else if (PyComplex_Check(i)) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
440 ci = ((PyComplexObject*)i)->cval; |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
441 else { |
|
5223
bc8832b52b50
1. Add string conversions to int(), long(), float(). (Not to complex()!)
Guido van Rossum <guido@python.org>
parents:
5182
diff
changeset
|
442 tmp = (*nbi->nb_float)(i); |
|
3962
f08d7f368ebf
Include mymath.h instead of declaring prototypes for math functions.
Guido van Rossum <guido@python.org>
parents:
3862
diff
changeset
|
443 if (tmp == NULL) |
|
f08d7f368ebf
Include mymath.h instead of declaring prototypes for math functions.
Guido van Rossum <guido@python.org>
parents:
3862
diff
changeset
|
444 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
445 ci.real = PyFloat_AsDouble(tmp); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
446 Py_DECREF(tmp); |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
447 ci.imag = 0.; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
448 } |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
449 cr.real -= ci.imag; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
450 cr.imag += ci.real; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
451 return PyComplex_FromCComplex(cr); |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
452 } |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
453 |
| 8561 | 454 static char complex_doc[] = |
| 455 "complex(real[, imag]) -> complex number\n\ | |
| 456 \n\ | |
| 457 Create a complex number from a real part and an optional imaginary part.\n\ | |
| 458 This is equivalent to (real + imag*1j) where imag defaults to 0."; | |
| 459 | |
| 460 | |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
461 #endif |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
462 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
463 static PyObject * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
464 builtin_dir(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
465 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
466 PyObject *args; |
| 86 | 467 { |
| 5421 | 468 static char *attrlist[] = {"__members__", "__methods__", NULL}; |
| 469 PyObject *v = NULL, *l = NULL, *m = NULL; | |
| 470 PyObject *d, *x; | |
| 471 int i; | |
| 472 char **s; | |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
473 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
474 if (!PyArg_ParseTuple(args, "|O:dir", &v)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
475 return NULL; |
| 86 | 476 if (v == NULL) { |
| 5421 | 477 x = PyEval_GetLocals(); |
| 478 if (x == NULL) | |
| 479 goto error; | |
| 480 l = PyMapping_Keys(x); | |
| 481 if (l == NULL) | |
| 482 goto error; | |
| 86 | 483 } |
| 484 else { | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
485 d = PyObject_GetAttrString(v, "__dict__"); |
| 5421 | 486 if (d == NULL) |
| 487 PyErr_Clear(); | |
| 488 else { | |
| 489 l = PyMapping_Keys(d); | |
| 490 if (l == NULL) | |
| 491 PyErr_Clear(); | |
| 492 Py_DECREF(d); | |
| 493 } | |
| 494 if (l == NULL) { | |
| 495 l = PyList_New(0); | |
| 496 if (l == NULL) | |
| 497 goto error; | |
| 498 } | |
| 499 for (s = attrlist; *s != NULL; s++) { | |
| 500 m = PyObject_GetAttrString(v, *s); | |
| 501 if (m == NULL) { | |
| 502 PyErr_Clear(); | |
| 503 continue; | |
| 504 } | |
| 505 for (i = 0; ; i++) { | |
| 506 x = PySequence_GetItem(m, i); | |
| 507 if (x == NULL) { | |
| 508 PyErr_Clear(); | |
| 509 break; | |
| 510 } | |
| 511 if (PyList_Append(l, x) != 0) { | |
| 512 Py_DECREF(x); | |
| 513 Py_DECREF(m); | |
| 514 goto error; | |
| 515 } | |
| 516 Py_DECREF(x); | |
| 517 } | |
| 518 Py_DECREF(m); | |
| 86 | 519 } |
|
385
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
520 } |
| 5421 | 521 if (PyList_Sort(l) != 0) |
| 522 goto error; | |
| 523 return l; | |
| 524 error: | |
| 525 Py_XDECREF(l); | |
| 526 return NULL; | |
| 86 | 527 } |
| 528 | |
| 8561 | 529 static char dir_doc[] = |
| 530 "dir([object]) -> list of strings\n\ | |
| 531 \n\ | |
| 532 Return an alphabetized list of names comprising (some of) the attributes\n\ | |
| 533 of the given object. Without an argument, the names in the current scope\n\ | |
| 534 are listed. With an instance argument, only the instance attributes are\n\ | |
| 535 returned. With a class argument, attributes of the base class are not\n\ | |
| 536 returned. For other types or arguments, this may list members or methods."; | |
| 537 | |
| 538 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
539 static PyObject * |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
540 builtin_divmod(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
541 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
542 PyObject *args; |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
543 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
544 PyObject *v, *w; |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
545 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
546 if (!PyArg_ParseTuple(args, "OO:divmod", &v, &w)) |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
547 return NULL; |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
548 return PyNumber_Divmod(v, w); |
| 86 | 549 } |
| 550 | |
| 8561 | 551 static char divmod_doc[] = |
| 552 "divmod(x, y) -> (div, mod)\n\ | |
| 553 \n\ | |
| 554 Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x."; | |
| 555 | |
| 556 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
557 static PyObject * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
558 builtin_eval(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
559 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
560 PyObject *args; |
| 86 | 561 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
562 PyObject *cmd; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
563 PyObject *globals = Py_None, *locals = Py_None; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
564 char *str; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
565 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
566 if (!PyArg_ParseTuple(args, "O|O!O!:eval", |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
567 &cmd, |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
568 &PyDict_Type, &globals, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
569 &PyDict_Type, &locals)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
570 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
571 if (globals == Py_None) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
572 globals = PyEval_GetGlobals(); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
573 if (locals == Py_None) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
574 locals = PyEval_GetLocals(); |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
575 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
576 else if (locals == Py_None) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
577 locals = globals; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
578 if (PyDict_GetItemString(globals, "__builtins__") == NULL) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
579 if (PyDict_SetItemString(globals, "__builtins__", |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
580 PyEval_GetBuiltins()) != 0) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
581 return NULL; |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
582 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
583 if (PyCode_Check(cmd)) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
584 return PyEval_EvalCode((PyCodeObject *) cmd, globals, locals); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
585 if (!PyString_Check(cmd)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
586 PyErr_SetString(PyExc_TypeError, |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
587 "eval() argument 1 must be string or code object"); |
| 86 | 588 return NULL; |
| 589 } | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
590 str = PyString_AsString(cmd); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
591 if ((int)strlen(str) != PyString_Size(cmd)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
592 PyErr_SetString(PyExc_ValueError, |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
593 "embedded '\\0' in string arg"); |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
594 return NULL; |
|
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
595 } |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
596 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
|
597 str++; |
|
5438
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5421
diff
changeset
|
598 return PyRun_String(str, Py_eval_input, globals, locals); |
| 86 | 599 } |
| 600 | |
| 8561 | 601 static char eval_doc[] = |
| 602 "eval(source[, globals[, locals]]) -> value\n\ | |
| 603 \n\ | |
| 604 Evaluate the source in the context of globals and locals.\n\ | |
| 605 The source may be a string representing a Python expression\n\ | |
| 606 or a code object as returned by compile().\n\ | |
| 607 The globals and locals are dictionaries, defaulting to the current\n\ | |
| 608 globals and locals. If only globals is given, locals defaults to it."; | |
| 609 | |
| 610 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
611 static PyObject * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
612 builtin_execfile(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
613 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
614 PyObject *args; |
| 673 | 615 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
616 char *filename; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
617 PyObject *globals = Py_None, *locals = Py_None; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
618 PyObject *res; |
| 673 | 619 FILE* fp; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
620 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
621 if (!PyArg_ParseTuple(args, "s|O!O!:execfile", |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
622 &filename, |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
623 &PyDict_Type, &globals, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
624 &PyDict_Type, &locals)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
625 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
626 if (globals == Py_None) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
627 globals = PyEval_GetGlobals(); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
628 if (locals == Py_None) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
629 locals = PyEval_GetLocals(); |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
630 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
631 else if (locals == Py_None) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
632 locals = globals; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
633 if (PyDict_GetItemString(globals, "__builtins__") == NULL) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
634 if (PyDict_SetItemString(globals, "__builtins__", |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
635 PyEval_GetBuiltins()) != 0) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
636 return NULL; |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
637 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
638 Py_BEGIN_ALLOW_THREADS |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
639 fp = fopen(filename, "r"); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
640 Py_END_ALLOW_THREADS |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
641 if (fp == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
642 PyErr_SetFromErrno(PyExc_IOError); |
| 673 | 643 return NULL; |
| 644 } | |
|
5438
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5421
diff
changeset
|
645 res = PyRun_File(fp, filename, Py_file_input, globals, locals); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
646 Py_BEGIN_ALLOW_THREADS |
| 673 | 647 fclose(fp); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
648 Py_END_ALLOW_THREADS |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
649 return res; |
| 673 | 650 } |
| 651 | |
| 8561 | 652 static char execfile_doc[] = |
| 653 "execfile(filename[, globals[, locals]])\n\ | |
| 654 \n\ | |
| 655 Read and execute a Python script from a file.\n\ | |
| 656 The globals and locals are dictionaries, defaulting to the current\n\ | |
| 657 globals and locals. If only globals is given, locals defaults to it."; | |
| 658 | |
| 659 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
660 static PyObject * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
661 builtin_float(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
662 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
663 PyObject *args; |
| 86 | 664 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
665 PyObject *v; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
666 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
667 if (!PyArg_ParseTuple(args, "O:float", &v)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
668 return NULL; |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
669 return PyNumber_Float(v); |
| 86 | 670 } |
| 671 | |
| 8561 | 672 static char float_doc[] = |
| 673 "float(x) -> floating point number\n\ | |
| 674 \n\ | |
| 675 Convert a string or number to a floating point number, if possible."; | |
| 676 | |
| 677 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
678 static PyObject * |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
679 builtin_getattr(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
680 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
681 PyObject *args; |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
682 { |
|
8581
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
683 PyObject *v, *result, *dflt = NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
684 PyObject *name; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
685 |
|
8581
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
686 if (!PyArg_ParseTuple(args, "OS|O:getattr", &v, &name, &dflt)) |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
687 return NULL; |
|
8581
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
688 result = PyObject_GetAttr(v, name); |
|
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
689 if (result == NULL && dflt != NULL) { |
|
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
690 PyErr_Clear(); |
|
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
691 Py_INCREF(dflt); |
|
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
692 result = dflt; |
|
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
693 } |
|
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
694 return result; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
695 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
696 |
| 8561 | 697 static char getattr_doc[] = |
|
8581
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
698 "getattr(object, name[, default]) -> value\n\ |
| 8561 | 699 \n\ |
|
8581
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
700 Get a named attribute from an object; getattr(x, 'y') is equivalent to x.y.\n\ |
|
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
701 When a default argument is given, it is returned when the attribute doesn't\n\ |
|
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
702 exist; without it, an exception is raised in that case."; |
| 8561 | 703 |
| 704 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
705 static PyObject * |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
706 builtin_globals(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
707 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
708 PyObject *args; |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
709 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
710 PyObject *d; |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
711 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
712 if (!PyArg_ParseTuple(args, "")) |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
713 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
714 d = PyEval_GetGlobals(); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
715 Py_INCREF(d); |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
716 return d; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
717 } |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
718 |
| 8561 | 719 static char globals_doc[] = |
| 720 "globals() -> dictionary\n\ | |
| 721 \n\ | |
| 722 Return the dictionary containing the current scope's global variables."; | |
| 723 | |
| 724 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
725 static PyObject * |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
726 builtin_hasattr(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
727 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
728 PyObject *args; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
729 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
730 PyObject *v; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
731 PyObject *name; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
732 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
733 if (!PyArg_ParseTuple(args, "OS:hasattr", &v, &name)) |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
734 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
735 v = PyObject_GetAttr(v, name); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
736 if (v == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
737 PyErr_Clear(); |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
738 Py_INCREF(Py_False); |
|
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
739 return Py_False; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
740 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
741 Py_DECREF(v); |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
742 Py_INCREF(Py_True); |
|
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
743 return Py_True; |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
744 } |
|
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
745 |
| 8561 | 746 static char hasattr_doc[] = |
| 747 "hasattr(object, name) -> Boolean\n\ | |
| 748 \n\ | |
| 749 Return whether the object has an attribute with the given name.\n\ | |
| 750 (This is done by calling getattr(object, name) and catching exceptions.)"; | |
| 751 | |
| 752 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
753 static PyObject * |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
754 builtin_id(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
755 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
756 PyObject *args; |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
757 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
758 PyObject *v; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
759 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
760 if (!PyArg_ParseTuple(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
|
761 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
762 return PyInt_FromLong((long)v); |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
763 } |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
764 |
| 8561 | 765 static char id_doc[] = |
| 766 "id(object) -> integer\n\ | |
| 767 \n\ | |
| 768 Return the identity of an object. This is guaranteed to be unique among\n\ | |
| 769 simultaneously existing objects. (Hint: it's the object's memory address.)"; | |
| 770 | |
| 771 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
772 static PyObject * |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
773 builtin_map(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
774 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
775 PyObject *args; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
776 { |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
777 typedef struct { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
778 PyObject *seq; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
779 PySequenceMethods *sqf; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
780 int len; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
781 } sequence; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
782 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
783 PyObject *func, *result; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
784 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
|
785 int n, len; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
786 register int i, j; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
787 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
788 n = PyTuple_Size(args); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
789 if (n < 2) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
790 PyErr_SetString(PyExc_TypeError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
791 "map() requires at least two args"); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
792 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
793 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
794 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
795 func = PyTuple_GetItem(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
|
796 n--; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
797 |
|
8661
30fbf18af29e
Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents:
8589
diff
changeset
|
798 if (func == Py_None && n == 1) { |
|
30fbf18af29e
Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents:
8589
diff
changeset
|
799 /* map(None, S) is the same as list(S). */ |
|
30fbf18af29e
Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents:
8589
diff
changeset
|
800 return PySequence_List(PyTuple_GetItem(args, 1)); |
|
30fbf18af29e
Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents:
8589
diff
changeset
|
801 } |
|
30fbf18af29e
Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents:
8589
diff
changeset
|
802 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
803 if ((seqs = PyMem_NEW(sequence, n)) == NULL) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
804 PyErr_NoMemory(); |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
805 goto Fail_2; |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
806 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
807 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
808 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
|
809 int curlen; |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
810 PySequenceMethods *sqf; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
811 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
812 if ((sqp->seq = PyTuple_GetItem(args, i + 1)) == NULL) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
813 goto Fail_2; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
814 |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
815 sqp->sqf = sqf = sqp->seq->ob_type->tp_as_sequence; |
|
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
816 if (sqf == NULL || |
|
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
817 sqf->sq_length == NULL || |
|
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
818 sqf->sq_item == NULL) |
|
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
819 { |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
820 static char errmsg[] = |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
821 "argument %d to map() must be a sequence object"; |
|
5388
13a30cea8dbf
Avoid sprintf buffer overflow if more than 9999 arguments.
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
822 char errbuf[sizeof(errmsg) + 25]; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
823 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
824 sprintf(errbuf, errmsg, i+2); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
825 PyErr_SetString(PyExc_TypeError, errbuf); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
826 goto Fail_2; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
827 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
828 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
829 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
|
830 goto Fail_2; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
831 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
832 if (curlen > len) |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
833 len = curlen; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
834 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
835 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
836 if ((result = (PyObject *) PyList_New(len)) == NULL) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
837 goto Fail_2; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
838 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
839 for (i = 0; ; ++i) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
840 PyObject *alist, *item=NULL, *value; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
841 int any = 0; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
842 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
843 if (func == Py_None && n == 1) |
|
2824
65c7105868f8
rename arglist to alist (conflict with new grammar symbol)
Guido van Rossum <guido@python.org>
parents:
2808
diff
changeset
|
844 alist = NULL; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
845 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
846 if ((alist = PyTuple_New(n)) == NULL) |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
847 goto Fail_1; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
848 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
849 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
850 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
|
851 if (sqp->len < 0) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
852 Py_INCREF(Py_None); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
853 item = Py_None; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
854 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
855 else { |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
856 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
|
857 if (item == NULL) { |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
858 if (PyErr_ExceptionMatches( |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
859 PyExc_IndexError)) |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
860 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
861 PyErr_Clear(); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
862 Py_INCREF(Py_None); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
863 item = Py_None; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
864 sqp->len = -1; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
865 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
866 else { |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
867 goto Fail_0; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
868 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
869 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
870 else |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
871 any = 1; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
872 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
873 } |
|
2824
65c7105868f8
rename arglist to alist (conflict with new grammar symbol)
Guido van Rossum <guido@python.org>
parents:
2808
diff
changeset
|
874 if (!alist) |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
875 break; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
876 if (PyTuple_SetItem(alist, j, item) < 0) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
877 Py_DECREF(item); |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
878 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
|
879 } |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
880 continue; |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
881 |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
882 Fail_0: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
883 Py_XDECREF(alist); |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
884 goto Fail_1; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
885 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
886 |
|
2824
65c7105868f8
rename arglist to alist (conflict with new grammar symbol)
Guido van Rossum <guido@python.org>
parents:
2808
diff
changeset
|
887 if (!alist) |
|
65c7105868f8
rename arglist to alist (conflict with new grammar symbol)
Guido van Rossum <guido@python.org>
parents:
2808
diff
changeset
|
888 alist = item; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
889 |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
890 if (!any) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
891 Py_DECREF(alist); |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
892 break; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
893 } |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
894 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
895 if (func == Py_None) |
|
2824
65c7105868f8
rename arglist to alist (conflict with new grammar symbol)
Guido van Rossum <guido@python.org>
parents:
2808
diff
changeset
|
896 value = alist; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
897 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
898 value = PyEval_CallObject(func, alist); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
899 Py_DECREF(alist); |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
900 if (value == NULL) |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
901 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
|
902 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
903 if (i >= len) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
904 if (PyList_Append(result, value) < 0) |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
905 goto Fail_1; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
906 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
907 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
908 if (PyList_SetItem(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
|
909 goto Fail_1; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
910 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
911 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
912 |
|
8661
30fbf18af29e
Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents:
8589
diff
changeset
|
913 if (i < len && PyList_SetSlice(result, i, len, NULL) < 0) |
|
30fbf18af29e
Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents:
8589
diff
changeset
|
914 goto Fail_1; |
|
30fbf18af29e
Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents:
8589
diff
changeset
|
915 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
916 PyMem_DEL(seqs); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
917 return result; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
918 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
919 Fail_1: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
920 Py_DECREF(result); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
921 Fail_2: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
922 if (seqs) PyMem_DEL(seqs); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
923 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
924 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
925 |
| 8561 | 926 static char map_doc[] = |
| 927 "map(function, sequence[, sequence, ...]) -> list\n\ | |
| 928 \n\ | |
| 929 Return a list of the results of applying the function to the items of\n\ | |
| 930 the argument sequence(s). If more than one sequence is given, the\n\ | |
| 931 function is called with an argument list consisting of the corresponding\n\ | |
| 932 item of each sequence, substituting None for missing values when not all\n\ | |
| 933 sequences have the same length. If the function is None, return a list of\n\ | |
| 934 the items of the sequence (or a list of tuples if more than one sequence)."; | |
| 935 | |
| 936 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
937 static PyObject * |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
938 builtin_setattr(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
939 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
940 PyObject *args; |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
941 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
942 PyObject *v; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
943 PyObject *name; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
944 PyObject *value; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
945 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
946 if (!PyArg_ParseTuple(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
|
947 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
948 if (PyObject_SetAttr(v, name, value) != 0) |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
949 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
950 Py_INCREF(Py_None); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
951 return Py_None; |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
952 } |
|
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
953 |
| 8561 | 954 static char setattr_doc[] = |
| 955 "setattr(object, name, value)\n\ | |
| 956 \n\ | |
| 957 Set a named attribute on an object; setattr(x, 'y', v) is equivalent to\n\ | |
| 958 ``x.y = v''."; | |
| 959 | |
| 960 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
961 static PyObject * |
| 1843 | 962 builtin_delattr(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
963 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
964 PyObject *args; |
| 1843 | 965 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
966 PyObject *v; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
967 PyObject *name; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
968 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
969 if (!PyArg_ParseTuple(args, "OS:delattr", &v, &name)) |
| 1843 | 970 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
971 if (PyObject_SetAttr(v, name, (PyObject *)NULL) != 0) |
| 1843 | 972 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
973 Py_INCREF(Py_None); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
974 return Py_None; |
| 1843 | 975 } |
| 976 | |
| 8561 | 977 static char delattr_doc[] = |
|
9514
a126107c433a
Fix cosmetic bug in delattr docstring discovered by JvR.
Guido van Rossum <guido@python.org>
parents:
9188
diff
changeset
|
978 "delattr(object, name)\n\ |
| 8561 | 979 \n\ |
| 980 Delete a named attribute on an object; delattr(x, 'y') is equivalent to\n\ | |
| 981 ``del x.y''."; | |
| 982 | |
| 983 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
984 static PyObject * |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
985 builtin_hash(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
986 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
987 PyObject *args; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
988 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
989 PyObject *v; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
990 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
|
991 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
992 if (!PyArg_ParseTuple(args, "O:hash", &v)) |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
993 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
994 x = PyObject_Hash(v); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
995 if (x == -1) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
996 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
997 return PyInt_FromLong(x); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
998 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
999 |
| 8561 | 1000 static char hash_doc[] = |
| 1001 "hash(object) -> integer\n\ | |
| 1002 \n\ | |
| 1003 Return a hash value for the object. Two objects with the same value have\n\ | |
| 1004 the same hash value. The reverse is not necessarily true, but likely."; | |
| 1005 | |
| 1006 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1007 static PyObject * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1008 builtin_hex(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1009 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1010 PyObject *args; |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
1011 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1012 PyObject *v; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1013 PyNumberMethods *nb; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1014 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1015 if (!PyArg_ParseTuple(args, "O:hex", &v)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1016 return NULL; |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
1017 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1018 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
|
1019 nb->nb_hex == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1020 PyErr_SetString(PyExc_TypeError, |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
1021 "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
|
1022 return NULL; |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
1023 } |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
1024 return (*nb->nb_hex)(v); |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
1025 } |
|
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
1026 |
| 8561 | 1027 static char hex_doc[] = |
| 1028 "hex(number) -> string\n\ | |
| 1029 \n\ | |
| 1030 Return the hexadecimal representation of an integer or long integer."; | |
| 1031 | |
| 1032 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1033 static PyObject *builtin_raw_input Py_PROTO((PyObject *, PyObject *)); |
|
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
|
1034 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1035 static PyObject * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1036 builtin_input(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1037 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1038 PyObject *args; |
| 86 | 1039 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1040 PyObject *line; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1041 char *str; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1042 PyObject *res; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1043 PyObject *globals, *locals; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1044 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1045 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
|
1046 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
|
1047 return line; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1048 if (!PyArg_Parse(line, "s;embedded '\\0' in input line", &str)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1049 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1050 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
|
1051 str++; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1052 globals = PyEval_GetGlobals(); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1053 locals = PyEval_GetLocals(); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1054 if (PyDict_GetItemString(globals, "__builtins__") == NULL) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1055 if (PyDict_SetItemString(globals, "__builtins__", |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1056 PyEval_GetBuiltins()) != 0) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
1057 return NULL; |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
1058 } |
|
5438
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5421
diff
changeset
|
1059 res = PyRun_String(str, Py_eval_input, globals, locals); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1060 Py_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
|
1061 return res; |
| 86 | 1062 } |
| 1063 | |
| 8561 | 1064 static char input_doc[] = |
| 1065 "input([prompt]) -> value\n\ | |
| 1066 \n\ | |
| 1067 Equivalent to eval(raw_input(prompt))."; | |
| 1068 | |
| 1069 | |
|
5092
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
1070 static PyObject * |
|
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
1071 builtin_intern(self, args) |
|
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
1072 PyObject *self; |
|
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
1073 PyObject *args; |
|
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
1074 { |
|
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
1075 PyObject *s; |
|
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
1076 if (!PyArg_ParseTuple(args, "S", &s)) |
|
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
1077 return NULL; |
|
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
1078 Py_INCREF(s); |
|
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
1079 PyString_InternInPlace(&s); |
|
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
1080 return s; |
|
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
1081 } |
|
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
1082 |
| 8561 | 1083 static char intern_doc[] = |
| 1084 "intern(string) -> string\n\ | |
| 1085 \n\ | |
| 1086 ``Intern'' the given string. This enters the string in the (global)\n\ | |
| 1087 table of interned strings whose purpose is to speed up dictionary lookups.\n\ | |
| 1088 Return the string itself or the previously interned string object with the\n\ | |
| 1089 same value."; | |
| 1090 | |
| 1091 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1092 static PyObject * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1093 builtin_int(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1094 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1095 PyObject *args; |
| 86 | 1096 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1097 PyObject *v; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1098 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1099 if (!PyArg_ParseTuple(args, "O:int", &v)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1100 return NULL; |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1101 return PyNumber_Int(v); |
| 86 | 1102 } |
| 1103 | |
| 8561 | 1104 static char int_doc[] = |
| 1105 "int(x) -> integer\n\ | |
| 1106 \n\ | |
| 1107 Convert a string or number to an integer, if possible.\n\ | |
| 1108 A floating point argument will be truncated towards zero."; | |
| 1109 | |
| 1110 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1111 static PyObject * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1112 builtin_len(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1113 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1114 PyObject *args; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1115 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1116 PyObject *v; |
|
8589
97dc6aa532e7
Fix a stupid little bug: len() of an unsized returns -1 and leaves an
Guido van Rossum <guido@python.org>
parents:
8581
diff
changeset
|
1117 long res; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1118 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1119 if (!PyArg_ParseTuple(args, "O:len", &v)) |
| 86 | 1120 return NULL; |
|
8589
97dc6aa532e7
Fix a stupid little bug: len() of an unsized returns -1 and leaves an
Guido van Rossum <guido@python.org>
parents:
8581
diff
changeset
|
1121 res = PyObject_Length(v); |
|
97dc6aa532e7
Fix a stupid little bug: len() of an unsized returns -1 and leaves an
Guido van Rossum <guido@python.org>
parents:
8581
diff
changeset
|
1122 if (res < 0 && PyErr_Occurred()) |
|
97dc6aa532e7
Fix a stupid little bug: len() of an unsized returns -1 and leaves an
Guido van Rossum <guido@python.org>
parents:
8581
diff
changeset
|
1123 return NULL; |
|
97dc6aa532e7
Fix a stupid little bug: len() of an unsized returns -1 and leaves an
Guido van Rossum <guido@python.org>
parents:
8581
diff
changeset
|
1124 return PyInt_FromLong(res); |
| 86 | 1125 } |
| 1126 | |
| 8561 | 1127 static char len_doc[] = |
| 1128 "len(object) -> integer\n\ | |
| 1129 \n\ | |
| 1130 Return the number of items of a sequence or mapping."; | |
| 1131 | |
| 1132 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1133 static PyObject * |
|
3493
03c6c18325ea
Add list() method, analogous to tuple().
Guido van Rossum <guido@python.org>
parents:
3365
diff
changeset
|
1134 builtin_list(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1135 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1136 PyObject *args; |
|
3493
03c6c18325ea
Add list() method, analogous to tuple().
Guido van Rossum <guido@python.org>
parents:
3365
diff
changeset
|
1137 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1138 PyObject *v; |
|
3493
03c6c18325ea
Add list() method, analogous to tuple().
Guido van Rossum <guido@python.org>
parents:
3365
diff
changeset
|
1139 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1140 if (!PyArg_ParseTuple(args, "O:list", &v)) |
|
3493
03c6c18325ea
Add list() method, analogous to tuple().
Guido van Rossum <guido@python.org>
parents:
3365
diff
changeset
|
1141 return NULL; |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1142 return PySequence_List(v); |
|
3493
03c6c18325ea
Add list() method, analogous to tuple().
Guido van Rossum <guido@python.org>
parents:
3365
diff
changeset
|
1143 } |
|
03c6c18325ea
Add list() method, analogous to tuple().
Guido van Rossum <guido@python.org>
parents:
3365
diff
changeset
|
1144 |
| 8561 | 1145 static char list_doc[] = |
| 1146 "list(sequence) -> list\n\ | |
| 1147 \n\ | |
| 1148 Return a new list whose items are the same as those of the argument sequence."; | |
| 1149 | |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1150 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1151 static PyObject * |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1152 builtin_slice(self, args) |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1153 PyObject *self; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1154 PyObject *args; |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1155 { |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1156 PyObject *start, *stop, *step; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1157 |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1158 start = stop = step = NULL; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1159 |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1160 if (!PyArg_ParseTuple(args, "O|OO:slice", &start, &stop, &step)) |
|
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1161 return NULL; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1162 |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1163 /* This swapping of stop and start is to maintain similarity with |
|
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1164 range(). */ |
|
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1165 if (stop == NULL) { |
|
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1166 stop = start; |
|
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1167 start = NULL; |
|
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1168 } |
|
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1169 return PySlice_New(start, stop, step); |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1170 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1171 |
| 8561 | 1172 static char slice_doc[] = |
| 1173 "slice([start,] step[, stop]) -> slice object\n\ | |
| 1174 \n\ | |
| 1175 Create a slice object. This is used for slicing by the Numeric extensions."; | |
| 1176 | |
| 1177 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1178 static PyObject * |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1179 builtin_locals(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1180 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1181 PyObject *args; |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1182 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1183 PyObject *d; |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1184 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1185 if (!PyArg_ParseTuple(args, "")) |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1186 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1187 d = PyEval_GetLocals(); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1188 Py_INCREF(d); |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1189 return d; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1190 } |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1191 |
| 8561 | 1192 static char locals_doc[] = |
| 1193 "locals() -> dictionary\n\ | |
| 1194 \n\ | |
| 1195 Return the dictionary containing the current scope's local variables."; | |
| 1196 | |
| 1197 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1198 static PyObject * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1199 builtin_long(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1200 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1201 PyObject *args; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1202 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1203 PyObject *v; |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
1204 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1205 if (!PyArg_ParseTuple(args, "O:long", &v)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1206 return NULL; |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1207 return PyNumber_Long(v); |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
1208 } |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
1209 |
| 8561 | 1210 static char long_doc[] = |
| 1211 "long(x) -> long integer\n\ | |
| 1212 \n\ | |
| 1213 Convert a string or number to a long integer, if possible.\n\ | |
| 1214 A floating point argument will be truncated towards zero."; | |
| 1215 | |
| 1216 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1217 static PyObject * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1218 min_max(args, sign) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1219 PyObject *args; |
| 86 | 1220 int sign; |
| 1221 { | |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1222 int i; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1223 PyObject *v, *w, *x; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1224 PySequenceMethods *sq; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1225 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1226 if (PyTuple_Size(args) > 1) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1227 v = args; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1228 else if (!PyArg_ParseTuple(args, "O:min/max", &v)) |
| 86 | 1229 return NULL; |
| 1230 sq = v->ob_type->tp_as_sequence; | |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1231 if (sq == NULL || sq->sq_item == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1232 PyErr_SetString(PyExc_TypeError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1233 "min() or max() of non-sequence"); |
| 86 | 1234 return NULL; |
| 1235 } | |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1236 w = NULL; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1237 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
|
1238 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
|
1239 if (x == NULL) { |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1240 if (PyErr_ExceptionMatches(PyExc_IndexError)) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1241 PyErr_Clear(); |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1242 break; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1243 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1244 Py_XDECREF(w); |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1245 return NULL; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1246 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1247 if (w == NULL) |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1248 w = x; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1249 else { |
|
5610
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5471
diff
changeset
|
1250 int c = PyObject_Compare(x, w); |
|
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5471
diff
changeset
|
1251 if (c && PyErr_Occurred()) { |
|
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5471
diff
changeset
|
1252 Py_DECREF(x); |
|
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5471
diff
changeset
|
1253 Py_XDECREF(w); |
|
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5471
diff
changeset
|
1254 return NULL; |
|
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5471
diff
changeset
|
1255 } |
|
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5471
diff
changeset
|
1256 if (c * sign > 0) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1257 Py_DECREF(w); |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1258 w = x; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1259 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1260 else |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1261 Py_DECREF(x); |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1262 } |
| 86 | 1263 } |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1264 if (w == NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1265 PyErr_SetString(PyExc_ValueError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1266 "min() or max() of empty sequence"); |
| 86 | 1267 return w; |
| 1268 } | |
| 1269 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1270 static PyObject * |
| 86 | 1271 builtin_min(self, v) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1272 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1273 PyObject *v; |
| 86 | 1274 { |
| 1275 return min_max(v, -1); | |
| 1276 } | |
| 1277 | |
| 8561 | 1278 static char min_doc[] = |
| 1279 "min(sequence) -> value\n\ | |
| 1280 min(a, b, c, ...) -> value\n\ | |
| 1281 \n\ | |
| 1282 With a single sequence argument, return its smallest item.\n\ | |
| 1283 With two or more arguments, return the smallest argument."; | |
| 1284 | |
| 1285 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1286 static PyObject * |
| 86 | 1287 builtin_max(self, v) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1288 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1289 PyObject *v; |
| 86 | 1290 { |
| 1291 return min_max(v, 1); | |
| 1292 } | |
| 1293 | |
| 8561 | 1294 static char max_doc[] = |
| 1295 "max(sequence) -> value\n\ | |
| 1296 max(a, b, c, ...) -> value\n\ | |
| 1297 \n\ | |
| 1298 With a single sequence argument, return its largest item.\n\ | |
| 1299 With two or more arguments, return the largest argument."; | |
| 1300 | |
| 1301 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1302 static PyObject * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1303 builtin_oct(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1304 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1305 PyObject *args; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1306 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1307 PyObject *v; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1308 PyNumberMethods *nb; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1309 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1310 if (!PyArg_ParseTuple(args, "O:oct", &v)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1311 return NULL; |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
1312 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
|
1313 nb->nb_oct == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1314 PyErr_SetString(PyExc_TypeError, |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
1315 "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
|
1316 return NULL; |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
1317 } |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
1318 return (*nb->nb_oct)(v); |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
1319 } |
|
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
1320 |
| 8561 | 1321 static char oct_doc[] = |
| 1322 "oct(number) -> string\n\ | |
| 1323 \n\ | |
| 1324 Return the octal representation of an integer or long integer."; | |
| 1325 | |
| 1326 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1327 static PyObject * |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
1328 builtin_open(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1329 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1330 PyObject *args; |
| 86 | 1331 { |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1332 char *name; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1333 char *mode = "r"; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1334 int bufsize = -1; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1335 PyObject *f; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1336 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1337 if (!PyArg_ParseTuple(args, "s|si:open", &name, &mode, &bufsize)) |
| 86 | 1338 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1339 f = PyFile_FromString(name, mode); |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1340 if (f != NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1341 PyFile_SetBufSize(f, bufsize); |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1342 return f; |
| 86 | 1343 } |
| 1344 | |
| 8561 | 1345 static char open_doc[] = |
| 1346 "open(filename[, mode[, buffering]]) -> file object\n\ | |
| 1347 \n\ | |
| 1348 Open a file. The mode can be 'r', 'w' or 'a' for reading (default),\n\ | |
| 1349 writing or appending. The file will be created if it doesn't exist\n\ | |
| 1350 when opened for writing or appending; it will be truncated when\n\ | |
| 1351 opened for writing. Add a 'b' to the mode for binary files.\n\ | |
| 1352 Add a '+' to the mode to allow simultaneous reading and writing.\n\ | |
| 1353 If the buffering argument is given, 0 means unbuffered, 1 means line\n\ | |
| 1354 buffered, and larger numbers specify the buffer size."; | |
| 1355 | |
| 1356 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1357 static PyObject * |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
1358 builtin_ord(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1359 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1360 PyObject *args; |
| 86 | 1361 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1362 char c; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1363 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1364 if (!PyArg_ParseTuple(args, "c:ord", &c)) |
| 86 | 1365 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1366 return PyInt_FromLong((long)(c & 0xff)); |
| 86 | 1367 } |
| 1368 | |
| 8561 | 1369 static char ord_doc[] = |
| 1370 "ord(c) -> integer\n\ | |
| 1371 \n\ | |
| 1372 Return the integer ordinal of a one character string."; | |
| 1373 | |
| 1374 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1375 static PyObject * |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1376 builtin_pow(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1377 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1378 PyObject *args; |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1379 { |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1380 PyObject *v, *w, *z = Py_None; |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1381 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1382 if (!PyArg_ParseTuple(args, "OO|O:pow", &v, &w, &z)) |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1383 return NULL; |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1384 return PyNumber_Power(v, w, z); |
|
223
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
1385 } |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
1386 |
| 8561 | 1387 static char pow_doc[] = |
| 1388 "pow(x, y[, z]) -> number\n\ | |
| 1389 \n\ | |
| 1390 With two arguments, equivalent to x**y. With three arguments,\n\ | |
| 1391 equivalent to (x**y) % z, but may be more efficient (e.g. for longs)."; | |
| 1392 | |
| 1393 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1394 static PyObject * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1395 builtin_range(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1396 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1397 PyObject *args; |
| 86 | 1398 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1399 long ilow = 0, ihigh = 0, istep = 1; |
| 86 | 1400 int i, n; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1401 PyObject *v; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1402 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1403 if (PyTuple_Size(args) <= 1) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1404 if (!PyArg_ParseTuple(args, |
|
2153
e54b8654f938
fix Alpha bug in (x)range; different __builtins__ initialization
Guido van Rossum <guido@python.org>
parents:
2120
diff
changeset
|
1405 "l;range() requires 1-3 int arguments", |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1406 &ihigh)) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1407 return NULL; |
| 86 | 1408 } |
| 1409 else { | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1410 if (!PyArg_ParseTuple(args, |
|
2153
e54b8654f938
fix Alpha bug in (x)range; different __builtins__ initialization
Guido van Rossum <guido@python.org>
parents:
2120
diff
changeset
|
1411 "ll|l;range() requires 1-3 int arguments", |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1412 &ilow, &ihigh, &istep)) |
| 86 | 1413 return NULL; |
| 1414 } | |
| 1415 if (istep == 0) { | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1416 PyErr_SetString(PyExc_ValueError, "zero step for range()"); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1417 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1418 } |
|
9849
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1419 /* A bit convoluted because this might overflow; due to Tim Peters */ |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1420 if (istep > 0) { |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1421 if (ihigh <= ilow) |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1422 n = 0; |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1423 else { |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1424 unsigned long hi = (unsigned long)ihigh; |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1425 unsigned long lo = (unsigned long)ilow; |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1426 unsigned long diff = hi - lo - 1; |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1427 n = (long)(diff / istep + 1); |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1428 } |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1429 } |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1430 else { |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1431 /* But any errors in this branch are my own --Guido */ |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1432 if (ihigh >= ilow) |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1433 n = 0; |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1434 else { |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1435 /* Swap lo and hi; use abs(istep) */ |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1436 unsigned long hi = (unsigned long)ilow; |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1437 unsigned long lo = (unsigned long)ihigh; |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1438 unsigned long diff = hi - lo - 1; |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1439 n = (long)(diff / (-istep) + 1); |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1440 } |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1441 } |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1442 if (n < 0) { |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1443 PyErr_SetString(PyExc_OverflowError, |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1444 "range() has more than sys.maxint items"); |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1445 return NULL; |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1446 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1447 v = PyList_New(n); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1448 if (v == NULL) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1449 return NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1450 for (i = 0; i < n; i++) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1451 PyObject *w = PyInt_FromLong(ilow); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1452 if (w == NULL) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1453 Py_DECREF(v); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1454 return NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1455 } |
|
8138
9d0310143600
Fred's right -- we need PyList_SET_ITEM().
Guido van Rossum <guido@python.org>
parents:
8132
diff
changeset
|
1456 PyList_SET_ITEM(v, i, w); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1457 ilow += istep; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1458 } |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1459 return v; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1460 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1461 |
| 8561 | 1462 static char range_doc[] = |
| 1463 "range([start,] stop[, step]) -> list of integers\n\ | |
| 1464 \n\ | |
| 1465 Return a list containing an arithmetic progression of integers.\n\ | |
| 1466 range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.\n\ | |
| 1467 When step is given, it specifies the increment (or decrement).\n\ | |
| 1468 For example, range(4) returns [0, 1, 2, 3]. The end point is omitted!\n\ | |
| 1469 These are exactly the valid indices for a list of 4 elements."; | |
| 1470 | |
| 1471 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1472 static PyObject * |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1473 builtin_xrange(self, args) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1474 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1475 PyObject *args; |
| 86 | 1476 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1477 long ilow = 0, ihigh = 0, istep = 1; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1478 long n; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1479 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1480 if (PyTuple_Size(args) <= 1) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1481 if (!PyArg_ParseTuple(args, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1482 "l;xrange() requires 1-3 int arguments", |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1483 &ihigh)) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1484 return NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1485 } |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1486 else { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1487 if (!PyArg_ParseTuple(args, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1488 "ll|l;xrange() requires 1-3 int arguments", |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1489 &ilow, &ihigh, &istep)) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1490 return NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1491 } |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1492 if (istep == 0) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1493 PyErr_SetString(PyExc_ValueError, "zero step for xrange()"); |
|
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
|
1494 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1495 } |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1496 /* XXX ought to check overflow of subtraction */ |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1497 if (istep > 0) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1498 n = (ihigh - ilow + istep - 1) / istep; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1499 else |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1500 n = (ihigh - ilow + istep + 1) / istep; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1501 if (n < 0) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1502 n = 0; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1503 return PyRange_New(ilow, n, istep, 1); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1504 } |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1505 |
| 8561 | 1506 static char xrange_doc[] = |
| 1507 "xrange([start,] stop[, step]) -> xrange object\n\ | |
| 1508 \n\ | |
| 1509 Like range(), but instead of returning a list, returns an object that\n\ | |
| 1510 generates the numbers in the range on demand. This is slightly slower\n\ | |
| 1511 than range() but more memory efficient."; | |
| 1512 | |
| 1513 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1514 static PyObject * |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1515 builtin_raw_input(self, args) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1516 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1517 PyObject *args; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1518 { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1519 PyObject *v = NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1520 PyObject *f; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1521 |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1522 if (!PyArg_ParseTuple(args, "|O:[raw_]input", &v)) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1523 return NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1524 if (PyFile_AsFile(PySys_GetObject("stdin")) == stdin && |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1525 PyFile_AsFile(PySys_GetObject("stdout")) == stdout && |
|
2857
eebbdbee54f9
be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
1526 isatty(fileno(stdin)) && isatty(fileno(stdout))) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1527 PyObject *po; |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1528 char *prompt; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1529 char *s; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1530 PyObject *result; |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1531 if (v != NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1532 po = PyObject_Str(v); |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1533 if (po == NULL) |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1534 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1535 prompt = PyString_AsString(po); |
|
8560
46fd630dce63
In raw_input(prompt), make sure that str(prompt) really a string
Guido van Rossum <guido@python.org>
parents:
8451
diff
changeset
|
1536 if (prompt == NULL) |
|
46fd630dce63
In raw_input(prompt), make sure that str(prompt) really a string
Guido van Rossum <guido@python.org>
parents:
8451
diff
changeset
|
1537 return NULL; |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1538 } |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1539 else { |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1540 po = NULL; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1541 prompt = ""; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1542 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1543 s = PyOS_Readline(prompt); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1544 Py_XDECREF(po); |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1545 if (s == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1546 PyErr_SetNone(PyExc_KeyboardInterrupt); |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1547 return NULL; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1548 } |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1549 if (*s == '\0') { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1550 PyErr_SetNone(PyExc_EOFError); |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1551 result = NULL; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1552 } |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1553 else { /* strip trailing '\n' */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1554 result = PyString_FromStringAndSize(s, strlen(s)-1); |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1555 } |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1556 free(s); |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1557 return result; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1558 } |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
1559 if (v != NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1560 f = PySys_GetObject("stdout"); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1561 if (f == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1562 PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout"); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1563 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1564 } |
|
5610
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5471
diff
changeset
|
1565 if (Py_FlushLine() != 0 || |
|
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5471
diff
changeset
|
1566 PyFile_WriteObject(v, f, Py_PRINT_RAW) != 0) |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
1567 return NULL; |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
1568 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1569 f = PySys_GetObject("stdin"); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1570 if (f == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1571 PyErr_SetString(PyExc_RuntimeError, "lost sys.stdin"); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1572 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1573 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1574 return PyFile_GetLine(f, -1); |
| 86 | 1575 } |
| 1576 | |
| 8561 | 1577 static char raw_input_doc[] = |
| 1578 "raw_input([prompt]) -> string\n\ | |
| 1579 \n\ | |
| 1580 Read a string from standard input. The trailing newline is stripped.\n\ | |
| 1581 If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.\n\ | |
| 1582 On Unix, GNU readline is used if enabled. The prompt string, if given,\n\ | |
| 1583 is printed without a trailing newline before reading."; | |
| 1584 | |
| 1585 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1586 static PyObject * |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1587 builtin_reduce(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1588 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1589 PyObject *args; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1590 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1591 PyObject *seq, *func, *result = NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1592 PySequenceMethods *sqf; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1593 register int i; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1594 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1595 if (!PyArg_ParseTuple(args, "OO|O:reduce", &func, &seq, &result)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1596 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1597 if (result != NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1598 Py_INCREF(result); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1599 |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1600 sqf = seq->ob_type->tp_as_sequence; |
|
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1601 if (sqf == NULL || sqf->sq_item == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1602 PyErr_SetString(PyExc_TypeError, |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1603 "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
|
1604 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1605 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1606 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1607 if ((args = PyTuple_New(2)) == NULL) |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1608 goto Fail; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1609 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1610 for (i = 0; ; ++i) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1611 PyObject *op2; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1612 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1613 if (args->ob_refcnt > 1) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1614 Py_DECREF(args); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1615 if ((args = PyTuple_New(2)) == NULL) |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1616 goto Fail; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1617 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1618 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1619 if ((op2 = (*sqf->sq_item)(seq, i)) == NULL) { |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1620 if (PyErr_ExceptionMatches(PyExc_IndexError)) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1621 PyErr_Clear(); |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1622 break; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1623 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1624 goto Fail; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1625 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1626 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1627 if (result == NULL) |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1628 result = op2; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1629 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1630 PyTuple_SetItem(args, 0, result); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1631 PyTuple_SetItem(args, 1, op2); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1632 if ((result = PyEval_CallObject(func, args)) == NULL) |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1633 goto Fail; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1634 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1635 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1636 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1637 Py_DECREF(args); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1638 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1639 if (result == NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1640 PyErr_SetString(PyExc_TypeError, |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1641 "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
|
1642 |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1643 return result; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1644 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1645 Fail: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1646 Py_XDECREF(args); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1647 Py_XDECREF(result); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1648 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1649 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1650 |
| 8561 | 1651 static char reduce_doc[] = |
| 1652 "reduce(function, sequence[, initial]) -> value\n\ | |
| 1653 \n\ | |
| 1654 Apply a function of two arguments cumulatively to the items of a sequence,\n\ | |
| 1655 from left to right, so as to reduce the sequence to a single value.\n\ | |
| 1656 For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates\n\ | |
| 1657 ((((1+2)+3)+4)+5). If initial is present, it is placed before the items\n\ | |
| 1658 of the sequence in the calculation, and serves as a default when the\n\ | |
| 1659 sequence is empty."; | |
| 1660 | |
| 1661 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1662 static PyObject * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1663 builtin_reload(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1664 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1665 PyObject *args; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1666 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1667 PyObject *v; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1668 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1669 if (!PyArg_ParseTuple(args, "O:reload", &v)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1670 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1671 return PyImport_ReloadModule(v); |
| 86 | 1672 } |
| 1673 | |
| 8561 | 1674 static char reload_doc[] = |
| 1675 "reload(module) -> module\n\ | |
| 1676 \n\ | |
| 1677 Reload the module. The module must have been successfully imported before."; | |
| 1678 | |
| 1679 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1680 static PyObject * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1681 builtin_repr(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1682 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1683 PyObject *args; |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1684 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1685 PyObject *v; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1686 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1687 if (!PyArg_ParseTuple(args, "O:repr", &v)) |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1688 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1689 return PyObject_Repr(v); |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1690 } |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1691 |
| 8561 | 1692 static char repr_doc[] = |
| 1693 "repr(object) -> string\n\ | |
| 1694 \n\ | |
| 1695 Return the canonical string representation of the object.\n\ | |
| 1696 For most object types, eval(repr(object)) == object."; | |
| 1697 | |
| 1698 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1699 static PyObject * |
|
1215
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1700 builtin_round(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1701 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1702 PyObject *args; |
|
1215
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1703 { |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1704 double x; |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1705 double f; |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1706 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
|
1707 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
|
1708 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1709 if (!PyArg_ParseTuple(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
|
1710 return NULL; |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1711 f = 1.0; |
|
8287
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1712 i = abs(ndigits); |
|
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1713 while (--i >= 0) |
|
1215
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1714 f = f*10.0; |
|
8287
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1715 if (ndigits < 0) |
|
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1716 x /= f; |
|
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1717 else |
|
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1718 x *= f; |
|
1215
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1719 if (x >= 0.0) |
|
8287
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1720 x = floor(x + 0.5); |
|
1215
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1721 else |
|
8287
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1722 x = ceil(x - 0.5); |
|
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1723 if (ndigits < 0) |
|
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1724 x *= f; |
|
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1725 else |
|
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1726 x /= f; |
|
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1727 return PyFloat_FromDouble(x); |
|
1215
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1728 } |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1729 |
| 8561 | 1730 static char round_doc[] = |
| 1731 "round(number[, ndigits]) -> floating point number\n\ | |
| 1732 \n\ | |
| 1733 Round a number to a given precision in decimal digits (default 0 digits).\n\ | |
| 1734 This always returns a floating point number. Precision may be negative."; | |
| 1735 | |
| 1736 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1737 static PyObject * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1738 builtin_str(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1739 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1740 PyObject *args; |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1741 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1742 PyObject *v; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1743 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1744 if (!PyArg_ParseTuple(args, "O:str", &v)) |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1745 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1746 return PyObject_Str(v); |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1747 } |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1748 |
| 8561 | 1749 static char str_doc[] = |
| 1750 "str(object) -> string\n\ | |
| 1751 \n\ | |
| 1752 Return a nice string representation of the object.\n\ | |
| 1753 If the argument is a string, the return value is the same object."; | |
| 1754 | |
| 1755 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1756 static PyObject * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1757 builtin_tuple(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1758 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1759 PyObject *args; |
|
1842
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1760 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1761 PyObject *v; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1762 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1763 if (!PyArg_ParseTuple(args, "O:tuple", &v)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1764 return NULL; |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1765 return PySequence_Tuple(v); |
|
1842
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1766 } |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1767 |
| 8561 | 1768 static char tuple_doc[] = |
| 1769 "tuple(sequence) -> list\n\ | |
| 1770 \n\ | |
| 1771 Return a tuple whose items are the same as those of the argument sequence.\n\ | |
| 1772 If the argument is a tuple, the return value is the same object."; | |
| 1773 | |
| 1774 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1775 static PyObject * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1776 builtin_type(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1777 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1778 PyObject *args; |
| 86 | 1779 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1780 PyObject *v; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1781 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1782 if (!PyArg_ParseTuple(args, "O:type", &v)) |
| 86 | 1783 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1784 v = (PyObject *)v->ob_type; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1785 Py_INCREF(v); |
| 86 | 1786 return v; |
| 1787 } | |
| 1788 | |
| 8561 | 1789 static char type_doc[] = |
| 1790 "type(object) -> type object\n\ | |
| 1791 \n\ | |
| 1792 Return the type of the object."; | |
| 1793 | |
| 1794 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1795 static PyObject * |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1796 builtin_vars(self, args) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1797 PyObject *self; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1798 PyObject *args; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1799 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1800 PyObject *v = NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1801 PyObject *d; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1802 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1803 if (!PyArg_ParseTuple(args, "|O:vars", &v)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1804 return NULL; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1805 if (v == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1806 d = PyEval_GetLocals(); |
|
2857
eebbdbee54f9
be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
1807 if (d == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1808 if (!PyErr_Occurred()) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1809 PyErr_SetString(PyExc_SystemError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1810 "no locals!?"); |
|
2857
eebbdbee54f9
be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
1811 } |
|
eebbdbee54f9
be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
1812 else |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1813 Py_INCREF(d); |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1814 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1815 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1816 d = PyObject_GetAttrString(v, "__dict__"); |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1817 if (d == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1818 PyErr_SetString(PyExc_TypeError, |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1819 "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
|
1820 return NULL; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1821 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1822 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1823 return d; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1824 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1825 |
| 8561 | 1826 static char vars_doc[] = |
| 1827 "vars([object]) -> dictionary\n\ | |
| 1828 \n\ | |
| 1829 Without arguments, equivalent to locals().\n\ | |
| 1830 With an argument, equivalent to object.__dict__."; | |
| 1831 | |
| 1832 | |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1833 static PyObject * |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1834 builtin_isinstance(self, args) |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1835 PyObject *self; |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1836 PyObject *args; |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1837 { |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1838 PyObject *inst; |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1839 PyObject *cls; |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1840 int retval; |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1841 |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1842 if (!PyArg_ParseTuple(args, "OO", &inst, &cls)) |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1843 return NULL; |
|
6706
cbc5e7d6ad23
Support type objects in isinstance().
Guido van Rossum <guido@python.org>
parents:
6334
diff
changeset
|
1844 if (PyType_Check(cls)) { |
|
6812
d85147dce185
Need a cast when comparing type object in isinstance()
Guido van Rossum <guido@python.org>
parents:
6706
diff
changeset
|
1845 retval = ((PyObject *)(inst->ob_type) == cls); |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1846 } |
|
6706
cbc5e7d6ad23
Support type objects in isinstance().
Guido van Rossum <guido@python.org>
parents:
6334
diff
changeset
|
1847 else { |
|
cbc5e7d6ad23
Support type objects in isinstance().
Guido van Rossum <guido@python.org>
parents:
6334
diff
changeset
|
1848 if (!PyClass_Check(cls)) { |
|
cbc5e7d6ad23
Support type objects in isinstance().
Guido van Rossum <guido@python.org>
parents:
6334
diff
changeset
|
1849 PyErr_SetString(PyExc_TypeError, |
|
cbc5e7d6ad23
Support type objects in isinstance().
Guido van Rossum <guido@python.org>
parents:
6334
diff
changeset
|
1850 "second argument must be a class"); |
|
cbc5e7d6ad23
Support type objects in isinstance().
Guido van Rossum <guido@python.org>
parents:
6334
diff
changeset
|
1851 return NULL; |
|
cbc5e7d6ad23
Support type objects in isinstance().
Guido van Rossum <guido@python.org>
parents:
6334
diff
changeset
|
1852 } |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1853 |
|
6706
cbc5e7d6ad23
Support type objects in isinstance().
Guido van Rossum <guido@python.org>
parents:
6334
diff
changeset
|
1854 if (!PyInstance_Check(inst)) |
|
cbc5e7d6ad23
Support type objects in isinstance().
Guido van Rossum <guido@python.org>
parents:
6334
diff
changeset
|
1855 retval = 0; |
|
cbc5e7d6ad23
Support type objects in isinstance().
Guido van Rossum <guido@python.org>
parents:
6334
diff
changeset
|
1856 else { |
|
cbc5e7d6ad23
Support type objects in isinstance().
Guido van Rossum <guido@python.org>
parents:
6334
diff
changeset
|
1857 PyObject *inclass = |
|
cbc5e7d6ad23
Support type objects in isinstance().
Guido van Rossum <guido@python.org>
parents:
6334
diff
changeset
|
1858 (PyObject*)((PyInstanceObject*)inst)->in_class; |
|
cbc5e7d6ad23
Support type objects in isinstance().
Guido van Rossum <guido@python.org>
parents:
6334
diff
changeset
|
1859 retval = PyClass_IsSubclass(inclass, cls); |
|
cbc5e7d6ad23
Support type objects in isinstance().
Guido van Rossum <guido@python.org>
parents:
6334
diff
changeset
|
1860 } |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1861 } |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1862 return PyInt_FromLong(retval); |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1863 } |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1864 |
| 8561 | 1865 static char isinstance_doc[] = |
| 1866 "isinstance(object, class-or-type) -> Boolean\n\ | |
| 1867 \n\ | |
| 1868 Return whether an object is an instance of a class or of a subclass thereof.\n\ | |
| 1869 With a type as second argument, return whether that is the object's type."; | |
| 1870 | |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1871 |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1872 static PyObject * |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1873 builtin_issubclass(self, args) |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1874 PyObject *self; |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1875 PyObject *args; |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1876 { |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1877 PyObject *derived; |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1878 PyObject *cls; |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1879 int retval; |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1880 |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1881 if (!PyArg_ParseTuple(args, "OO", &derived, &cls)) |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1882 return NULL; |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1883 if (!PyClass_Check(derived) || !PyClass_Check(cls)) { |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1884 PyErr_SetString(PyExc_TypeError, "arguments must be classes"); |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1885 return NULL; |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1886 } |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1887 /* shortcut */ |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1888 if (!(retval = (derived == cls))) |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1889 retval = PyClass_IsSubclass(derived, cls); |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1890 |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1891 return PyInt_FromLong(retval); |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1892 } |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1893 |
| 8561 | 1894 static char issubclass_doc[] = |
| 1895 "issubclass(C, B) -> Boolean\n\ | |
| 1896 \n\ | |
| 1897 Return whether class C is a subclass (i.e., a derived class) of class B."; | |
| 1898 | |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1899 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1900 static PyMethodDef builtin_methods[] = { |
| 8561 | 1901 {"__import__", builtin___import__, 1, import_doc}, |
| 1902 {"abs", builtin_abs, 1, abs_doc}, | |
| 1903 {"apply", builtin_apply, 1, apply_doc}, | |
| 1904 {"callable", builtin_callable, 1, callable_doc}, | |
| 1905 {"chr", builtin_chr, 1, chr_doc}, | |
| 1906 {"cmp", builtin_cmp, 1, cmp_doc}, | |
| 1907 {"coerce", builtin_coerce, 1, coerce_doc}, | |
| 1908 {"compile", builtin_compile, 1, compile_doc}, | |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
1909 #ifndef WITHOUT_COMPLEX |
| 8561 | 1910 {"complex", builtin_complex, 1, complex_doc}, |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
1911 #endif |
| 8561 | 1912 {"delattr", builtin_delattr, 1, delattr_doc}, |
| 1913 {"dir", builtin_dir, 1, dir_doc}, | |
| 1914 {"divmod", builtin_divmod, 1, divmod_doc}, | |
| 1915 {"eval", builtin_eval, 1, eval_doc}, | |
| 1916 {"execfile", builtin_execfile, 1, execfile_doc}, | |
| 1917 {"filter", builtin_filter, 1, filter_doc}, | |
| 1918 {"float", builtin_float, 1, float_doc}, | |
| 1919 {"getattr", builtin_getattr, 1, getattr_doc}, | |
| 1920 {"globals", builtin_globals, 1, globals_doc}, | |
| 1921 {"hasattr", builtin_hasattr, 1, hasattr_doc}, | |
| 1922 {"hash", builtin_hash, 1, hash_doc}, | |
| 1923 {"hex", builtin_hex, 1, hex_doc}, | |
| 1924 {"id", builtin_id, 1, id_doc}, | |
| 1925 {"input", builtin_input, 1, input_doc}, | |
| 1926 {"intern", builtin_intern, 1, intern_doc}, | |
| 1927 {"int", builtin_int, 1, int_doc}, | |
| 1928 {"isinstance", builtin_isinstance, 1, isinstance_doc}, | |
| 1929 {"issubclass", builtin_issubclass, 1, issubclass_doc}, | |
| 1930 {"len", builtin_len, 1, len_doc}, | |
| 1931 {"list", builtin_list, 1, list_doc}, | |
| 1932 {"locals", builtin_locals, 1, locals_doc}, | |
| 1933 {"long", builtin_long, 1, long_doc}, | |
| 1934 {"map", builtin_map, 1, map_doc}, | |
| 1935 {"max", builtin_max, 1, max_doc}, | |
| 1936 {"min", builtin_min, 1, min_doc}, | |
| 1937 {"oct", builtin_oct, 1, oct_doc}, | |
| 1938 {"open", builtin_open, 1, open_doc}, | |
| 1939 {"ord", builtin_ord, 1, ord_doc}, | |
| 1940 {"pow", builtin_pow, 1, pow_doc}, | |
| 1941 {"range", builtin_range, 1, range_doc}, | |
| 1942 {"raw_input", builtin_raw_input, 1, raw_input_doc}, | |
| 1943 {"reduce", builtin_reduce, 1, reduce_doc}, | |
| 1944 {"reload", builtin_reload, 1, reload_doc}, | |
| 1945 {"repr", builtin_repr, 1, repr_doc}, | |
| 1946 {"round", builtin_round, 1, round_doc}, | |
| 1947 {"setattr", builtin_setattr, 1, setattr_doc}, | |
| 1948 {"slice", builtin_slice, 1, slice_doc}, | |
| 1949 {"str", builtin_str, 1, str_doc}, | |
| 1950 {"tuple", builtin_tuple, 1, tuple_doc}, | |
| 1951 {"type", builtin_type, 1, type_doc}, | |
| 1952 {"vars", builtin_vars, 1, vars_doc}, | |
| 1953 {"xrange", builtin_xrange, 1, xrange_doc}, | |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
1954 {NULL, NULL}, |
| 86 | 1955 }; |
| 1956 | |
| 1957 /* Predefined exceptions */ | |
| 1958 | |
|
6318
cdc5a40fcf97
Introduce PyExc_Exception as the conceptual root class for all exceptions.
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1959 PyObject *PyExc_Exception; |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
1960 PyObject *PyExc_StandardError; |
|
6326
b0183994021b
[Py_Exc]NumberError => [Py_Exc]ArithmeticError
Barry Warsaw <barry@python.org>
parents:
6318
diff
changeset
|
1961 PyObject *PyExc_ArithmeticError; |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
1962 PyObject *PyExc_LookupError; |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
1963 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1964 PyObject *PyExc_AssertionError; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1965 PyObject *PyExc_AttributeError; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1966 PyObject *PyExc_EOFError; |
|
5471
8e5d6d3103ae
Oops -- missed FloatingPointError in renaming.
Guido van Rossum <guido@python.org>
parents:
5438
diff
changeset
|
1967 PyObject *PyExc_FloatingPointError; |
|
8704
83c8adaa084f
Added support for two new standard errors: EnvironmentError and
Barry Warsaw <barry@python.org>
parents:
8661
diff
changeset
|
1968 PyObject *PyExc_EnvironmentError; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1969 PyObject *PyExc_IOError; |
|
8704
83c8adaa084f
Added support for two new standard errors: EnvironmentError and
Barry Warsaw <barry@python.org>
parents:
8661
diff
changeset
|
1970 PyObject *PyExc_OSError; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1971 PyObject *PyExc_ImportError; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1972 PyObject *PyExc_IndexError; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1973 PyObject *PyExc_KeyError; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1974 PyObject *PyExc_KeyboardInterrupt; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1975 PyObject *PyExc_MemoryError; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1976 PyObject *PyExc_NameError; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1977 PyObject *PyExc_OverflowError; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1978 PyObject *PyExc_RuntimeError; |
|
9567
b7158db347d9
Added new builtin standard exception: NotImplementedError (its C
Barry Warsaw <barry@python.org>
parents:
9514
diff
changeset
|
1979 PyObject *PyExc_NotImplementedError; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1980 PyObject *PyExc_SyntaxError; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1981 PyObject *PyExc_SystemError; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1982 PyObject *PyExc_SystemExit; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1983 PyObject *PyExc_TypeError; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1984 PyObject *PyExc_ValueError; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1985 PyObject *PyExc_ZeroDivisionError; |
| 463 | 1986 |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
1987 PyObject *PyExc_MemoryErrorInst; |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
1988 |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
1989 static struct |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
1990 { |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
1991 char* name; |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
1992 PyObject** exc; |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
1993 int leaf_exc; |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
1994 } |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
1995 bltin_exc[] = { |
|
6318
cdc5a40fcf97
Introduce PyExc_Exception as the conceptual root class for all exceptions.
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
1996 {"Exception", &PyExc_Exception, 0}, |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
1997 {"StandardError", &PyExc_StandardError, 0}, |
|
6326
b0183994021b
[Py_Exc]NumberError => [Py_Exc]ArithmeticError
Barry Warsaw <barry@python.org>
parents:
6318
diff
changeset
|
1998 {"ArithmeticError", &PyExc_ArithmeticError, 0}, |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
1999 {"LookupError", &PyExc_LookupError, 0}, |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2000 {"AssertionError", &PyExc_AssertionError, 1}, |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2001 {"AttributeError", &PyExc_AttributeError, 1}, |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2002 {"EOFError", &PyExc_EOFError, 1}, |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2003 {"FloatingPointError", &PyExc_FloatingPointError, 1}, |
|
8704
83c8adaa084f
Added support for two new standard errors: EnvironmentError and
Barry Warsaw <barry@python.org>
parents:
8661
diff
changeset
|
2004 {"EnvironmentError", &PyExc_EnvironmentError, 1}, |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2005 {"IOError", &PyExc_IOError, 1}, |
|
8704
83c8adaa084f
Added support for two new standard errors: EnvironmentError and
Barry Warsaw <barry@python.org>
parents:
8661
diff
changeset
|
2006 {"OSError", &PyExc_OSError, 1}, |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2007 {"ImportError", &PyExc_ImportError, 1}, |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2008 {"IndexError", &PyExc_IndexError, 1}, |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2009 {"KeyError", &PyExc_KeyError, 1}, |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2010 {"KeyboardInterrupt", &PyExc_KeyboardInterrupt, 1}, |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2011 {"MemoryError", &PyExc_MemoryError, 1}, |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2012 {"NameError", &PyExc_NameError, 1}, |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2013 {"OverflowError", &PyExc_OverflowError, 1}, |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2014 {"RuntimeError", &PyExc_RuntimeError, 1}, |
|
9567
b7158db347d9
Added new builtin standard exception: NotImplementedError (its C
Barry Warsaw <barry@python.org>
parents:
9514
diff
changeset
|
2015 {"NotImplementedError",&PyExc_NotImplementedError,1}, |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2016 {"SyntaxError", &PyExc_SyntaxError, 1}, |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2017 {"SystemError", &PyExc_SystemError, 1}, |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2018 {"SystemExit", &PyExc_SystemExit, 1}, |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2019 {"TypeError", &PyExc_TypeError, 1}, |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2020 {"ValueError", &PyExc_ValueError, 1}, |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2021 {"ZeroDivisionError", &PyExc_ZeroDivisionError, 1}, |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2022 {NULL, NULL} |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2023 }; |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2024 |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2025 |
|
9112
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2026 /* import exceptions module to extract class exceptions. on success, |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2027 * return 1. on failure return 0 which signals _PyBuiltin_Init_2 to fall |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2028 * back to using old-style string based exceptions. |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2029 */ |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2030 static int |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2031 init_class_exc(dict) |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2032 PyObject *dict; |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2033 { |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2034 int i; |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2035 PyObject *m = PyImport_ImportModule("exceptions"); |
|
9112
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2036 PyObject *args = NULL; |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2037 PyObject *d = NULL; |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2038 |
|
9112
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2039 /* make sure we got the module and its dictionary */ |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2040 if (m == NULL || |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2041 (d = PyModule_GetDict(m)) == NULL) |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2042 { |
|
9112
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2043 PySys_WriteStderr("'import exceptions' failed; "); |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2044 if (Py_VerboseFlag) { |
|
9112
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2045 PySys_WriteStderr("traceback:\n"); |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2046 PyErr_Print(); |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2047 } |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2048 else { |
|
9112
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2049 PySys_WriteStderr("use -v for traceback\n"); |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2050 } |
|
9112
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2051 goto finally; |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2052 } |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2053 for (i = 0; bltin_exc[i].name; i++) { |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2054 /* dig the exception out of the module */ |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2055 PyObject *exc = PyDict_GetItemString(d, bltin_exc[i].name); |
|
9112
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2056 if (!exc) { |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2057 PySys_WriteStderr( |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2058 "Built-in exception class not found: %s. Library mismatch?\n", |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2059 bltin_exc[i].name); |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2060 goto finally; |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2061 } |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2062 /* free the old-style exception string object */ |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2063 Py_XDECREF(*bltin_exc[i].exc); |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2064 |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2065 /* squirrel away a pointer to the exception */ |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2066 Py_INCREF(exc); |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2067 *bltin_exc[i].exc = exc; |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2068 |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2069 /* and insert the name in the __builtin__ module */ |
|
9112
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2070 if (PyDict_SetItemString(dict, bltin_exc[i].name, exc)) { |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2071 PySys_WriteStderr( |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2072 "Cannot insert exception into __builtin__: %s\n", |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2073 bltin_exc[i].name); |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2074 goto finally; |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2075 } |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2076 } |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2077 |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2078 /* we need one pre-allocated instance */ |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2079 args = Py_BuildValue("()"); |
|
9112
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2080 if (!args || |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2081 !(PyExc_MemoryErrorInst = |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2082 PyEval_CallObject(PyExc_MemoryError, args))) |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2083 { |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2084 PySys_WriteStderr("Cannot pre-allocate MemoryError instance\n"); |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2085 goto finally; |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2086 } |
|
9112
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2087 Py_DECREF(args); |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2088 |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2089 /* we're done with the exceptions module */ |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2090 Py_DECREF(m); |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2091 |
|
9112
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2092 if (PyErr_Occurred()) { |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2093 PySys_WriteStderr("Cannot initialize standard class exceptions; "); |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2094 if (Py_VerboseFlag) { |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2095 PySys_WriteStderr("traceback:\n"); |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2096 PyErr_Print(); |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2097 } |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2098 else |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2099 PySys_WriteStderr("use -v for traceback\n"); |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2100 goto finally; |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2101 } |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2102 return 1; |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2103 finally: |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2104 Py_XDECREF(m); |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2105 Py_XDECREF(args); |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2106 PyErr_Clear(); |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2107 return 0; |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2108 } |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2109 |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2110 |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2111 static void |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2112 fini_instances() |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2113 { |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2114 Py_XDECREF(PyExc_MemoryErrorInst); |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2115 PyExc_MemoryErrorInst = NULL; |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2116 } |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2117 |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2118 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2119 static PyObject * |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2120 newstdexception(dict, name) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2121 PyObject *dict; |
| 495 | 2122 char *name; |
| 86 | 2123 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2124 PyObject *v = PyString_FromString(name); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2125 if (v == NULL || PyDict_SetItemString(dict, name, v) != 0) |
|
9112
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2126 Py_FatalError("Cannot create string-based exceptions"); |
| 86 | 2127 return v; |
| 2128 } | |
| 2129 | |
| 2130 static void | |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2131 initerrors(dict) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2132 PyObject *dict; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2133 { |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2134 int i; |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2135 int exccnt = 0; |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2136 for (i = 0; bltin_exc[i].name; i++, exccnt++) { |
|
9112
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2137 Py_XDECREF(*bltin_exc[i].exc); |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2138 if (bltin_exc[i].leaf_exc) |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2139 *bltin_exc[i].exc = |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2140 newstdexception(dict, bltin_exc[i].name); |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2141 } |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2142 |
|
8704
83c8adaa084f
Added support for two new standard errors: EnvironmentError and
Barry Warsaw <barry@python.org>
parents:
8661
diff
changeset
|
2143 /* This is kind of bogus because we special case the some of the |
|
83c8adaa084f
Added support for two new standard errors: EnvironmentError and
Barry Warsaw <barry@python.org>
parents:
8661
diff
changeset
|
2144 * new exceptions to be nearly forward compatible. But this means |
|
83c8adaa084f
Added support for two new standard errors: EnvironmentError and
Barry Warsaw <barry@python.org>
parents:
8661
diff
changeset
|
2145 * we hard code knowledge about exceptions.py into C here. I don't |
|
83c8adaa084f
Added support for two new standard errors: EnvironmentError and
Barry Warsaw <barry@python.org>
parents:
8661
diff
changeset
|
2146 * have a better solution, though. |
|
83c8adaa084f
Added support for two new standard errors: EnvironmentError and
Barry Warsaw <barry@python.org>
parents:
8661
diff
changeset
|
2147 */ |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2148 PyExc_LookupError = PyTuple_New(2); |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2149 Py_INCREF(PyExc_IndexError); |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2150 PyTuple_SET_ITEM(PyExc_LookupError, 0, PyExc_IndexError); |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2151 Py_INCREF(PyExc_KeyError); |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2152 PyTuple_SET_ITEM(PyExc_LookupError, 1, PyExc_KeyError); |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2153 PyDict_SetItemString(dict, "LookupError", PyExc_LookupError); |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2154 |
|
6326
b0183994021b
[Py_Exc]NumberError => [Py_Exc]ArithmeticError
Barry Warsaw <barry@python.org>
parents:
6318
diff
changeset
|
2155 PyExc_ArithmeticError = PyTuple_New(3); |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2156 Py_INCREF(PyExc_OverflowError); |
|
6326
b0183994021b
[Py_Exc]NumberError => [Py_Exc]ArithmeticError
Barry Warsaw <barry@python.org>
parents:
6318
diff
changeset
|
2157 PyTuple_SET_ITEM(PyExc_ArithmeticError, 0, PyExc_OverflowError); |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2158 Py_INCREF(PyExc_ZeroDivisionError); |
|
6326
b0183994021b
[Py_Exc]NumberError => [Py_Exc]ArithmeticError
Barry Warsaw <barry@python.org>
parents:
6318
diff
changeset
|
2159 PyTuple_SET_ITEM(PyExc_ArithmeticError, 1, PyExc_ZeroDivisionError); |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2160 Py_INCREF(PyExc_FloatingPointError); |
|
6326
b0183994021b
[Py_Exc]NumberError => [Py_Exc]ArithmeticError
Barry Warsaw <barry@python.org>
parents:
6318
diff
changeset
|
2161 PyTuple_SET_ITEM(PyExc_ArithmeticError, 2, PyExc_FloatingPointError); |
|
b0183994021b
[Py_Exc]NumberError => [Py_Exc]ArithmeticError
Barry Warsaw <barry@python.org>
parents:
6318
diff
changeset
|
2162 PyDict_SetItemString(dict, "ArithmeticError", PyExc_ArithmeticError); |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2163 |
|
8704
83c8adaa084f
Added support for two new standard errors: EnvironmentError and
Barry Warsaw <barry@python.org>
parents:
8661
diff
changeset
|
2164 PyExc_EnvironmentError = PyTuple_New(2); |
|
83c8adaa084f
Added support for two new standard errors: EnvironmentError and
Barry Warsaw <barry@python.org>
parents:
8661
diff
changeset
|
2165 Py_INCREF(PyExc_IOError); |
|
83c8adaa084f
Added support for two new standard errors: EnvironmentError and
Barry Warsaw <barry@python.org>
parents:
8661
diff
changeset
|
2166 PyTuple_SET_ITEM(PyExc_EnvironmentError, 0, PyExc_IOError); |
|
83c8adaa084f
Added support for two new standard errors: EnvironmentError and
Barry Warsaw <barry@python.org>
parents:
8661
diff
changeset
|
2167 Py_INCREF(PyExc_OSError); |
|
83c8adaa084f
Added support for two new standard errors: EnvironmentError and
Barry Warsaw <barry@python.org>
parents:
8661
diff
changeset
|
2168 PyTuple_SET_ITEM(PyExc_EnvironmentError, 1, PyExc_OSError); |
|
83c8adaa084f
Added support for two new standard errors: EnvironmentError and
Barry Warsaw <barry@python.org>
parents:
8661
diff
changeset
|
2169 PyDict_SetItemString(dict, "EnvironmentError", PyExc_EnvironmentError); |
|
83c8adaa084f
Added support for two new standard errors: EnvironmentError and
Barry Warsaw <barry@python.org>
parents:
8661
diff
changeset
|
2170 |
|
6327
4b4775b49bfa
initerrors(): Eliminate circular reference which was causing a small
Barry Warsaw <barry@python.org>
parents:
6326
diff
changeset
|
2171 PyExc_StandardError = PyTuple_New(exccnt-2); |
|
4b4775b49bfa
initerrors(): Eliminate circular reference which was causing a small
Barry Warsaw <barry@python.org>
parents:
6326
diff
changeset
|
2172 for (i = 2; bltin_exc[i].name; i++) { |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2173 PyObject *exc = *bltin_exc[i].exc; |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2174 Py_INCREF(exc); |
|
6327
4b4775b49bfa
initerrors(): Eliminate circular reference which was causing a small
Barry Warsaw <barry@python.org>
parents:
6326
diff
changeset
|
2175 PyTuple_SET_ITEM(PyExc_StandardError, i-2, exc); |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2176 } |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2177 PyDict_SetItemString(dict, "StandardError", PyExc_StandardError); |
|
6318
cdc5a40fcf97
Introduce PyExc_Exception as the conceptual root class for all exceptions.
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
2178 |
|
cdc5a40fcf97
Introduce PyExc_Exception as the conceptual root class for all exceptions.
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
2179 /* Exception is treated differently; for now, it's == StandardError */ |
|
cdc5a40fcf97
Introduce PyExc_Exception as the conceptual root class for all exceptions.
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
2180 PyExc_Exception = PyExc_StandardError; |
|
cdc5a40fcf97
Introduce PyExc_Exception as the conceptual root class for all exceptions.
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
2181 Py_INCREF(PyExc_Exception); |
|
cdc5a40fcf97
Introduce PyExc_Exception as the conceptual root class for all exceptions.
Guido van Rossum <guido@python.org>
parents:
6243
diff
changeset
|
2182 PyDict_SetItemString(dict, "Exception", PyExc_Exception); |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2183 |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2184 if (PyErr_Occurred()) |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2185 Py_FatalError("Could not initialize built-in string exceptions"); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2186 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2187 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2188 static void |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2189 finierrors() |
| 86 | 2190 { |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2191 int i; |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2192 for (i = 0; bltin_exc[i].name; i++) { |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2193 PyObject *exc = *bltin_exc[i].exc; |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2194 Py_XDECREF(exc); |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2195 *bltin_exc[i].exc = NULL; |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2196 } |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2197 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2198 |
| 8561 | 2199 static char builtin_doc[] = |
| 2200 "Built-in functions, exceptions, and other objects.\n\ | |
| 2201 \n\ | |
| 2202 Noteworthy: None is the `nil' object; Ellipsis represents `...' in slices."; | |
| 2203 | |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2204 PyObject * |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2205 _PyBuiltin_Init_1() |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2206 { |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2207 PyObject *mod, *dict; |
| 8561 | 2208 mod = Py_InitModule4("__builtin__", builtin_methods, |
| 2209 builtin_doc, (PyObject *)NULL, | |
| 2210 PYTHON_API_VERSION); | |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2211 if (mod == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2212 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2213 dict = PyModule_GetDict(mod); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2214 initerrors(dict); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2215 if (PyDict_SetItemString(dict, "None", Py_None) < 0) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2216 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2217 if (PyDict_SetItemString(dict, "Ellipsis", Py_Ellipsis) < 0) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2218 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2219 if (PyDict_SetItemString(dict, "__debug__", |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2220 PyInt_FromLong(Py_OptimizeFlag == 0)) < 0) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2221 return NULL; |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2222 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2223 return mod; |
| 86 | 2224 } |
| 2225 | |
| 2226 void | |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2227 _PyBuiltin_Init_2(dict) |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2228 PyObject *dict; |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2229 { |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2230 /* if Python was started with -X, initialize the class exceptions */ |
|
9112
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2231 if (Py_UseClassExceptionsFlag) { |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2232 if (!init_class_exc(dict)) { |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2233 /* class based exceptions could not be |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2234 * initialized. Fall back to using string based |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2235 * exceptions. |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2236 */ |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2237 PySys_WriteStderr( |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2238 "Warning! Falling back to string-based exceptions\n"); |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2239 initerrors(dict); |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2240 } |
|
83660cda3e3f
Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents:
9069
diff
changeset
|
2241 } |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2242 } |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2243 |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2244 |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2245 void |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2246 _PyBuiltin_Fini_1() |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2247 { |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2248 fini_instances(); |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2249 } |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2250 |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2251 |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2252 void |
|
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2253 _PyBuiltin_Fini_2() |
| 86 | 2254 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2255 finierrors(); |
| 86 | 2256 } |
|
301
c28fabe21165
Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
2257 |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2258 |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1387
diff
changeset
|
2259 /* 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
|
2260 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2261 static PyObject * |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2262 filtertuple(func, tuple) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2263 PyObject *func; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2264 PyObject *tuple; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2265 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2266 PyObject *result; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2267 register int i, j; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2268 int len = PyTuple_Size(tuple); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2269 |
|
2890
04e1690fb4d1
avoid resize of 0-length tuple
Guido van Rossum <guido@python.org>
parents:
2857
diff
changeset
|
2270 if (len == 0) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2271 Py_INCREF(tuple); |
|
2890
04e1690fb4d1
avoid resize of 0-length tuple
Guido van Rossum <guido@python.org>
parents:
2857
diff
changeset
|
2272 return tuple; |
|
04e1690fb4d1
avoid resize of 0-length tuple
Guido van Rossum <guido@python.org>
parents:
2857
diff
changeset
|
2273 } |
|
04e1690fb4d1
avoid resize of 0-length tuple
Guido van Rossum <guido@python.org>
parents:
2857
diff
changeset
|
2274 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2275 if ((result = PyTuple_New(len)) == NULL) |
|
1387
f992ac2a38d5
* rangeobject.{c,h}, bltinmodule.c: removed non-essential ops from range
Guido van Rossum <guido@python.org>
parents:
1380
diff
changeset
|
2276 return NULL; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2277 |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
2278 for (i = j = 0; i < len; ++i) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2279 PyObject *item, *good; |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
2280 int ok; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2281 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2282 if ((item = PyTuple_GetItem(tuple, i)) == NULL) |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
2283 goto Fail_1; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2284 if (func == Py_None) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2285 Py_INCREF(item); |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
2286 good = item; |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
2287 } |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
2288 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2289 PyObject *arg = Py_BuildValue("(O)", item); |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
2290 if (arg == NULL) |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
2291 goto Fail_1; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2292 good = PyEval_CallObject(func, arg); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2293 Py_DECREF(arg); |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
2294 if (good == NULL) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2295 goto Fail_1; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2296 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2297 ok = PyObject_IsTrue(good); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2298 Py_DECREF(good); |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
2299 if (ok) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2300 Py_INCREF(item); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2301 if (PyTuple_SetItem(result, j++, item) < 0) |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
2302 goto Fail_1; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2303 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2304 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2305 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2306 if (_PyTuple_Resize(&result, j, 0) < 0) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2307 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2308 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2309 return result; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2310 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2311 Fail_1: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2312 Py_DECREF(result); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2313 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2314 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2315 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2316 |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1387
diff
changeset
|
2317 /* 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
|
2318 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2319 static PyObject * |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2320 filterstring(func, strobj) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2321 PyObject *func; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2322 PyObject *strobj; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2323 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2324 PyObject *result; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2325 register int i, j; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2326 int len = PyString_Size(strobj); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2327 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2328 if (func == Py_None) { |
|
1387
f992ac2a38d5
* rangeobject.{c,h}, bltinmodule.c: removed non-essential ops from range
Guido van Rossum <guido@python.org>
parents:
1380
diff
changeset
|
2329 /* No character is ever false -- share input string */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2330 Py_INCREF(strobj); |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
2331 return strobj; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2332 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2333 if ((result = PyString_FromStringAndSize(NULL, len)) == NULL) |
|
1387
f992ac2a38d5
* rangeobject.{c,h}, bltinmodule.c: removed non-essential ops from range
Guido van Rossum <guido@python.org>
parents:
1380
diff
changeset
|
2334 return NULL; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2335 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2336 for (i = j = 0; i < len; ++i) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2337 PyObject *item, *arg, *good; |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
2338 int ok; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2339 |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
2340 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
|
2341 if (item == NULL) |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
2342 goto Fail_1; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2343 arg = Py_BuildValue("(O)", item); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2344 Py_DECREF(item); |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
2345 if (arg == NULL) |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
2346 goto Fail_1; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2347 good = PyEval_CallObject(func, arg); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2348 Py_DECREF(arg); |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
2349 if (good == NULL) |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
2350 goto Fail_1; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2351 ok = PyObject_IsTrue(good); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2352 Py_DECREF(good); |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
2353 if (ok) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2354 PyString_AS_STRING((PyStringObject *)result)[j++] = |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2355 PyString_AS_STRING((PyStringObject *)item)[0]; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2356 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2357 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2358 if (j < len && _PyString_Resize(&result, j) < 0) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2359 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2360 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2361 return result; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2362 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2363 Fail_1: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2364 Py_DECREF(result); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2365 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2366 } |
