annotate Python/bltinmodule.c @ 12149:0ac577eb8282 legacy-trunk

rename args variable in CALL_FUNCTION to callargs (avoids name override) add missing DECREFs in error handling code of CALL_FUNCTION
author Jeremy Hylton <jeremy@alum.mit.edu>
date Fri, 31 Mar 2000 01:22:54 +0000
parents 8bdc25d22925
children 70154e2e9c89
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 /* Built-in functions */
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
35
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
68 static char import_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
69 "__import__(name, globals, locals, fromlist) -> module\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
70 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
71 Import a module. The globals are only used to determine the context;\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
72 they are not modified. The locals are currently unused. The fromlist\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
73 should be a list of names to emulate ``from name import ...'', or an\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
74 empty list to emulate ``import name''.\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
75 When importing a module from a package, note that __import__('A.B', ...)\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
76 returns package A when fromlist is empty, but its submodule B when\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
77 fromlist is not empty.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
91
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
92 static char abs_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
93 "abs(number) -> number\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
94 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
95 Return the absolute value of the argument.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
96
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
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
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
132 static char apply_doc[] =
11621
0ec803cbd872 Adjusted apply() docstring based on comments from Gerrit Holl
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
133 "apply(object, args[, kwargs]) -> value\n\
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
134 \n\
11621
0ec803cbd872 Adjusted apply() docstring based on comments from Gerrit Holl
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
135 Call a callable object with positional arguments taken from the tuple args,\n\
0ec803cbd872 Adjusted apply() docstring based on comments from Gerrit Holl
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
136 and keyword arguments taken from the optional dictionary kwargs.\n\
0ec803cbd872 Adjusted apply() docstring based on comments from Gerrit Holl
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
137 Note that classes are callable, as are instances with a __call__() method.";
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
138
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
139
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
140 static PyObject *
10428
3571b4c1bc0e New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents: 10292
diff changeset
141 builtin_buffer(self, args)
3571b4c1bc0e New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents: 10292
diff changeset
142 PyObject *self;
3571b4c1bc0e New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents: 10292
diff changeset
143 PyObject *args;
3571b4c1bc0e New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents: 10292
diff changeset
144 {
3571b4c1bc0e New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents: 10292
diff changeset
145 PyObject *ob;
3571b4c1bc0e New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents: 10292
diff changeset
146 int offset = 0;
3571b4c1bc0e New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents: 10292
diff changeset
147 int size = Py_END_OF_BUFFER;
3571b4c1bc0e New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents: 10292
diff changeset
148
3571b4c1bc0e New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents: 10292
diff changeset
149 if ( !PyArg_ParseTuple(args, "O|ii:buffer", &ob, &offset, &size) )
3571b4c1bc0e New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents: 10292
diff changeset
150 return NULL;
3571b4c1bc0e New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents: 10292
diff changeset
151 return PyBuffer_FromObject(ob, offset, size);
3571b4c1bc0e New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents: 10292
diff changeset
152 }
3571b4c1bc0e New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents: 10292
diff changeset
153
3571b4c1bc0e New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents: 10292
diff changeset
154 static char buffer_doc[] =
11973
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
155 "buffer(object [, offset[, size]]) -> object\n\
10428
3571b4c1bc0e New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents: 10292
diff changeset
156 \n\
3571b4c1bc0e New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents: 10292
diff changeset
157 Creates a new buffer object which references the given object.\n\
3571b4c1bc0e New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents: 10292
diff changeset
158 The buffer will reference a slice of the target object from the\n\
3571b4c1bc0e New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents: 10292
diff changeset
159 start of the object (or at the specified offset). The slice will\n\
3571b4c1bc0e New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents: 10292
diff changeset
160 extend to the end of the target object (or with the specified size).";
3571b4c1bc0e New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents: 10292
diff changeset
161
3571b4c1bc0e New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents: 10292
diff changeset
162
3571b4c1bc0e New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents: 10292
diff changeset
163 static PyObject *
11973
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
164 builtin_unicode(self, args)
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
165 PyObject *self;
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
166 PyObject *args;
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
167 {
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
168 char *s;
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
169 int len;
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
170 char *encoding = NULL;
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
171 char *errors = NULL;
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
172
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
173 if ( !PyArg_ParseTuple(args, "s#|ss:unicode", &s, &len,
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
174 &encoding, &errors) )
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
175 return NULL;
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
176 return PyUnicode_Decode(s, len, encoding, errors);
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
177 }
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
178
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
179 static char unicode_doc[] =
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
180 "unicode(string [, encoding[, errors]]) -> object\n\
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
181 \n\
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
182 Creates a new unicode object from the given encoded string.\n\
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
183 encoding defaults to 'utf-8' and errors, defining the error handling,\n\
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
184 to 'strict'.";
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
185
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
186
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
187 static PyObject *
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
188 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
189 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
190 PyObject *args;
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
191 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
192 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
193
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
194 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
195 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
196 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
197 }
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
198
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
199 static char callable_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
200 "callable(object) -> Boolean\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
201 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
202 Return whether the object is callable (i.e., some kind of function).\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
203 Note that classes are callable, as are instances with a __call__() method.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
204
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
205
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
206 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
207 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
208 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
209 PyObject *args;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
210 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
211 PyObject *func, *seq, *result;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
212 PySequenceMethods *sqf;
1375
f3a325662d39 * listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
213 int len;
f3a325662d39 * listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
214 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
215
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
216 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
217 return NULL;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
218
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
219 if (PyString_Check(seq)) {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
220 PyObject *r = filterstring(func, seq);
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
221 return r;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
222 }
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
223
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
224 if (PyTuple_Check(seq)) {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
225 PyObject *r = filtertuple(func, seq);
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
226 return r;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
227 }
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
228
8402
0cb0394c2edc A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents: 8287
diff changeset
229 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
230 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
231 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
232 "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
233 goto Fail_2;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
234 }
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
235
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
236 if ((len = (*sqf->sq_length)(seq)) < 0)
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
237 goto Fail_2;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
238
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
239 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
240 Py_INCREF(seq);
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
241 result = seq;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
242 }
1375
f3a325662d39 * listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
243 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
244 if ((result = PyList_New(len)) == NULL)
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
245 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
246 }
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
247
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
248 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
249 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
250 int ok;
f3a325662d39 * listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
251
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
252 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
253 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
254 PyErr_Clear();
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
255 break;
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
256 }
1375
f3a325662d39 * listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
257 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
258 }
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
259
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
260 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
261 good = item;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
262 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
263 }
f3a325662d39 * listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
264 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
265 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
266 if (arg == NULL)
f3a325662d39 * listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
267 goto Fail_1;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
268 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
269 Py_DECREF(arg);
2120
84b61fe44573 fix subtle refcount big in filter() -- Tim MacKenzie
Guido van Rossum <guido@python.org>
parents: 2113
diff changeset
270 if (good == NULL) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
271 Py_DECREF(item);
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
272 goto Fail_1;
2120
84b61fe44573 fix subtle refcount big in filter() -- Tim MacKenzie
Guido van Rossum <guido@python.org>
parents: 2113
diff changeset
273 }
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
274 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
275 ok = PyObject_IsTrue(good);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
276 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
277 if (ok) {
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
278 if (j < len) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
279 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
280 goto Fail_1;
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
281 }
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
282 else {
9991
ddbbed8cb830 builtin_map(): A better fix for the previous leak plug (remember
Barry Warsaw <barry@python.org>
parents: 9980
diff changeset
283 int status = PyList_Append(result, item);
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
284 j++;
9991
ddbbed8cb830 builtin_map(): A better fix for the previous leak plug (remember
Barry Warsaw <barry@python.org>
parents: 9980
diff changeset
285 Py_DECREF(item);
ddbbed8cb830 builtin_map(): A better fix for the previous leak plug (remember
Barry Warsaw <barry@python.org>
parents: 9980
diff changeset
286 if (status < 0)
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
287 goto Fail_1;
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
288 }
2120
84b61fe44573 fix subtle refcount big in filter() -- Tim MacKenzie
Guido van Rossum <guido@python.org>
parents: 2113
diff changeset
289 } else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
290 Py_DECREF(item);
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
291 }
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
292 }
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
293
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
294
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
295 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
296 goto Fail_1;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
297
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
298 return result;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
299
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
300 Fail_1:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
301 Py_DECREF(result);
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
302 Fail_2:
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
303 return NULL;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
304 }
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
305
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
306 static char filter_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
307 "filter(function, sequence) -> list\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
308 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
309 Return a list containing those items of sequence for which function(item)\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
310 is true. If function is None, return a list of items that are true.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
311
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
312
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
313 static PyObject *
959
68b302ad84a1 use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents: 955
diff changeset
314 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
315 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
316 PyObject *args;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
317 {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
318 long x;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
319 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
320
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
321 if (!PyArg_ParseTuple(args, "l:chr", &x))
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
322 return NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
323 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
324 PyErr_SetString(PyExc_ValueError,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
325 "chr() arg not in range(256)");
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
326 return NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
327 }
5317
c72c7e1930b3 Keep gcc -Wall and Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents: 5223
diff changeset
328 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
329 return PyString_FromStringAndSize(s, 1);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
330 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
331
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
332 static char chr_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
333 "chr(i) -> character\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
334 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
335 Return a string of one character with ordinal i; 0 <= i < 256.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
336
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
337
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
338 static PyObject *
11973
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
339 builtin_unichr(self, args)
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
340 PyObject *self;
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
341 PyObject *args;
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
342 {
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
343 long x;
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
344 Py_UNICODE s[1];
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
345
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
346 if (!PyArg_ParseTuple(args, "l:unichr", &x))
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
347 return NULL;
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
348 if (x < 0 || x >= 65536) {
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
349 PyErr_SetString(PyExc_ValueError,
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
350 "unichr() arg not in range(65536)");
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
351 return NULL;
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
352 }
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
353 s[0] = (Py_UNICODE)x;
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
354 return PyUnicode_FromUnicode(s, 1);
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
355 }
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
356
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
357 static char unichr_doc[] =
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
358 "unichr(i) -> unicode character\n\
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
359 \n\
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
360 Return a unicode string of one character with ordinal i; 0 <= i < 65536.";
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
361
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
362
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
363 static PyObject *
1079
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
364 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
365 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
366 PyObject *args;
1079
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
367 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
368 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
369 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
370
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
371 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
372 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
373 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
374 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
375 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
376 }
e4c6a0dd5c2b * bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
377
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
378 static char cmp_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
379 "cmp(x, y) -> integer\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
380 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
381 Return negative if x<y, zero if x==y, positive if x>y.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
382
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
383
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
384 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
385 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
386 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
387 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
388 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
389 PyObject *v, *w;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
390 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
391
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
392 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
393 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
394 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
395 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
396 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
397 Py_DECREF(v);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
398 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
399 return res;
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
400 }
222f04f55083 Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
401
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
402 static char coerce_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
403 "coerce(x, y) -> None or (x1, y1)\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
404 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
405 When x and y can be coerced to values of the same type, return a tuple\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
406 containing the coerced values. When they can't be coerced, return None.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
407
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
408
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
409 static PyObject *
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
410 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
411 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
412 PyObject *args;
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
413 {
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
414 char *str;
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
415 char *filename;
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
416 char *startstr;
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
417 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
418
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
419 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
420 return NULL;
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
421 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
422 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
423 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
424 start = Py_eval_input;
2808
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
425 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
426 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
427 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
428 PyErr_SetString(PyExc_ValueError,
2808
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
429 "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
430 return NULL;
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
431 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
432 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
433 }
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
434
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
435 static char compile_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
436 "compile(source, filename, mode) -> code object\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
437 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
438 Compile the source string (a Python module, statement or expression)\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
439 into a code object that can be executed by the exec statement or eval().\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
440 The filename will be used for run-time error messages.\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
441 The mode must be 'exec' to compile a module, 'single' to compile a\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
442 single (interactive) statement, or 'eval' to compile an expression.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
443
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
444
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 2890
diff changeset
445 #ifndef WITHOUT_COMPLEX
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 2890
diff changeset
446
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
447 static PyObject *
10466
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
448 complex_from_string(v)
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
449 PyObject *v;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
450 {
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
451 extern double strtod Py_PROTO((const char *, char **));
10529
540c8173e4fd Remove unused variable from complex_from_string() code.
Guido van Rossum <guido@python.org>
parents: 10466
diff changeset
452 char *s, *start, *end;
10466
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
453 double x=0.0, y=0.0, z;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
454 int got_re=0, got_im=0, done=0;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
455 int digit_or_dot;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
456 int sw_error=0;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
457 int sign;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
458 char buffer[256]; /* For errors */
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
459
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
460 start = s = PyString_AS_STRING(v);
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
461
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
462 /* position on first nonblank */
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
463 while (*s && isspace(Py_CHARMASK(*s)))
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
464 s++;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
465 if (s[0] == '\0') {
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
466 PyErr_SetString(PyExc_ValueError,
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
467 "empty string for complex()");
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
468 return NULL;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
469 }
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
470
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
471 z = -1.0;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
472 sign = 1;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
473 do {
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
474
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
475 switch (*s) {
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
476
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
477 case '\0':
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
478 if (s-start != PyString_GET_SIZE(v)) {
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
479 PyErr_SetString(
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
480 PyExc_ValueError,
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
481 "null byte in argument for complex()");
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
482 return NULL;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
483 }
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
484 if(!done) sw_error=1;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
485 break;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
486
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
487 case '-':
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
488 sign = -1;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
489 /* Fallthrough */
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
490 case '+':
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
491 if (done) sw_error=1;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
492 s++;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
493 if ( *s=='\0'||*s=='+'||*s=='-' ||
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
494 isspace(Py_CHARMASK(*s)) ) sw_error=1;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
495 break;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
496
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
497 case 'J':
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
498 case 'j':
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
499 if (got_im || done) {
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
500 sw_error = 1;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
501 break;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
502 }
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
503 if (z<0.0) {
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
504 y=sign;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
505 }
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
506 else{
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
507 y=sign*z;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
508 }
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
509 got_im=1;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
510 s++;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
511 if (*s!='+' && *s!='-' )
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
512 done=1;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
513 break;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
514
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
515 default:
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
516 if (isspace(Py_CHARMASK(*s))) {
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
517 while (*s && isspace(Py_CHARMASK(*s)))
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
518 s++;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
519 if (s[0] != '\0')
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
520 sw_error=1;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
521 else
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
522 done = 1;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
523 break;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
524 }
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
525 digit_or_dot =
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
526 (*s=='.' || isdigit(Py_CHARMASK(*s)));
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
527 if (done||!digit_or_dot) {
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
528 sw_error=1;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
529 break;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
530 }
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
531 errno = 0;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
532 PyFPE_START_PROTECT("strtod", return 0)
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
533 z = strtod(s, &end) ;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
534 PyFPE_END_PROTECT(z)
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
535 if (errno != 0) {
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
536 sprintf(buffer,
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
537 "float() out of range: %.150s", s);
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
538 PyErr_SetString(
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
539 PyExc_ValueError,
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
540 buffer);
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
541 return NULL;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
542 }
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
543 s=end;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
544 if (*s=='J' || *s=='j') {
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
545
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
546 break;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
547 }
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
548 if (got_re) {
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
549 sw_error=1;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
550 break;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
551 }
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
552
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
553 /* accept a real part */
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
554 x=sign*z;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
555 got_re=1;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
556 if (got_im) done=1;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
557 z = -1.0;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
558 sign = 1;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
559 break;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
560
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
561 } /* end of switch */
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
562
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
563 } while (*s!='\0' && !sw_error);
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
564
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
565 if (sw_error) {
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
566 PyErr_SetString(PyExc_ValueError,
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
567 "malformed string for complex()");
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
568 return NULL;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
569 }
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
570
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
571 return PyComplex_FromDoubles(x,y);
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
572 }
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
573
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
574 static PyObject *
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 2890
diff changeset
575 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
576 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
577 PyObject *args;
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 2890
diff changeset
578 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
579 PyObject *r, *i, *tmp;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
580 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
581 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
582 int own_r = 0;
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 2890
diff changeset
583
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 2890
diff changeset
584 i = NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
585 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
586 return NULL;
10466
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
587 if (PyString_Check(r))
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
588 return complex_from_string(r);
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 2890
diff changeset
589 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
590 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
591 (i != NULL &&
bc8832b52b50 1. Add string conversions to int(), long(), float(). (Not to complex()!)
Guido van Rossum <guido@python.org>
parents: 5182
diff changeset
592 ((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
593 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
594 PyErr_SetString(PyExc_TypeError,
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 2890
diff changeset
595 "complex() argument can't be converted to complex");
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 2890
diff changeset
596 return NULL;
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 2890
diff changeset
597 }
4595
f8f3da3fdaed Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
598 /* 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
599 if (PyInstance_Check(r)) {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
600 static PyObject *complexstr;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
601 PyObject *f;
4595
f8f3da3fdaed Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
602 if (complexstr == NULL) {
5010
f0cf8d275fbc Intern the string "__complex__".
Guido van Rossum <guido@python.org>
parents: 4655
diff changeset
603 complexstr = PyString_InternFromString("__complex__");
4595
f8f3da3fdaed Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
604 if (complexstr == NULL)
f8f3da3fdaed Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
605 return NULL;
f8f3da3fdaed Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
606 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
607 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
608 if (f == NULL)
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
609 PyErr_Clear();
4595
f8f3da3fdaed Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
610 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
611 PyObject *args = Py_BuildValue("()");
4595
f8f3da3fdaed Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
612 if (args == NULL)
f8f3da3fdaed Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
613 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
614 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
615 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
616 Py_DECREF(f);
4595
f8f3da3fdaed Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
617 if (r == NULL)
f8f3da3fdaed Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
618 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
619 own_r = 1;
4595
f8f3da3fdaed Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
620 }
f8f3da3fdaed Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
621 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
622 if (PyComplex_Check(r)) {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
623 cr = ((PyComplexObject*)r)->cval;
7982
a909a2869ac5 Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 7678
diff changeset
624 if (own_r) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
625 Py_DECREF(r);
7982
a909a2869ac5 Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 7678
diff changeset
626 }
5223
bc8832b52b50 1. Add string conversions to int(), long(), float(). (Not to complex()!)
Guido van Rossum <guido@python.org>
parents: 5182
diff changeset
627 }
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 2890
diff changeset
628 else {
3962
f08d7f368ebf Include mymath.h instead of declaring prototypes for math functions.
Guido van Rossum <guido@python.org>
parents: 3862
diff changeset
629 tmp = (*nbr->nb_float)(r);
7982
a909a2869ac5 Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 7678
diff changeset
630 if (own_r) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
631 Py_DECREF(r);
7982
a909a2869ac5 Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 7678
diff changeset
632 }
3962
f08d7f368ebf Include mymath.h instead of declaring prototypes for math functions.
Guido van Rossum <guido@python.org>
parents: 3862
diff changeset
633 if (tmp == NULL)
f08d7f368ebf Include mymath.h instead of declaring prototypes for math functions.
Guido van Rossum <guido@python.org>
parents: 3862
diff changeset
634 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
635 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
636 Py_DECREF(tmp);
10466
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
637 cr.imag = 0.0;
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 2890
diff changeset
638 }
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 2890
diff changeset
639 if (i == NULL) {
10466
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
640 ci.real = 0.0;
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
641 ci.imag = 0.0;
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 2890
diff changeset
642 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
643 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
644 ci = ((PyComplexObject*)i)->cval;
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 2890
diff changeset
645 else {
5223
bc8832b52b50 1. Add string conversions to int(), long(), float(). (Not to complex()!)
Guido van Rossum <guido@python.org>
parents: 5182
diff changeset
646 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
647 if (tmp == NULL)
f08d7f368ebf Include mymath.h instead of declaring prototypes for math functions.
Guido van Rossum <guido@python.org>
parents: 3862
diff changeset
648 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
649 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
650 Py_DECREF(tmp);
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 2890
diff changeset
651 ci.imag = 0.;
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 2890
diff changeset
652 }
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 2890
diff changeset
653 cr.real -= ci.imag;
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 2890
diff changeset
654 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
655 return PyComplex_FromCComplex(cr);
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 2890
diff changeset
656 }
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 2890
diff changeset
657
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
658 static char complex_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
659 "complex(real[, imag]) -> complex number\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
660 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
661 Create a complex number from a real part and an optional imaginary part.\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
662 This is equivalent to (real + imag*1j) where imag defaults to 0.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
663
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
664
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 2890
diff changeset
665 #endif
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 2890
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 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
668 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
669 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
670 PyObject *args;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
671 {
5421
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
672 static char *attrlist[] = {"__members__", "__methods__", NULL};
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
673 PyObject *v = NULL, *l = NULL, *m = NULL;
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
674 PyObject *d, *x;
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
675 int i;
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
676 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
677
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
678 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
679 return NULL;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
680 if (v == NULL) {
5421
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
681 x = PyEval_GetLocals();
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
682 if (x == NULL)
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
683 goto error;
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
684 l = PyMapping_Keys(x);
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
685 if (l == NULL)
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
686 goto error;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
687 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
688 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
689 d = PyObject_GetAttrString(v, "__dict__");
5421
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
690 if (d == NULL)
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
691 PyErr_Clear();
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
692 else {
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
693 l = PyMapping_Keys(d);
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
694 if (l == NULL)
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
695 PyErr_Clear();
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
696 Py_DECREF(d);
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
697 }
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
698 if (l == NULL) {
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
699 l = PyList_New(0);
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
700 if (l == NULL)
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
701 goto error;
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
702 }
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
703 for (s = attrlist; *s != NULL; s++) {
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
704 m = PyObject_GetAttrString(v, *s);
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
705 if (m == NULL) {
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
706 PyErr_Clear();
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
707 continue;
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
708 }
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
709 for (i = 0; ; i++) {
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
710 x = PySequence_GetItem(m, i);
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
711 if (x == NULL) {
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
712 PyErr_Clear();
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
713 break;
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
714 }
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
715 if (PyList_Append(l, x) != 0) {
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
716 Py_DECREF(x);
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
717 Py_DECREF(m);
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
718 goto error;
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
719 }
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
720 Py_DECREF(x);
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
721 }
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
722 Py_DECREF(m);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
723 }
385
039aee6cbd78 Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents: 332
diff changeset
724 }
5421
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
725 if (PyList_Sort(l) != 0)
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
726 goto error;
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
727 return l;
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
728 error:
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
729 Py_XDECREF(l);
dacbfaa07c40 New dir() function --
Guido van Rossum <guido@python.org>
parents: 5388
diff changeset
730 return NULL;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
731 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
732
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
733 static char dir_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
734 "dir([object]) -> list of strings\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
735 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
736 Return an alphabetized list of names comprising (some of) the attributes\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
737 of the given object. Without an argument, the names in the current scope\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
738 are listed. With an instance argument, only the instance attributes are\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
739 returned. With a class argument, attributes of the base class are not\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
740 returned. For other types or arguments, this may list members or methods.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
741
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
742
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
743 static PyObject *
2087
65146b52f16b * Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
744 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
745 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
746 PyObject *args;
2087
65146b52f16b * Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
747 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
748 PyObject *v, *w;
2087
65146b52f16b * Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
749
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
750 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
751 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
752 return PyNumber_Divmod(v, w);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
753 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
754
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
755 static char divmod_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
756 "divmod(x, y) -> (div, mod)\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
757 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
758 Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
759
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
760
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
761 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
762 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
763 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
764 PyObject *args;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
765 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
766 PyObject *cmd;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
767 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
768 char *str;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2002
diff changeset
769
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
770 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
771 &cmd,
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
772 &PyDict_Type, &globals,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
773 &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
774 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
775 if (globals == Py_None) {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
776 globals = PyEval_GetGlobals();
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
777 if (locals == Py_None)
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
778 locals = PyEval_GetLocals();
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2087
diff changeset
779 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
780 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
781 locals = globals;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
782 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
783 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
784 PyEval_GetBuiltins()) != 0)
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2087
diff changeset
785 return NULL;
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2087
diff changeset
786 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
787 if (PyCode_Check(cmd))
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
788 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
789 if (!PyString_Check(cmd)) {
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,
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2002
diff changeset
791 "eval() argument 1 must be string or code object");
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
792 return NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
793 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
794 str = PyString_AsString(cmd);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
795 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
796 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
797 "embedded '\\0' in string arg");
959
68b302ad84a1 use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents: 955
diff changeset
798 return NULL;
68b302ad84a1 use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents: 955
diff changeset
799 }
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2002
diff changeset
800 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
801 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
802 return PyRun_String(str, Py_eval_input, globals, locals);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
803 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
804
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
805 static char eval_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
806 "eval(source[, globals[, locals]]) -> value\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
807 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
808 Evaluate the source in the context of globals and locals.\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
809 The source may be a string representing a Python expression\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
810 or a code object as returned by compile().\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
811 The globals and locals are dictionaries, defaulting to the current\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
812 globals and locals. If only globals is given, locals defaults to it.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
813
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
814
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
815 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
816 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
817 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
818 PyObject *args;
673
71d496259ad3 Added execfile().
Guido van Rossum <guido@python.org>
parents: 662
diff changeset
819 {
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2002
diff changeset
820 char *filename;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
821 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
822 PyObject *res;
673
71d496259ad3 Added execfile().
Guido van Rossum <guido@python.org>
parents: 662
diff changeset
823 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
824
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
825 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
826 &filename,
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
827 &PyDict_Type, &globals,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
828 &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
829 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
830 if (globals == Py_None) {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
831 globals = PyEval_GetGlobals();
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
832 if (locals == Py_None)
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
833 locals = PyEval_GetLocals();
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2087
diff changeset
834 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
835 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
836 locals = globals;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
837 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
838 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
839 PyEval_GetBuiltins()) != 0)
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2087
diff changeset
840 return NULL;
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2087
diff changeset
841 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
842 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
843 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
844 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
845 if (fp == NULL) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
846 PyErr_SetFromErrno(PyExc_IOError);
673
71d496259ad3 Added execfile().
Guido van Rossum <guido@python.org>
parents: 662
diff changeset
847 return NULL;
71d496259ad3 Added execfile().
Guido van Rossum <guido@python.org>
parents: 662
diff changeset
848 }
5438
e926c331ebbf Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents: 5421
diff changeset
849 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
850 Py_BEGIN_ALLOW_THREADS
673
71d496259ad3 Added execfile().
Guido van Rossum <guido@python.org>
parents: 662
diff changeset
851 fclose(fp);
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
852 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
853 return res;
673
71d496259ad3 Added execfile().
Guido van Rossum <guido@python.org>
parents: 662
diff changeset
854 }
71d496259ad3 Added execfile().
Guido van Rossum <guido@python.org>
parents: 662
diff changeset
855
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
856 static char execfile_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
857 "execfile(filename[, globals[, locals]])\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
858 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
859 Read and execute a Python script from a file.\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
860 The globals and locals are dictionaries, defaulting to the current\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
861 globals and locals. If only globals is given, locals defaults to it.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
862
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
863
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
864 static PyObject *
959
68b302ad84a1 use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents: 955
diff changeset
865 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
866 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
867 PyObject *args;
644
59f9325bb8ec Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents: 606
diff changeset
868 {
8581
221667f89064 Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents: 8561
diff changeset
869 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
870 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
871
8581
221667f89064 Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents: 8561
diff changeset
872 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
873 return NULL;
8581
221667f89064 Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents: 8561
diff changeset
874 result = PyObject_GetAttr(v, name);
221667f89064 Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents: 8561
diff changeset
875 if (result == NULL && dflt != NULL) {
221667f89064 Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents: 8561
diff changeset
876 PyErr_Clear();
221667f89064 Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents: 8561
diff changeset
877 Py_INCREF(dflt);
221667f89064 Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents: 8561
diff changeset
878 result = dflt;
221667f89064 Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents: 8561
diff changeset
879 }
221667f89064 Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents: 8561
diff changeset
880 return result;
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
881 }
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
882
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
883 static char getattr_doc[] =
8581
221667f89064 Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents: 8561
diff changeset
884 "getattr(object, name[, default]) -> value\n\
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
885 \n\
8581
221667f89064 Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents: 8561
diff changeset
886 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
887 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
888 exist; without it, an exception is raised in that case.";
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
889
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
890
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
891 static PyObject *
2808
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
892 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
893 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
894 PyObject *args;
2808
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
895 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
896 PyObject *d;
2808
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
897
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11800
diff changeset
898 if (!PyArg_ParseTuple(args, ":globals"))
2808
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
899 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
900 d = PyEval_GetGlobals();
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
901 Py_INCREF(d);
2808
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
902 return d;
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
903 }
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
904
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
905 static char globals_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
906 "globals() -> dictionary\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
907 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
908 Return the dictionary containing the current scope's global variables.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
909
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
910
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
911 static PyObject *
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
912 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
913 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
914 PyObject *args;
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
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 PyObject *v;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
917 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
918
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
919 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
920 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
921 v = PyObject_GetAttr(v, name);
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
922 if (v == NULL) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
923 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
924 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
925 return Py_False;
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
926 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
927 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
928 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
929 return Py_True;
644
59f9325bb8ec Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents: 606
diff changeset
930 }
59f9325bb8ec Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents: 606
diff changeset
931
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
932 static char hasattr_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
933 "hasattr(object, name) -> Boolean\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
934 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
935 Return whether the object has an attribute with the given name.\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
936 (This is done by calling getattr(object, name) and catching exceptions.)";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
937
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
938
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
939 static PyObject *
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
940 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
941 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
942 PyObject *args;
1263
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
943 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
944 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
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, "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
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 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
949 }
65a1e4e9cd54 * Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
950
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
951 static char id_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
952 "id(object) -> integer\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
953 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
954 Return the identity of an object. This is guaranteed to be unique among\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
955 simultaneously existing objects. (Hint: it's the object's memory address.)";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
956
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
957
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
958 static PyObject *
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
959 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
960 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
961 PyObject *args;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
962 {
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
963 typedef struct {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
964 PyObject *seq;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
965 PySequenceMethods *sqf;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
966 int len;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
967 } sequence;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
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 PyObject *func, *result;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
970 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
971 int n, len;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
972 register int i, j;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
973
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
974 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
975 if (n < 2) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
976 PyErr_SetString(PyExc_TypeError,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
977 "map() requires at least two args");
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
978 return NULL;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
979 }
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
980
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
981 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
982 n--;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
983
8661
30fbf18af29e Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents: 8589
diff changeset
984 if (func == Py_None && n == 1) {
30fbf18af29e Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents: 8589
diff changeset
985 /* 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
986 return PySequence_List(PyTuple_GetItem(args, 1));
30fbf18af29e Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents: 8589
diff changeset
987 }
30fbf18af29e Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents: 8589
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 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
990 PyErr_NoMemory();
1375
f3a325662d39 * listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
991 goto Fail_2;
f3a325662d39 * listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
992 }
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
993
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
994 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
995 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
996 PySequenceMethods *sqf;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
997
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
998 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
999 goto Fail_2;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1000
8402
0cb0394c2edc A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents: 8287
diff changeset
1001 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
1002 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
1003 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
1004 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
1005 {
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1006 static char errmsg[] =
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1007 "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
1008 char errbuf[sizeof(errmsg) + 25];
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1009
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1010 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
1011 PyErr_SetString(PyExc_TypeError, errbuf);
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1012 goto Fail_2;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1013 }
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1014
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1015 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
1016 goto Fail_2;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1017
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1018 if (curlen > len)
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1019 len = curlen;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1020 }
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1021
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1022 if ((result = (PyObject *) PyList_New(len)) == NULL)
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1023 goto Fail_2;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1024
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1025 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
1026 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
1027 int any = 0;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1028
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1029 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
1030 alist = NULL;
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1031 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1032 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
1033 goto Fail_1;
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1034 }
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1035
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1036 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
1037 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
1038 Py_INCREF(Py_None);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1039 item = Py_None;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1040 }
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1041 else {
1375
f3a325662d39 * listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
1042 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
1043 if (item == NULL) {
6145
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
1044 if (PyErr_ExceptionMatches(
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
1045 PyExc_IndexError))
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
1046 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1047 PyErr_Clear();
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1048 Py_INCREF(Py_None);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1049 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
1050 sqp->len = -1;
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1051 }
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1052 else {
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1053 goto Fail_0;
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1054 }
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1055 }
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1056 else
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1057 any = 1;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1058
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1059 }
2824
65c7105868f8 rename arglist to alist (conflict with new grammar symbol)
Guido van Rossum <guido@python.org>
parents: 2808
diff changeset
1060 if (!alist)
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1061 break;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1062 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
1063 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
1064 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
1065 }
1375
f3a325662d39 * listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
1066 continue;
f3a325662d39 * listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
1067
f3a325662d39 * listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
1068 Fail_0:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1069 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
1070 goto Fail_1;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1071 }
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1072
2824
65c7105868f8 rename arglist to alist (conflict with new grammar symbol)
Guido van Rossum <guido@python.org>
parents: 2808
diff changeset
1073 if (!alist)
65c7105868f8 rename arglist to alist (conflict with new grammar symbol)
Guido van Rossum <guido@python.org>
parents: 2808
diff changeset
1074 alist = item;
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1075
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1076 if (!any) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1077 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
1078 break;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1079 }
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1080
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1081 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
1082 value = alist;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1083 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1084 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
1085 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
1086 if (value == NULL)
f3a325662d39 * listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
1087 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
1088 }
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1089 if (i >= len) {
9991
ddbbed8cb830 builtin_map(): A better fix for the previous leak plug (remember
Barry Warsaw <barry@python.org>
parents: 9980
diff changeset
1090 int status = PyList_Append(result, value);
ddbbed8cb830 builtin_map(): A better fix for the previous leak plug (remember
Barry Warsaw <barry@python.org>
parents: 9980
diff changeset
1091 Py_DECREF(value);
ddbbed8cb830 builtin_map(): A better fix for the previous leak plug (remember
Barry Warsaw <barry@python.org>
parents: 9980
diff changeset
1092 if (status < 0)
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1093 goto Fail_1;
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1094 }
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1095 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1096 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
1097 goto Fail_1;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1098 }
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1099 }
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1100
8661
30fbf18af29e Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents: 8589
diff changeset
1101 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
1102 goto Fail_1;
30fbf18af29e Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents: 8589
diff changeset
1103
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1104 PyMem_DEL(seqs);
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1105 return result;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1106
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1107 Fail_1:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1108 Py_DECREF(result);
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1109 Fail_2:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1110 if (seqs) PyMem_DEL(seqs);
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1111 return NULL;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1112 }
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1113
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1114 static char map_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1115 "map(function, sequence[, sequence, ...]) -> list\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1116 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1117 Return a list of the results of applying the function to the items of\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1118 the argument sequence(s). If more than one sequence is given, the\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1119 function is called with an argument list consisting of the corresponding\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1120 item of each sequence, substituting None for missing values when not all\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1121 sequences have the same length. If the function is None, return a list of\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1122 the items of the sequence (or a list of tuples if more than one sequence).";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1123
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1124
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1125 static PyObject *
959
68b302ad84a1 use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents: 955
diff changeset
1126 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
1127 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1128 PyObject *args;
644
59f9325bb8ec Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents: 606
diff changeset
1129 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1130 PyObject *v;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1131 PyObject *name;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1132 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
1133
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1134 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
1135 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1136 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
1137 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1138 Py_INCREF(Py_None);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1139 return Py_None;
644
59f9325bb8ec Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents: 606
diff changeset
1140 }
59f9325bb8ec Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents: 606
diff changeset
1141
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1142 static char setattr_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1143 "setattr(object, name, value)\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1144 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1145 Set a named attribute on an object; setattr(x, 'y', v) is equivalent to\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1146 ``x.y = v''.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1147
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1148
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1149 static PyObject *
1843
8294bbd94535 Added delattr()
Guido van Rossum <guido@python.org>
parents: 1842
diff changeset
1150 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
1151 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1152 PyObject *args;
1843
8294bbd94535 Added delattr()
Guido van Rossum <guido@python.org>
parents: 1842
diff changeset
1153 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1154 PyObject *v;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1155 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
1156
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1157 if (!PyArg_ParseTuple(args, "OS:delattr", &v, &name))
1843
8294bbd94535 Added delattr()
Guido van Rossum <guido@python.org>
parents: 1842
diff changeset
1158 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1159 if (PyObject_SetAttr(v, name, (PyObject *)NULL) != 0)
1843
8294bbd94535 Added delattr()
Guido van Rossum <guido@python.org>
parents: 1842
diff changeset
1160 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1161 Py_INCREF(Py_None);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1162 return Py_None;
1843
8294bbd94535 Added delattr()
Guido van Rossum <guido@python.org>
parents: 1842
diff changeset
1163 }
8294bbd94535 Added delattr()
Guido van Rossum <guido@python.org>
parents: 1842
diff changeset
1164
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1165 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
1166 "delattr(object, name)\n\
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1167 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1168 Delete a named attribute on an object; delattr(x, 'y') is equivalent to\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1169 ``del x.y''.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1170
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1171
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1172 static PyObject *
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1173 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
1174 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1175 PyObject *args;
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1176 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1177 PyObject *v;
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1178 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
1179
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1180 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
1181 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1182 x = PyObject_Hash(v);
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1183 if (x == -1)
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1184 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1185 return PyInt_FromLong(x);
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1186 }
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1187
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1188 static char hash_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1189 "hash(object) -> integer\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1190 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1191 Return a hash value for the object. Two objects with the same value have\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1192 the same hash value. The reverse is not necessarily true, but likely.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1193
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1194
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1195 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
1196 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
1197 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1198 PyObject *args;
404
9cd38d1ac391 Made dir() more robust.
Guido van Rossum <guido@python.org>
parents: 385
diff changeset
1199 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1200 PyObject *v;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1201 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
1202
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1203 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
1204 return NULL;
1049
2ed511171809 Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents: 972
diff changeset
1205
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2002
diff changeset
1206 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
1207 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
1208 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
1209 "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
1210 return NULL;
404
9cd38d1ac391 Made dir() more robust.
Guido van Rossum <guido@python.org>
parents: 385
diff changeset
1211 }
1049
2ed511171809 Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents: 972
diff changeset
1212 return (*nb->nb_hex)(v);
404
9cd38d1ac391 Made dir() more robust.
Guido van Rossum <guido@python.org>
parents: 385
diff changeset
1213 }
9cd38d1ac391 Made dir() more robust.
Guido van Rossum <guido@python.org>
parents: 385
diff changeset
1214
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1215 static char hex_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1216 "hex(number) -> string\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1217 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1218 Return the hexadecimal representation of an integer or long integer.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1219
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1220
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1221 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
1222
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1223 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
1224 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
1225 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1226 PyObject *args;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1227 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1228 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
1229 char *str;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1230 PyObject *res;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1231 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
1232
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2002
diff changeset
1233 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
1234 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
1235 return line;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1236 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
1237 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2002
diff changeset
1238 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
1239 str++;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1240 globals = PyEval_GetGlobals();
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1241 locals = PyEval_GetLocals();
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1242 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
1243 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
1244 PyEval_GetBuiltins()) != 0)
2098
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2087
diff changeset
1245 return NULL;
b7be0382f9ee __builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents: 2087
diff changeset
1246 }
5438
e926c331ebbf Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents: 5421
diff changeset
1247 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
1248 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
1249 return res;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1250 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1251
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1252 static char input_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1253 "input([prompt]) -> value\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1254 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1255 Equivalent to eval(raw_input(prompt)).";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1256
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1257
5092
cb7aadd9d9f2 Added intern() function.
Guido van Rossum <guido@python.org>
parents: 5010
diff changeset
1258 static PyObject *
cb7aadd9d9f2 Added intern() function.
Guido van Rossum <guido@python.org>
parents: 5010
diff changeset
1259 builtin_intern(self, args)
cb7aadd9d9f2 Added intern() function.
Guido van Rossum <guido@python.org>
parents: 5010
diff changeset
1260 PyObject *self;
cb7aadd9d9f2 Added intern() function.
Guido van Rossum <guido@python.org>
parents: 5010
diff changeset
1261 PyObject *args;
cb7aadd9d9f2 Added intern() function.
Guido van Rossum <guido@python.org>
parents: 5010
diff changeset
1262 {
cb7aadd9d9f2 Added intern() function.
Guido van Rossum <guido@python.org>
parents: 5010
diff changeset
1263 PyObject *s;
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11800
diff changeset
1264 if (!PyArg_ParseTuple(args, "S:intern", &s))
5092
cb7aadd9d9f2 Added intern() function.
Guido van Rossum <guido@python.org>
parents: 5010
diff changeset
1265 return NULL;
cb7aadd9d9f2 Added intern() function.
Guido van Rossum <guido@python.org>
parents: 5010
diff changeset
1266 Py_INCREF(s);
cb7aadd9d9f2 Added intern() function.
Guido van Rossum <guido@python.org>
parents: 5010
diff changeset
1267 PyString_InternInPlace(&s);
cb7aadd9d9f2 Added intern() function.
Guido van Rossum <guido@python.org>
parents: 5010
diff changeset
1268 return s;
cb7aadd9d9f2 Added intern() function.
Guido van Rossum <guido@python.org>
parents: 5010
diff changeset
1269 }
cb7aadd9d9f2 Added intern() function.
Guido van Rossum <guido@python.org>
parents: 5010
diff changeset
1270
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1271 static char intern_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1272 "intern(string) -> string\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1273 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1274 ``Intern'' the given string. This enters the string in the (global)\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1275 table of interned strings whose purpose is to speed up dictionary lookups.\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1276 Return the string itself or the previously interned string object with the\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1277 same value.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1278
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1279
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1280 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
1281 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
1282 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1283 PyObject *args;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1284 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1285 PyObject *v;
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1286 int base = -909; /* unlikely! */
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2002
diff changeset
1287
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1288 if (!PyArg_ParseTuple(args, "O|i:int", &v, &base))
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2002
diff changeset
1289 return NULL;
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1290 if (base == -909)
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1291 return PyNumber_Int(v);
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1292 else if (!PyString_Check(v)) {
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1293 PyErr_SetString(PyExc_TypeError,
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1294 "can't convert non-string with explicit base");
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1295 return NULL;
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1296 }
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1297 return PyInt_FromString(PyString_AS_STRING(v), NULL, base);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1298 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1299
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1300 static char int_doc[] =
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1301 "int(x[, base]) -> integer\n\
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1302 \n\
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1303 Convert a string or number to an integer, if possible. A floating point\n\
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1304 argument will be truncated towards zero (this does not include a string\n\
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1305 representation of a floating point number!) When converting a string, use\n\
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1306 the optional base. It is an error to supply a base when converting a\n\
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1307 non-string.";
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1308
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1309
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1310 static PyObject *
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1311 builtin_long(self, args)
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1312 PyObject *self;
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1313 PyObject *args;
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1314 {
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1315 PyObject *v;
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1316 int base = -909; /* unlikely! */
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1317
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1318 if (!PyArg_ParseTuple(args, "O|i:long", &v, &base))
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1319 return NULL;
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1320 if (base == -909)
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1321 return PyNumber_Long(v);
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1322 else if (!PyString_Check(v)) {
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1323 PyErr_SetString(PyExc_TypeError,
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1324 "can't convert non-string with explicit base");
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1325 return NULL;
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1326 }
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1327 return PyLong_FromString(PyString_AS_STRING(v), NULL, base);
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1328 }
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1329
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1330 static char long_doc[] =
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1331 "long(x) -> long integer\n\
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1332 long(x, base) -> long integer\n\
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1333 \n\
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1334 Convert a string or number to a long integer, if possible. A floating\n\
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1335 point argument will be truncated towards zero (this does not include a\n\
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1336 string representation of a floating point number!) When converting a\n\
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1337 string, use the given base. It is an error to supply a base when\n\
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1338 converting a non-string.";
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1339
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1340
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1341 static PyObject *
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1342 builtin_float(self, args)
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1343 PyObject *self;
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1344 PyObject *args;
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1345 {
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1346 PyObject *v;
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1347
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1348 if (!PyArg_ParseTuple(args, "O:float", &v))
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1349 return NULL;
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1350 if (PyString_Check(v))
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1351 return PyFloat_FromString(v, NULL);
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1352 return PyNumber_Float(v);
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1353 }
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1354
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1355 static char float_doc[] =
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1356 "float(x) -> floating point number\n\
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1357 \n\
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 11132
diff changeset
1358 Convert a string or number to a floating point number, if possible.";
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1359
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1360
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1361 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
1362 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
1363 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1364 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
1365 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1366 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
1367 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
1368
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1369 if (!PyArg_ParseTuple(args, "O:len", &v))
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1370 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
1371 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
1372 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
1373 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
1374 return PyInt_FromLong(res);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1375 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1376
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1377 static char len_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1378 "len(object) -> integer\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1379 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1380 Return the number of items of a sequence or mapping.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1381
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1382
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1383 static PyObject *
3493
03c6c18325ea Add list() method, analogous to tuple().
Guido van Rossum <guido@python.org>
parents: 3365
diff changeset
1384 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
1385 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1386 PyObject *args;
3493
03c6c18325ea Add list() method, analogous to tuple().
Guido van Rossum <guido@python.org>
parents: 3365
diff changeset
1387 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1388 PyObject *v;
3493
03c6c18325ea Add list() method, analogous to tuple().
Guido van Rossum <guido@python.org>
parents: 3365
diff changeset
1389
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1390 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
1391 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
1392 return PySequence_List(v);
3493
03c6c18325ea Add list() method, analogous to tuple().
Guido van Rossum <guido@python.org>
parents: 3365
diff changeset
1393 }
03c6c18325ea Add list() method, analogous to tuple().
Guido van Rossum <guido@python.org>
parents: 3365
diff changeset
1394
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1395 static char list_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1396 "list(sequence) -> list\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1397 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1398 Return a new list whose items are the same as those of the argument sequence.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1399
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1400
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1401 static PyObject *
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1402 builtin_slice(self, args)
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1403 PyObject *self;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1404 PyObject *args;
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1405 {
8402
0cb0394c2edc A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents: 8287
diff changeset
1406 PyObject *start, *stop, *step;
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1407
8402
0cb0394c2edc A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents: 8287
diff changeset
1408 start = stop = step = NULL;
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1409
8402
0cb0394c2edc A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents: 8287
diff changeset
1410 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
1411 return NULL;
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1412
8402
0cb0394c2edc A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents: 8287
diff changeset
1413 /* 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
1414 range(). */
0cb0394c2edc A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents: 8287
diff changeset
1415 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
1416 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
1417 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
1418 }
0cb0394c2edc A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents: 8287
diff changeset
1419 return PySlice_New(start, stop, step);
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1420 }
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
1421
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1422 static char slice_doc[] =
11132
41a46978a444 Fixed order of parameters in slice() docstring. The Library Reference
Fred Drake <fdrake@acm.org>
parents: 11030
diff changeset
1423 "slice([start,] stop[, step]) -> slice object\n\
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1424 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1425 Create a slice object. This is used for slicing by the Numeric extensions.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1426
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1427
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1428 static PyObject *
2808
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1429 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
1430 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1431 PyObject *args;
2808
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1432 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1433 PyObject *d;
2808
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1434
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11800
diff changeset
1435 if (!PyArg_ParseTuple(args, ":locals"))
2808
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1436 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1437 d = PyEval_GetLocals();
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1438 Py_INCREF(d);
2808
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1439 return d;
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1440 }
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1441
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1442 static char locals_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1443 "locals() -> dictionary\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1444 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1445 Return the dictionary containing the current scope's local variables.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1446
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1447
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1448 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
1449 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
1450 PyObject *args;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1451 int sign;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1452 {
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1453 int i;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1454 PyObject *v, *w, *x;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1455 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
1456
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1457 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
1458 v = args;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1459 else if (!PyArg_ParseTuple(args, "O:min/max", &v))
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1460 return NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1461 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
1462 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
1463 PyErr_SetString(PyExc_TypeError,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1464 "min() or max() of non-sequence");
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1465 return NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1466 }
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1467 w = NULL;
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1468 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
1469 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
1470 if (x == NULL) {
6145
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
1471 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
1472 PyErr_Clear();
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1473 break;
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1474 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1475 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
1476 return NULL;
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1477 }
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1478 if (w == NULL)
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1479 w = x;
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1480 else {
5610
10e9cfa010f0 PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents: 5471
diff changeset
1481 int c = PyObject_Compare(x, w);
10e9cfa010f0 PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents: 5471
diff changeset
1482 if (c && PyErr_Occurred()) {
10e9cfa010f0 PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents: 5471
diff changeset
1483 Py_DECREF(x);
10e9cfa010f0 PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents: 5471
diff changeset
1484 Py_XDECREF(w);
10e9cfa010f0 PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents: 5471
diff changeset
1485 return NULL;
10e9cfa010f0 PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents: 5471
diff changeset
1486 }
10e9cfa010f0 PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents: 5471
diff changeset
1487 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
1488 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
1489 w = x;
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1490 }
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1491 else
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1492 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
1493 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1494 }
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1495 if (w == NULL)
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1496 PyErr_SetString(PyExc_ValueError,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1497 "min() or max() of empty sequence");
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1498 return w;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1499 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1500
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1501 static PyObject *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1502 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
1503 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1504 PyObject *v;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1505 {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1506 return min_max(v, -1);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1507 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1508
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1509 static char min_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1510 "min(sequence) -> value\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1511 min(a, b, c, ...) -> value\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1512 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1513 With a single sequence argument, return its smallest item.\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1514 With two or more arguments, return the smallest argument.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1515
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1516
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1517 static PyObject *
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1518 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
1519 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1520 PyObject *v;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1521 {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1522 return min_max(v, 1);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1523 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1524
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1525 static char max_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1526 "max(sequence) -> value\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1527 max(a, b, c, ...) -> value\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1528 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1529 With a single sequence argument, return its largest item.\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1530 With two or more arguments, return the largest argument.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1531
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1532
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1533 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
1534 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
1535 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1536 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
1537 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1538 PyObject *v;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1539 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
1540
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1541 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
1542 return NULL;
1049
2ed511171809 Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents: 972
diff changeset
1543 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
1544 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
1545 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
1546 "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
1547 return NULL;
404
9cd38d1ac391 Made dir() more robust.
Guido van Rossum <guido@python.org>
parents: 385
diff changeset
1548 }
1049
2ed511171809 Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents: 972
diff changeset
1549 return (*nb->nb_oct)(v);
404
9cd38d1ac391 Made dir() more robust.
Guido van Rossum <guido@python.org>
parents: 385
diff changeset
1550 }
9cd38d1ac391 Made dir() more robust.
Guido van Rossum <guido@python.org>
parents: 385
diff changeset
1551
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1552 static char oct_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1553 "oct(number) -> string\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1554 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1555 Return the octal representation of an integer or long integer.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1556
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1557
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1558 static PyObject *
959
68b302ad84a1 use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents: 955
diff changeset
1559 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
1560 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1561 PyObject *args;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1562 {
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1563 char *name;
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1564 char *mode = "r";
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1565 int bufsize = -1;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1566 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
1567
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1568 if (!PyArg_ParseTuple(args, "s|si:open", &name, &mode, &bufsize))
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1569 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1570 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
1571 if (f != NULL)
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1572 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
1573 return f;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1574 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1575
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1576 static char open_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1577 "open(filename[, mode[, buffering]]) -> file object\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1578 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1579 Open a file. The mode can be 'r', 'w' or 'a' for reading (default),\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1580 writing or appending. The file will be created if it doesn't exist\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1581 when opened for writing or appending; it will be truncated when\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1582 opened for writing. Add a 'b' to the mode for binary files.\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1583 Add a '+' to the mode to allow simultaneous reading and writing.\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1584 If the buffering argument is given, 0 means unbuffered, 1 means line\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1585 buffered, and larger numbers specify the buffer size.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1586
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1587
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1588 static PyObject *
959
68b302ad84a1 use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents: 955
diff changeset
1589 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
1590 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1591 PyObject *args;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1592 {
11973
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
1593 PyObject *obj;
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
1594 long ord;
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
1595
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
1596 if (!PyArg_ParseTuple(args, "O:ord", &obj))
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
1597 return NULL;
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2002
diff changeset
1598
11973
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
1599 if (PyString_Check(obj) && PyString_GET_SIZE(obj) == 1)
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
1600 ord = (long)((unsigned char)*PyString_AS_STRING(obj));
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
1601 else if (PyUnicode_Check(obj) && PyUnicode_GET_SIZE(obj) == 1)
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
1602 ord = (long)*PyUnicode_AS_UNICODE(obj);
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
1603 else {
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
1604 PyErr_SetString(PyExc_TypeError,
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
1605 "expected a string or unicode character");
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1606 return NULL;
11973
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
1607 }
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
1608
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
1609 return PyInt_FromLong(ord);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1610 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1611
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1612 static char ord_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1613 "ord(c) -> integer\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1614 \n\
11973
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
1615 Return the integer ordinal of a one character [unicode] string.";
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1616
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1617
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1618 static PyObject *
2087
65146b52f16b * Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
1619 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
1620 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1621 PyObject *args;
2087
65146b52f16b * Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
1622 {
8402
0cb0394c2edc A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents: 8287
diff changeset
1623 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
1624
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1625 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
1626 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
1627 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
1628 }
6693c5d87f3a Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents: 182
diff changeset
1629
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1630 static char pow_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1631 "pow(x, y[, z]) -> number\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1632 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1633 With two arguments, equivalent to x**y. With three arguments,\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1634 equivalent to (x**y) % z, but may be more efficient (e.g. for longs).";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1635
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1636
10279
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1637 /* Return number of items in range/xrange (lo, hi, step). step > 0
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1638 * required. Return a value < 0 if & only if the true value is too
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1639 * large to fit in a signed long.
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1640 */
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1641 static long
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1642 get_len_of_range(lo, hi, step)
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1643 long lo;
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1644 long hi;
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1645 long step; /* must be > 0 */
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1646 {
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1647 /* -------------------------------------------------------------
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1648 If lo >= hi, the range is empty.
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1649 Else if n values are in the range, the last one is
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1650 lo + (n-1)*step, which must be <= hi-1. Rearranging,
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1651 n <= (hi - lo - 1)/step + 1, so taking the floor of the RHS gives
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1652 the proper value. Since lo < hi in this case, hi-lo-1 >= 0, so
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1653 the RHS is non-negative and so truncation is the same as the
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1654 floor. Letting M be the largest positive long, the worst case
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1655 for the RHS numerator is hi=M, lo=-M-1, and then
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1656 hi-lo-1 = M-(-M-1)-1 = 2*M. Therefore unsigned long has enough
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1657 precision to compute the RHS exactly.
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1658 ---------------------------------------------------------------*/
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1659 long n = 0;
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1660 if (lo < hi) {
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1661 unsigned long uhi = (unsigned long)hi;
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1662 unsigned long ulo = (unsigned long)lo;
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1663 unsigned long diff = uhi - ulo - 1;
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1664 n = (long)(diff / (unsigned long)step + 1);
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1665 }
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1666 return n;
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1667 }
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
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 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
1670 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
1671 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1672 PyObject *args;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1673 {
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2002
diff changeset
1674 long ilow = 0, ihigh = 0, istep = 1;
10279
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1675 long bign;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1676 int i, n;
10279
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1677
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1678 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
1679
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1680 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
1681 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
1682 "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
1683 &ihigh))
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2002
diff changeset
1684 return NULL;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1685 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1686 else {
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,
2153
e54b8654f938 fix Alpha bug in (x)range; different __builtins__ initialization
Guido van Rossum <guido@python.org>
parents: 2120
diff changeset
1688 "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
1689 &ilow, &ihigh, &istep))
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1690 return NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1691 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1692 if (istep == 0) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1693 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
1694 return NULL;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1695 }
10279
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1696 if (istep > 0)
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1697 bign = get_len_of_range(ilow, ihigh, istep);
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1698 else
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1699 bign = get_len_of_range(ihigh, ilow, -istep);
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1700 n = (int)bign;
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1701 if (bign < 0 || (long)n != bign) {
9849
5e9ef9d8575b Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents: 9567
diff changeset
1702 PyErr_SetString(PyExc_OverflowError,
10279
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1703 "range() has too many items");
9849
5e9ef9d8575b Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents: 9567
diff changeset
1704 return NULL;
5e9ef9d8575b Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents: 9567
diff changeset
1705 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1706 v = PyList_New(n);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1707 if (v == NULL)
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1708 return NULL;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1709 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
1710 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
1711 if (w == NULL) {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1712 Py_DECREF(v);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1713 return NULL;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1714 }
8138
9d0310143600 Fred's right -- we need PyList_SET_ITEM().
Guido van Rossum <guido@python.org>
parents: 8132
diff changeset
1715 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
1716 ilow += istep;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1717 }
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1718 return v;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1719 }
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1720
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1721 static char range_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1722 "range([start,] stop[, step]) -> list of integers\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1723 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1724 Return a list containing an arithmetic progression of integers.\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1725 range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1726 When step is given, it specifies the increment (or decrement).\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1727 For example, range(4) returns [0, 1, 2, 3]. The end point is omitted!\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1728 These are exactly the valid indices for a list of 4 elements.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1729
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1730
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1731 static PyObject *
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1732 builtin_xrange(self, args)
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1733 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1734 PyObject *args;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1735 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1736 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
1737 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
1738
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1739 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
1740 if (!PyArg_ParseTuple(args,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1741 "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
1742 &ihigh))
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1743 return NULL;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1744 }
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1745 else {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1746 if (!PyArg_ParseTuple(args,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1747 "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
1748 &ilow, &ihigh, &istep))
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1749 return NULL;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1750 }
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1751 if (istep == 0) {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1752 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
1753 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1754 }
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1755 if (istep > 0)
10279
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1756 n = get_len_of_range(ilow, ihigh, istep);
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1757 else
10279
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1758 n = get_len_of_range(ihigh, ilow, -istep);
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1759 if (n < 0) {
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1760 PyErr_SetString(PyExc_OverflowError,
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1761 "xrange() has more than sys.maxint items");
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1762 return NULL;
886ea255f381 Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents: 10020
diff changeset
1763 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1764 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
1765 }
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1766
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1767 static char xrange_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1768 "xrange([start,] stop[, step]) -> xrange object\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1769 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1770 Like range(), but instead of returning a list, returns an object that\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1771 generates the numbers in the range on demand. This is slightly slower\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1772 than range() but more memory efficient.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1773
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
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 *
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1776 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
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;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1779 {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1780 PyObject *v = NULL;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1781 PyObject *f;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1782
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1783 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
1784 return NULL;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1785 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
1786 PyFile_AsFile(PySys_GetObject("stdout")) == stdout &&
2857
eebbdbee54f9 be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
1787 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
1788 PyObject *po;
2808
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1789 char *prompt;
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1790 char *s;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1791 PyObject *result;
2808
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1792 if (v != NULL) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1793 po = PyObject_Str(v);
2808
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1794 if (po == NULL)
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1795 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1796 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
1797 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
1798 return NULL;
2808
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1799 }
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1800 else {
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1801 po = NULL;
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1802 prompt = "";
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1803 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1804 s = PyOS_Readline(prompt);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1805 Py_XDECREF(po);
2808
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1806 if (s == NULL) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1807 PyErr_SetNone(PyExc_KeyboardInterrupt);
2808
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1808 return NULL;
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1809 }
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1810 if (*s == '\0') {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1811 PyErr_SetNone(PyExc_EOFError);
2808
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1812 result = NULL;
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1813 }
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1814 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
1815 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
1816 }
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1817 free(s);
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1818 return result;
9318ac51691e added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents: 2375
diff changeset
1819 }
284
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 253
diff changeset
1820 if (v != NULL) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1821 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
1822 if (f == NULL) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1823 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
1824 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2002
diff changeset
1825 }
5610
10e9cfa010f0 PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents: 5471
diff changeset
1826 if (Py_FlushLine() != 0 ||
10e9cfa010f0 PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents: 5471
diff changeset
1827 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
1828 return NULL;
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 253
diff changeset
1829 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1830 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
1831 if (f == NULL) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1832 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
1833 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2002
diff changeset
1834 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1835 return PyFile_GetLine(f, -1);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1836 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1837
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1838 static char raw_input_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1839 "raw_input([prompt]) -> string\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1840 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1841 Read a string from standard input. The trailing newline is stripped.\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1842 If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1843 On Unix, GNU readline is used if enabled. The prompt string, if given,\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1844 is printed without a trailing newline before reading.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1845
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1846
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1847 static PyObject *
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1848 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
1849 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1850 PyObject *args;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1851 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1852 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
1853 PySequenceMethods *sqf;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1854 register int i;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1855
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1856 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
1857 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 2002
diff changeset
1858 if (result != NULL)
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1859 Py_INCREF(result);
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1860
8402
0cb0394c2edc A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents: 8287
diff changeset
1861 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
1862 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
1863 PyErr_SetString(PyExc_TypeError,
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1864 "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
1865 return NULL;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1866 }
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1867
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1868 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
1869 goto Fail;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1870
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1871 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
1872 PyObject *op2;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1873
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1874 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
1875 Py_DECREF(args);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1876 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
1877 goto Fail;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1878 }
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1879
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1880 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
1881 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
1882 PyErr_Clear();
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1883 break;
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1884 }
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1885 goto Fail;
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1886 }
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1887
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1888 if (result == NULL)
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1889 result = op2;
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1890 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1891 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
1892 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
1893 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
1894 goto Fail;
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1895 }
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1896 }
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1897
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1898 Py_DECREF(args);
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1899
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1900 if (result == NULL)
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1901 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
1902 "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
1903
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1904 return result;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1905
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
1906 Fail:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1907 Py_XDECREF(args);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1908 Py_XDECREF(result);
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1909 return NULL;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1910 }
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
1911
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1912 static char reduce_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1913 "reduce(function, sequence[, initial]) -> value\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1914 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1915 Apply a function of two arguments cumulatively to the items of a sequence,\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1916 from left to right, so as to reduce the sequence to a single value.\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1917 For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1918 ((((1+2)+3)+4)+5). If initial is present, it is placed before the items\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1919 of the sequence in the calculation, and serves as a default when the\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1920 sequence is empty.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1921
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1922
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1923 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
1924 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
1925 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1926 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
1927 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1928 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
1929
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1930 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
1931 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1932 return PyImport_ReloadModule(v);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1933 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
1934
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1935 static char reload_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1936 "reload(module) -> module\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1937 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1938 Reload the module. The module must have been successfully imported before.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1939
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1940
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1941 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
1942 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
1943 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1944 PyObject *args;
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1079
diff changeset
1945 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1946 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
1947
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1948 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
1949 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1950 return PyObject_Repr(v);
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1079
diff changeset
1951 }
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1079
diff changeset
1952
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1953 static char repr_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1954 "repr(object) -> string\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1955 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1956 Return the canonical string representation of the object.\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1957 For most object types, eval(repr(object)) == object.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1958
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1959
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1960 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
1961 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
1962 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1963 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
1964 {
9d6cf529bb71 bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents: 1096
diff changeset
1965 double x;
9d6cf529bb71 bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents: 1096
diff changeset
1966 double f;
9d6cf529bb71 bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents: 1096
diff changeset
1967 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
1968 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
1969
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1970 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
1971 return NULL;
9d6cf529bb71 bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents: 1096
diff changeset
1972 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
1973 i = abs(ndigits);
d3bf3c2ad75a Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents: 8138
diff changeset
1974 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
1975 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
1976 if (ndigits < 0)
d3bf3c2ad75a Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents: 8138
diff changeset
1977 x /= f;
d3bf3c2ad75a Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents: 8138
diff changeset
1978 else
d3bf3c2ad75a Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents: 8138
diff changeset
1979 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
1980 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
1981 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
1982 else
8287
d3bf3c2ad75a Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents: 8138
diff changeset
1983 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
1984 if (ndigits < 0)
d3bf3c2ad75a Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents: 8138
diff changeset
1985 x *= f;
d3bf3c2ad75a Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents: 8138
diff changeset
1986 else
d3bf3c2ad75a Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents: 8138
diff changeset
1987 x /= f;
d3bf3c2ad75a Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents: 8138
diff changeset
1988 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
1989 }
9d6cf529bb71 bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents: 1096
diff changeset
1990
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1991 static char round_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1992 "round(number[, ndigits]) -> floating point number\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1993 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1994 Round a number to a given precision in decimal digits (default 0 digits).\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1995 This always returns a floating point number. Precision may be negative.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1996
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
1997
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
1998 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
1999 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
2000 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2001 PyObject *args;
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1079
diff changeset
2002 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2003 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
2004
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2005 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
2006 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2007 return PyObject_Str(v);
1094
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1079
diff changeset
2008 }
d2af6bdcb6d0 * config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents: 1079
diff changeset
2009
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2010 static char str_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2011 "str(object) -> string\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2012 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2013 Return a nice string representation of the object.\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2014 If the argument is a string, the return value is the same object.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2015
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2016
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2017 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
2018 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
2019 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2020 PyObject *args;
1842
65cc727f1436 * Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents: 1841
diff changeset
2021 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2022 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
2023
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2024 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
2025 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
2026 return PySequence_Tuple(v);
1842
65cc727f1436 * Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents: 1841
diff changeset
2027 }
65cc727f1436 * Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents: 1841
diff changeset
2028
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2029 static char tuple_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2030 "tuple(sequence) -> list\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2031 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2032 Return a tuple whose items are the same as those of the argument sequence.\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2033 If the argument is a tuple, the return value is the same object.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2034
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2035
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2036 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
2037 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
2038 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2039 PyObject *args;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
2040 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2041 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
2042
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2043 if (!PyArg_ParseTuple(args, "O:type", &v))
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
2044 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2045 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
2046 Py_INCREF(v);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
2047 return v;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
2048 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
2049
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2050 static char type_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2051 "type(object) -> type object\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2052 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2053 Return the type of the object.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2054
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2055
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2056 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
2057 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
2058 PyObject *self;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2059 PyObject *args;
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
2060 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2061 PyObject *v = NULL;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2062 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
2063
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2064 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
2065 return NULL;
1840
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
2066 if (v == NULL) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2067 d = PyEval_GetLocals();
2857
eebbdbee54f9 be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
2068 if (d == NULL) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2069 if (!PyErr_Occurred())
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2070 PyErr_SetString(PyExc_SystemError,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2071 "no locals!?");
2857
eebbdbee54f9 be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
2072 }
eebbdbee54f9 be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents: 2844
diff changeset
2073 else
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2074 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
2075 }
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
2076 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2077 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
2078 if (d == NULL) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2079 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
2080 "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
2081 return NULL;
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
2082 }
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
2083 }
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
2084 return d;
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
2085 }
bfd11620a2d8 * Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents: 1444
diff changeset
2086
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2087 static char vars_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2088 "vars([object]) -> dictionary\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2089 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2090 Without arguments, equivalent to locals().\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2091 With an argument, equivalent to object.__dict__.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2092
10995
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2093 static int
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2094 abstract_issubclass(derived, cls, err, first)
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2095 PyObject *derived;
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2096 PyObject *cls;
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2097 char *err;
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2098 int first;
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2099 {
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2100 static PyObject *__bases__ = NULL;
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2101 PyObject *bases;
11010
e9442734bc49 # Darn! Local variable l declared but not used in abstract_issubclass().
Guido van Rossum <guido@python.org>
parents: 10995
diff changeset
2102 int i, n;
10995
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2103 int r = 0;
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2104
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2105 if (__bases__ == NULL) {
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2106 __bases__ = PyString_FromString("__bases__");
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2107 if (__bases__ == NULL)
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2108 return -1;
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2109 }
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2110
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2111 if (first) {
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2112 bases = PyObject_GetAttr(cls, __bases__);
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2113 if (bases == NULL || !PyTuple_Check(bases)) {
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2114 Py_XDECREF(bases);
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2115 PyErr_SetString(PyExc_TypeError, err);
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2116 return -1;
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2117 }
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2118 Py_DECREF(bases);
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2119 }
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2120
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2121 if (derived == cls)
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2122 return 1;
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2123
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2124 bases = PyObject_GetAttr(derived, __bases__);
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2125 if (bases == NULL || !PyTuple_Check(bases)) {
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2126 Py_XDECREF(bases);
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2127 PyErr_SetString(PyExc_TypeError, err);
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2128 return -1;
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2129 }
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2130
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2131 n = PyTuple_GET_SIZE(bases);
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2132 for (i = 0; i < n; i++) {
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2133 r = abstract_issubclass(PyTuple_GET_ITEM(bases, i),
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2134 cls, err, 0);
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2135 if (r != 0)
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2136 break;
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2137 }
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2138
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2139 Py_DECREF(bases);
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2140
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2141 return r;
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2142 }
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2143
6145
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2144 static PyObject *
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2145 builtin_isinstance(self, args)
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2146 PyObject *self;
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2147 PyObject *args;
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2148 {
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2149 PyObject *inst;
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2150 PyObject *cls;
10995
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2151 PyObject *icls;
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2152 static PyObject *__class__ = NULL;
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2153 int retval = 0;
6145
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2154
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11800
diff changeset
2155 if (!PyArg_ParseTuple(args, "OO:isinstance", &inst, &cls))
6145
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2156 return NULL;
10995
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2157
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2158 if (PyClass_Check(cls)) {
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2159 if (PyInstance_Check(inst)) {
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2160 PyObject *inclass =
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2161 (PyObject*)((PyInstanceObject*)inst)->in_class;
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2162 retval = PyClass_IsSubclass(inclass, cls);
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2163 }
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2164 }
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2165 else 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
2166 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
2167 }
10995
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2168 else if (!PyInstance_Check(inst)) {
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2169 if (__class__ == NULL) {
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2170 __class__ = PyString_FromString("__class__");
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2171 if (__class__ == NULL)
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2172 return NULL;
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2173 }
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2174 icls = PyObject_GetAttr(inst, __class__);
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2175 if (icls != NULL) {
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2176 retval = abstract_issubclass(
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2177 icls, cls,
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2178 "second argument must be a class",
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2179 1);
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2180 Py_DECREF(icls);
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2181 if (retval < 0)
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2182 return NULL;
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2183 }
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2184 else {
6706
cbc5e7d6ad23 Support type objects in isinstance().
Guido van Rossum <guido@python.org>
parents: 6334
diff changeset
2185 PyErr_SetString(PyExc_TypeError,
cbc5e7d6ad23 Support type objects in isinstance().
Guido van Rossum <guido@python.org>
parents: 6334
diff changeset
2186 "second argument must be a class");
cbc5e7d6ad23 Support type objects in isinstance().
Guido van Rossum <guido@python.org>
parents: 6334
diff changeset
2187 return NULL;
cbc5e7d6ad23 Support type objects in isinstance().
Guido van Rossum <guido@python.org>
parents: 6334
diff changeset
2188 }
10995
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2189 }
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2190 else {
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2191 PyErr_SetString(PyExc_TypeError,
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2192 "second argument must be a class");
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2193 return NULL;
6145
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2194 }
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2195 return PyInt_FromLong(retval);
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2196 }
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2197
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2198 static char isinstance_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2199 "isinstance(object, class-or-type) -> Boolean\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2200 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2201 Return whether an object is an instance of a class or of a subclass thereof.\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2202 With a type as second argument, return whether that is the object's type.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2203
6145
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2204
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2205 static PyObject *
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2206 builtin_issubclass(self, args)
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2207 PyObject *self;
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2208 PyObject *args;
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2209 {
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2210 PyObject *derived;
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2211 PyObject *cls;
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2212 int retval;
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2213
11882
dc65c5f6ad7c Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents: 11800
diff changeset
2214 if (!PyArg_ParseTuple(args, "OO:issubclass", &derived, &cls))
6145
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2215 return NULL;
10995
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2216
6145
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2217 if (!PyClass_Check(derived) || !PyClass_Check(cls)) {
10995
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2218 retval = abstract_issubclass(
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2219 derived, cls, "arguments must be classes", 1);
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2220 if (retval < 0)
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2221 return NULL;
6145
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2222 }
10995
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2223 else {
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2224 /* shortcut */
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2225 if (!(retval = (derived == cls)))
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2226 retval = PyClass_IsSubclass(derived, cls);
0d186c10a70e Patch by Jim Fulton (code style tweaked a bit) to support
Guido van Rossum <guido@python.org>
parents: 10529
diff changeset
2227 }
6145
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2228
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2229 return PyInt_FromLong(retval);
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2230 }
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2231
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2232 static char issubclass_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2233 "issubclass(C, B) -> Boolean\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2234 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2235 Return whether class C is a subclass (i.e., a derived class) of class B.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2236
6145
341fcb7bad90 Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents: 5926
diff changeset
2237
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2238 static PyMethodDef builtin_methods[] = {
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2239 {"__import__", builtin___import__, 1, import_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2240 {"abs", builtin_abs, 1, abs_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2241 {"apply", builtin_apply, 1, apply_doc},
10428
3571b4c1bc0e New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents: 10292
diff changeset
2242 {"buffer", builtin_buffer, 1, buffer_doc},
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2243 {"callable", builtin_callable, 1, callable_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2244 {"chr", builtin_chr, 1, chr_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2245 {"cmp", builtin_cmp, 1, cmp_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2246 {"coerce", builtin_coerce, 1, coerce_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2247 {"compile", builtin_compile, 1, compile_doc},
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 2890
diff changeset
2248 #ifndef WITHOUT_COMPLEX
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2249 {"complex", builtin_complex, 1, complex_doc},
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 2890
diff changeset
2250 #endif
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2251 {"delattr", builtin_delattr, 1, delattr_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2252 {"dir", builtin_dir, 1, dir_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2253 {"divmod", builtin_divmod, 1, divmod_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2254 {"eval", builtin_eval, 1, eval_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2255 {"execfile", builtin_execfile, 1, execfile_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2256 {"filter", builtin_filter, 1, filter_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2257 {"float", builtin_float, 1, float_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2258 {"getattr", builtin_getattr, 1, getattr_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2259 {"globals", builtin_globals, 1, globals_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2260 {"hasattr", builtin_hasattr, 1, hasattr_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2261 {"hash", builtin_hash, 1, hash_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2262 {"hex", builtin_hex, 1, hex_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2263 {"id", builtin_id, 1, id_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2264 {"input", builtin_input, 1, input_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2265 {"intern", builtin_intern, 1, intern_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2266 {"int", builtin_int, 1, int_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2267 {"isinstance", builtin_isinstance, 1, isinstance_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2268 {"issubclass", builtin_issubclass, 1, issubclass_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2269 {"len", builtin_len, 1, len_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2270 {"list", builtin_list, 1, list_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2271 {"locals", builtin_locals, 1, locals_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2272 {"long", builtin_long, 1, long_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2273 {"map", builtin_map, 1, map_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2274 {"max", builtin_max, 1, max_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2275 {"min", builtin_min, 1, min_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2276 {"oct", builtin_oct, 1, oct_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2277 {"open", builtin_open, 1, open_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2278 {"ord", builtin_ord, 1, ord_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2279 {"pow", builtin_pow, 1, pow_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2280 {"range", builtin_range, 1, range_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2281 {"raw_input", builtin_raw_input, 1, raw_input_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2282 {"reduce", builtin_reduce, 1, reduce_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2283 {"reload", builtin_reload, 1, reload_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2284 {"repr", builtin_repr, 1, repr_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2285 {"round", builtin_round, 1, round_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2286 {"setattr", builtin_setattr, 1, setattr_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2287 {"slice", builtin_slice, 1, slice_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2288 {"str", builtin_str, 1, str_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2289 {"tuple", builtin_tuple, 1, tuple_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2290 {"type", builtin_type, 1, type_doc},
11973
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
2291 {"unicode", builtin_unicode, 1, unicode_doc},
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
2292 {"unichr", builtin_unichr, 1, unichr_doc},
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2293 {"vars", builtin_vars, 1, vars_doc},
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2294 {"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
2295 {NULL, NULL},
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
2296 };
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
2297
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
2298 /* Predefined exceptions */
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
2299
6318
cdc5a40fcf97 Introduce PyExc_Exception as the conceptual root class for all exceptions.
Guido van Rossum <guido@python.org>
parents: 6243
diff changeset
2300 PyObject *PyExc_Exception;
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2301 PyObject *PyExc_StandardError;
6326
b0183994021b [Py_Exc]NumberError => [Py_Exc]ArithmeticError
Barry Warsaw <barry@python.org>
parents: 6318
diff changeset
2302 PyObject *PyExc_ArithmeticError;
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2303 PyObject *PyExc_LookupError;
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2304
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2305 PyObject *PyExc_AssertionError;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2306 PyObject *PyExc_AttributeError;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2307 PyObject *PyExc_EOFError;
5471
8e5d6d3103ae Oops -- missed FloatingPointError in renaming.
Guido van Rossum <guido@python.org>
parents: 5438
diff changeset
2308 PyObject *PyExc_FloatingPointError;
8704
83c8adaa084f Added support for two new standard errors: EnvironmentError and
Barry Warsaw <barry@python.org>
parents: 8661
diff changeset
2309 PyObject *PyExc_EnvironmentError;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2310 PyObject *PyExc_IOError;
8704
83c8adaa084f Added support for two new standard errors: EnvironmentError and
Barry Warsaw <barry@python.org>
parents: 8661
diff changeset
2311 PyObject *PyExc_OSError;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2312 PyObject *PyExc_ImportError;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2313 PyObject *PyExc_IndexError;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2314 PyObject *PyExc_KeyError;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2315 PyObject *PyExc_KeyboardInterrupt;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2316 PyObject *PyExc_MemoryError;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2317 PyObject *PyExc_NameError;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2318 PyObject *PyExc_OverflowError;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2319 PyObject *PyExc_RuntimeError;
9567
b7158db347d9 Added new builtin standard exception: NotImplementedError (its C
Barry Warsaw <barry@python.org>
parents: 9514
diff changeset
2320 PyObject *PyExc_NotImplementedError;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2321 PyObject *PyExc_SyntaxError;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2322 PyObject *PyExc_SystemError;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2323 PyObject *PyExc_SystemExit;
11030
3be935be3781 Patch by Tim Peters:
Guido van Rossum <guido@python.org>
parents: 11010
diff changeset
2324 PyObject *PyExc_UnboundLocalError;
11973
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
2325 PyObject *PyExc_UnicodeError;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2326 PyObject *PyExc_TypeError;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2327 PyObject *PyExc_ValueError;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2328 PyObject *PyExc_ZeroDivisionError;
11800
449b074c3051 Changes by Mark Hammond related to the new WindowsError exception.
Guido van Rossum <guido@python.org>
parents: 11621
diff changeset
2329 #ifdef MS_WINDOWS
449b074c3051 Changes by Mark Hammond related to the new WindowsError exception.
Guido van Rossum <guido@python.org>
parents: 11621
diff changeset
2330 PyObject *PyExc_WindowsError;
449b074c3051 Changes by Mark Hammond related to the new WindowsError exception.
Guido van Rossum <guido@python.org>
parents: 11621
diff changeset
2331 #endif
463
c97f4c6ba6c6 Added new exceptions.
Guido van Rossum <guido@python.org>
parents: 404
diff changeset
2332
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2333 PyObject *PyExc_MemoryErrorInst;
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2334
10466
36ba4dbff686 Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents: 10428
diff changeset
2335 static struct
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2336 {
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2337 char* name;
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2338 PyObject** exc;
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2339 int leaf_exc;
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2340 }
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2341 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
2342 {"Exception", &PyExc_Exception, 0},
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2343 {"StandardError", &PyExc_StandardError, 0},
6326
b0183994021b [Py_Exc]NumberError => [Py_Exc]ArithmeticError
Barry Warsaw <barry@python.org>
parents: 6318
diff changeset
2344 {"ArithmeticError", &PyExc_ArithmeticError, 0},
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2345 {"LookupError", &PyExc_LookupError, 0},
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2346 {"AssertionError", &PyExc_AssertionError, 1},
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2347 {"AttributeError", &PyExc_AttributeError, 1},
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2348 {"EOFError", &PyExc_EOFError, 1},
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2349 {"FloatingPointError", &PyExc_FloatingPointError, 1},
10020
94125a1343d8 bltin_exc[]: EnvironmentError is not a "leaf exception", so set it's
Barry Warsaw <barry@python.org>
parents: 9991
diff changeset
2350 {"EnvironmentError", &PyExc_EnvironmentError, 0},
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2351 {"IOError", &PyExc_IOError, 1},
8704
83c8adaa084f Added support for two new standard errors: EnvironmentError and
Barry Warsaw <barry@python.org>
parents: 8661
diff changeset
2352 {"OSError", &PyExc_OSError, 1},
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2353 {"ImportError", &PyExc_ImportError, 1},
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2354 {"IndexError", &PyExc_IndexError, 1},
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2355 {"KeyError", &PyExc_KeyError, 1},
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2356 {"KeyboardInterrupt", &PyExc_KeyboardInterrupt, 1},
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2357 {"MemoryError", &PyExc_MemoryError, 1},
11030
3be935be3781 Patch by Tim Peters:
Guido van Rossum <guido@python.org>
parents: 11010
diff changeset
2358 /* Note: NameError is not a leaf in exceptions.py, but unlike
3be935be3781 Patch by Tim Peters:
Guido van Rossum <guido@python.org>
parents: 11010
diff changeset
2359 the other non-leafs NameError is meant to be raised directly
3be935be3781 Patch by Tim Peters:
Guido van Rossum <guido@python.org>
parents: 11010
diff changeset
2360 at times -- the leaf_exc member really seems to mean something
3be935be3781 Patch by Tim Peters:
Guido van Rossum <guido@python.org>
parents: 11010
diff changeset
2361 like "this is an abstract base class" when false.
3be935be3781 Patch by Tim Peters:
Guido van Rossum <guido@python.org>
parents: 11010
diff changeset
2362 */
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2363 {"NameError", &PyExc_NameError, 1},
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2364 {"OverflowError", &PyExc_OverflowError, 1},
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2365 {"RuntimeError", &PyExc_RuntimeError, 1},
9567
b7158db347d9 Added new builtin standard exception: NotImplementedError (its C
Barry Warsaw <barry@python.org>
parents: 9514
diff changeset
2366 {"NotImplementedError",&PyExc_NotImplementedError,1},
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2367 {"SyntaxError", &PyExc_SyntaxError, 1},
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2368 {"SystemError", &PyExc_SystemError, 1},
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2369 {"SystemExit", &PyExc_SystemExit, 1},
11030
3be935be3781 Patch by Tim Peters:
Guido van Rossum <guido@python.org>
parents: 11010
diff changeset
2370 {"UnboundLocalError", &PyExc_UnboundLocalError, 1},
11973
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
2371 {"UnicodeError", &PyExc_UnicodeError, 1},
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2372 {"TypeError", &PyExc_TypeError, 1},
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2373 {"ValueError", &PyExc_ValueError, 1},
11800
449b074c3051 Changes by Mark Hammond related to the new WindowsError exception.
Guido van Rossum <guido@python.org>
parents: 11621
diff changeset
2374 #ifdef MS_WINDOWS
449b074c3051 Changes by Mark Hammond related to the new WindowsError exception.
Guido van Rossum <guido@python.org>
parents: 11621
diff changeset
2375 {"WindowsError", &PyExc_WindowsError, 1},
449b074c3051 Changes by Mark Hammond related to the new WindowsError exception.
Guido van Rossum <guido@python.org>
parents: 11621
diff changeset
2376 #endif
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2377 {"ZeroDivisionError", &PyExc_ZeroDivisionError, 1},
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2378 {NULL, NULL}
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2379 };
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2380
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2381
9112
83660cda3e3f Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents: 9069
diff changeset
2382 /* 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
2383 * 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
2384 * 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
2385 */
83660cda3e3f Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents: 9069
diff changeset
2386 static int
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2387 init_class_exc(dict)
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2388 PyObject *dict;
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2389 {
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2390 int i;
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2391 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
2392 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
2393 PyObject *d = NULL;
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2394
9112
83660cda3e3f Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents: 9069
diff changeset
2395 /* 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
2396 if (m == NULL ||
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2397 (d = PyModule_GetDict(m)) == NULL)
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2398 {
9112
83660cda3e3f Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents: 9069
diff changeset
2399 PySys_WriteStderr("'import exceptions' failed; ");
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2400 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
2401 PySys_WriteStderr("traceback:\n");
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2402 PyErr_Print();
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2403 }
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2404 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
2405 PySys_WriteStderr("use -v for traceback\n");
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2406 }
9112
83660cda3e3f Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents: 9069
diff changeset
2407 goto finally;
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2408 }
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2409 for (i = 0; bltin_exc[i].name; i++) {
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2410 /* dig the exception out of the module */
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2411 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
2412 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
2413 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
2414 "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
2415 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
2416 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
2417 }
83660cda3e3f Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents: 9069
diff changeset
2418 /* free the old-style exception string object */
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2419 Py_XDECREF(*bltin_exc[i].exc);
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2420
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2421 /* squirrel away a pointer to the exception */
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2422 Py_INCREF(exc);
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2423 *bltin_exc[i].exc = exc;
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2424
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2425 /* 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
2426 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
2427 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
2428 "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
2429 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
2430 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
2431 }
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2432 }
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2433
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2434 /* we need one pre-allocated instance */
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2435 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
2436 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
2437 !(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
2438 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
2439 {
83660cda3e3f Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents: 9069
diff changeset
2440 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
2441 goto finally;
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2442 }
9112
83660cda3e3f Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents: 9069
diff changeset
2443 Py_DECREF(args);
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2444
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2445 /* we're done with the exceptions module */
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2446 Py_DECREF(m);
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2447
9112
83660cda3e3f Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents: 9069
diff changeset
2448 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
2449 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
2450 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
2451 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
2452 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
2453 }
83660cda3e3f Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents: 9069
diff changeset
2454 else
83660cda3e3f Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents: 9069
diff changeset
2455 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
2456 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
2457 }
83660cda3e3f Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents: 9069
diff changeset
2458 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
2459 finally:
83660cda3e3f Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents: 9069
diff changeset
2460 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
2461 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
2462 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
2463 return 0;
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2464 }
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2465
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2466
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2467 static void
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2468 fini_instances()
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2469 {
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2470 Py_XDECREF(PyExc_MemoryErrorInst);
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2471 PyExc_MemoryErrorInst = NULL;
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2472 }
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2473
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2474
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2475 static PyObject *
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
2476 newstdexception(dict, name)
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
2477 PyObject *dict;
495
0ac9d5db41c8 Regularize exceptions.
Guido van Rossum <guido@python.org>
parents: 480
diff changeset
2478 char *name;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
2479 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2480 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
2481 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
2482 Py_FatalError("Cannot create string-based exceptions");
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
2483 return v;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
2484 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
2485
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
2486 static void
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
2487 initerrors(dict)
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
2488 PyObject *dict;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
2489 {
10292
1c6b10dea9f0 (initerrors): Make sure that the exception tuples ("base-classes" when
Barry Warsaw <barry@python.org>
parents: 10279
diff changeset
2490 int i, j;
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2491 int exccnt = 0;
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2492 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
2493 Py_XDECREF(*bltin_exc[i].exc);
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2494 if (bltin_exc[i].leaf_exc)
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2495 *bltin_exc[i].exc =
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2496 newstdexception(dict, bltin_exc[i].name);
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2497 }
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2498
8704
83c8adaa084f Added support for two new standard errors: EnvironmentError and
Barry Warsaw <barry@python.org>
parents: 8661
diff changeset
2499 /* 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
2500 * 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
2501 * 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
2502 * have a better solution, though.
83c8adaa084f Added support for two new standard errors: EnvironmentError and
Barry Warsaw <barry@python.org>
parents: 8661
diff changeset
2503 */
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2504 PyExc_LookupError = PyTuple_New(2);
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2505 Py_INCREF(PyExc_IndexError);
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2506 PyTuple_SET_ITEM(PyExc_LookupError, 0, PyExc_IndexError);
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2507 Py_INCREF(PyExc_KeyError);
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2508 PyTuple_SET_ITEM(PyExc_LookupError, 1, PyExc_KeyError);
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2509 PyDict_SetItemString(dict, "LookupError", PyExc_LookupError);
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2510
6326
b0183994021b [Py_Exc]NumberError => [Py_Exc]ArithmeticError
Barry Warsaw <barry@python.org>
parents: 6318
diff changeset
2511 PyExc_ArithmeticError = PyTuple_New(3);
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2512 Py_INCREF(PyExc_OverflowError);
6326
b0183994021b [Py_Exc]NumberError => [Py_Exc]ArithmeticError
Barry Warsaw <barry@python.org>
parents: 6318
diff changeset
2513 PyTuple_SET_ITEM(PyExc_ArithmeticError, 0, PyExc_OverflowError);
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2514 Py_INCREF(PyExc_ZeroDivisionError);
6326
b0183994021b [Py_Exc]NumberError => [Py_Exc]ArithmeticError
Barry Warsaw <barry@python.org>
parents: 6318
diff changeset
2515 PyTuple_SET_ITEM(PyExc_ArithmeticError, 1, PyExc_ZeroDivisionError);
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2516 Py_INCREF(PyExc_FloatingPointError);
6326
b0183994021b [Py_Exc]NumberError => [Py_Exc]ArithmeticError
Barry Warsaw <barry@python.org>
parents: 6318
diff changeset
2517 PyTuple_SET_ITEM(PyExc_ArithmeticError, 2, PyExc_FloatingPointError);
b0183994021b [Py_Exc]NumberError => [Py_Exc]ArithmeticError
Barry Warsaw <barry@python.org>
parents: 6318
diff changeset
2518 PyDict_SetItemString(dict, "ArithmeticError", PyExc_ArithmeticError);
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2519
8704
83c8adaa084f Added support for two new standard errors: EnvironmentError and
Barry Warsaw <barry@python.org>
parents: 8661
diff changeset
2520 PyExc_EnvironmentError = PyTuple_New(2);
83c8adaa084f Added support for two new standard errors: EnvironmentError and
Barry Warsaw <barry@python.org>
parents: 8661
diff changeset
2521 Py_INCREF(PyExc_IOError);
83c8adaa084f Added support for two new standard errors: EnvironmentError and
Barry Warsaw <barry@python.org>
parents: 8661
diff changeset
2522 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
2523 Py_INCREF(PyExc_OSError);
83c8adaa084f Added support for two new standard errors: EnvironmentError and
Barry Warsaw <barry@python.org>
parents: 8661
diff changeset
2524 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
2525 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
2526
11030
3be935be3781 Patch by Tim Peters:
Guido van Rossum <guido@python.org>
parents: 11010
diff changeset
2527 /* Make UnboundLocalError an alias for NameError */
3be935be3781 Patch by Tim Peters:
Guido van Rossum <guido@python.org>
parents: 11010
diff changeset
2528 Py_INCREF(PyExc_NameError);
3be935be3781 Patch by Tim Peters:
Guido van Rossum <guido@python.org>
parents: 11010
diff changeset
2529 Py_DECREF(PyExc_UnboundLocalError);
3be935be3781 Patch by Tim Peters:
Guido van Rossum <guido@python.org>
parents: 11010
diff changeset
2530 PyExc_UnboundLocalError = PyExc_NameError;
3be935be3781 Patch by Tim Peters:
Guido van Rossum <guido@python.org>
parents: 11010
diff changeset
2531 if (PyDict_SetItemString(dict, "UnboundLocalError",
3be935be3781 Patch by Tim Peters:
Guido van Rossum <guido@python.org>
parents: 11010
diff changeset
2532 PyExc_NameError) != 0)
3be935be3781 Patch by Tim Peters:
Guido van Rossum <guido@python.org>
parents: 11010
diff changeset
2533 Py_FatalError("Cannot create string-based exceptions");
3be935be3781 Patch by Tim Peters:
Guido van Rossum <guido@python.org>
parents: 11010
diff changeset
2534
11973
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
2535 /* Make UnicodeError an alias for ValueError */
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
2536 Py_INCREF(PyExc_ValueError);
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
2537 Py_DECREF(PyExc_UnicodeError);
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
2538 PyExc_UnicodeError = PyExc_ValueError;
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
2539 if (PyDict_SetItemString(dict, "UnicodeError",
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
2540 PyExc_ValueError) != 0)
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
2541 Py_FatalError("Cannot create string-based exceptions");
8bdc25d22925 Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
2542
10292
1c6b10dea9f0 (initerrors): Make sure that the exception tuples ("base-classes" when
Barry Warsaw <barry@python.org>
parents: 10279
diff changeset
2543 /* missing from the StandardError tuple: Exception, StandardError,
1c6b10dea9f0 (initerrors): Make sure that the exception tuples ("base-classes" when
Barry Warsaw <barry@python.org>
parents: 10279
diff changeset
2544 * and SystemExit
1c6b10dea9f0 (initerrors): Make sure that the exception tuples ("base-classes" when
Barry Warsaw <barry@python.org>
parents: 10279
diff changeset
2545 */
1c6b10dea9f0 (initerrors): Make sure that the exception tuples ("base-classes" when
Barry Warsaw <barry@python.org>
parents: 10279
diff changeset
2546 PyExc_StandardError = PyTuple_New(exccnt-3);
1c6b10dea9f0 (initerrors): Make sure that the exception tuples ("base-classes" when
Barry Warsaw <barry@python.org>
parents: 10279
diff changeset
2547 for (i = 2, j = 0; bltin_exc[i].name; i++) {
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2548 PyObject *exc = *bltin_exc[i].exc;
10292
1c6b10dea9f0 (initerrors): Make sure that the exception tuples ("base-classes" when
Barry Warsaw <barry@python.org>
parents: 10279
diff changeset
2549 /* SystemExit is not an error, but it is an exception */
1c6b10dea9f0 (initerrors): Make sure that the exception tuples ("base-classes" when
Barry Warsaw <barry@python.org>
parents: 10279
diff changeset
2550 if (exc != PyExc_SystemExit) {
1c6b10dea9f0 (initerrors): Make sure that the exception tuples ("base-classes" when
Barry Warsaw <barry@python.org>
parents: 10279
diff changeset
2551 Py_INCREF(exc);
1c6b10dea9f0 (initerrors): Make sure that the exception tuples ("base-classes" when
Barry Warsaw <barry@python.org>
parents: 10279
diff changeset
2552 PyTuple_SET_ITEM(PyExc_StandardError, j++, exc);
1c6b10dea9f0 (initerrors): Make sure that the exception tuples ("base-classes" when
Barry Warsaw <barry@python.org>
parents: 10279
diff changeset
2553 }
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2554 }
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2555 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
2556
10292
1c6b10dea9f0 (initerrors): Make sure that the exception tuples ("base-classes" when
Barry Warsaw <barry@python.org>
parents: 10279
diff changeset
2557 /* Exception is a 2-tuple */
1c6b10dea9f0 (initerrors): Make sure that the exception tuples ("base-classes" when
Barry Warsaw <barry@python.org>
parents: 10279
diff changeset
2558 PyExc_Exception = PyTuple_New(2);
1c6b10dea9f0 (initerrors): Make sure that the exception tuples ("base-classes" when
Barry Warsaw <barry@python.org>
parents: 10279
diff changeset
2559 Py_INCREF(PyExc_SystemExit);
1c6b10dea9f0 (initerrors): Make sure that the exception tuples ("base-classes" when
Barry Warsaw <barry@python.org>
parents: 10279
diff changeset
2560 PyTuple_SET_ITEM(PyExc_Exception, 0, PyExc_SystemExit);
1c6b10dea9f0 (initerrors): Make sure that the exception tuples ("base-classes" when
Barry Warsaw <barry@python.org>
parents: 10279
diff changeset
2561 Py_INCREF(PyExc_StandardError);
1c6b10dea9f0 (initerrors): Make sure that the exception tuples ("base-classes" when
Barry Warsaw <barry@python.org>
parents: 10279
diff changeset
2562 PyTuple_SET_ITEM(PyExc_Exception, 1, 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
2563 PyDict_SetItemString(dict, "Exception", PyExc_Exception);
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2564
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2565 if (PyErr_Occurred())
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2566 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
2567 }
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
2568
10292
1c6b10dea9f0 (initerrors): Make sure that the exception tuples ("base-classes" when
Barry Warsaw <barry@python.org>
parents: 10279
diff changeset
2569
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
2570 static void
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
2571 finierrors()
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
2572 {
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2573 int i;
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2574 for (i = 0; bltin_exc[i].name; i++) {
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2575 PyObject *exc = *bltin_exc[i].exc;
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2576 Py_XDECREF(exc);
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2577 *bltin_exc[i].exc = NULL;
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2578 }
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
2579 }
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
2580
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2581 static char builtin_doc[] =
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2582 "Built-in functions, exceptions, and other objects.\n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2583 \n\
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2584 Noteworthy: None is the `nil' object; Ellipsis represents `...' in slices.";
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2585
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
2586 PyObject *
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2587 _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
2588 {
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
2589 PyObject *mod, *dict;
8561
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2590 mod = Py_InitModule4("__builtin__", builtin_methods,
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2591 builtin_doc, (PyObject *)NULL,
8973e7085cf4 Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8560
diff changeset
2592 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
2593 if (mod == NULL)
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
2594 return NULL;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
2595 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
2596 initerrors(dict);
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
2597 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
2598 return NULL;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
2599 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
2600 return NULL;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
2601 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
2602 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
2603 return NULL;
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2604
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
2605 return mod;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
2606 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
2607
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
2608 void
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2609 _PyBuiltin_Init_2(dict)
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2610 PyObject *dict;
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2611 {
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2612 /* 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
2613 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
2614 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
2615 /* 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
2616 * 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
2617 * exceptions.
83660cda3e3f Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents: 9069
diff changeset
2618 */
83660cda3e3f Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents: 9069
diff changeset
2619 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
2620 "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
2621 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
2622 }
83660cda3e3f Several changes that Python carry on in the face of errors in the
Barry Warsaw <barry@python.org>
parents: 9069
diff changeset
2623 }
6198
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2624 }
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2625
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2626
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2627 void
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2628 _PyBuiltin_Fini_1()
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2629 {
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2630 fini_instances();
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2631 }
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2632
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2633
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2634 void
c43ca8dd0081 Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents: 6145
diff changeset
2635 _PyBuiltin_Fini_2()
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
2636 {
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5610
diff changeset
2637 finierrors();
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents:
diff changeset
2638 }
301
c28fabe21165 Add and use coerce() routine for mixed mode arithmetic
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
2639
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2640
1393
7d6a2d950f13 * nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents: 1387
diff changeset
2641 /* 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
2642
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2643 static PyObject *
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2644 filtertuple(func, tuple)
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2645 PyObject *func;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2646 PyObject *tuple;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2647 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2648 PyObject *result;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2649 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
2650 int len = PyTuple_Size(tuple);
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2651
2890
04e1690fb4d1 avoid resize of 0-length tuple
Guido van Rossum <guido@python.org>
parents: 2857
diff changeset
2652 if (len == 0) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2653 Py_INCREF(tuple);
2890
04e1690fb4d1 avoid resize of 0-length tuple
Guido van Rossum <guido@python.org>
parents: 2857
diff changeset
2654 return tuple;
04e1690fb4d1 avoid resize of 0-length tuple
Guido van Rossum <guido@python.org>
parents: 2857
diff changeset
2655 }
04e1690fb4d1 avoid resize of 0-length tuple
Guido van Rossum <guido@python.org>
parents: 2857
diff changeset
2656
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2657 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
2658 return NULL;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2659
1375
f3a325662d39 * listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
2660 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
2661 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
2662 int ok;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2663
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2664 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
2665 goto Fail_1;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2666 if (func == Py_None) {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2667 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
2668 good = item;
f3a325662d39 * listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
2669 }
f3a325662d39 * listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
2670 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2671 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
2672 if (arg == NULL)
f3a325662d39 * listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
2673 goto Fail_1;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2674 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
2675 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
2676 if (good == NULL)
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2677 goto Fail_1;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2678 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2679 ok = PyObject_IsTrue(good);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2680 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
2681 if (ok) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2682 Py_INCREF(item);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2683 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
2684 goto Fail_1;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2685 }
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2686 }
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2687
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2688 if (_PyTuple_Resize(&result, j, 0) < 0)
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2689 return NULL;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2690
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2691 return result;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2692
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2693 Fail_1:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2694 Py_DECREF(result);
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2695 return NULL;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2696 }
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2697
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2698
1393
7d6a2d950f13 * nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents: 1387
diff changeset
2699 /* 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
2700
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2701 static PyObject *
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2702 filterstring(func, strobj)
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2703 PyObject *func;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2704 PyObject *strobj;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2705 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2706 PyObject *result;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2707 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
2708 int len = PyString_Size(strobj);
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2709
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2710 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
2711 /* 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
2712 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
2713 return strobj;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2714 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2715 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
2716 return NULL;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2717
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2718 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
2719 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
2720 int ok;
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2721
1375
f3a325662d39 * listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
2722 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
2723 if (item == NULL)
f3a325662d39 * listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
2724 goto Fail_1;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2725 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
2726 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
2727 if (arg == NULL)
f3a325662d39 * listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
2728 goto Fail_1;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2729 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
2730 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
2731 if (good == NULL)
f3a325662d39 * listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents: 1369
diff changeset
2732 goto Fail_1;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2733 ok = PyObject_IsTrue(good);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2734 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
2735 if (ok)
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2736 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
2737 PyString_AS_STRING((PyStringObject *)item)[0];
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2738 }
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2739
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2740 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
2741 return NULL;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2742
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2743 return result;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2744
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2745 Fail_1:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5317
diff changeset
2746 Py_DECREF(result);
1369
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2747 return NULL;
89e1e5d9ccbf * compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents: 1360
diff changeset
2748 }