Mercurial > cpython-lru_cache-weakref
annotate Python/bltinmodule.c @ 17683:e9a4e27e8d4e legacy-trunk
Make PyIter_Next() a little smarter (wrt its knowledge of iterator
internals) so clients can be a lot dumber (wrt their knowledge).
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Sat, 05 May 2001 00:14:56 +0000 |
| parents | bf7f166d3c97 |
| children | aab6c1f19289 |
| rev | line source |
|---|---|
|
15637
7fb7c51a2e61
Whoops! Two stray characters crept in to my last check-in
Andrew M. Kuchling <amk@amk.ca>
parents:
15635
diff
changeset
|
1 |
| 86 | 2 /* Built-in functions */ |
| 3 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
4 #include "Python.h" |
| 86 | 5 |
| 6 #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
|
7 #include "compile.h" |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
8 #include "eval.h" |
| 86 | 9 |
|
5317
c72c7e1930b3
Keep gcc -Wall and Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents:
5223
diff
changeset
|
10 #include <ctype.h> |
|
c72c7e1930b3
Keep gcc -Wall and Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents:
5223
diff
changeset
|
11 |
|
4655
c75a2f2dc220
Add unistd.h to make gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4595
diff
changeset
|
12 #ifdef HAVE_UNISTD_H |
|
c75a2f2dc220
Add unistd.h to make gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4595
diff
changeset
|
13 #include <unistd.h> |
|
c75a2f2dc220
Add unistd.h to make gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4595
diff
changeset
|
14 #endif |
|
c75a2f2dc220
Add unistd.h to make gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4595
diff
changeset
|
15 |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
16 /* Forward */ |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13446
diff
changeset
|
17 static PyObject *filterstring(PyObject *, PyObject *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13446
diff
changeset
|
18 static PyObject *filtertuple (PyObject *, PyObject *); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
19 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
20 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
21 builtin___import__(PyObject *self, 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
|
22 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
23 char *name; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
24 PyObject *globals = NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
25 PyObject *locals = NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
26 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
|
27 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
28 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
|
29 &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
|
30 return NULL; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6198
diff
changeset
|
31 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
|
32 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
33 |
| 8561 | 34 static char import_doc[] = |
| 35 "__import__(name, globals, locals, fromlist) -> module\n\ | |
| 36 \n\ | |
| 37 Import a module. The globals are only used to determine the context;\n\ | |
| 38 they are not modified. The locals are currently unused. The fromlist\n\ | |
| 39 should be a list of names to emulate ``from name import ...'', or an\n\ | |
| 40 empty list to emulate ``import name''.\n\ | |
| 41 When importing a module from a package, note that __import__('A.B', ...)\n\ | |
| 42 returns package A when fromlist is empty, but its submodule B when\n\ | |
| 43 fromlist is not empty."; | |
| 44 | |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
45 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
46 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
47 builtin_abs(PyObject *self, 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
|
48 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
49 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
|
50 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
51 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
|
52 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
|
53 return PyNumber_Absolute(v); |
| 86 | 54 } |
| 55 | |
| 8561 | 56 static char abs_doc[] = |
| 57 "abs(number) -> number\n\ | |
| 58 \n\ | |
| 59 Return the absolute value of the argument."; | |
| 60 | |
| 61 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
62 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
63 builtin_apply(PyObject *self, PyObject *args) |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
64 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
65 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
|
66 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
|
67 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
68 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
|
69 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
|
70 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
|
71 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
|
72 if (!PySequence_Check(alist)) { |
|
16017
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16011
diff
changeset
|
73 PyErr_Format(PyExc_TypeError, |
|
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16011
diff
changeset
|
74 "apply() arg 2 expect sequence, found %s", |
|
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16011
diff
changeset
|
75 alist->ob_type->tp_name); |
|
9188
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
76 return NULL; |
|
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
77 } |
|
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
78 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
|
79 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
|
80 return NULL; |
|
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
81 alist = t; |
|
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
82 } |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
83 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
84 if (kwdict != NULL && !PyDict_Check(kwdict)) { |
|
16017
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16011
diff
changeset
|
85 PyErr_Format(PyExc_TypeError, |
|
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16011
diff
changeset
|
86 "apply() arg 3 expected dictionary, found %s", |
|
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16011
diff
changeset
|
87 kwdict->ob_type->tp_name); |
|
9188
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
88 goto finally; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2824
diff
changeset
|
89 } |
|
9188
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
90 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
|
91 finally: |
|
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
92 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
|
93 return retval; |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
94 } |
|
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
95 |
| 8561 | 96 static char apply_doc[] = |
|
15832
0ae389e935fc
Update the docstring for apply() so that "args" is marked as optional
Fred Drake <fdrake@acm.org>
parents:
15829
diff
changeset
|
97 "apply(object[, args[, kwargs]]) -> value\n\ |
| 8561 | 98 \n\ |
|
11621
0ec803cbd872
Adjusted apply() docstring based on comments from Gerrit Holl
Fred Drake <fdrake@acm.org>
parents:
11383
diff
changeset
|
99 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
|
100 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
|
101 Note that classes are callable, as are instances with a __call__() method."; |
| 8561 | 102 |
| 103 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
104 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
105 builtin_buffer(PyObject *self, PyObject *args) |
|
10428
3571b4c1bc0e
New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents:
10292
diff
changeset
|
106 { |
|
3571b4c1bc0e
New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents:
10292
diff
changeset
|
107 PyObject *ob; |
|
3571b4c1bc0e
New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents:
10292
diff
changeset
|
108 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
|
109 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
|
110 |
|
3571b4c1bc0e
New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents:
10292
diff
changeset
|
111 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
|
112 return NULL; |
|
3571b4c1bc0e
New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents:
10292
diff
changeset
|
113 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
|
114 } |
|
3571b4c1bc0e
New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents:
10292
diff
changeset
|
115 |
|
3571b4c1bc0e
New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents:
10292
diff
changeset
|
116 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
|
117 "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
|
118 \n\ |
|
15829
9308dc8c85e0
(Modified) patch by Ping - SF Patch #102681.
Guido van Rossum <guido@python.org>
parents:
15727
diff
changeset
|
119 Create a new buffer object which references the given 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
|
120 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
|
121 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
|
122 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
|
123 |
|
3571b4c1bc0e
New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents:
10292
diff
changeset
|
124 |
|
3571b4c1bc0e
New builtin buffer() creates a derived read-only buffer from any
Guido van Rossum <guido@python.org>
parents:
10292
diff
changeset
|
125 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
126 builtin_unicode(PyObject *self, PyObject *args) |
|
11973
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
127 { |
| 12368 | 128 PyObject *v; |
|
11973
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
129 char *encoding = NULL; |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
130 char *errors = NULL; |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
131 |
| 12368 | 132 if ( !PyArg_ParseTuple(args, "O|ss:unicode", &v, &encoding, &errors) ) |
|
11973
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
133 return NULL; |
|
13402
7fbdb581838f
Fixed unicode() to use the new API PyUnicode_FromEncodedObject().
Marc-André Lemburg <mal@egenix.com>
parents:
13330
diff
changeset
|
134 return PyUnicode_FromEncodedObject(v, encoding, errors); |
|
11973
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
135 } |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
136 |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
137 static char unicode_doc[] = |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
138 "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
|
139 \n\ |
|
15829
9308dc8c85e0
(Modified) patch by Ping - SF Patch #102681.
Guido van Rossum <guido@python.org>
parents:
15727
diff
changeset
|
140 Create a new Unicode object from the given encoded string.\n\ |
|
12647
035abb930317
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
141 encoding defaults to the current default string encoding and \n\ |
|
035abb930317
M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
142 errors, defining the error handling, to 'strict'."; |
|
11973
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
143 |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
144 |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
145 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
146 builtin_callable(PyObject *self, PyObject *args) |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
147 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
148 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
|
149 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
150 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
|
151 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
152 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
|
153 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
154 |
| 8561 | 155 static char callable_doc[] = |
| 156 "callable(object) -> Boolean\n\ | |
| 157 \n\ | |
| 158 Return whether the object is callable (i.e., some kind of function).\n\ | |
| 159 Note that classes are callable, as are instances with a __call__() method."; | |
| 160 | |
| 161 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
162 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
163 builtin_filter(PyObject *self, PyObject *args) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
164 { |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
165 PyObject *func, *seq, *result, *it; |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
166 int len; /* guess for result list size */ |
|
17683
e9a4e27e8d4e
Make PyIter_Next() a little smarter (wrt its knowledge of iterator
Tim Peters <tim.peters@gmail.com>
parents:
17677
diff
changeset
|
167 register int j; |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
168 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
169 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
|
170 return NULL; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
171 |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
172 /* Strings and tuples return a result of the same type. */ |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
173 if (PyString_Check(seq)) |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
174 return filterstring(func, seq); |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
175 if (PyTuple_Check(seq)) |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
176 return filtertuple(func, seq); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
177 |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
178 /* Get iterator. */ |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
179 it = PyObject_GetIter(seq); |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
180 if (it == NULL) |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
181 return NULL; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
182 |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
183 /* Guess a result list size. */ |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
184 len = -1; /* unknown */ |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
185 if (PySequence_Check(seq) && |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
186 seq->ob_type->tp_as_sequence->sq_length) { |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
187 len = PySequence_Size(seq); |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
188 if (len < 0) |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
189 PyErr_Clear(); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
190 } |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
191 if (len < 0) |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
192 len = 8; /* arbitrary */ |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
193 |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
194 /* Get a result list. */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
195 if (PyList_Check(seq) && seq->ob_refcnt == 1) { |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
196 /* Eww - can modify the list in-place. */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
197 Py_INCREF(seq); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
198 result = seq; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
199 } |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
200 else { |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
201 result = PyList_New(len); |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
202 if (result == NULL) |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
203 goto Fail_it; |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
204 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
205 |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
206 /* Build the result list. */ |
|
17683
e9a4e27e8d4e
Make PyIter_Next() a little smarter (wrt its knowledge of iterator
Tim Peters <tim.peters@gmail.com>
parents:
17677
diff
changeset
|
207 j = 0; |
|
e9a4e27e8d4e
Make PyIter_Next() a little smarter (wrt its knowledge of iterator
Tim Peters <tim.peters@gmail.com>
parents:
17677
diff
changeset
|
208 for (;;) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
209 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
|
210 int ok; |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
211 |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
212 item = PyIter_Next(it); |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
213 if (item == NULL) { |
|
17683
e9a4e27e8d4e
Make PyIter_Next() a little smarter (wrt its knowledge of iterator
Tim Peters <tim.peters@gmail.com>
parents:
17677
diff
changeset
|
214 if (PyErr_Occurred()) |
|
e9a4e27e8d4e
Make PyIter_Next() a little smarter (wrt its knowledge of iterator
Tim Peters <tim.peters@gmail.com>
parents:
17677
diff
changeset
|
215 goto Fail_result_it; |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
216 break; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
217 } |
|
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 (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
|
220 good = item; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
221 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
|
222 } |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
223 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
224 PyObject *arg = Py_BuildValue("(O)", item); |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
225 if (arg == NULL) { |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
226 Py_DECREF(item); |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
227 goto Fail_result_it; |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
228 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
229 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
|
230 Py_DECREF(arg); |
|
2120
84b61fe44573
fix subtle refcount big in filter() -- Tim MacKenzie
Guido van Rossum <guido@python.org>
parents:
2113
diff
changeset
|
231 if (good == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
232 Py_DECREF(item); |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
233 goto Fail_result_it; |
|
2120
84b61fe44573
fix subtle refcount big in filter() -- Tim MacKenzie
Guido van Rossum <guido@python.org>
parents:
2113
diff
changeset
|
234 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
235 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
236 ok = PyObject_IsTrue(good); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
237 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
|
238 if (ok) { |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
239 if (j < len) |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
240 PyList_SET_ITEM(result, j, item); |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
241 else { |
|
9991
ddbbed8cb830
builtin_map(): A better fix for the previous leak plug (remember
Barry Warsaw <barry@python.org>
parents:
9980
diff
changeset
|
242 int status = PyList_Append(result, item); |
|
ddbbed8cb830
builtin_map(): A better fix for the previous leak plug (remember
Barry Warsaw <barry@python.org>
parents:
9980
diff
changeset
|
243 Py_DECREF(item); |
|
ddbbed8cb830
builtin_map(): A better fix for the previous leak plug (remember
Barry Warsaw <barry@python.org>
parents:
9980
diff
changeset
|
244 if (status < 0) |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
245 goto Fail_result_it; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
246 } |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
247 ++j; |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
248 } |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
249 else |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
250 Py_DECREF(item); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
251 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
252 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
253 |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
254 /* Cut back result list if len is too big. */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
255 if (j < len && PyList_SetSlice(result, j, len, NULL) < 0) |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
256 goto Fail_result_it; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
257 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
258 return result; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
259 |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
260 Fail_result_it: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
261 Py_DECREF(result); |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
262 Fail_it: |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
263 Py_DECREF(it); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
264 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
265 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
266 |
| 8561 | 267 static char filter_doc[] = |
| 268 "filter(function, sequence) -> list\n\ | |
| 269 \n\ | |
| 270 Return a list containing those items of sequence for which function(item)\n\ | |
| 271 is true. If function is None, return a list of items that are true."; | |
| 272 | |
| 273 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
274 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
275 builtin_chr(PyObject *self, PyObject *args) |
| 86 | 276 { |
| 277 long x; | |
| 278 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
|
279 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
280 if (!PyArg_ParseTuple(args, "l:chr", &x)) |
| 86 | 281 return NULL; |
| 282 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
|
283 PyErr_SetString(PyExc_ValueError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
284 "chr() arg not in range(256)"); |
| 86 | 285 return NULL; |
| 286 } | |
|
5317
c72c7e1930b3
Keep gcc -Wall and Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents:
5223
diff
changeset
|
287 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
|
288 return PyString_FromStringAndSize(s, 1); |
| 86 | 289 } |
| 290 | |
| 8561 | 291 static char chr_doc[] = |
| 292 "chr(i) -> character\n\ | |
| 293 \n\ | |
| 294 Return a string of one character with ordinal i; 0 <= i < 256."; | |
| 295 | |
| 296 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
297 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
298 builtin_unichr(PyObject *self, PyObject *args) |
|
11973
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
299 { |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
300 long x; |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
301 Py_UNICODE s[1]; |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
302 |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
303 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
|
304 return NULL; |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
305 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
|
306 PyErr_SetString(PyExc_ValueError, |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
307 "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
|
308 return NULL; |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
309 } |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
310 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
|
311 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
|
312 } |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
313 |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
314 static char unichr_doc[] = |
|
12386
32e9d0e78935
When refering to Unicode characters in exception messages and
Fred Drake <fdrake@acm.org>
parents:
12384
diff
changeset
|
315 "unichr(i) -> Unicode character\n\ |
|
11973
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
316 \n\ |
|
12386
32e9d0e78935
When refering to Unicode characters in exception messages and
Fred Drake <fdrake@acm.org>
parents:
12384
diff
changeset
|
317 Return a Unicode string of one character with ordinal i; 0 <= i < 65536."; |
|
11973
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
318 |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
319 |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
320 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
321 builtin_cmp(PyObject *self, PyObject *args) |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
322 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
323 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
|
324 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
|
325 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
326 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
|
327 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
|
328 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
|
329 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
|
330 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
|
331 } |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
332 |
| 8561 | 333 static char cmp_doc[] = |
| 334 "cmp(x, y) -> integer\n\ | |
| 335 \n\ | |
| 336 Return negative if x<y, zero if x==y, positive if x>y."; | |
| 337 | |
| 338 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
339 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
340 builtin_coerce(PyObject *self, 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
|
341 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
342 PyObject *v, *w; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
343 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
|
344 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
345 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
|
346 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
347 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
|
348 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
349 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
|
350 Py_DECREF(v); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
351 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
|
352 return res; |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
353 } |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
354 |
| 8561 | 355 static char coerce_doc[] = |
| 356 "coerce(x, y) -> None or (x1, y1)\n\ | |
| 357 \n\ | |
| 358 When x and y can be coerced to values of the same type, return a tuple\n\ | |
| 359 containing the coerced values. When they can't be coerced, return None."; | |
| 360 | |
| 361 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
362 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
363 builtin_compile(PyObject *self, PyObject *args) |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
364 { |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
365 char *str; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
366 char *filename; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
367 char *startstr; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
368 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
|
369 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
370 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
|
371 return NULL; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
372 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
|
373 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
|
374 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
|
375 start = Py_eval_input; |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
376 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
|
377 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
|
378 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
379 PyErr_SetString(PyExc_ValueError, |
| 15318 | 380 "compile() arg 3 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
|
381 return NULL; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
382 } |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17111
diff
changeset
|
383 if (PyEval_GetNestedScopes()) { |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17111
diff
changeset
|
384 PyCompilerFlags cf; |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17111
diff
changeset
|
385 cf.cf_nested_scopes = 1; |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17111
diff
changeset
|
386 return Py_CompileStringFlags(str, filename, start, &cf); |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17111
diff
changeset
|
387 } else |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17111
diff
changeset
|
388 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
|
389 } |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
390 |
| 8561 | 391 static char compile_doc[] = |
| 392 "compile(source, filename, mode) -> code object\n\ | |
| 393 \n\ | |
| 394 Compile the source string (a Python module, statement or expression)\n\ | |
| 395 into a code object that can be executed by the exec statement or eval().\n\ | |
| 396 The filename will be used for run-time error messages.\n\ | |
| 397 The mode must be 'exec' to compile a module, 'single' to compile a\n\ | |
| 398 single (interactive) statement, or 'eval' to compile an expression."; | |
| 399 | |
| 400 | |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
401 #ifndef WITHOUT_COMPLEX |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
402 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
403 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
404 complex_from_string(PyObject *v) |
|
10466
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
405 { |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13446
diff
changeset
|
406 extern double strtod(const char *, char **); |
|
12248
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
407 const char *s, *start; |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
408 char *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
|
409 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
|
410 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
|
411 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
|
412 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
|
413 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
|
414 char buffer[256]; /* For errors */ |
|
14052
275bc4f9d50d
comples_from_string(): Move s_buffer[] up to the top-level function
Barry Warsaw <barry@python.org>
parents:
13943
diff
changeset
|
415 char s_buffer[256]; |
|
12248
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
416 int len; |
|
10466
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
417 |
|
12248
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
418 if (PyString_Check(v)) { |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
419 s = PyString_AS_STRING(v); |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
420 len = PyString_GET_SIZE(v); |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
421 } |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
422 else if (PyUnicode_Check(v)) { |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
423 if (PyUnicode_GET_SIZE(v) >= sizeof(s_buffer)) { |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
424 PyErr_SetString(PyExc_ValueError, |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
425 "complex() literal too large to convert"); |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
426 return NULL; |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
427 } |
|
15829
9308dc8c85e0
(Modified) patch by Ping - SF Patch #102681.
Guido van Rossum <guido@python.org>
parents:
15727
diff
changeset
|
428 if (PyUnicode_EncodeDecimal(PyUnicode_AS_UNICODE(v), |
|
12248
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
429 PyUnicode_GET_SIZE(v), |
|
15829
9308dc8c85e0
(Modified) patch by Ping - SF Patch #102681.
Guido van Rossum <guido@python.org>
parents:
15727
diff
changeset
|
430 s_buffer, |
|
12248
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
431 NULL)) |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
432 return NULL; |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
433 s = s_buffer; |
|
13943
5780b198abc8
Clean up a couple of warnings on Win64. The downcast of the strlen size_t
Trent Mick <trentm@activestate.com>
parents:
13822
diff
changeset
|
434 len = (int)strlen(s); |
|
12248
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
435 } |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
436 else if (PyObject_AsCharBuffer(v, &s, &len)) { |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
437 PyErr_SetString(PyExc_TypeError, |
| 15318 | 438 "complex() arg is not a string"); |
|
12248
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
439 return NULL; |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
440 } |
|
10466
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
441 |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
442 /* position on first nonblank */ |
|
12248
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
443 start = s; |
|
10466
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
444 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
|
445 s++; |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
446 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
|
447 PyErr_SetString(PyExc_ValueError, |
| 15318 | 448 "complex() arg is an empty string"); |
|
10466
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
449 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
|
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 |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
452 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
|
453 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
|
454 do { |
|
15829
9308dc8c85e0
(Modified) patch by Ping - SF Patch #102681.
Guido van Rossum <guido@python.org>
parents:
15727
diff
changeset
|
455 |
|
10466
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
456 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
|
457 |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
458 case '\0': |
|
12248
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
459 if (s-start != len) { |
|
10466
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
460 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
|
461 PyExc_ValueError, |
| 15318 | 462 "complex() arg contains a null byte"); |
|
10466
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
463 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
|
464 } |
|
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(!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
|
466 break; |
|
15829
9308dc8c85e0
(Modified) patch by Ping - SF Patch #102681.
Guido van Rossum <guido@python.org>
parents:
15727
diff
changeset
|
467 |
|
10466
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
468 case '-': |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
469 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
|
470 /* Fallthrough */ |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
471 case '+': |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
472 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
|
473 s++; |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
474 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
|
475 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
|
476 break; |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
477 |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
478 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
|
479 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
|
480 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
|
481 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
|
482 break; |
|
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 (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
|
485 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
|
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 else{ |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
488 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
|
489 } |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
490 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
|
491 s++; |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
492 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
|
493 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
|
494 break; |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
495 |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
496 default: |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
497 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
|
498 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
|
499 s++; |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
500 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
|
501 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
|
502 else |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
503 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
|
504 break; |
|
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 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
|
507 (*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
|
508 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
|
509 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
|
510 break; |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
511 } |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
512 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
|
513 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
|
514 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
|
515 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
|
516 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
|
517 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
|
518 "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
|
519 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
|
520 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
|
521 buffer); |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
522 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
|
523 } |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
524 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
|
525 if (*s=='J' || *s=='j') { |
|
15829
9308dc8c85e0
(Modified) patch by Ping - SF Patch #102681.
Guido van Rossum <guido@python.org>
parents:
15727
diff
changeset
|
526 |
|
10466
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
527 break; |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
528 } |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
529 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
|
530 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
|
531 break; |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
532 } |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
533 |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
534 /* 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
|
535 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
|
536 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
|
537 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
|
538 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
|
539 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
|
540 break; |
|
15829
9308dc8c85e0
(Modified) patch by Ping - SF Patch #102681.
Guido van Rossum <guido@python.org>
parents:
15727
diff
changeset
|
541 |
|
10466
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
542 } /* 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
|
543 |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
544 } 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
|
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 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
|
547 PyErr_SetString(PyExc_ValueError, |
| 15318 | 548 "complex() arg is a malformed string"); |
|
10466
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
549 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
|
550 } |
|
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 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
|
553 } |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
554 |
|
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
555 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
556 builtin_complex(PyObject *self, PyObject *args) |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
557 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
558 PyObject *r, *i, *tmp; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
559 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
|
560 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
|
561 int own_r = 0; |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
562 |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
563 i = NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
564 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
|
565 return NULL; |
|
12248
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
566 if (PyString_Check(r) || PyUnicode_Check(r)) |
|
10466
36ba4dbff686
Patch by Nick and Stephanie Lockwood to implement complex() with a string
Guido van Rossum <guido@python.org>
parents:
10428
diff
changeset
|
567 return complex_from_string(r); |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
568 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
|
569 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
|
570 (i != NULL && |
|
bc8832b52b50
1. Add string conversions to int(), long(), float(). (Not to complex()!)
Guido van Rossum <guido@python.org>
parents:
5182
diff
changeset
|
571 ((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
|
572 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
|
573 PyErr_SetString(PyExc_TypeError, |
| 15318 | 574 "complex() arg can't be converted to complex"); |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
575 return NULL; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
576 } |
|
4595
f8f3da3fdaed
Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
577 /* 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
|
578 if (PyInstance_Check(r)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
579 static PyObject *complexstr; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
580 PyObject *f; |
|
4595
f8f3da3fdaed
Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
581 if (complexstr == NULL) { |
|
5010
f0cf8d275fbc
Intern the string "__complex__".
Guido van Rossum <guido@python.org>
parents:
4655
diff
changeset
|
582 complexstr = PyString_InternFromString("__complex__"); |
|
4595
f8f3da3fdaed
Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
583 if (complexstr == NULL) |
|
f8f3da3fdaed
Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
584 return NULL; |
|
f8f3da3fdaed
Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
585 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
586 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
|
587 if (f == NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
588 PyErr_Clear(); |
|
4595
f8f3da3fdaed
Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
589 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
590 PyObject *args = Py_BuildValue("()"); |
|
4595
f8f3da3fdaed
Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
591 if (args == NULL) |
|
f8f3da3fdaed
Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
592 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
593 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
|
594 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
|
595 Py_DECREF(f); |
|
4595
f8f3da3fdaed
Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
596 if (r == NULL) |
|
f8f3da3fdaed
Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
597 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
|
598 own_r = 1; |
|
4595
f8f3da3fdaed
Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
599 } |
|
f8f3da3fdaed
Support __complex__ method on instances, for complex() conversion.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
600 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
601 if (PyComplex_Check(r)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
602 cr = ((PyComplexObject*)r)->cval; |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
7678
diff
changeset
|
603 if (own_r) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
604 Py_DECREF(r); |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
7678
diff
changeset
|
605 } |
|
5223
bc8832b52b50
1. Add string conversions to int(), long(), float(). (Not to complex()!)
Guido van Rossum <guido@python.org>
parents:
5182
diff
changeset
|
606 } |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
607 else { |
|
16011
d90eeab5f9a4
Fix for the bug in complex() just reported by Ping.
Guido van Rossum <guido@python.org>
parents:
15952
diff
changeset
|
608 tmp = PyNumber_Float(r); |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
7678
diff
changeset
|
609 if (own_r) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
610 Py_DECREF(r); |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
7678
diff
changeset
|
611 } |
|
3962
f08d7f368ebf
Include mymath.h instead of declaring prototypes for math functions.
Guido van Rossum <guido@python.org>
parents:
3862
diff
changeset
|
612 if (tmp == NULL) |
|
f08d7f368ebf
Include mymath.h instead of declaring prototypes for math functions.
Guido van Rossum <guido@python.org>
parents:
3862
diff
changeset
|
613 return NULL; |
|
16011
d90eeab5f9a4
Fix for the bug in complex() just reported by Ping.
Guido van Rossum <guido@python.org>
parents:
15952
diff
changeset
|
614 if (!PyFloat_Check(tmp)) { |
|
d90eeab5f9a4
Fix for the bug in complex() just reported by Ping.
Guido van Rossum <guido@python.org>
parents:
15952
diff
changeset
|
615 PyErr_SetString(PyExc_TypeError, |
|
d90eeab5f9a4
Fix for the bug in complex() just reported by Ping.
Guido van Rossum <guido@python.org>
parents:
15952
diff
changeset
|
616 "float(r) didn't return a float"); |
|
d90eeab5f9a4
Fix for the bug in complex() just reported by Ping.
Guido van Rossum <guido@python.org>
parents:
15952
diff
changeset
|
617 Py_DECREF(tmp); |
|
d90eeab5f9a4
Fix for the bug in complex() just reported by Ping.
Guido van Rossum <guido@python.org>
parents:
15952
diff
changeset
|
618 return NULL; |
|
d90eeab5f9a4
Fix for the bug in complex() just reported by Ping.
Guido van Rossum <guido@python.org>
parents:
15952
diff
changeset
|
619 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
620 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
|
621 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
|
622 cr.imag = 0.0; |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
623 } |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
624 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
|
625 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
|
626 ci.imag = 0.0; |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
627 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
628 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
|
629 ci = ((PyComplexObject*)i)->cval; |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
630 else { |
|
5223
bc8832b52b50
1. Add string conversions to int(), long(), float(). (Not to complex()!)
Guido van Rossum <guido@python.org>
parents:
5182
diff
changeset
|
631 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
|
632 if (tmp == NULL) |
|
f08d7f368ebf
Include mymath.h instead of declaring prototypes for math functions.
Guido van Rossum <guido@python.org>
parents:
3862
diff
changeset
|
633 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
634 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
|
635 Py_DECREF(tmp); |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
636 ci.imag = 0.; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
637 } |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
638 cr.real -= ci.imag; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
639 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
|
640 return PyComplex_FromCComplex(cr); |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
641 } |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
642 |
| 8561 | 643 static char complex_doc[] = |
| 644 "complex(real[, imag]) -> complex number\n\ | |
| 645 \n\ | |
| 646 Create a complex number from a real part and an optional imaginary part.\n\ | |
| 647 This is equivalent to (real + imag*1j) where imag defaults to 0."; | |
| 648 | |
| 649 | |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
650 #endif |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
651 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
652 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
653 builtin_dir(PyObject *self, PyObject *args) |
| 86 | 654 { |
| 5421 | 655 static char *attrlist[] = {"__members__", "__methods__", NULL}; |
| 656 PyObject *v = NULL, *l = NULL, *m = NULL; | |
| 657 PyObject *d, *x; | |
| 658 int i; | |
| 659 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
|
660 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
661 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
|
662 return NULL; |
| 86 | 663 if (v == NULL) { |
| 5421 | 664 x = PyEval_GetLocals(); |
| 665 if (x == NULL) | |
| 666 goto error; | |
| 667 l = PyMapping_Keys(x); | |
| 668 if (l == NULL) | |
| 669 goto error; | |
| 86 | 670 } |
| 671 else { | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
672 d = PyObject_GetAttrString(v, "__dict__"); |
| 5421 | 673 if (d == NULL) |
| 674 PyErr_Clear(); | |
| 675 else { | |
| 676 l = PyMapping_Keys(d); | |
| 677 if (l == NULL) | |
| 678 PyErr_Clear(); | |
| 679 Py_DECREF(d); | |
| 680 } | |
| 681 if (l == NULL) { | |
| 682 l = PyList_New(0); | |
| 683 if (l == NULL) | |
| 684 goto error; | |
| 685 } | |
| 686 for (s = attrlist; *s != NULL; s++) { | |
| 687 m = PyObject_GetAttrString(v, *s); | |
| 688 if (m == NULL) { | |
| 689 PyErr_Clear(); | |
| 690 continue; | |
| 691 } | |
| 692 for (i = 0; ; i++) { | |
| 693 x = PySequence_GetItem(m, i); | |
| 694 if (x == NULL) { | |
| 695 PyErr_Clear(); | |
| 696 break; | |
| 697 } | |
| 698 if (PyList_Append(l, x) != 0) { | |
| 699 Py_DECREF(x); | |
| 700 Py_DECREF(m); | |
| 701 goto error; | |
| 702 } | |
| 703 Py_DECREF(x); | |
| 704 } | |
| 705 Py_DECREF(m); | |
| 86 | 706 } |
|
385
039aee6cbd78
Protect dir() against non-directory __dict__ attributes.
Guido van Rossum <guido@python.org>
parents:
332
diff
changeset
|
707 } |
| 5421 | 708 if (PyList_Sort(l) != 0) |
| 709 goto error; | |
| 710 return l; | |
| 711 error: | |
| 712 Py_XDECREF(l); | |
| 713 return NULL; | |
| 86 | 714 } |
| 715 | |
| 8561 | 716 static char dir_doc[] = |
| 717 "dir([object]) -> list of strings\n\ | |
| 718 \n\ | |
| 719 Return an alphabetized list of names comprising (some of) the attributes\n\ | |
| 720 of the given object. Without an argument, the names in the current scope\n\ | |
| 721 are listed. With an instance argument, only the instance attributes are\n\ | |
| 722 returned. With a class argument, attributes of the base class are not\n\ | |
| 723 returned. For other types or arguments, this may list members or methods."; | |
| 724 | |
| 725 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
726 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
727 builtin_divmod(PyObject *self, PyObject *args) |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
728 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
729 PyObject *v, *w; |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
730 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
731 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
|
732 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
|
733 return PyNumber_Divmod(v, w); |
| 86 | 734 } |
| 735 | |
| 8561 | 736 static char divmod_doc[] = |
| 737 "divmod(x, y) -> (div, mod)\n\ | |
| 738 \n\ | |
| 739 Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x."; | |
| 740 | |
| 741 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
742 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
743 builtin_eval(PyObject *self, PyObject *args) |
| 86 | 744 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
745 PyObject *cmd; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
746 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
|
747 char *str; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
748 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
749 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
|
750 &cmd, |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
751 &PyDict_Type, &globals, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
752 &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
|
753 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
754 if (globals == Py_None) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
755 globals = PyEval_GetGlobals(); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
756 if (locals == Py_None) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
757 locals = PyEval_GetLocals(); |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
758 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
759 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
|
760 locals = globals; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
761 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
|
762 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
|
763 PyEval_GetBuiltins()) != 0) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
764 return NULL; |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
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 if (PyCode_Check(cmd)) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
767 return PyEval_EvalCode((PyCodeObject *) cmd, globals, locals); |
|
14696
85038a024b19
This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents:
14662
diff
changeset
|
768 if (!PyString_Check(cmd) && |
|
85038a024b19
This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents:
14662
diff
changeset
|
769 !PyUnicode_Check(cmd)) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
770 PyErr_SetString(PyExc_TypeError, |
| 15318 | 771 "eval() arg 1 must be a string or code object"); |
| 86 | 772 return NULL; |
| 773 } | |
|
14696
85038a024b19
This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents:
14662
diff
changeset
|
774 if (PyString_AsStringAndSize(cmd, &str, NULL)) |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
775 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
|
776 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
|
777 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
|
778 return PyRun_String(str, Py_eval_input, globals, locals); |
| 86 | 779 } |
| 780 | |
| 8561 | 781 static char eval_doc[] = |
| 782 "eval(source[, globals[, locals]]) -> value\n\ | |
| 783 \n\ | |
| 784 Evaluate the source in the context of globals and locals.\n\ | |
| 785 The source may be a string representing a Python expression\n\ | |
| 786 or a code object as returned by compile().\n\ | |
| 787 The globals and locals are dictionaries, defaulting to the current\n\ | |
| 788 globals and locals. If only globals is given, locals defaults to it."; | |
| 789 | |
| 790 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
791 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
792 builtin_execfile(PyObject *self, PyObject *args) |
| 673 | 793 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
794 char *filename; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
795 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
|
796 PyObject *res; |
| 673 | 797 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
|
798 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
799 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
|
800 &filename, |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
801 &PyDict_Type, &globals, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
802 &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
|
803 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
804 if (globals == Py_None) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
805 globals = PyEval_GetGlobals(); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
806 if (locals == Py_None) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
807 locals = PyEval_GetLocals(); |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
808 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
809 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
|
810 locals = globals; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
811 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
|
812 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
|
813 PyEval_GetBuiltins()) != 0) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
814 return NULL; |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
815 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
816 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
|
817 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
|
818 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
|
819 if (fp == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
820 PyErr_SetFromErrno(PyExc_IOError); |
| 673 | 821 return NULL; |
| 822 } | |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17111
diff
changeset
|
823 if (PyEval_GetNestedScopes()) { |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17111
diff
changeset
|
824 PyCompilerFlags cf; |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17111
diff
changeset
|
825 cf.cf_nested_scopes = 1; |
|
17641
9be7758a8c94
Fix buglet reported on c.l.py: map(fnc, file.xreadlines()) blows up.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
826 res = PyRun_FileExFlags(fp, filename, Py_file_input, globals, |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17111
diff
changeset
|
827 locals, 1, &cf); |
|
17641
9be7758a8c94
Fix buglet reported on c.l.py: map(fnc, file.xreadlines()) blows up.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
828 } else |
|
9be7758a8c94
Fix buglet reported on c.l.py: map(fnc, file.xreadlines()) blows up.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
829 res = PyRun_FileEx(fp, filename, Py_file_input, globals, |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17111
diff
changeset
|
830 locals, 1); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
831 return res; |
| 673 | 832 } |
| 833 | |
| 8561 | 834 static char execfile_doc[] = |
| 835 "execfile(filename[, globals[, locals]])\n\ | |
| 836 \n\ | |
| 837 Read and execute a Python script from a file.\n\ | |
| 838 The globals and locals are dictionaries, defaulting to the current\n\ | |
| 839 globals and locals. If only globals is given, locals defaults to it."; | |
| 840 | |
| 841 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
842 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
843 builtin_getattr(PyObject *self, PyObject *args) |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
844 { |
|
8581
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
845 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
|
846 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
|
847 |
|
14662
2d6188c2ea56
Deferred the attribute name object type checking to the underlying
Marc-André Lemburg <mal@egenix.com>
parents:
14375
diff
changeset
|
848 if (!PyArg_ParseTuple(args, "OO|O:getattr", &v, &name, &dflt)) |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
849 return NULL; |
|
8581
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
850 result = PyObject_GetAttr(v, name); |
|
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
851 if (result == NULL && dflt != NULL) { |
|
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
852 PyErr_Clear(); |
|
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
853 Py_INCREF(dflt); |
|
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
854 result = dflt; |
|
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
855 } |
|
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
856 return result; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
857 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
858 |
| 8561 | 859 static char getattr_doc[] = |
|
8581
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
860 "getattr(object, name[, default]) -> value\n\ |
| 8561 | 861 \n\ |
|
8581
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
862 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
|
863 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
|
864 exist; without it, an exception is raised in that case."; |
| 8561 | 865 |
| 866 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
867 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
868 builtin_globals(PyObject *self, PyObject *args) |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
869 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
870 PyObject *d; |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
871 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11800
diff
changeset
|
872 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
|
873 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
874 d = PyEval_GetGlobals(); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
875 Py_INCREF(d); |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
876 return d; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
877 } |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
878 |
| 8561 | 879 static char globals_doc[] = |
| 880 "globals() -> dictionary\n\ | |
| 881 \n\ | |
| 882 Return the dictionary containing the current scope's global variables."; | |
| 883 | |
| 884 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
885 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
886 builtin_hasattr(PyObject *self, PyObject *args) |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
887 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
888 PyObject *v; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
889 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
|
890 |
|
14662
2d6188c2ea56
Deferred the attribute name object type checking to the underlying
Marc-André Lemburg <mal@egenix.com>
parents:
14375
diff
changeset
|
891 if (!PyArg_ParseTuple(args, "OO:hasattr", &v, &name)) |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
892 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
893 v = PyObject_GetAttr(v, name); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
894 if (v == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
895 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
|
896 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
|
897 return Py_False; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
898 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
899 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
|
900 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
|
901 return Py_True; |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
902 } |
|
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
903 |
| 8561 | 904 static char hasattr_doc[] = |
| 905 "hasattr(object, name) -> Boolean\n\ | |
| 906 \n\ | |
| 907 Return whether the object has an attribute with the given name.\n\ | |
| 908 (This is done by calling getattr(object, name) and catching exceptions.)"; | |
| 909 | |
| 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 * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
912 builtin_id(PyObject *self, PyObject *args) |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
913 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
914 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
|
915 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
916 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
|
917 return NULL; |
| 13078 | 918 return PyLong_FromVoidPtr(v); |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
919 } |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
920 |
| 8561 | 921 static char id_doc[] = |
| 922 "id(object) -> integer\n\ | |
| 923 \n\ | |
| 924 Return the identity of an object. This is guaranteed to be unique among\n\ | |
| 925 simultaneously existing objects. (Hint: it's the object's memory address.)"; | |
| 926 | |
| 927 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
928 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
929 builtin_map(PyObject *self, PyObject *args) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
930 { |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
931 typedef struct { |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
932 PyObject *it; /* the iterator object */ |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
933 int saw_StopIteration; /* bool: did the iterator end? */ |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
934 } sequence; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
935 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
936 PyObject *func, *result; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
937 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
|
938 int n, len; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
939 register int i, j; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
940 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
941 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
|
942 if (n < 2) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
943 PyErr_SetString(PyExc_TypeError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
944 "map() requires at least two args"); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
945 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
946 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
947 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
948 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
|
949 n--; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
950 |
|
8661
30fbf18af29e
Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents:
8589
diff
changeset
|
951 if (func == Py_None && n == 1) { |
|
30fbf18af29e
Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents:
8589
diff
changeset
|
952 /* 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
|
953 return PySequence_List(PyTuple_GetItem(args, 1)); |
|
30fbf18af29e
Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents:
8589
diff
changeset
|
954 } |
|
30fbf18af29e
Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents:
8589
diff
changeset
|
955 |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
956 /* Get space for sequence descriptors. Must NULL out the iterator |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
957 * pointers so that jumping to Fail_2 later doesn't see trash. |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
958 */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
959 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
|
960 PyErr_NoMemory(); |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
961 return NULL; |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
962 } |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
963 for (i = 0; i < n; ++i) { |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
964 seqs[i].it = (PyObject*)NULL; |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
965 seqs[i].saw_StopIteration = 0; |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
966 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
967 |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
968 /* Do a first pass to obtain iterators for the arguments, and set len |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
969 * to the largest of their lengths. |
|
17641
9be7758a8c94
Fix buglet reported on c.l.py: map(fnc, file.xreadlines()) blows up.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
970 */ |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
971 len = 0; |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
972 for (i = 0, sqp = seqs; i < n; ++i, ++sqp) { |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
973 PyObject *curseq; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
974 int curlen; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
975 |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
976 /* Get iterator. */ |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
977 curseq = PyTuple_GetItem(args, i+1); |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
978 sqp->it = PyObject_GetIter(curseq); |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
979 if (sqp->it == NULL) { |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
980 static char errmsg[] = |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
981 "argument %d to map() must support iteration"; |
|
5388
13a30cea8dbf
Avoid sprintf buffer overflow if more than 9999 arguments.
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
982 char errbuf[sizeof(errmsg) + 25]; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
983 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
|
984 PyErr_SetString(PyExc_TypeError, errbuf); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
985 goto Fail_2; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
986 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
987 |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
988 /* Update len. */ |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
989 curlen = -1; /* unknown */ |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
990 if (PySequence_Check(curseq) && |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
991 curseq->ob_type->tp_as_sequence->sq_length) { |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
992 curlen = PySequence_Size(curseq); |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
993 if (curlen < 0) |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
994 PyErr_Clear(); |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
995 } |
|
17641
9be7758a8c94
Fix buglet reported on c.l.py: map(fnc, file.xreadlines()) blows up.
Tim Peters <tim.peters@gmail.com>
parents:
17597
diff
changeset
|
996 if (curlen < 0) |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
997 curlen = 8; /* arbitrary */ |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
998 if (curlen > len) |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
999 len = curlen; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1000 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1001 |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1002 /* Get space for the result list. */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1003 if ((result = (PyObject *) PyList_New(len)) == NULL) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1004 goto Fail_2; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1005 |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1006 /* Iterate over the sequences until all have stopped. */ |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1007 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
|
1008 PyObject *alist, *item=NULL, *value; |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1009 int numactive = 0; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1010 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1011 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
|
1012 alist = NULL; |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1013 else if ((alist = PyTuple_New(n)) == NULL) |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1014 goto Fail_1; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1015 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1016 for (j = 0, sqp = seqs; j < n; ++j, ++sqp) { |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1017 if (sqp->saw_StopIteration) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1018 Py_INCREF(Py_None); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1019 item = Py_None; |
|
1369
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 else { |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1022 item = PyIter_Next(sqp->it); |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1023 if (item) |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1024 ++numactive; |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1025 else { |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1026 if (PyErr_Occurred()) { |
|
17683
e9a4e27e8d4e
Make PyIter_Next() a little smarter (wrt its knowledge of iterator
Tim Peters <tim.peters@gmail.com>
parents:
17677
diff
changeset
|
1027 Py_XDECREF(alist); |
|
e9a4e27e8d4e
Make PyIter_Next() a little smarter (wrt its knowledge of iterator
Tim Peters <tim.peters@gmail.com>
parents:
17677
diff
changeset
|
1028 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
|
1029 } |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1030 Py_INCREF(Py_None); |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1031 item = Py_None; |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1032 sqp->saw_StopIteration = 1; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1033 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1034 } |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1035 if (alist) |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1036 PyTuple_SET_ITEM(alist, j, item); |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1037 else |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1038 break; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1039 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1040 |
|
2824
65c7105868f8
rename arglist to alist (conflict with new grammar symbol)
Guido van Rossum <guido@python.org>
parents:
2808
diff
changeset
|
1041 if (!alist) |
|
65c7105868f8
rename arglist to alist (conflict with new grammar symbol)
Guido van Rossum <guido@python.org>
parents:
2808
diff
changeset
|
1042 alist = item; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1043 |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1044 if (numactive == 0) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1045 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
|
1046 break; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1047 } |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1048 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1049 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
|
1050 value = alist; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1051 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1052 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
|
1053 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
|
1054 if (value == NULL) |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1055 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
|
1056 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1057 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
|
1058 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
|
1059 Py_DECREF(value); |
|
ddbbed8cb830
builtin_map(): A better fix for the previous leak plug (remember
Barry Warsaw <barry@python.org>
parents:
9980
diff
changeset
|
1060 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
|
1061 goto Fail_1; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1062 } |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1063 else if (PyList_SetItem(result, i, value) < 0) |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1064 goto Fail_1; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1065 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1066 |
|
8661
30fbf18af29e
Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents:
8589
diff
changeset
|
1067 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
|
1068 goto Fail_1; |
|
30fbf18af29e
Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents:
8589
diff
changeset
|
1069 |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1070 goto Succeed; |
|
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 Fail_1: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1073 Py_DECREF(result); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1074 Fail_2: |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1075 result = NULL; |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1076 Succeed: |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1077 assert(seqs); |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1078 for (i = 0; i < n; ++i) |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1079 Py_XDECREF(seqs[i].it); |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1080 PyMem_DEL(seqs); |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
1081 return result; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1082 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1083 |
| 8561 | 1084 static char map_doc[] = |
| 1085 "map(function, sequence[, sequence, ...]) -> list\n\ | |
| 1086 \n\ | |
| 1087 Return a list of the results of applying the function to the items of\n\ | |
| 1088 the argument sequence(s). If more than one sequence is given, the\n\ | |
| 1089 function is called with an argument list consisting of the corresponding\n\ | |
| 1090 item of each sequence, substituting None for missing values when not all\n\ | |
| 1091 sequences have the same length. If the function is None, return a list of\n\ | |
| 1092 the items of the sequence (or a list of tuples if more than one sequence)."; | |
| 1093 | |
| 1094 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1095 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1096 builtin_setattr(PyObject *self, PyObject *args) |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
1097 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1098 PyObject *v; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1099 PyObject *name; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1100 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
|
1101 |
|
14662
2d6188c2ea56
Deferred the attribute name object type checking to the underlying
Marc-André Lemburg <mal@egenix.com>
parents:
14375
diff
changeset
|
1102 if (!PyArg_ParseTuple(args, "OOO:setattr", &v, &name, &value)) |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
1103 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1104 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
|
1105 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1106 Py_INCREF(Py_None); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1107 return Py_None; |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
1108 } |
|
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
1109 |
| 8561 | 1110 static char setattr_doc[] = |
| 1111 "setattr(object, name, value)\n\ | |
| 1112 \n\ | |
| 1113 Set a named attribute on an object; setattr(x, 'y', v) is equivalent to\n\ | |
| 1114 ``x.y = v''."; | |
| 1115 | |
| 1116 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1117 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1118 builtin_delattr(PyObject *self, PyObject *args) |
| 1843 | 1119 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1120 PyObject *v; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1121 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
|
1122 |
|
14662
2d6188c2ea56
Deferred the attribute name object type checking to the underlying
Marc-André Lemburg <mal@egenix.com>
parents:
14375
diff
changeset
|
1123 if (!PyArg_ParseTuple(args, "OO:delattr", &v, &name)) |
| 1843 | 1124 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1125 if (PyObject_SetAttr(v, name, (PyObject *)NULL) != 0) |
| 1843 | 1126 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1127 Py_INCREF(Py_None); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1128 return Py_None; |
| 1843 | 1129 } |
| 1130 | |
| 8561 | 1131 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
|
1132 "delattr(object, name)\n\ |
| 8561 | 1133 \n\ |
| 1134 Delete a named attribute on an object; delattr(x, 'y') is equivalent to\n\ | |
| 1135 ``del x.y''."; | |
| 1136 | |
| 1137 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1138 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1139 builtin_hash(PyObject *self, PyObject *args) |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1140 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1141 PyObject *v; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1142 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
|
1143 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1144 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
|
1145 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1146 x = PyObject_Hash(v); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1147 if (x == -1) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1148 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1149 return PyInt_FromLong(x); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1150 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1151 |
| 8561 | 1152 static char hash_doc[] = |
| 1153 "hash(object) -> integer\n\ | |
| 1154 \n\ | |
| 1155 Return a hash value for the object. Two objects with the same value have\n\ | |
| 1156 the same hash value. The reverse is not necessarily true, but likely."; | |
| 1157 | |
| 1158 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1159 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1160 builtin_hex(PyObject *self, PyObject *args) |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
1161 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1162 PyObject *v; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1163 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
|
1164 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1165 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
|
1166 return NULL; |
|
15829
9308dc8c85e0
(Modified) patch by Ping - SF Patch #102681.
Guido van Rossum <guido@python.org>
parents:
15727
diff
changeset
|
1167 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1168 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
|
1169 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
|
1170 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
|
1171 "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
|
1172 return NULL; |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
1173 } |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
1174 return (*nb->nb_hex)(v); |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
1175 } |
|
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
1176 |
| 8561 | 1177 static char hex_doc[] = |
| 1178 "hex(number) -> string\n\ | |
| 1179 \n\ | |
| 1180 Return the hexadecimal representation of an integer or long integer."; | |
| 1181 | |
| 1182 | |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13446
diff
changeset
|
1183 static PyObject *builtin_raw_input(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
|
1184 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1185 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1186 builtin_input(PyObject *self, PyObject *args) |
| 86 | 1187 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1188 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
|
1189 char *str; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1190 PyObject *res; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1191 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
|
1192 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1193 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
|
1194 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
|
1195 return line; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1196 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
|
1197 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1198 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
|
1199 str++; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1200 globals = PyEval_GetGlobals(); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1201 locals = PyEval_GetLocals(); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1202 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
|
1203 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
|
1204 PyEval_GetBuiltins()) != 0) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
1205 return NULL; |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
1206 } |
|
5438
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5421
diff
changeset
|
1207 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
|
1208 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
|
1209 return res; |
| 86 | 1210 } |
| 1211 | |
| 8561 | 1212 static char input_doc[] = |
| 1213 "input([prompt]) -> value\n\ | |
| 1214 \n\ | |
| 1215 Equivalent to eval(raw_input(prompt))."; | |
| 1216 | |
| 1217 | |
|
5092
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
1218 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1219 builtin_intern(PyObject *self, PyObject *args) |
|
5092
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
1220 { |
|
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
1221 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
|
1222 if (!PyArg_ParseTuple(args, "S:intern", &s)) |
|
5092
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
1223 return NULL; |
|
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
1224 Py_INCREF(s); |
|
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
1225 PyString_InternInPlace(&s); |
|
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
1226 return s; |
|
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
1227 } |
|
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
1228 |
| 8561 | 1229 static char intern_doc[] = |
| 1230 "intern(string) -> string\n\ | |
| 1231 \n\ | |
| 1232 ``Intern'' the given string. This enters the string in the (global)\n\ | |
| 1233 table of interned strings whose purpose is to speed up dictionary lookups.\n\ | |
| 1234 Return the string itself or the previously interned string object with the\n\ | |
| 1235 same value."; | |
| 1236 | |
| 1237 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1238 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1239 builtin_int(PyObject *self, PyObject *args) |
| 86 | 1240 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1241 PyObject *v; |
|
11383
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1242 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
|
1243 |
|
11383
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1244 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
|
1245 return NULL; |
|
11383
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1246 if (base == -909) |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1247 return PyNumber_Int(v); |
|
12248
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
1248 else if (PyString_Check(v)) |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
1249 return PyInt_FromString(PyString_AS_STRING(v), NULL, base); |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
1250 else if (PyUnicode_Check(v)) |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
1251 return PyInt_FromUnicode(PyUnicode_AS_UNICODE(v), |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
1252 PyUnicode_GET_SIZE(v), |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
1253 base); |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
1254 else { |
|
11383
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1255 PyErr_SetString(PyExc_TypeError, |
| 15318 | 1256 "int() can't convert non-string with explicit base"); |
|
11383
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1257 return NULL; |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1258 } |
| 86 | 1259 } |
| 1260 | |
| 8561 | 1261 static char int_doc[] = |
|
11383
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1262 "int(x[, base]) -> integer\n\ |
| 8561 | 1263 \n\ |
|
11383
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1264 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
|
1265 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
|
1266 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
|
1267 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
|
1268 non-string."; |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1269 |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1270 |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1271 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1272 builtin_long(PyObject *self, PyObject *args) |
|
11383
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1273 { |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1274 PyObject *v; |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1275 int base = -909; /* unlikely! */ |
|
15829
9308dc8c85e0
(Modified) patch by Ping - SF Patch #102681.
Guido van Rossum <guido@python.org>
parents:
15727
diff
changeset
|
1276 |
|
11383
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1277 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
|
1278 return NULL; |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1279 if (base == -909) |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1280 return PyNumber_Long(v); |
|
12248
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
1281 else if (PyString_Check(v)) |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
1282 return PyLong_FromString(PyString_AS_STRING(v), NULL, base); |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
1283 else if (PyUnicode_Check(v)) |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
1284 return PyLong_FromUnicode(PyUnicode_AS_UNICODE(v), |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
1285 PyUnicode_GET_SIZE(v), |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
1286 base); |
|
70154e2e9c89
Marc-Andre's third try at this bulk patch seems to work (except that
Guido van Rossum <guido@python.org>
parents:
11973
diff
changeset
|
1287 else { |
|
11383
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1288 PyErr_SetString(PyExc_TypeError, |
| 15318 | 1289 "long() can't convert non-string with explicit base"); |
|
11383
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1290 return NULL; |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1291 } |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1292 } |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1293 |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1294 static char long_doc[] = |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1295 "long(x) -> long integer\n\ |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1296 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
|
1297 \n\ |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1298 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
|
1299 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
|
1300 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
|
1301 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
|
1302 converting a non-string."; |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1303 |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1304 |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1305 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1306 builtin_float(PyObject *self, PyObject *args) |
|
11383
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1307 { |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1308 PyObject *v; |
|
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 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
|
1311 return NULL; |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1312 if (PyString_Check(v)) |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1313 return PyFloat_FromString(v, NULL); |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1314 return PyNumber_Float(v); |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1315 } |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1316 |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1317 static char float_doc[] = |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1318 "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
|
1319 \n\ |
|
aca7b5eaf5e8
Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents:
11132
diff
changeset
|
1320 Convert a string or number to a floating point number, if possible."; |
| 8561 | 1321 |
| 1322 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1323 static PyObject * |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1324 builtin_iter(PyObject *self, PyObject *args) |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1325 { |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1326 PyObject *v, *w = NULL; |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1327 |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1328 if (!PyArg_ParseTuple(args, "O|O:iter", &v, &w)) |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1329 return NULL; |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1330 if (w == NULL) |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1331 return PyObject_GetIter(v); |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1332 if (!PyCallable_Check(v)) { |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1333 PyErr_SetString(PyExc_TypeError, |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1334 "iter(v, w): v must be callable"); |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1335 return NULL; |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1336 } |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1337 return PyCallIter_New(v, w); |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1338 } |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1339 |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1340 static char iter_doc[] = |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1341 "iter(collection) -> iterator\n\ |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1342 iter(callable, sentinel) -> iterator\n\ |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1343 \n\ |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1344 Get an iterator from an object. In the first form, the argument must\n\ |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1345 supply its own iterator, or be a sequence.\n\ |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1346 In the second form, the callable is called until it returns the sentinel."; |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1347 |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1348 |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1349 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1350 builtin_len(PyObject *self, 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
|
1351 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1352 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
|
1353 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
|
1354 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1355 if (!PyArg_ParseTuple(args, "O:len", &v)) |
| 86 | 1356 return NULL; |
|
13576
61e4c29d53d8
replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13447
diff
changeset
|
1357 res = PyObject_Size(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
|
1358 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
|
1359 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
|
1360 return PyInt_FromLong(res); |
| 86 | 1361 } |
| 1362 | |
| 8561 | 1363 static char len_doc[] = |
| 1364 "len(object) -> integer\n\ | |
| 1365 \n\ | |
| 1366 Return the number of items of a sequence or mapping."; | |
| 1367 | |
| 1368 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1369 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1370 builtin_list(PyObject *self, PyObject *args) |
|
3493
03c6c18325ea
Add list() method, analogous to tuple().
Guido van Rossum <guido@python.org>
parents:
3365
diff
changeset
|
1371 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1372 PyObject *v; |
|
3493
03c6c18325ea
Add list() method, analogous to tuple().
Guido van Rossum <guido@python.org>
parents:
3365
diff
changeset
|
1373 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1374 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
|
1375 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
|
1376 return PySequence_List(v); |
|
3493
03c6c18325ea
Add list() method, analogous to tuple().
Guido van Rossum <guido@python.org>
parents:
3365
diff
changeset
|
1377 } |
|
03c6c18325ea
Add list() method, analogous to tuple().
Guido van Rossum <guido@python.org>
parents:
3365
diff
changeset
|
1378 |
| 8561 | 1379 static char list_doc[] = |
| 1380 "list(sequence) -> list\n\ | |
| 1381 \n\ | |
| 1382 Return a new list whose items are the same as those of the argument sequence."; | |
| 1383 | |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1384 |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1385 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1386 builtin_slice(PyObject *self, PyObject *args) |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1387 { |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1388 PyObject *start, *stop, *step; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1389 |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1390 start = stop = step = NULL; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1391 |
|
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 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
|
1393 return NULL; |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1394 |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1395 /* 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
|
1396 range(). */ |
|
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1397 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
|
1398 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
|
1399 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
|
1400 } |
|
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1401 return PySlice_New(start, stop, step); |
|
3839
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1402 } |
|
22e29b1747e1
Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents:
3766
diff
changeset
|
1403 |
| 8561 | 1404 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
|
1405 "slice([start,] stop[, step]) -> slice object\n\ |
| 8561 | 1406 \n\ |
| 1407 Create a slice object. This is used for slicing by the Numeric extensions."; | |
| 1408 | |
| 1409 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1410 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1411 builtin_locals(PyObject *self, PyObject *args) |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1412 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1413 PyObject *d; |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1414 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11800
diff
changeset
|
1415 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
|
1416 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1417 d = PyEval_GetLocals(); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1418 Py_INCREF(d); |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1419 return d; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1420 } |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1421 |
| 8561 | 1422 static char locals_doc[] = |
| 1423 "locals() -> dictionary\n\ | |
| 1424 \n\ | |
| 1425 Return the dictionary containing the current scope's local variables."; | |
| 1426 | |
| 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 * |
|
15949
76ad2a9a3e53
Use rich comparisons in min and max.
Guido van Rossum <guido@python.org>
parents:
15832
diff
changeset
|
1429 min_max(PyObject *args, int op) |
| 86 | 1430 { |
|
17667
76ee8b62ee2a
Generalize max(seq) and min(seq) to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17654
diff
changeset
|
1431 PyObject *v, *w, *x, *it; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
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 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
|
1434 v = args; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1435 else if (!PyArg_ParseTuple(args, "O:min/max", &v)) |
| 86 | 1436 return NULL; |
|
17667
76ee8b62ee2a
Generalize max(seq) and min(seq) to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17654
diff
changeset
|
1437 |
|
76ee8b62ee2a
Generalize max(seq) and min(seq) to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17654
diff
changeset
|
1438 it = PyObject_GetIter(v); |
|
76ee8b62ee2a
Generalize max(seq) and min(seq) to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17654
diff
changeset
|
1439 if (it == NULL) |
| 86 | 1440 return NULL; |
|
17667
76ee8b62ee2a
Generalize max(seq) and min(seq) to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17654
diff
changeset
|
1441 |
|
76ee8b62ee2a
Generalize max(seq) and min(seq) to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17654
diff
changeset
|
1442 w = NULL; /* the result */ |
|
17683
e9a4e27e8d4e
Make PyIter_Next() a little smarter (wrt its knowledge of iterator
Tim Peters <tim.peters@gmail.com>
parents:
17677
diff
changeset
|
1443 for (;;) { |
|
17667
76ee8b62ee2a
Generalize max(seq) and min(seq) to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17654
diff
changeset
|
1444 x = PyIter_Next(it); |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1445 if (x == NULL) { |
|
17667
76ee8b62ee2a
Generalize max(seq) and min(seq) to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17654
diff
changeset
|
1446 if (PyErr_Occurred()) { |
|
17683
e9a4e27e8d4e
Make PyIter_Next() a little smarter (wrt its knowledge of iterator
Tim Peters <tim.peters@gmail.com>
parents:
17677
diff
changeset
|
1447 Py_XDECREF(w); |
|
e9a4e27e8d4e
Make PyIter_Next() a little smarter (wrt its knowledge of iterator
Tim Peters <tim.peters@gmail.com>
parents:
17677
diff
changeset
|
1448 Py_DECREF(it); |
|
e9a4e27e8d4e
Make PyIter_Next() a little smarter (wrt its knowledge of iterator
Tim Peters <tim.peters@gmail.com>
parents:
17677
diff
changeset
|
1449 return NULL; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1450 } |
|
17667
76ee8b62ee2a
Generalize max(seq) and min(seq) to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17654
diff
changeset
|
1451 break; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1452 } |
|
17667
76ee8b62ee2a
Generalize max(seq) and min(seq) to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17654
diff
changeset
|
1453 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1454 if (w == NULL) |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1455 w = x; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1456 else { |
|
15949
76ad2a9a3e53
Use rich comparisons in min and max.
Guido van Rossum <guido@python.org>
parents:
15832
diff
changeset
|
1457 int cmp = PyObject_RichCompareBool(x, w, op); |
|
76ad2a9a3e53
Use rich comparisons in min and max.
Guido van Rossum <guido@python.org>
parents:
15832
diff
changeset
|
1458 if (cmp > 0) { |
|
76ad2a9a3e53
Use rich comparisons in min and max.
Guido van Rossum <guido@python.org>
parents:
15832
diff
changeset
|
1459 Py_DECREF(w); |
|
76ad2a9a3e53
Use rich comparisons in min and max.
Guido van Rossum <guido@python.org>
parents:
15832
diff
changeset
|
1460 w = x; |
|
76ad2a9a3e53
Use rich comparisons in min and max.
Guido van Rossum <guido@python.org>
parents:
15832
diff
changeset
|
1461 } |
|
76ad2a9a3e53
Use rich comparisons in min and max.
Guido van Rossum <guido@python.org>
parents:
15832
diff
changeset
|
1462 else if (cmp < 0) { |
|
5610
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5471
diff
changeset
|
1463 Py_DECREF(x); |
|
17667
76ee8b62ee2a
Generalize max(seq) and min(seq) to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17654
diff
changeset
|
1464 Py_DECREF(w); |
|
76ee8b62ee2a
Generalize max(seq) and min(seq) to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17654
diff
changeset
|
1465 Py_DECREF(it); |
|
5610
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5471
diff
changeset
|
1466 return NULL; |
|
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5471
diff
changeset
|
1467 } |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1468 else |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1469 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
|
1470 } |
| 86 | 1471 } |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1472 if (w == NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1473 PyErr_SetString(PyExc_ValueError, |
| 15318 | 1474 "min() or max() arg is an empty sequence"); |
|
17667
76ee8b62ee2a
Generalize max(seq) and min(seq) to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17654
diff
changeset
|
1475 Py_DECREF(it); |
| 86 | 1476 return w; |
| 1477 } | |
| 1478 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1479 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1480 builtin_min(PyObject *self, PyObject *v) |
| 86 | 1481 { |
|
15949
76ad2a9a3e53
Use rich comparisons in min and max.
Guido van Rossum <guido@python.org>
parents:
15832
diff
changeset
|
1482 return min_max(v, Py_LT); |
| 86 | 1483 } |
| 1484 | |
| 8561 | 1485 static char min_doc[] = |
| 1486 "min(sequence) -> value\n\ | |
| 1487 min(a, b, c, ...) -> value\n\ | |
| 1488 \n\ | |
| 1489 With a single sequence argument, return its smallest item.\n\ | |
| 1490 With two or more arguments, return the smallest argument."; | |
| 1491 | |
| 1492 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1493 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1494 builtin_max(PyObject *self, PyObject *v) |
| 86 | 1495 { |
|
15949
76ad2a9a3e53
Use rich comparisons in min and max.
Guido van Rossum <guido@python.org>
parents:
15832
diff
changeset
|
1496 return min_max(v, Py_GT); |
| 86 | 1497 } |
| 1498 | |
| 8561 | 1499 static char max_doc[] = |
| 1500 "max(sequence) -> value\n\ | |
| 1501 max(a, b, c, ...) -> value\n\ | |
| 1502 \n\ | |
| 1503 With a single sequence argument, return its largest item.\n\ | |
| 1504 With two or more arguments, return the largest argument."; | |
| 1505 | |
| 1506 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1507 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1508 builtin_oct(PyObject *self, 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
|
1509 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1510 PyObject *v; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1511 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
|
1512 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1513 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
|
1514 return NULL; |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
1515 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
|
1516 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
|
1517 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
|
1518 "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
|
1519 return NULL; |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
1520 } |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
1521 return (*nb->nb_oct)(v); |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
1522 } |
|
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
1523 |
| 8561 | 1524 static char oct_doc[] = |
| 1525 "oct(number) -> string\n\ | |
| 1526 \n\ | |
| 1527 Return the octal representation of an integer or long integer."; | |
| 1528 | |
| 1529 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1530 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1531 builtin_open(PyObject *self, PyObject *args) |
| 86 | 1532 { |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1533 char *name; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1534 char *mode = "r"; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1535 int bufsize = -1; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1536 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
|
1537 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1538 if (!PyArg_ParseTuple(args, "s|si:open", &name, &mode, &bufsize)) |
| 86 | 1539 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1540 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
|
1541 if (f != NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1542 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
|
1543 return f; |
| 86 | 1544 } |
| 1545 | |
| 8561 | 1546 static char open_doc[] = |
| 1547 "open(filename[, mode[, buffering]]) -> file object\n\ | |
| 1548 \n\ | |
| 1549 Open a file. The mode can be 'r', 'w' or 'a' for reading (default),\n\ | |
| 1550 writing or appending. The file will be created if it doesn't exist\n\ | |
| 1551 when opened for writing or appending; it will be truncated when\n\ | |
| 1552 opened for writing. Add a 'b' to the mode for binary files.\n\ | |
| 1553 Add a '+' to the mode to allow simultaneous reading and writing.\n\ | |
| 1554 If the buffering argument is given, 0 means unbuffered, 1 means line\n\ | |
| 1555 buffered, and larger numbers specify the buffer size."; | |
| 1556 | |
| 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 * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1559 builtin_ord(PyObject *self, PyObject *args) |
| 86 | 1560 { |
|
11973
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1561 PyObject *obj; |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1562 long ord; |
|
12384
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1563 int size; |
|
11973
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1564 |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1565 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
|
1566 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
|
1567 |
|
12384
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1568 if (PyString_Check(obj)) { |
|
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1569 size = PyString_GET_SIZE(obj); |
|
15635
838551869790
Patch #102955, fixing one of the warnings in bug #121479:
Andrew M. Kuchling <amk@amk.ca>
parents:
15478
diff
changeset
|
1570 if (size == 1) { |
|
12384
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1571 ord = (long)((unsigned char)*PyString_AS_STRING(obj)); |
|
15635
838551869790
Patch #102955, fixing one of the warnings in bug #121479:
Andrew M. Kuchling <amk@amk.ca>
parents:
15478
diff
changeset
|
1572 return PyInt_FromLong(ord); |
|
838551869790
Patch #102955, fixing one of the warnings in bug #121479:
Andrew M. Kuchling <amk@amk.ca>
parents:
15478
diff
changeset
|
1573 } |
|
12384
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1574 } else if (PyUnicode_Check(obj)) { |
|
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1575 size = PyUnicode_GET_SIZE(obj); |
|
15635
838551869790
Patch #102955, fixing one of the warnings in bug #121479:
Andrew M. Kuchling <amk@amk.ca>
parents:
15478
diff
changeset
|
1576 if (size == 1) { |
|
12384
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1577 ord = (long)*PyUnicode_AS_UNICODE(obj); |
|
15635
838551869790
Patch #102955, fixing one of the warnings in bug #121479:
Andrew M. Kuchling <amk@amk.ca>
parents:
15478
diff
changeset
|
1578 return PyInt_FromLong(ord); |
|
838551869790
Patch #102955, fixing one of the warnings in bug #121479:
Andrew M. Kuchling <amk@amk.ca>
parents:
15478
diff
changeset
|
1579 } |
|
12384
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1580 } else { |
|
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1581 PyErr_Format(PyExc_TypeError, |
|
15654
6405f30aa08c
CHange error messages for ord(), using "string" instead of "string or Unicode"
Andrew M. Kuchling <amk@amk.ca>
parents:
15637
diff
changeset
|
1582 "ord() expected string of length 1, but " \ |
|
12384
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1583 "%.200s found", obj->ob_type->tp_name); |
| 86 | 1584 return NULL; |
|
11973
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1585 } |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1586 |
|
15829
9308dc8c85e0
(Modified) patch by Ping - SF Patch #102681.
Guido van Rossum <guido@python.org>
parents:
15727
diff
changeset
|
1587 PyErr_Format(PyExc_TypeError, |
|
15654
6405f30aa08c
CHange error messages for ord(), using "string" instead of "string or Unicode"
Andrew M. Kuchling <amk@amk.ca>
parents:
15637
diff
changeset
|
1588 "ord() expected a character, " |
|
6405f30aa08c
CHange error messages for ord(), using "string" instead of "string or Unicode"
Andrew M. Kuchling <amk@amk.ca>
parents:
15637
diff
changeset
|
1589 "but string of length %d found", |
|
12384
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1590 size); |
|
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1591 return NULL; |
| 86 | 1592 } |
| 1593 | |
| 8561 | 1594 static char ord_doc[] = |
| 1595 "ord(c) -> integer\n\ | |
| 1596 \n\ | |
|
15829
9308dc8c85e0
(Modified) patch by Ping - SF Patch #102681.
Guido van Rossum <guido@python.org>
parents:
15727
diff
changeset
|
1597 Return the integer ordinal of a one-character string."; |
| 8561 | 1598 |
| 1599 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1600 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1601 builtin_pow(PyObject *self, PyObject *args) |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1602 { |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1603 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
|
1604 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1605 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
|
1606 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
|
1607 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
|
1608 } |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
1609 |
| 8561 | 1610 static char pow_doc[] = |
| 1611 "pow(x, y[, z]) -> number\n\ | |
| 1612 \n\ | |
| 1613 With two arguments, equivalent to x**y. With three arguments,\n\ | |
| 1614 equivalent to (x**y) % z, but may be more efficient (e.g. for longs)."; | |
| 1615 | |
| 1616 | |
|
10279
886ea255f381
Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents:
10020
diff
changeset
|
1617 /* 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
|
1618 * 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
|
1619 * 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
|
1620 */ |
|
886ea255f381
Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents:
10020
diff
changeset
|
1621 static long |
|
13679
61f65de19e1e
Another missed ansification.
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
1622 get_len_of_range(long lo, long hi, long step) |
|
10279
886ea255f381
Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents:
10020
diff
changeset
|
1623 { |
|
886ea255f381
Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents:
10020
diff
changeset
|
1624 /* ------------------------------------------------------------- |
|
886ea255f381
Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents:
10020
diff
changeset
|
1625 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
|
1626 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
|
1627 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
|
1628 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
|
1629 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
|
1630 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
|
1631 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
|
1632 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
|
1633 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
|
1634 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
|
1635 ---------------------------------------------------------------*/ |
|
886ea255f381
Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents:
10020
diff
changeset
|
1636 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
|
1637 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
|
1638 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
|
1639 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
|
1640 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
|
1641 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
|
1642 } |
|
886ea255f381
Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents:
10020
diff
changeset
|
1643 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
|
1644 } |
|
886ea255f381
Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents:
10020
diff
changeset
|
1645 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1646 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1647 builtin_range(PyObject *self, PyObject *args) |
| 86 | 1648 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1649 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
|
1650 long bign; |
| 86 | 1651 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
|
1652 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1653 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
|
1654 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1655 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
|
1656 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
|
1657 "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
|
1658 &ihigh)) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1659 return NULL; |
| 86 | 1660 } |
| 1661 else { | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1662 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
|
1663 "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
|
1664 &ilow, &ihigh, &istep)) |
| 86 | 1665 return NULL; |
| 1666 } | |
| 1667 if (istep == 0) { | |
| 15318 | 1668 PyErr_SetString(PyExc_ValueError, "range() arg 3 must not be zero"); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1669 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1670 } |
|
10279
886ea255f381
Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents:
10020
diff
changeset
|
1671 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
|
1672 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
|
1673 else |
|
886ea255f381
Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents:
10020
diff
changeset
|
1674 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
|
1675 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
|
1676 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
|
1677 PyErr_SetString(PyExc_OverflowError, |
| 15318 | 1678 "range() result 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
|
1679 return NULL; |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1680 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1681 v = PyList_New(n); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1682 if (v == NULL) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1683 return NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1684 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
|
1685 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
|
1686 if (w == NULL) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1687 Py_DECREF(v); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1688 return NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1689 } |
|
8138
9d0310143600
Fred's right -- we need PyList_SET_ITEM().
Guido van Rossum <guido@python.org>
parents:
8132
diff
changeset
|
1690 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
|
1691 ilow += istep; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1692 } |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1693 return v; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1694 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1695 |
| 8561 | 1696 static char range_doc[] = |
| 1697 "range([start,] stop[, step]) -> list of integers\n\ | |
| 1698 \n\ | |
| 1699 Return a list containing an arithmetic progression of integers.\n\ | |
| 1700 range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.\n\ | |
| 1701 When step is given, it specifies the increment (or decrement).\n\ | |
| 1702 For example, range(4) returns [0, 1, 2, 3]. The end point is omitted!\n\ | |
| 1703 These are exactly the valid indices for a list of 4 elements."; | |
| 1704 | |
| 1705 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1706 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1707 builtin_xrange(PyObject *self, PyObject *args) |
| 86 | 1708 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1709 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
|
1710 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
|
1711 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1712 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
|
1713 if (!PyArg_ParseTuple(args, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1714 "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
|
1715 &ihigh)) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1716 return NULL; |
|
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 else { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1719 if (!PyArg_ParseTuple(args, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1720 "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
|
1721 &ilow, &ihigh, &istep)) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1722 return NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1723 } |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1724 if (istep == 0) { |
| 15318 | 1725 PyErr_SetString(PyExc_ValueError, "xrange() arg 3 must not be zero"); |
|
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
|
1726 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1727 } |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1728 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
|
1729 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
|
1730 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
|
1731 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
|
1732 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
|
1733 PyErr_SetString(PyExc_OverflowError, |
| 15318 | 1734 "xrange() result has too many items"); |
|
10279
886ea255f381
Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents:
10020
diff
changeset
|
1735 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
|
1736 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1737 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
|
1738 } |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1739 |
| 8561 | 1740 static char xrange_doc[] = |
| 1741 "xrange([start,] stop[, step]) -> xrange object\n\ | |
| 1742 \n\ | |
| 1743 Like range(), but instead of returning a list, returns an object that\n\ | |
| 1744 generates the numbers in the range on demand. This is slightly slower\n\ | |
| 1745 than range() but more memory efficient."; | |
| 1746 | |
| 1747 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1748 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1749 builtin_raw_input(PyObject *self, PyObject *args) |
|
5373
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 PyObject *v = NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1752 PyObject *f; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1753 |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1754 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
|
1755 return NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1756 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
|
1757 PyFile_AsFile(PySys_GetObject("stdout")) == stdout && |
|
2857
eebbdbee54f9
be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
1758 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
|
1759 PyObject *po; |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1760 char *prompt; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1761 char *s; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1762 PyObject *result; |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1763 if (v != NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1764 po = PyObject_Str(v); |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1765 if (po == NULL) |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1766 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1767 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
|
1768 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
|
1769 return NULL; |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1770 } |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1771 else { |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1772 po = NULL; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1773 prompt = ""; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
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 s = PyOS_Readline(prompt); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1776 Py_XDECREF(po); |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1777 if (s == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1778 PyErr_SetNone(PyExc_KeyboardInterrupt); |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1779 return NULL; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1780 } |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1781 if (*s == '\0') { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1782 PyErr_SetNone(PyExc_EOFError); |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1783 result = NULL; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1784 } |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1785 else { /* strip trailing '\n' */ |
| 13078 | 1786 size_t len = strlen(s); |
| 1787 if (len > INT_MAX) { | |
| 1788 PyErr_SetString(PyExc_OverflowError, "input too long"); | |
| 1789 result = NULL; | |
| 1790 } | |
| 1791 else { | |
| 1792 result = PyString_FromStringAndSize(s, (int)(len-1)); | |
| 1793 } | |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1794 } |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12572
diff
changeset
|
1795 PyMem_FREE(s); |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1796 return result; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1797 } |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
1798 if (v != NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1799 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
|
1800 if (f == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1801 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
|
1802 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1803 } |
|
5610
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5471
diff
changeset
|
1804 if (Py_FlushLine() != 0 || |
|
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5471
diff
changeset
|
1805 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
|
1806 return NULL; |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
1807 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1808 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
|
1809 if (f == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1810 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
|
1811 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1812 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1813 return PyFile_GetLine(f, -1); |
| 86 | 1814 } |
| 1815 | |
| 8561 | 1816 static char raw_input_doc[] = |
| 1817 "raw_input([prompt]) -> string\n\ | |
| 1818 \n\ | |
| 1819 Read a string from standard input. The trailing newline is stripped.\n\ | |
| 1820 If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.\n\ | |
| 1821 On Unix, GNU readline is used if enabled. The prompt string, if given,\n\ | |
| 1822 is printed without a trailing newline before reading."; | |
| 1823 | |
| 1824 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1825 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1826 builtin_reduce(PyObject *self, PyObject *args) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1827 { |
|
17677
bf7f166d3c97
Generalize reduce() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17675
diff
changeset
|
1828 PyObject *seq, *func, *result = NULL, *it; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
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 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
|
1831 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1832 if (result != NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1833 Py_INCREF(result); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1834 |
|
17677
bf7f166d3c97
Generalize reduce() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17675
diff
changeset
|
1835 it = PyObject_GetIter(seq); |
|
bf7f166d3c97
Generalize reduce() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17675
diff
changeset
|
1836 if (it == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1837 PyErr_SetString(PyExc_TypeError, |
|
17677
bf7f166d3c97
Generalize reduce() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17675
diff
changeset
|
1838 "reduce() arg 2 must support iteration"); |
|
bf7f166d3c97
Generalize reduce() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17675
diff
changeset
|
1839 Py_XDECREF(result); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1840 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1841 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1842 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1843 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
|
1844 goto Fail; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1845 |
|
17677
bf7f166d3c97
Generalize reduce() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17675
diff
changeset
|
1846 for (;;) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1847 PyObject *op2; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1848 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1849 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
|
1850 Py_DECREF(args); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1851 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
|
1852 goto Fail; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1853 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1854 |
|
17677
bf7f166d3c97
Generalize reduce() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17675
diff
changeset
|
1855 op2 = PyIter_Next(it); |
|
bf7f166d3c97
Generalize reduce() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17675
diff
changeset
|
1856 if (op2 == NULL) { |
|
17683
e9a4e27e8d4e
Make PyIter_Next() a little smarter (wrt its knowledge of iterator
Tim Peters <tim.peters@gmail.com>
parents:
17677
diff
changeset
|
1857 if (PyErr_Occurred()) |
|
e9a4e27e8d4e
Make PyIter_Next() a little smarter (wrt its knowledge of iterator
Tim Peters <tim.peters@gmail.com>
parents:
17677
diff
changeset
|
1858 goto Fail; |
|
e9a4e27e8d4e
Make PyIter_Next() a little smarter (wrt its knowledge of iterator
Tim Peters <tim.peters@gmail.com>
parents:
17677
diff
changeset
|
1859 break; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1860 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1861 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1862 if (result == NULL) |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1863 result = op2; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1864 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1865 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
|
1866 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
|
1867 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
|
1868 goto Fail; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1869 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1870 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1871 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1872 Py_DECREF(args); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1873 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1874 if (result == NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1875 PyErr_SetString(PyExc_TypeError, |
| 15318 | 1876 "reduce() of empty sequence with no initial value"); |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1877 |
|
17677
bf7f166d3c97
Generalize reduce() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17675
diff
changeset
|
1878 Py_DECREF(it); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1879 return result; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1880 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1881 Fail: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1882 Py_XDECREF(args); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1883 Py_XDECREF(result); |
|
17677
bf7f166d3c97
Generalize reduce() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17675
diff
changeset
|
1884 Py_DECREF(it); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1885 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1886 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1887 |
| 8561 | 1888 static char reduce_doc[] = |
| 1889 "reduce(function, sequence[, initial]) -> value\n\ | |
| 1890 \n\ | |
| 1891 Apply a function of two arguments cumulatively to the items of a sequence,\n\ | |
| 1892 from left to right, so as to reduce the sequence to a single value.\n\ | |
| 1893 For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates\n\ | |
| 1894 ((((1+2)+3)+4)+5). If initial is present, it is placed before the items\n\ | |
| 1895 of the sequence in the calculation, and serves as a default when the\n\ | |
| 1896 sequence is empty."; | |
| 1897 | |
| 1898 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1899 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1900 builtin_reload(PyObject *self, 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
|
1901 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1902 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
|
1903 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1904 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
|
1905 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1906 return PyImport_ReloadModule(v); |
| 86 | 1907 } |
| 1908 | |
| 8561 | 1909 static char reload_doc[] = |
| 1910 "reload(module) -> module\n\ | |
| 1911 \n\ | |
| 1912 Reload the module. The module must have been successfully imported before."; | |
| 1913 | |
| 1914 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1915 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1916 builtin_repr(PyObject *self, PyObject *args) |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1917 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1918 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
|
1919 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1920 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
|
1921 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1922 return PyObject_Repr(v); |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1923 } |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1924 |
| 8561 | 1925 static char repr_doc[] = |
| 1926 "repr(object) -> string\n\ | |
| 1927 \n\ | |
| 1928 Return the canonical string representation of the object.\n\ | |
| 1929 For most object types, eval(repr(object)) == object."; | |
| 1930 | |
| 1931 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1932 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1933 builtin_round(PyObject *self, 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
|
1934 { |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1935 double x; |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1936 double f; |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1937 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
|
1938 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
|
1939 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1940 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
|
1941 return NULL; |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1942 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
|
1943 i = abs(ndigits); |
|
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1944 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
|
1945 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
|
1946 if (ndigits < 0) |
|
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1947 x /= f; |
|
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1948 else |
|
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1949 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
|
1950 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
|
1951 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
|
1952 else |
|
8287
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1953 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
|
1954 if (ndigits < 0) |
|
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1955 x *= f; |
|
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1956 else |
|
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1957 x /= f; |
|
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1958 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
|
1959 } |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1960 |
| 8561 | 1961 static char round_doc[] = |
| 1962 "round(number[, ndigits]) -> floating point number\n\ | |
| 1963 \n\ | |
| 1964 Round a number to a given precision in decimal digits (default 0 digits).\n\ | |
| 1965 This always returns a floating point number. Precision may be negative."; | |
| 1966 | |
| 1967 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1968 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1969 builtin_str(PyObject *self, PyObject *args) |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1970 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1971 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
|
1972 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1973 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
|
1974 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1975 return PyObject_Str(v); |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1976 } |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1977 |
| 8561 | 1978 static char str_doc[] = |
| 1979 "str(object) -> string\n\ | |
| 1980 \n\ | |
| 1981 Return a nice string representation of the object.\n\ | |
| 1982 If the argument is a string, the return value is the same object."; | |
| 1983 | |
| 1984 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1985 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1986 builtin_tuple(PyObject *self, PyObject *args) |
|
1842
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1987 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1988 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
|
1989 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1990 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
|
1991 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
|
1992 return PySequence_Tuple(v); |
|
1842
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1993 } |
|
65cc727f1436
* Python/bltinmodule.c: added tuple() builtin
Guido van Rossum <guido@python.org>
parents:
1841
diff
changeset
|
1994 |
| 8561 | 1995 static char tuple_doc[] = |
| 1996 "tuple(sequence) -> list\n\ | |
| 1997 \n\ | |
| 1998 Return a tuple whose items are the same as those of the argument sequence.\n\ | |
| 1999 If the argument is a tuple, the return value is the same object."; | |
| 2000 | |
| 2001 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2002 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
2003 builtin_type(PyObject *self, PyObject *args) |
| 86 | 2004 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2005 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
|
2006 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2007 if (!PyArg_ParseTuple(args, "O:type", &v)) |
| 86 | 2008 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2009 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
|
2010 Py_INCREF(v); |
| 86 | 2011 return v; |
| 2012 } | |
| 2013 | |
| 8561 | 2014 static char type_doc[] = |
| 2015 "type(object) -> type object\n\ | |
| 2016 \n\ | |
| 2017 Return the type of the object."; | |
| 2018 | |
| 2019 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2020 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
2021 builtin_vars(PyObject *self, PyObject *args) |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
2022 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2023 PyObject *v = NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2024 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
|
2025 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2026 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
|
2027 return NULL; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
2028 if (v == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2029 d = PyEval_GetLocals(); |
|
2857
eebbdbee54f9
be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
2030 if (d == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2031 if (!PyErr_Occurred()) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2032 PyErr_SetString(PyExc_SystemError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2033 "no locals!?"); |
|
2857
eebbdbee54f9
be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
2034 } |
|
eebbdbee54f9
be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
2035 else |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2036 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
|
2037 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
2038 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2039 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
|
2040 if (d == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2041 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
|
2042 "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
|
2043 return NULL; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
2044 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
2045 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
2046 return d; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
2047 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
2048 |
| 8561 | 2049 static char vars_doc[] = |
| 2050 "vars([object]) -> dictionary\n\ | |
| 2051 \n\ | |
| 2052 Without arguments, equivalent to locals().\n\ | |
| 2053 With an argument, equivalent to object.__dict__."; | |
| 2054 | |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2055 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
2056 builtin_isinstance(PyObject *self, PyObject *args) |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2057 { |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2058 PyObject *inst; |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2059 PyObject *cls; |
|
17111
bf678a11c21a
Move the code implementing isinstance() and issubclass() to new C
Guido van Rossum <guido@python.org>
parents:
16048
diff
changeset
|
2060 int retval; |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2061 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11800
diff
changeset
|
2062 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
|
2063 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
|
2064 |
|
17111
bf678a11c21a
Move the code implementing isinstance() and issubclass() to new C
Guido van Rossum <guido@python.org>
parents:
16048
diff
changeset
|
2065 retval = PyObject_IsInstance(inst, cls); |
|
bf678a11c21a
Move the code implementing isinstance() and issubclass() to new C
Guido van Rossum <guido@python.org>
parents:
16048
diff
changeset
|
2066 if (retval < 0) |
|
15829
9308dc8c85e0
(Modified) patch by Ping - SF Patch #102681.
Guido van Rossum <guido@python.org>
parents:
15727
diff
changeset
|
2067 return NULL; |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2068 return PyInt_FromLong(retval); |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2069 } |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2070 |
| 8561 | 2071 static char isinstance_doc[] = |
| 2072 "isinstance(object, class-or-type) -> Boolean\n\ | |
| 2073 \n\ | |
| 2074 Return whether an object is an instance of a class or of a subclass thereof.\n\ | |
| 2075 With a type as second argument, return whether that is the object's type."; | |
| 2076 | |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2077 |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2078 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
2079 builtin_issubclass(PyObject *self, PyObject *args) |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2080 { |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2081 PyObject *derived; |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2082 PyObject *cls; |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2083 int retval; |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2084 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11800
diff
changeset
|
2085 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
|
2086 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
|
2087 |
|
17111
bf678a11c21a
Move the code implementing isinstance() and issubclass() to new C
Guido van Rossum <guido@python.org>
parents:
16048
diff
changeset
|
2088 retval = PyObject_IsSubclass(derived, cls); |
|
bf678a11c21a
Move the code implementing isinstance() and issubclass() to new C
Guido van Rossum <guido@python.org>
parents:
16048
diff
changeset
|
2089 if (retval < 0) |
|
bf678a11c21a
Move the code implementing isinstance() and issubclass() to new C
Guido van Rossum <guido@python.org>
parents:
16048
diff
changeset
|
2090 return NULL; |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2091 return PyInt_FromLong(retval); |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2092 } |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2093 |
| 8561 | 2094 static char issubclass_doc[] = |
| 2095 "issubclass(C, B) -> Boolean\n\ | |
| 2096 \n\ | |
| 2097 Return whether class C is a subclass (i.e., a derived class) of class B."; | |
| 2098 | |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
2099 |
|
13822
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2100 static PyObject* |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2101 builtin_zip(PyObject *self, PyObject *args) |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2102 { |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2103 PyObject *ret; |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2104 int itemsize = PySequence_Length(args); |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2105 int i, j; |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2106 |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2107 if (itemsize < 1) { |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2108 PyErr_SetString(PyExc_TypeError, |
| 15318 | 2109 "zip() requires at least one sequence"); |
|
13822
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2110 return NULL; |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2111 } |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2112 /* args must be a tuple */ |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2113 assert(PyTuple_Check(args)); |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2114 |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2115 if ((ret = PyList_New(0)) == NULL) |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2116 return NULL; |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2117 |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2118 for (i = 0;; i++) { |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2119 PyObject *next = PyTuple_New(itemsize); |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2120 if (!next) { |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2121 Py_DECREF(ret); |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2122 return NULL; |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2123 } |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2124 for (j = 0; j < itemsize; j++) { |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2125 PyObject *seq = PyTuple_GET_ITEM(args, j); |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2126 PyObject *item = PySequence_GetItem(seq, i); |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2127 |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2128 if (!item) { |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2129 if (PyErr_ExceptionMatches(PyExc_IndexError)) { |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2130 PyErr_Clear(); |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2131 Py_DECREF(next); |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2132 return ret; |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2133 } |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2134 Py_DECREF(next); |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2135 Py_DECREF(ret); |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2136 return NULL; |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2137 } |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2138 PyTuple_SET_ITEM(next, j, item); |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2139 } |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2140 PyList_Append(ret, next); |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2141 Py_DECREF(next); |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2142 } |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2143 /* no return */ |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2144 } |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2145 |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2146 |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2147 static char zip_doc[] = |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2148 "zip(seq1 [, seq2 [...]]) -> [(seq1[0], seq2[0] ...), (...)]\n\ |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2149 \n\ |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2150 Return a list of tuples, where each tuple contains the i-th element\n\ |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2151 from each of the argument sequences. The returned list is truncated\n\ |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2152 in length to the length of the shortest argument sequence."; |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2153 |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2154 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2155 static PyMethodDef builtin_methods[] = { |
| 8561 | 2156 {"__import__", builtin___import__, 1, import_doc}, |
| 2157 {"abs", builtin_abs, 1, abs_doc}, | |
| 2158 {"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
|
2159 {"buffer", builtin_buffer, 1, buffer_doc}, |
| 8561 | 2160 {"callable", builtin_callable, 1, callable_doc}, |
| 2161 {"chr", builtin_chr, 1, chr_doc}, | |
| 2162 {"cmp", builtin_cmp, 1, cmp_doc}, | |
| 2163 {"coerce", builtin_coerce, 1, coerce_doc}, | |
| 2164 {"compile", builtin_compile, 1, compile_doc}, | |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
2165 #ifndef WITHOUT_COMPLEX |
| 8561 | 2166 {"complex", builtin_complex, 1, complex_doc}, |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
2890
diff
changeset
|
2167 #endif |
| 8561 | 2168 {"delattr", builtin_delattr, 1, delattr_doc}, |
| 2169 {"dir", builtin_dir, 1, dir_doc}, | |
| 2170 {"divmod", builtin_divmod, 1, divmod_doc}, | |
| 2171 {"eval", builtin_eval, 1, eval_doc}, | |
| 2172 {"execfile", builtin_execfile, 1, execfile_doc}, | |
| 2173 {"filter", builtin_filter, 1, filter_doc}, | |
| 2174 {"float", builtin_float, 1, float_doc}, | |
| 2175 {"getattr", builtin_getattr, 1, getattr_doc}, | |
| 2176 {"globals", builtin_globals, 1, globals_doc}, | |
| 2177 {"hasattr", builtin_hasattr, 1, hasattr_doc}, | |
| 2178 {"hash", builtin_hash, 1, hash_doc}, | |
| 2179 {"hex", builtin_hex, 1, hex_doc}, | |
| 2180 {"id", builtin_id, 1, id_doc}, | |
| 2181 {"input", builtin_input, 1, input_doc}, | |
| 2182 {"intern", builtin_intern, 1, intern_doc}, | |
| 2183 {"int", builtin_int, 1, int_doc}, | |
| 2184 {"isinstance", builtin_isinstance, 1, isinstance_doc}, | |
| 2185 {"issubclass", builtin_issubclass, 1, issubclass_doc}, | |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
2186 {"iter", builtin_iter, 1, iter_doc}, |
| 8561 | 2187 {"len", builtin_len, 1, len_doc}, |
| 2188 {"list", builtin_list, 1, list_doc}, | |
| 2189 {"locals", builtin_locals, 1, locals_doc}, | |
| 2190 {"long", builtin_long, 1, long_doc}, | |
| 2191 {"map", builtin_map, 1, map_doc}, | |
| 2192 {"max", builtin_max, 1, max_doc}, | |
| 2193 {"min", builtin_min, 1, min_doc}, | |
| 2194 {"oct", builtin_oct, 1, oct_doc}, | |
| 2195 {"open", builtin_open, 1, open_doc}, | |
| 2196 {"ord", builtin_ord, 1, ord_doc}, | |
| 2197 {"pow", builtin_pow, 1, pow_doc}, | |
| 2198 {"range", builtin_range, 1, range_doc}, | |
| 2199 {"raw_input", builtin_raw_input, 1, raw_input_doc}, | |
| 2200 {"reduce", builtin_reduce, 1, reduce_doc}, | |
| 2201 {"reload", builtin_reload, 1, reload_doc}, | |
| 2202 {"repr", builtin_repr, 1, repr_doc}, | |
| 2203 {"round", builtin_round, 1, round_doc}, | |
| 2204 {"setattr", builtin_setattr, 1, setattr_doc}, | |
| 2205 {"slice", builtin_slice, 1, slice_doc}, | |
| 2206 {"str", builtin_str, 1, str_doc}, | |
| 2207 {"tuple", builtin_tuple, 1, tuple_doc}, | |
| 2208 {"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
|
2209 {"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
|
2210 {"unichr", builtin_unichr, 1, unichr_doc}, |
| 8561 | 2211 {"vars", builtin_vars, 1, vars_doc}, |
| 2212 {"xrange", builtin_xrange, 1, xrange_doc}, | |
|
13822
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
2213 {"zip", builtin_zip, 1, zip_doc}, |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
2214 {NULL, NULL}, |
| 86 | 2215 }; |
| 2216 | |
| 8561 | 2217 static char builtin_doc[] = |
| 2218 "Built-in functions, exceptions, and other objects.\n\ | |
| 2219 \n\ | |
| 2220 Noteworthy: None is the `nil' object; Ellipsis represents `...' in slices."; | |
| 2221 | |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2222 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
2223 _PyBuiltin_Init(void) |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2224 { |
|
12961
eb911eca9ee9
Christopher Fandrich <cfandrich@8cs.com>:
Fred Drake <fdrake@acm.org>
parents:
12756
diff
changeset
|
2225 PyObject *mod, *dict, *debug; |
| 8561 | 2226 mod = Py_InitModule4("__builtin__", builtin_methods, |
| 2227 builtin_doc, (PyObject *)NULL, | |
| 2228 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
|
2229 if (mod == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2230 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2231 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
|
2232 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
|
2233 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2234 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
|
2235 return NULL; |
|
15829
9308dc8c85e0
(Modified) patch by Ping - SF Patch #102681.
Guido van Rossum <guido@python.org>
parents:
15727
diff
changeset
|
2236 if (PyDict_SetItemString(dict, "NotImplemented", |
|
15727
641ad6c833be
Add NotImplemented to the builtin module.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15654
diff
changeset
|
2237 Py_NotImplemented) < 0) |
|
641ad6c833be
Add NotImplemented to the builtin module.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
15654
diff
changeset
|
2238 return NULL; |
|
12961
eb911eca9ee9
Christopher Fandrich <cfandrich@8cs.com>:
Fred Drake <fdrake@acm.org>
parents:
12756
diff
changeset
|
2239 debug = PyInt_FromLong(Py_OptimizeFlag == 0); |
|
eb911eca9ee9
Christopher Fandrich <cfandrich@8cs.com>:
Fred Drake <fdrake@acm.org>
parents:
12756
diff
changeset
|
2240 if (PyDict_SetItemString(dict, "__debug__", debug) < 0) { |
|
eb911eca9ee9
Christopher Fandrich <cfandrich@8cs.com>:
Fred Drake <fdrake@acm.org>
parents:
12756
diff
changeset
|
2241 Py_XDECREF(debug); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2242 return NULL; |
|
12961
eb911eca9ee9
Christopher Fandrich <cfandrich@8cs.com>:
Fred Drake <fdrake@acm.org>
parents:
12756
diff
changeset
|
2243 } |
|
eb911eca9ee9
Christopher Fandrich <cfandrich@8cs.com>:
Fred Drake <fdrake@acm.org>
parents:
12756
diff
changeset
|
2244 Py_XDECREF(debug); |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
2245 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
2246 return mod; |
| 86 | 2247 } |
| 2248 | |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1387
diff
changeset
|
2249 /* 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
|
2250 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2251 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
2252 filtertuple(PyObject *func, PyObject *tuple) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2253 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2254 PyObject *result; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2255 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
|
2256 int len = PyTuple_Size(tuple); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2257 |
|
2890
04e1690fb4d1
avoid resize of 0-length tuple
Guido van Rossum <guido@python.org>
parents:
2857
diff
changeset
|
2258 if (len == 0) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2259 Py_INCREF(tuple); |
|
2890
04e1690fb4d1
avoid resize of 0-length tuple
Guido van Rossum <guido@python.org>
parents:
2857
diff
changeset
|
2260 return tuple; |
|
04e1690fb4d1
avoid resize of 0-length tuple
Guido van Rossum <guido@python.org>
parents:
2857
diff
changeset
|
2261 } |
|
04e1690fb4d1
avoid resize of 0-length tuple
Guido van Rossum <guido@python.org>
parents:
2857
diff
changeset
|
2262 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2263 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
|
2264 return NULL; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2265 |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
2266 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
|
2267 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
|
2268 int ok; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2269 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2270 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
|
2271 goto Fail_1; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2272 if (func == Py_None) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2273 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
|
2274 good = item; |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
2275 } |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
2276 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2277 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
|
2278 if (arg == NULL) |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
2279 goto Fail_1; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2280 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
|
2281 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
|
2282 if (good == NULL) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2283 goto Fail_1; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2284 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2285 ok = PyObject_IsTrue(good); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2286 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
|
2287 if (ok) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2288 Py_INCREF(item); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2289 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
|
2290 goto Fail_1; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2291 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2292 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2293 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2294 if (_PyTuple_Resize(&result, j, 0) < 0) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2295 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2296 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2297 return result; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2298 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2299 Fail_1: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2300 Py_DECREF(result); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2301 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2302 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2303 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2304 |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1387
diff
changeset
|
2305 /* 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
|
2306 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2307 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
2308 filterstring(PyObject *func, PyObject *strobj) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2309 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2310 PyObject *result; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2311 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
|
2312 int len = PyString_Size(strobj); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2313 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2314 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
|
2315 /* 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
|
2316 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
|
2317 return strobj; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2318 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2319 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
|
2320 return NULL; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2321 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2322 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
|
2323 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
|
2324 int ok; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2325 |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
2326 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
|
2327 if (item == NULL) |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
2328 goto Fail_1; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2329 arg = Py_BuildValue("(O)", item); |
|
17337
96ea0eccdb31
SF patch #413552 - Premature decref on object
Tim Peters <tim.peters@gmail.com>
parents:
17125
diff
changeset
|
2330 if (arg == NULL) { |
|
96ea0eccdb31
SF patch #413552 - Premature decref on object
Tim Peters <tim.peters@gmail.com>
parents:
17125
diff
changeset
|
2331 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
|
2332 goto Fail_1; |
|
17337
96ea0eccdb31
SF patch #413552 - Premature decref on object
Tim Peters <tim.peters@gmail.com>
parents:
17125
diff
changeset
|
2333 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2334 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
|
2335 Py_DECREF(arg); |
|
17337
96ea0eccdb31
SF patch #413552 - Premature decref on object
Tim Peters <tim.peters@gmail.com>
parents:
17125
diff
changeset
|
2336 if (good == NULL) { |
|
96ea0eccdb31
SF patch #413552 - Premature decref on object
Tim Peters <tim.peters@gmail.com>
parents:
17125
diff
changeset
|
2337 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
|
2338 goto Fail_1; |
|
17337
96ea0eccdb31
SF patch #413552 - Premature decref on object
Tim Peters <tim.peters@gmail.com>
parents:
17125
diff
changeset
|
2339 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2340 ok = PyObject_IsTrue(good); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2341 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
|
2342 if (ok) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2343 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
|
2344 PyString_AS_STRING((PyStringObject *)item)[0]; |
|
17337
96ea0eccdb31
SF patch #413552 - Premature decref on object
Tim Peters <tim.peters@gmail.com>
parents:
17125
diff
changeset
|
2345 Py_DECREF(item); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2346 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2347 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2348 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
|
2349 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2350 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2351 return result; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2352 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2353 Fail_1: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
2354 Py_DECREF(result); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2355 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
2356 } |
