Mercurial > cpython-lru_cache-weakref
annotate Python/bltinmodule.c @ 27652:ed91bf601b2d legacy-trunk
SF #661437, apply() should get PendingDeprecation
| author | Neal Norwitz <nnorwitz@gmail.com> |
|---|---|
| date | Mon, 03 Feb 2003 20:23:33 +0000 |
| parents | 91a573243d5d |
| children | ce3faab06de7 |
| 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 |
|
20654
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20471
diff
changeset
|
12 #ifdef RISCOS |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20471
diff
changeset
|
13 #include "unixstuff.h" |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20471
diff
changeset
|
14 #endif |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20471
diff
changeset
|
15 |
|
17822
50376d470648
Fix the Py_FileSystemDefaultEncoding checkin - declare the variable in a fileobject.h, and initialize it in bltinmodule.
Mark Hammond <mhammond@skippinet.com.au>
parents:
17817
diff
changeset
|
16 /* The default encoding used by the platform file system APIs |
|
50376d470648
Fix the Py_FileSystemDefaultEncoding checkin - declare the variable in a fileobject.h, and initialize it in bltinmodule.
Mark Hammond <mhammond@skippinet.com.au>
parents:
17817
diff
changeset
|
17 Can remain NULL for all platforms that don't have such a concept |
|
50376d470648
Fix the Py_FileSystemDefaultEncoding checkin - declare the variable in a fileobject.h, and initialize it in bltinmodule.
Mark Hammond <mhammond@skippinet.com.au>
parents:
17817
diff
changeset
|
18 */ |
|
24071
8142f8d668a0
Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents:
23868
diff
changeset
|
19 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) |
|
17822
50376d470648
Fix the Py_FileSystemDefaultEncoding checkin - declare the variable in a fileobject.h, and initialize it in bltinmodule.
Mark Hammond <mhammond@skippinet.com.au>
parents:
17817
diff
changeset
|
20 const char *Py_FileSystemDefaultEncoding = "mbcs"; |
|
50376d470648
Fix the Py_FileSystemDefaultEncoding checkin - declare the variable in a fileobject.h, and initialize it in bltinmodule.
Mark Hammond <mhammond@skippinet.com.au>
parents:
17817
diff
changeset
|
21 #else |
|
50376d470648
Fix the Py_FileSystemDefaultEncoding checkin - declare the variable in a fileobject.h, and initialize it in bltinmodule.
Mark Hammond <mhammond@skippinet.com.au>
parents:
17817
diff
changeset
|
22 const char *Py_FileSystemDefaultEncoding = NULL; /* use default */ |
|
50376d470648
Fix the Py_FileSystemDefaultEncoding checkin - declare the variable in a fileobject.h, and initialize it in bltinmodule.
Mark Hammond <mhammond@skippinet.com.au>
parents:
17817
diff
changeset
|
23 #endif |
|
17817
f7c385226f65
Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents:
17694
diff
changeset
|
24 |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
25 /* Forward */ |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13446
diff
changeset
|
26 static PyObject *filterstring(PyObject *, PyObject *); |
|
27385
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
27 #ifdef Py_USING_UNICODE |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
28 static PyObject *filterunicode(PyObject *, PyObject *); |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
29 #endif |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13446
diff
changeset
|
30 static PyObject *filtertuple (PyObject *, PyObject *); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
31 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
32 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
33 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
|
34 { |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
35 char *name; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
36 PyObject *globals = NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
37 PyObject *locals = NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
38 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
|
39 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
40 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
|
41 &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
|
42 return NULL; |
|
6243
4279f4eb210a
First part of package support.
Guido van Rossum <guido@python.org>
parents:
6198
diff
changeset
|
43 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
|
44 } |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
45 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
46 PyDoc_STRVAR(import_doc, |
| 8561 | 47 "__import__(name, globals, locals, fromlist) -> module\n\ |
| 48 \n\ | |
| 49 Import a module. The globals are only used to determine the context;\n\ | |
| 50 they are not modified. The locals are currently unused. The fromlist\n\ | |
| 51 should be a list of names to emulate ``from name import ...'', or an\n\ | |
| 52 empty list to emulate ``import name''.\n\ | |
| 53 When importing a module from a package, note that __import__('A.B', ...)\n\ | |
| 54 returns package A when fromlist is empty, but its submodule B when\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
55 fromlist is not empty."); |
| 8561 | 56 |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
57 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
58 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
59 builtin_abs(PyObject *self, 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
|
60 { |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
61 return PyNumber_Absolute(v); |
| 86 | 62 } |
| 63 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
64 PyDoc_STRVAR(abs_doc, |
| 8561 | 65 "abs(number) -> number\n\ |
| 66 \n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
67 Return the absolute value of the argument."); |
| 8561 | 68 |
| 69 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
70 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
71 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
|
72 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
73 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
|
74 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
|
75 |
|
27652
ed91bf601b2d
SF #661437, apply() should get PendingDeprecation
Neal Norwitz <nnorwitz@gmail.com>
parents:
27385
diff
changeset
|
76 PyErr_Warn(PyExc_PendingDeprecationWarning, |
|
ed91bf601b2d
SF #661437, apply() should get PendingDeprecation
Neal Norwitz <nnorwitz@gmail.com>
parents:
27385
diff
changeset
|
77 "use func(*args, **kwargs) instead of " |
|
ed91bf601b2d
SF #661437, apply() should get PendingDeprecation
Neal Norwitz <nnorwitz@gmail.com>
parents:
27385
diff
changeset
|
78 "apply(func, args, kwargs)"); |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
79 if (!PyArg_UnpackTuple(args, "apply", 1, 3, &func, &alist, &kwdict)) |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
80 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
|
81 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
|
82 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
|
83 if (!PySequence_Check(alist)) { |
|
16017
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16011
diff
changeset
|
84 PyErr_Format(PyExc_TypeError, |
|
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16011
diff
changeset
|
85 "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
|
86 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
|
87 return NULL; |
|
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
88 } |
|
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
89 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
|
90 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
|
91 return NULL; |
|
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
92 alist = t; |
|
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
93 } |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
94 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
95 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
|
96 PyErr_Format(PyExc_TypeError, |
|
7234d7c3c29f
clearer error messages for apply() and "no locals"
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16011
diff
changeset
|
97 "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
|
98 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
|
99 goto finally; |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2824
diff
changeset
|
100 } |
|
9188
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
101 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
|
102 finally: |
|
a1672e775f33
builtin_apply(): Second argument type check is relaxed to allow any sequence.
Barry Warsaw <barry@python.org>
parents:
9112
diff
changeset
|
103 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
|
104 return retval; |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
105 } |
|
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
106 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
107 PyDoc_STRVAR(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
|
108 "apply(object[, args[, kwargs]]) -> value\n\ |
| 8561 | 109 \n\ |
|
11621
0ec803cbd872
Adjusted apply() docstring based on comments from Gerrit Holl
Fred Drake <fdrake@acm.org>
parents:
11383
diff
changeset
|
110 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
|
111 and keyword arguments taken from the optional dictionary kwargs.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
112 Note that classes are callable, as are instances with a __call__() method."); |
| 8561 | 113 |
| 114 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
115 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
116 builtin_callable(PyObject *self, PyObject *v) |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
117 { |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22205
diff
changeset
|
118 return PyBool_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
|
119 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
120 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
121 PyDoc_STRVAR(callable_doc, |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22205
diff
changeset
|
122 "callable(object) -> bool\n\ |
| 8561 | 123 \n\ |
| 124 Return whether the object is callable (i.e., some kind of function).\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
125 Note that classes are callable, as are instances with a __call__() method."); |
| 8561 | 126 |
| 127 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
128 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
129 builtin_filter(PyObject *self, PyObject *args) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
130 { |
|
24863
a3ebd1233c00
A nice little speed-up for filter():
Guido van Rossum <guido@python.org>
parents:
24817
diff
changeset
|
131 PyObject *func, *seq, *result, *it, *arg; |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
132 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
|
133 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
|
134 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
135 if (!PyArg_UnpackTuple(args, "filter", 2, 2, &func, &seq)) |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
136 return NULL; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
137 |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
138 /* 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
|
139 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
|
140 return filterstring(func, seq); |
|
27385
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
141 #ifdef Py_USING_UNICODE |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
142 if (PyUnicode_Check(seq)) |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
143 return filterunicode(func, seq); |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
144 #endif |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
145 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
|
146 return filtertuple(func, seq); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
147 |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
148 /* Get iterator. */ |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
149 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
|
150 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
|
151 return NULL; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
152 |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
153 /* 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
|
154 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
|
155 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
|
156 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
|
157 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
|
158 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
|
159 PyErr_Clear(); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
160 } |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
161 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
|
162 len = 8; /* arbitrary */ |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
163 |
|
24863
a3ebd1233c00
A nice little speed-up for filter():
Guido van Rossum <guido@python.org>
parents:
24817
diff
changeset
|
164 /* Pre-allocate argument list tuple. */ |
|
a3ebd1233c00
A nice little speed-up for filter():
Guido van Rossum <guido@python.org>
parents:
24817
diff
changeset
|
165 arg = PyTuple_New(1); |
|
a3ebd1233c00
A nice little speed-up for filter():
Guido van Rossum <guido@python.org>
parents:
24817
diff
changeset
|
166 if (arg == NULL) |
|
a3ebd1233c00
A nice little speed-up for filter():
Guido van Rossum <guido@python.org>
parents:
24817
diff
changeset
|
167 goto Fail_arg; |
|
a3ebd1233c00
A nice little speed-up for filter():
Guido van Rossum <guido@python.org>
parents:
24817
diff
changeset
|
168 |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
169 /* 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
|
170 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
|
171 /* 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
|
172 Py_INCREF(seq); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
173 result = seq; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
174 } |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
175 else { |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
176 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
|
177 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
|
178 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
|
179 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
180 |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
181 /* 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
|
182 j = 0; |
|
e9a4e27e8d4e
Make PyIter_Next() a little smarter (wrt its knowledge of iterator
Tim Peters <tim.peters@gmail.com>
parents:
17677
diff
changeset
|
183 for (;;) { |
|
24863
a3ebd1233c00
A nice little speed-up for filter():
Guido van Rossum <guido@python.org>
parents:
24817
diff
changeset
|
184 PyObject *item; |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
185 int ok; |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
186 |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
187 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
|
188 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
|
189 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
|
190 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
|
191 break; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
192 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
193 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
194 if (func == Py_None) { |
|
24863
a3ebd1233c00
A nice little speed-up for filter():
Guido van Rossum <guido@python.org>
parents:
24817
diff
changeset
|
195 ok = PyObject_IsTrue(item); |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
196 } |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
197 else { |
|
24863
a3ebd1233c00
A nice little speed-up for filter():
Guido van Rossum <guido@python.org>
parents:
24817
diff
changeset
|
198 PyObject *good; |
|
a3ebd1233c00
A nice little speed-up for filter():
Guido van Rossum <guido@python.org>
parents:
24817
diff
changeset
|
199 PyTuple_SET_ITEM(arg, 0, item); |
|
a3ebd1233c00
A nice little speed-up for filter():
Guido van Rossum <guido@python.org>
parents:
24817
diff
changeset
|
200 good = PyObject_Call(func, arg, NULL); |
|
a3ebd1233c00
A nice little speed-up for filter():
Guido van Rossum <guido@python.org>
parents:
24817
diff
changeset
|
201 PyTuple_SET_ITEM(arg, 0, NULL); |
|
2120
84b61fe44573
fix subtle refcount big in filter() -- Tim MacKenzie
Guido van Rossum <guido@python.org>
parents:
2113
diff
changeset
|
202 if (good == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
203 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
|
204 goto Fail_result_it; |
|
2120
84b61fe44573
fix subtle refcount big in filter() -- Tim MacKenzie
Guido van Rossum <guido@python.org>
parents:
2113
diff
changeset
|
205 } |
|
24863
a3ebd1233c00
A nice little speed-up for filter():
Guido van Rossum <guido@python.org>
parents:
24817
diff
changeset
|
206 ok = PyObject_IsTrue(good); |
|
a3ebd1233c00
A nice little speed-up for filter():
Guido van Rossum <guido@python.org>
parents:
24817
diff
changeset
|
207 Py_DECREF(good); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
208 } |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
209 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
|
210 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
|
211 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
|
212 else { |
|
9991
ddbbed8cb830
builtin_map(): A better fix for the previous leak plug (remember
Barry Warsaw <barry@python.org>
parents:
9980
diff
changeset
|
213 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
|
214 Py_DECREF(item); |
|
ddbbed8cb830
builtin_map(): A better fix for the previous leak plug (remember
Barry Warsaw <barry@python.org>
parents:
9980
diff
changeset
|
215 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
|
216 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
|
217 } |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
218 ++j; |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
219 } |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
220 else |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
221 Py_DECREF(item); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
222 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
223 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
224 |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
225 /* 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
|
226 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
|
227 goto Fail_result_it; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
228 |
|
17874
eb03c6fc31e5
SF bug #425836: Reference leak in filter().
Tim Peters <tim.peters@gmail.com>
parents:
17822
diff
changeset
|
229 Py_DECREF(it); |
|
24863
a3ebd1233c00
A nice little speed-up for filter():
Guido van Rossum <guido@python.org>
parents:
24817
diff
changeset
|
230 Py_DECREF(arg); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
231 return result; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
232 |
|
17654
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
233 Fail_result_it: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
234 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
|
235 Fail_it: |
|
a97e18e499a9
Generalize filter(f, seq) to work with iterators. This also generalizes
Tim Peters <tim.peters@gmail.com>
parents:
17641
diff
changeset
|
236 Py_DECREF(it); |
|
24863
a3ebd1233c00
A nice little speed-up for filter():
Guido van Rossum <guido@python.org>
parents:
24817
diff
changeset
|
237 Fail_arg: |
|
a3ebd1233c00
A nice little speed-up for filter():
Guido van Rossum <guido@python.org>
parents:
24817
diff
changeset
|
238 Py_DECREF(arg); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
239 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
240 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
241 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
242 PyDoc_STRVAR(filter_doc, |
|
22225
67a5e25dc88b
backport tim_one's checkin of
Michael W. Hudson <mwh@python.net>
parents:
21712
diff
changeset
|
243 "filter(function or None, sequence) -> list, tuple, or string\n" |
|
67a5e25dc88b
backport tim_one's checkin of
Michael W. Hudson <mwh@python.net>
parents:
21712
diff
changeset
|
244 "\n" |
|
67a5e25dc88b
backport tim_one's checkin of
Michael W. Hudson <mwh@python.net>
parents:
21712
diff
changeset
|
245 "Return those items of sequence for which function(item) is true. If\n" |
|
67a5e25dc88b
backport tim_one's checkin of
Michael W. Hudson <mwh@python.net>
parents:
21712
diff
changeset
|
246 "function is None, return the items that are true. If sequence is a tuple\n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
247 "or string, return the same type, else return a list."); |
| 8561 | 248 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
249 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
250 builtin_chr(PyObject *self, PyObject *args) |
| 86 | 251 { |
| 252 long x; | |
| 253 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
|
254 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
255 if (!PyArg_ParseTuple(args, "l:chr", &x)) |
| 86 | 256 return NULL; |
| 257 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
|
258 PyErr_SetString(PyExc_ValueError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
259 "chr() arg not in range(256)"); |
| 86 | 260 return NULL; |
| 261 } | |
|
5317
c72c7e1930b3
Keep gcc -Wall and Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents:
5223
diff
changeset
|
262 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
|
263 return PyString_FromStringAndSize(s, 1); |
| 86 | 264 } |
| 265 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
266 PyDoc_STRVAR(chr_doc, |
| 8561 | 267 "chr(i) -> character\n\ |
| 268 \n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
269 Return a string of one character with ordinal i; 0 <= i < 256."); |
| 8561 | 270 |
| 271 | |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19301
diff
changeset
|
272 #ifdef Py_USING_UNICODE |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
273 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
274 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
|
275 { |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
276 long x; |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
277 |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
278 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
|
279 return NULL; |
|
18282
f38923ce3c6b
more unicode tweaks: make unichr(0xdddddddd) behave like u"\Udddddddd"
Fredrik Lundh <fredrik@pythonware.com>
parents:
18281
diff
changeset
|
280 |
|
24737
eaa87632b1e8
Add C API PyUnicode_FromOrdinal() which exposes unichr() at C level.
Marc-André Lemburg <mal@egenix.com>
parents:
24071
diff
changeset
|
281 return PyUnicode_FromOrdinal(x); |
|
11973
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
282 } |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
283 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
284 PyDoc_STRVAR(unichr_doc, |
|
12386
32e9d0e78935
When refering to Unicode characters in exception messages and
Fred Drake <fdrake@acm.org>
parents:
12384
diff
changeset
|
285 "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
|
286 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
287 Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff."); |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19301
diff
changeset
|
288 #endif |
|
11973
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
289 |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
290 |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
291 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
292 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
|
293 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
294 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
|
295 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
|
296 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
297 if (!PyArg_UnpackTuple(args, "cmp", 2, 2, &a, &b)) |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
298 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
|
299 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
|
300 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
|
301 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
|
302 } |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
303 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
304 PyDoc_STRVAR(cmp_doc, |
| 8561 | 305 "cmp(x, y) -> integer\n\ |
| 306 \n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
307 Return negative if x<y, zero if x==y, positive if x>y."); |
| 8561 | 308 |
| 309 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
310 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
311 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
|
312 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
313 PyObject *v, *w; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
314 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
|
315 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
316 if (!PyArg_UnpackTuple(args, "coerce", 2, 2, &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
|
317 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
318 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
|
319 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
320 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
|
321 Py_DECREF(v); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
322 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
|
323 return res; |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
324 } |
|
222f04f55083
Changes so that user-defined classes can implement operations invoked
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
325 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
326 PyDoc_STRVAR(coerce_doc, |
| 8561 | 327 "coerce(x, y) -> None or (x1, y1)\n\ |
| 328 \n\ | |
| 329 When x and y can be coerced to values of the same type, return a tuple\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
330 containing the coerced values. When they can't be coerced, return None."); |
| 8561 | 331 |
| 332 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
333 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
334 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
|
335 { |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
336 char *str; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
337 char *filename; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
338 char *startstr; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
339 int start; |
|
19355
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
340 int dont_inherit = 0; |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
341 int supplied_flags = 0; |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18436
diff
changeset
|
342 PyCompilerFlags cf; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
343 |
|
23305
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
344 if (!PyArg_ParseTuple(args, "sss|ii:compile", &str, &filename, |
|
19355
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
345 &startstr, &supplied_flags, &dont_inherit)) |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
346 return NULL; |
|
19355
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
347 |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
348 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
|
349 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
|
350 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
|
351 start = Py_eval_input; |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
352 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
|
353 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
|
354 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
355 PyErr_SetString(PyExc_ValueError, |
| 15318 | 356 "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
|
357 return NULL; |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
358 } |
|
19355
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
359 |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
360 if (supplied_flags & ~(PyCF_MASK | PyCF_MASK_OBSOLETE)) { |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
361 PyErr_SetString(PyExc_ValueError, |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
362 "compile(): unrecognised flags"); |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
363 return NULL; |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
364 } |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
365 /* XXX Warn if (supplied_flags & PyCF_MASK_OBSOLETE) != 0? */ |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
366 |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
367 cf.cf_flags = supplied_flags; |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
368 if (!dont_inherit) { |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
369 PyEval_MergeCompilerFlags(&cf); |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
370 } |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
371 return Py_CompileStringFlags(str, filename, start, &cf); |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
372 } |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
373 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
374 PyDoc_STRVAR(compile_doc, |
|
19355
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
375 "compile(source, filename, mode[, flags[, dont_inherit]]) -> code object\n\ |
| 8561 | 376 \n\ |
| 377 Compile the source string (a Python module, statement or expression)\n\ | |
| 378 into a code object that can be executed by the exec statement or eval().\n\ | |
| 379 The filename will be used for run-time error messages.\n\ | |
| 380 The mode must be 'exec' to compile a module, 'single' to compile a\n\ | |
|
19355
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
381 single (interactive) statement, or 'eval' to compile an expression.\n\ |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
382 The flags argument, if present, controls which future statements influence\n\ |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
383 the compilation of the code.\n\ |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
384 The dont_inherit argument, if non-zero, stops the compilation inheriting\n\ |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
385 the effects of any future statements in effect in the code calling\n\ |
|
d5acff178ad5
A fiddled version of the rest of Michael Hudson's SF patch
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
386 compile; if absent or zero these statements do influence the compilation,\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
387 in addition to any features explicitly specified."); |
| 8561 | 388 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
389 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
390 builtin_dir(PyObject *self, PyObject *args) |
| 86 | 391 { |
|
19665
08c3c9edd99b
Make dir() wordier (see the new docstring). The new behavior is a mixed
Tim Peters <tim.peters@gmail.com>
parents:
19471
diff
changeset
|
392 PyObject *arg = NULL; |
|
08c3c9edd99b
Make dir() wordier (see the new docstring). The new behavior is a mixed
Tim Peters <tim.peters@gmail.com>
parents:
19471
diff
changeset
|
393 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
394 if (!PyArg_UnpackTuple(args, "dir", 0, 1, &arg)) |
|
19665
08c3c9edd99b
Make dir() wordier (see the new docstring). The new behavior is a mixed
Tim Peters <tim.peters@gmail.com>
parents:
19471
diff
changeset
|
395 return NULL; |
|
19705
b7f6fbc087a7
At Guido's suggestion, here's a new C API function, PyObject_Dir(), like
Tim Peters <tim.peters@gmail.com>
parents:
19670
diff
changeset
|
396 return PyObject_Dir(arg); |
| 86 | 397 } |
| 398 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
399 PyDoc_STRVAR(dir_doc, |
|
19665
08c3c9edd99b
Make dir() wordier (see the new docstring). The new behavior is a mixed
Tim Peters <tim.peters@gmail.com>
parents:
19471
diff
changeset
|
400 "dir([object]) -> list of strings\n" |
|
08c3c9edd99b
Make dir() wordier (see the new docstring). The new behavior is a mixed
Tim Peters <tim.peters@gmail.com>
parents:
19471
diff
changeset
|
401 "\n" |
|
08c3c9edd99b
Make dir() wordier (see the new docstring). The new behavior is a mixed
Tim Peters <tim.peters@gmail.com>
parents:
19471
diff
changeset
|
402 "Return an alphabetized list of names comprising (some of) the attributes\n" |
|
08c3c9edd99b
Make dir() wordier (see the new docstring). The new behavior is a mixed
Tim Peters <tim.peters@gmail.com>
parents:
19471
diff
changeset
|
403 "of the given object, and of attributes reachable from it:\n" |
|
08c3c9edd99b
Make dir() wordier (see the new docstring). The new behavior is a mixed
Tim Peters <tim.peters@gmail.com>
parents:
19471
diff
changeset
|
404 "\n" |
|
08c3c9edd99b
Make dir() wordier (see the new docstring). The new behavior is a mixed
Tim Peters <tim.peters@gmail.com>
parents:
19471
diff
changeset
|
405 "No argument: the names in the current scope.\n" |
|
08c3c9edd99b
Make dir() wordier (see the new docstring). The new behavior is a mixed
Tim Peters <tim.peters@gmail.com>
parents:
19471
diff
changeset
|
406 "Module object: the module attributes.\n" |
|
19670
78cfb993f274
builtin_dir(): Treat classic classes like types. Use PyDict_Keys instead
Tim Peters <tim.peters@gmail.com>
parents:
19665
diff
changeset
|
407 "Type or class object: its attributes, and recursively the attributes of\n" |
|
78cfb993f274
builtin_dir(): Treat classic classes like types. Use PyDict_Keys instead
Tim Peters <tim.peters@gmail.com>
parents:
19665
diff
changeset
|
408 " its bases.\n" |
|
19665
08c3c9edd99b
Make dir() wordier (see the new docstring). The new behavior is a mixed
Tim Peters <tim.peters@gmail.com>
parents:
19471
diff
changeset
|
409 "Otherwise: its attributes, its class's attributes, and recursively the\n" |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
410 " attributes of its class's base classes."); |
| 8561 | 411 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
412 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
413 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
|
414 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
415 PyObject *v, *w; |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
416 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
417 if (!PyArg_UnpackTuple(args, "divmod", 2, 2, &v, &w)) |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
418 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
|
419 return PyNumber_Divmod(v, w); |
| 86 | 420 } |
| 421 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
422 PyDoc_STRVAR(divmod_doc, |
| 8561 | 423 "divmod(x, y) -> (div, mod)\n\ |
| 424 \n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
425 Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x."); |
| 8561 | 426 |
| 427 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
428 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
429 builtin_eval(PyObject *self, PyObject *args) |
| 86 | 430 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
431 PyObject *cmd; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
432 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
|
433 char *str; |
|
19357
be9b50704e4c
Fix for bug [#452230] future division isn't propagated.
Tim Peters <tim.peters@gmail.com>
parents:
19355
diff
changeset
|
434 PyCompilerFlags cf; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
435 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
436 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
|
437 &cmd, |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
438 &PyDict_Type, &globals, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
439 &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
|
440 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
441 if (globals == Py_None) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
442 globals = PyEval_GetGlobals(); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
443 if (locals == Py_None) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
444 locals = PyEval_GetLocals(); |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
445 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
446 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
|
447 locals = globals; |
|
19357
be9b50704e4c
Fix for bug [#452230] future division isn't propagated.
Tim Peters <tim.peters@gmail.com>
parents:
19355
diff
changeset
|
448 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
449 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
|
450 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
|
451 PyEval_GetBuiltins()) != 0) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
452 return NULL; |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
453 } |
|
19357
be9b50704e4c
Fix for bug [#452230] future division isn't propagated.
Tim Peters <tim.peters@gmail.com>
parents:
19355
diff
changeset
|
454 |
|
18885
22456d0ee737
Fix for SF bug [ #443866 ] Evaluating func_code causing core dump
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18836
diff
changeset
|
455 if (PyCode_Check(cmd)) { |
|
21398
de125792bfaa
Fix for SF bug [ #492403 ] exec() segfaults on closure's func_code
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21077
diff
changeset
|
456 if (PyCode_GetNumFree((PyCodeObject *)cmd) > 0) { |
|
18885
22456d0ee737
Fix for SF bug [ #443866 ] Evaluating func_code causing core dump
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18836
diff
changeset
|
457 PyErr_SetString(PyExc_TypeError, |
|
22456d0ee737
Fix for SF bug [ #443866 ] Evaluating func_code causing core dump
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18836
diff
changeset
|
458 "code object passed to eval() may not contain free variables"); |
|
22456d0ee737
Fix for SF bug [ #443866 ] Evaluating func_code causing core dump
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18836
diff
changeset
|
459 return NULL; |
|
22456d0ee737
Fix for SF bug [ #443866 ] Evaluating func_code causing core dump
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18836
diff
changeset
|
460 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
461 return PyEval_EvalCode((PyCodeObject *) cmd, globals, locals); |
|
18885
22456d0ee737
Fix for SF bug [ #443866 ] Evaluating func_code causing core dump
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18836
diff
changeset
|
462 } |
|
19357
be9b50704e4c
Fix for bug [#452230] future division isn't propagated.
Tim Peters <tim.peters@gmail.com>
parents:
19355
diff
changeset
|
463 |
|
14696
85038a024b19
This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents:
14662
diff
changeset
|
464 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
|
465 !PyUnicode_Check(cmd)) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
466 PyErr_SetString(PyExc_TypeError, |
| 15318 | 467 "eval() arg 1 must be a string or code object"); |
| 86 | 468 return NULL; |
| 469 } | |
|
14696
85038a024b19
This patch adds a new Python C API called PyString_AsStringAndSize()
Marc-André Lemburg <mal@egenix.com>
parents:
14662
diff
changeset
|
470 if (PyString_AsStringAndSize(cmd, &str, NULL)) |
|
959
68b302ad84a1
use getargs() in more cases;
Guido van Rossum <guido@python.org>
parents:
955
diff
changeset
|
471 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
|
472 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
|
473 str++; |
|
19357
be9b50704e4c
Fix for bug [#452230] future division isn't propagated.
Tim Peters <tim.peters@gmail.com>
parents:
19355
diff
changeset
|
474 |
|
be9b50704e4c
Fix for bug [#452230] future division isn't propagated.
Tim Peters <tim.peters@gmail.com>
parents:
19355
diff
changeset
|
475 cf.cf_flags = 0; |
|
be9b50704e4c
Fix for bug [#452230] future division isn't propagated.
Tim Peters <tim.peters@gmail.com>
parents:
19355
diff
changeset
|
476 (void)PyEval_MergeCompilerFlags(&cf); |
|
be9b50704e4c
Fix for bug [#452230] future division isn't propagated.
Tim Peters <tim.peters@gmail.com>
parents:
19355
diff
changeset
|
477 return PyRun_StringFlags(str, Py_eval_input, globals, locals, &cf); |
| 86 | 478 } |
| 479 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
480 PyDoc_STRVAR(eval_doc, |
| 8561 | 481 "eval(source[, globals[, locals]]) -> value\n\ |
| 482 \n\ | |
| 483 Evaluate the source in the context of globals and locals.\n\ | |
| 484 The source may be a string representing a Python expression\n\ | |
| 485 or a code object as returned by compile().\n\ | |
| 486 The globals and locals are dictionaries, defaulting to the current\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
487 globals and locals. If only globals is given, locals defaults to it."); |
| 8561 | 488 |
| 489 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
490 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
491 builtin_execfile(PyObject *self, PyObject *args) |
| 673 | 492 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
493 char *filename; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
494 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
|
495 PyObject *res; |
|
19726
5487d9d53a0e
builtin_execfile(): initialize another local that the GCC on leroy
Guido van Rossum <guido@python.org>
parents:
19705
diff
changeset
|
496 FILE* fp = NULL; |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18436
diff
changeset
|
497 PyCompilerFlags cf; |
|
19053
2bb242dc69d8
Patch #448227: Raise an exception when a directory is passed to execfile.
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
498 int exists; |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
499 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
500 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
|
501 &filename, |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
502 &PyDict_Type, &globals, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
503 &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
|
504 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
505 if (globals == Py_None) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
506 globals = PyEval_GetGlobals(); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
507 if (locals == Py_None) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
508 locals = PyEval_GetLocals(); |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
509 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
510 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
|
511 locals = globals; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
512 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
|
513 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
|
514 PyEval_GetBuiltins()) != 0) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
515 return NULL; |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
516 } |
|
19053
2bb242dc69d8
Patch #448227: Raise an exception when a directory is passed to execfile.
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
517 |
|
2bb242dc69d8
Patch #448227: Raise an exception when a directory is passed to execfile.
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
518 exists = 0; |
|
2bb242dc69d8
Patch #448227: Raise an exception when a directory is passed to execfile.
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
519 /* Test for existence or directory. */ |
|
22205
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
520 #if defined(PLAN9) |
|
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
521 { |
|
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
522 Dir *d; |
|
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
523 |
|
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
524 if ((d = dirstat(filename))!=nil) { |
|
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
525 if(d->mode & DMDIR) |
|
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
526 werrstr("is a directory"); |
|
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
527 else |
|
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
528 exists = 1; |
|
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
529 free(d); |
|
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
530 } |
|
19053
2bb242dc69d8
Patch #448227: Raise an exception when a directory is passed to execfile.
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
531 } |
|
22205
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
532 #elif defined(RISCOS) |
|
20654
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20471
diff
changeset
|
533 if (object_exists(filename)) { |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20471
diff
changeset
|
534 if (isdir(filename)) |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20471
diff
changeset
|
535 errno = EISDIR; |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20471
diff
changeset
|
536 else |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20471
diff
changeset
|
537 exists = 1; |
|
edd9d0b3c47e
SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents:
20471
diff
changeset
|
538 } |
|
22205
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
539 #else /* standard Posix */ |
|
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
540 { |
|
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
541 struct stat s; |
|
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
542 if (stat(filename, &s) == 0) { |
|
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
543 if (S_ISDIR(s.st_mode)) |
|
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
544 # if defined(PY_OS2) && defined(PYCC_VACPP) |
|
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
545 errno = EOS2ERR; |
|
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
546 # else |
|
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
547 errno = EISDIR; |
|
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
548 # endif |
|
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
549 else |
|
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
550 exists = 1; |
|
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
551 } |
|
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
552 } |
|
f4487350c537
Patch #494045: patches errno and stat to cope on plan9.
Martin v. Löwis <martin@v.loewis.de>
parents:
22225
diff
changeset
|
553 #endif |
|
19053
2bb242dc69d8
Patch #448227: Raise an exception when a directory is passed to execfile.
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
554 |
|
2bb242dc69d8
Patch #448227: Raise an exception when a directory is passed to execfile.
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
555 if (exists) { |
|
2bb242dc69d8
Patch #448227: Raise an exception when a directory is passed to execfile.
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
556 Py_BEGIN_ALLOW_THREADS |
|
23029
8291473fde3e
Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents:
22785
diff
changeset
|
557 fp = fopen(filename, "r" PY_STDIOTEXTMODE); |
|
19053
2bb242dc69d8
Patch #448227: Raise an exception when a directory is passed to execfile.
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
558 Py_END_ALLOW_THREADS |
|
2bb242dc69d8
Patch #448227: Raise an exception when a directory is passed to execfile.
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
559 |
|
2bb242dc69d8
Patch #448227: Raise an exception when a directory is passed to execfile.
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
560 if (fp == NULL) { |
|
2bb242dc69d8
Patch #448227: Raise an exception when a directory is passed to execfile.
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
561 exists = 0; |
|
2bb242dc69d8
Patch #448227: Raise an exception when a directory is passed to execfile.
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
562 } |
|
2bb242dc69d8
Patch #448227: Raise an exception when a directory is passed to execfile.
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
563 } |
|
2bb242dc69d8
Patch #448227: Raise an exception when a directory is passed to execfile.
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
564 |
|
2bb242dc69d8
Patch #448227: Raise an exception when a directory is passed to execfile.
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
565 if (!exists) { |
|
25046
434bc1dea4f8
execfile should call PyErr_SetFromErrnoWithFilename instead of
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
24863
diff
changeset
|
566 PyErr_SetFromErrnoWithFilename(PyExc_IOError, filename); |
| 673 | 567 return NULL; |
| 568 } | |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18436
diff
changeset
|
569 cf.cf_flags = 0; |
|
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18436
diff
changeset
|
570 if (PyEval_MergeCompilerFlags(&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
|
571 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
|
572 locals, 1, &cf); |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18436
diff
changeset
|
573 else |
|
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
|
574 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
|
575 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
|
576 return res; |
| 673 | 577 } |
| 578 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
579 PyDoc_STRVAR(execfile_doc, |
| 8561 | 580 "execfile(filename[, globals[, locals]])\n\ |
| 581 \n\ | |
| 582 Read and execute a Python script from a file.\n\ | |
| 583 The globals and locals are dictionaries, defaulting to the current\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
584 globals and locals. If only globals is given, locals defaults to it."); |
| 8561 | 585 |
| 586 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
587 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
588 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
|
589 { |
|
8581
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
590 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
|
591 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
|
592 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
593 if (!PyArg_UnpackTuple(args, "getattr", 2, 3, &v, &name, &dflt)) |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
594 return NULL; |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19301
diff
changeset
|
595 #ifdef Py_USING_UNICODE |
|
18888
f12e1a766a14
Fix for SF byg [ #420304 ] getattr function w/ default
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18885
diff
changeset
|
596 if (PyUnicode_Check(name)) { |
|
f12e1a766a14
Fix for SF byg [ #420304 ] getattr function w/ default
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18885
diff
changeset
|
597 name = _PyUnicode_AsDefaultEncodedString(name, NULL); |
|
f12e1a766a14
Fix for SF byg [ #420304 ] getattr function w/ default
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18885
diff
changeset
|
598 if (name == NULL) |
|
f12e1a766a14
Fix for SF byg [ #420304 ] getattr function w/ default
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18885
diff
changeset
|
599 return NULL; |
|
f12e1a766a14
Fix for SF byg [ #420304 ] getattr function w/ default
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18885
diff
changeset
|
600 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19301
diff
changeset
|
601 #endif |
|
18888
f12e1a766a14
Fix for SF byg [ #420304 ] getattr function w/ default
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18885
diff
changeset
|
602 |
|
f12e1a766a14
Fix for SF byg [ #420304 ] getattr function w/ default
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18885
diff
changeset
|
603 if (!PyString_Check(name)) { |
|
f12e1a766a14
Fix for SF byg [ #420304 ] getattr function w/ default
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18885
diff
changeset
|
604 PyErr_SetString(PyExc_TypeError, |
|
f12e1a766a14
Fix for SF byg [ #420304 ] getattr function w/ default
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18885
diff
changeset
|
605 "attribute name must be string"); |
|
f12e1a766a14
Fix for SF byg [ #420304 ] getattr function w/ default
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18885
diff
changeset
|
606 return NULL; |
|
f12e1a766a14
Fix for SF byg [ #420304 ] getattr function w/ default
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18885
diff
changeset
|
607 } |
|
8581
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
608 result = PyObject_GetAttr(v, name); |
|
20471
bbdc0abfbb13
SF patch #471852 (anonymous) notes that getattr(obj, name, default)
Guido van Rossum <guido@python.org>
parents:
20307
diff
changeset
|
609 if (result == NULL && dflt != NULL && |
|
bbdc0abfbb13
SF patch #471852 (anonymous) notes that getattr(obj, name, default)
Guido van Rossum <guido@python.org>
parents:
20307
diff
changeset
|
610 PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
bbdc0abfbb13
SF patch #471852 (anonymous) notes that getattr(obj, name, default)
Guido van Rossum <guido@python.org>
parents:
20307
diff
changeset
|
611 { |
|
8581
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
612 PyErr_Clear(); |
|
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
613 Py_INCREF(dflt); |
|
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
614 result = dflt; |
|
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
615 } |
|
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
616 return result; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
617 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
618 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
619 PyDoc_STRVAR(getattr_doc, |
|
8581
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
620 "getattr(object, name[, default]) -> value\n\ |
| 8561 | 621 \n\ |
|
8581
221667f89064
Experimental feature: add default argument to getattr().
Guido van Rossum <guido@python.org>
parents:
8561
diff
changeset
|
622 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
|
623 When a default argument is given, it is returned when the attribute doesn't\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
624 exist; without it, an exception is raised in that case."); |
| 8561 | 625 |
| 626 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
627 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
628 builtin_globals(PyObject *self) |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
629 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
630 PyObject *d; |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
631 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
632 d = PyEval_GetGlobals(); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
633 Py_INCREF(d); |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
634 return d; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
635 } |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
636 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
637 PyDoc_STRVAR(globals_doc, |
| 8561 | 638 "globals() -> dictionary\n\ |
| 639 \n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
640 Return the dictionary containing the current scope's global variables."); |
| 8561 | 641 |
| 642 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
643 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
644 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
|
645 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
646 PyObject *v; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
647 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
|
648 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
649 if (!PyArg_UnpackTuple(args, "hasattr", 2, 2, &v, &name)) |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
650 return NULL; |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19301
diff
changeset
|
651 #ifdef Py_USING_UNICODE |
|
18890
fb837c5ae5d3
Do for hasattr() what was done for getattr()
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18888
diff
changeset
|
652 if (PyUnicode_Check(name)) { |
|
fb837c5ae5d3
Do for hasattr() what was done for getattr()
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18888
diff
changeset
|
653 name = _PyUnicode_AsDefaultEncodedString(name, NULL); |
|
fb837c5ae5d3
Do for hasattr() what was done for getattr()
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18888
diff
changeset
|
654 if (name == NULL) |
|
fb837c5ae5d3
Do for hasattr() what was done for getattr()
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18888
diff
changeset
|
655 return NULL; |
|
fb837c5ae5d3
Do for hasattr() what was done for getattr()
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18888
diff
changeset
|
656 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19301
diff
changeset
|
657 #endif |
|
18890
fb837c5ae5d3
Do for hasattr() what was done for getattr()
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18888
diff
changeset
|
658 |
|
fb837c5ae5d3
Do for hasattr() what was done for getattr()
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18888
diff
changeset
|
659 if (!PyString_Check(name)) { |
|
fb837c5ae5d3
Do for hasattr() what was done for getattr()
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18888
diff
changeset
|
660 PyErr_SetString(PyExc_TypeError, |
|
fb837c5ae5d3
Do for hasattr() what was done for getattr()
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18888
diff
changeset
|
661 "attribute name must be string"); |
|
fb837c5ae5d3
Do for hasattr() what was done for getattr()
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18888
diff
changeset
|
662 return NULL; |
|
fb837c5ae5d3
Do for hasattr() what was done for getattr()
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18888
diff
changeset
|
663 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
664 v = PyObject_GetAttr(v, name); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
665 if (v == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
666 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
|
667 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
|
668 return Py_False; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
669 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
670 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
|
671 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
|
672 return Py_True; |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
673 } |
|
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
674 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
675 PyDoc_STRVAR(hasattr_doc, |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22205
diff
changeset
|
676 "hasattr(object, name) -> bool\n\ |
| 8561 | 677 \n\ |
| 678 Return whether the object has an attribute with the given name.\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
679 (This is done by calling getattr(object, name) and catching exceptions.)"); |
| 8561 | 680 |
| 681 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
682 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
683 builtin_id(PyObject *self, PyObject *v) |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
684 { |
| 13078 | 685 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
|
686 } |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
687 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
688 PyDoc_STRVAR(id_doc, |
| 8561 | 689 "id(object) -> integer\n\ |
| 690 \n\ | |
| 691 Return the identity of an object. This is guaranteed to be unique among\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
692 simultaneously existing objects. (Hint: it's the object's memory address.)"); |
| 8561 | 693 |
| 694 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
695 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
696 builtin_map(PyObject *self, PyObject *args) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
697 { |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
698 typedef struct { |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
699 PyObject *it; /* the iterator object */ |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
700 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
|
701 } sequence; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
702 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
703 PyObject *func, *result; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
704 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
|
705 int n, len; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
706 register int i, j; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
707 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
708 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
|
709 if (n < 2) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
710 PyErr_SetString(PyExc_TypeError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
711 "map() requires at least two args"); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
712 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
713 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
714 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
715 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
|
716 n--; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
717 |
|
8661
30fbf18af29e
Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents:
8589
diff
changeset
|
718 if (func == Py_None && n == 1) { |
|
30fbf18af29e
Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents:
8589
diff
changeset
|
719 /* 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
|
720 return PySequence_List(PyTuple_GetItem(args, 1)); |
|
30fbf18af29e
Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents:
8589
diff
changeset
|
721 } |
|
30fbf18af29e
Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents:
8589
diff
changeset
|
722 |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
723 /* 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
|
724 * 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
|
725 */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
726 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
|
727 PyErr_NoMemory(); |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
728 return NULL; |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
729 } |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
730 for (i = 0; i < n; ++i) { |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
731 seqs[i].it = (PyObject*)NULL; |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
732 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
|
733 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
734 |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
735 /* 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
|
736 * 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
|
737 */ |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
738 len = 0; |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
739 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
|
740 PyObject *curseq; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
741 int curlen; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
742 |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
743 /* Get iterator. */ |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
744 curseq = PyTuple_GetItem(args, i+1); |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
745 sqp->it = PyObject_GetIter(curseq); |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
746 if (sqp->it == NULL) { |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
747 static char errmsg[] = |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
748 "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
|
749 char errbuf[sizeof(errmsg) + 25]; |
|
21077
379fc66f4c96
Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20871
diff
changeset
|
750 PyOS_snprintf(errbuf, sizeof(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
|
751 PyErr_SetString(PyExc_TypeError, errbuf); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
752 goto Fail_2; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
753 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
754 |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
755 /* Update len. */ |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
756 curlen = -1; /* unknown */ |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
757 if (PySequence_Check(curseq) && |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
758 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
|
759 curlen = PySequence_Size(curseq); |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
760 if (curlen < 0) |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
761 PyErr_Clear(); |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
762 } |
|
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
|
763 if (curlen < 0) |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
764 curlen = 8; /* arbitrary */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18890
diff
changeset
|
765 if (curlen > len) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18890
diff
changeset
|
766 len = curlen; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
767 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
768 |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
769 /* 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
|
770 if ((result = (PyObject *) PyList_New(len)) == NULL) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
771 goto Fail_2; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
772 |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
773 /* 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
|
774 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
|
775 PyObject *alist, *item=NULL, *value; |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
776 int numactive = 0; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
777 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
778 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
|
779 alist = NULL; |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
780 else if ((alist = PyTuple_New(n)) == NULL) |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
781 goto Fail_1; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
782 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
783 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
|
784 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
|
785 Py_INCREF(Py_None); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
786 item = Py_None; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
787 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
788 else { |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
789 item = PyIter_Next(sqp->it); |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
790 if (item) |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
791 ++numactive; |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
792 else { |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
793 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
|
794 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
|
795 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
|
796 } |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
797 Py_INCREF(Py_None); |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
798 item = Py_None; |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
799 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
|
800 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
801 } |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
802 if (alist) |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
803 PyTuple_SET_ITEM(alist, j, item); |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
804 else |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
805 break; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
806 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
807 |
|
2824
65c7105868f8
rename arglist to alist (conflict with new grammar symbol)
Guido van Rossum <guido@python.org>
parents:
2808
diff
changeset
|
808 if (!alist) |
|
65c7105868f8
rename arglist to alist (conflict with new grammar symbol)
Guido van Rossum <guido@python.org>
parents:
2808
diff
changeset
|
809 alist = item; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
810 |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
811 if (numactive == 0) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
812 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
|
813 break; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
814 } |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
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 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
|
817 value = alist; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
818 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
819 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
|
820 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
|
821 if (value == NULL) |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
822 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
|
823 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
824 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
|
825 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
|
826 Py_DECREF(value); |
|
ddbbed8cb830
builtin_map(): A better fix for the previous leak plug (remember
Barry Warsaw <barry@python.org>
parents:
9980
diff
changeset
|
827 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
|
828 goto Fail_1; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
829 } |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
830 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
|
831 goto Fail_1; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
832 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
833 |
|
8661
30fbf18af29e
Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents:
8589
diff
changeset
|
834 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
|
835 goto Fail_1; |
|
30fbf18af29e
Small changes to map() and filter():
Guido van Rossum <guido@python.org>
parents:
8589
diff
changeset
|
836 |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
837 goto Succeed; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
838 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
839 Fail_1: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
840 Py_DECREF(result); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
841 Fail_2: |
|
17675
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
842 result = NULL; |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
843 Succeed: |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
844 assert(seqs); |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
845 for (i = 0; i < n; ++i) |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
846 Py_XDECREF(seqs[i].it); |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
847 PyMem_DEL(seqs); |
|
0be277039d93
Generalize map() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17667
diff
changeset
|
848 return result; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
849 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
850 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
851 PyDoc_STRVAR(map_doc, |
| 8561 | 852 "map(function, sequence[, sequence, ...]) -> list\n\ |
| 853 \n\ | |
| 854 Return a list of the results of applying the function to the items of\n\ | |
| 855 the argument sequence(s). If more than one sequence is given, the\n\ | |
| 856 function is called with an argument list consisting of the corresponding\n\ | |
| 857 item of each sequence, substituting None for missing values when not all\n\ | |
| 858 sequences have the same length. If the function is None, return a list of\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
859 the items of the sequence (or a list of tuples if more than one sequence)."); |
| 8561 | 860 |
| 861 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
862 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
863 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
|
864 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
865 PyObject *v; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
866 PyObject *name; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
867 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
|
868 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
869 if (!PyArg_UnpackTuple(args, "setattr", 3, 3, &v, &name, &value)) |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
870 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
871 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
|
872 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
873 Py_INCREF(Py_None); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
874 return Py_None; |
|
644
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
875 } |
|
59f9325bb8ec
Added getattr and setattr built-in functions.
Guido van Rossum <guido@python.org>
parents:
606
diff
changeset
|
876 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
877 PyDoc_STRVAR(setattr_doc, |
| 8561 | 878 "setattr(object, name, value)\n\ |
| 879 \n\ | |
| 880 Set a named attribute on an object; setattr(x, 'y', v) is equivalent to\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
881 ``x.y = v''."); |
| 8561 | 882 |
| 883 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
884 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
885 builtin_delattr(PyObject *self, PyObject *args) |
| 1843 | 886 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
887 PyObject *v; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
888 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
|
889 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
890 if (!PyArg_UnpackTuple(args, "delattr", 2, 2, &v, &name)) |
| 1843 | 891 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
892 if (PyObject_SetAttr(v, name, (PyObject *)NULL) != 0) |
| 1843 | 893 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
894 Py_INCREF(Py_None); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
895 return Py_None; |
| 1843 | 896 } |
| 897 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
898 PyDoc_STRVAR(delattr_doc, |
|
9514
a126107c433a
Fix cosmetic bug in delattr docstring discovered by JvR.
Guido van Rossum <guido@python.org>
parents:
9188
diff
changeset
|
899 "delattr(object, name)\n\ |
| 8561 | 900 \n\ |
| 901 Delete a named attribute on an object; delattr(x, 'y') is equivalent to\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
902 ``del x.y''."); |
| 8561 | 903 |
| 904 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
905 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
906 builtin_hash(PyObject *self, PyObject *v) |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
907 { |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
908 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
|
909 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
910 x = PyObject_Hash(v); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
911 if (x == -1) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
912 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
913 return PyInt_FromLong(x); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
914 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
915 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
916 PyDoc_STRVAR(hash_doc, |
| 8561 | 917 "hash(object) -> integer\n\ |
| 918 \n\ | |
| 919 Return a hash value for the object. Two objects with the same value have\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
920 the same hash value. The reverse is not necessarily true, but likely."); |
| 8561 | 921 |
| 922 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
923 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
924 builtin_hex(PyObject *self, PyObject *v) |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
925 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
926 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
|
927 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
928 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
|
929 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
|
930 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
|
931 "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
|
932 return NULL; |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
933 } |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
934 return (*nb->nb_hex)(v); |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
935 } |
|
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
936 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
937 PyDoc_STRVAR(hex_doc, |
| 8561 | 938 "hex(number) -> string\n\ |
| 939 \n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
940 Return the hexadecimal representation of an integer or long integer."); |
| 8561 | 941 |
| 942 | |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13446
diff
changeset
|
943 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
|
944 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
945 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
946 builtin_input(PyObject *self, PyObject *args) |
| 86 | 947 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
948 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
|
949 char *str; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
950 PyObject *res; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
951 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
|
952 |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
953 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
|
954 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
|
955 return line; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
956 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
|
957 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
958 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
|
959 str++; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
960 globals = PyEval_GetGlobals(); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
961 locals = PyEval_GetLocals(); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
962 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
|
963 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
|
964 PyEval_GetBuiltins()) != 0) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
965 return NULL; |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2087
diff
changeset
|
966 } |
|
5438
e926c331ebbf
Instead of importing graminit.h whenever one of the three grammar 'root'
Guido van Rossum <guido@python.org>
parents:
5421
diff
changeset
|
967 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
|
968 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
|
969 return res; |
| 86 | 970 } |
| 971 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
972 PyDoc_STRVAR(input_doc, |
| 8561 | 973 "input([prompt]) -> value\n\ |
| 974 \n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
975 Equivalent to eval(raw_input(prompt))."); |
| 8561 | 976 |
| 977 | |
|
5092
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
978 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
979 builtin_intern(PyObject *self, PyObject *args) |
|
5092
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
980 { |
|
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
981 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
|
982 if (!PyArg_ParseTuple(args, "S:intern", &s)) |
|
5092
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
983 return NULL; |
|
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
984 Py_INCREF(s); |
|
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
985 PyString_InternInPlace(&s); |
|
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
986 return s; |
|
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
987 } |
|
cb7aadd9d9f2
Added intern() function.
Guido van Rossum <guido@python.org>
parents:
5010
diff
changeset
|
988 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
989 PyDoc_STRVAR(intern_doc, |
| 8561 | 990 "intern(string) -> string\n\ |
| 991 \n\ | |
| 992 ``Intern'' the given string. This enters the string in the (global)\n\ | |
| 993 table of interned strings whose purpose is to speed up dictionary lookups.\n\ | |
| 994 Return the string itself or the previously interned string object with the\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
995 same value."); |
| 8561 | 996 |
| 997 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
998 static PyObject * |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
999 builtin_iter(PyObject *self, PyObject *args) |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1000 { |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1001 PyObject *v, *w = NULL; |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1002 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
1003 if (!PyArg_UnpackTuple(args, "iter", 1, 2, &v, &w)) |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1004 return NULL; |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1005 if (w == NULL) |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1006 return PyObject_GetIter(v); |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1007 if (!PyCallable_Check(v)) { |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1008 PyErr_SetString(PyExc_TypeError, |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1009 "iter(v, w): v must be callable"); |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1010 return NULL; |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1011 } |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1012 return PyCallIter_New(v, w); |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1013 } |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1014 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1015 PyDoc_STRVAR(iter_doc, |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1016 "iter(collection) -> iterator\n\ |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1017 iter(callable, sentinel) -> iterator\n\ |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1018 \n\ |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1019 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
|
1020 supply its own iterator, or be a sequence.\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1021 In the second form, the callable is called until it returns the sentinel."); |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1022 |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1023 |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
17337
diff
changeset
|
1024 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1025 builtin_len(PyObject *self, 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
|
1026 { |
|
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
|
1027 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
|
1028 |
|
13576
61e4c29d53d8
replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13447
diff
changeset
|
1029 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
|
1030 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
|
1031 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
|
1032 return PyInt_FromLong(res); |
| 86 | 1033 } |
| 1034 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1035 PyDoc_STRVAR(len_doc, |
| 8561 | 1036 "len(object) -> integer\n\ |
| 1037 \n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1038 Return the number of items of a sequence or mapping."); |
| 8561 | 1039 |
| 1040 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1041 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1042 builtin_locals(PyObject *self) |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1043 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1044 PyObject *d; |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1045 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1046 d = PyEval_GetLocals(); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1047 Py_INCREF(d); |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1048 return d; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1049 } |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1050 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1051 PyDoc_STRVAR(locals_doc, |
| 8561 | 1052 "locals() -> dictionary\n\ |
| 1053 \n\ | |
|
27076
753306f9b0a0
SF bug #655271: Slightly modify locals() doc
Raymond Hettinger <python@rcn.com>
parents:
26824
diff
changeset
|
1054 Update and return a dictionary containing the current scope's local variables."); |
| 8561 | 1055 |
| 1056 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1057 static PyObject * |
|
15949
76ad2a9a3e53
Use rich comparisons in min and max.
Guido van Rossum <guido@python.org>
parents:
15832
diff
changeset
|
1058 min_max(PyObject *args, int op) |
| 86 | 1059 { |
|
17667
76ee8b62ee2a
Generalize max(seq) and min(seq) to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17654
diff
changeset
|
1060 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
|
1061 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1062 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
|
1063 v = args; |
|
26824
fb36d9b50df5
Make error message more specific for min() and max().
Raymond Hettinger <python@rcn.com>
parents:
26818
diff
changeset
|
1064 else if (!PyArg_UnpackTuple(args, (op==Py_LT) ? "min" : "max", 1, 1, &v)) |
| 86 | 1065 return NULL; |
|
23305
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1066 |
|
17667
76ee8b62ee2a
Generalize max(seq) and min(seq) to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17654
diff
changeset
|
1067 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
|
1068 if (it == NULL) |
| 86 | 1069 return NULL; |
|
17667
76ee8b62ee2a
Generalize max(seq) and min(seq) to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17654
diff
changeset
|
1070 |
|
76ee8b62ee2a
Generalize max(seq) and min(seq) to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17654
diff
changeset
|
1071 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
|
1072 for (;;) { |
|
17667
76ee8b62ee2a
Generalize max(seq) and min(seq) to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17654
diff
changeset
|
1073 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
|
1074 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
|
1075 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
|
1076 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
|
1077 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
|
1078 return NULL; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1079 } |
|
17667
76ee8b62ee2a
Generalize max(seq) and min(seq) to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17654
diff
changeset
|
1080 break; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1081 } |
|
17667
76ee8b62ee2a
Generalize max(seq) and min(seq) to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17654
diff
changeset
|
1082 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1083 if (w == NULL) |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1084 w = x; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1085 else { |
|
15949
76ad2a9a3e53
Use rich comparisons in min and max.
Guido van Rossum <guido@python.org>
parents:
15832
diff
changeset
|
1086 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
|
1087 if (cmp > 0) { |
|
76ad2a9a3e53
Use rich comparisons in min and max.
Guido van Rossum <guido@python.org>
parents:
15832
diff
changeset
|
1088 Py_DECREF(w); |
|
76ad2a9a3e53
Use rich comparisons in min and max.
Guido van Rossum <guido@python.org>
parents:
15832
diff
changeset
|
1089 w = x; |
|
76ad2a9a3e53
Use rich comparisons in min and max.
Guido van Rossum <guido@python.org>
parents:
15832
diff
changeset
|
1090 } |
|
76ad2a9a3e53
Use rich comparisons in min and max.
Guido van Rossum <guido@python.org>
parents:
15832
diff
changeset
|
1091 else if (cmp < 0) { |
|
5610
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5471
diff
changeset
|
1092 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
|
1093 Py_DECREF(w); |
|
76ee8b62ee2a
Generalize max(seq) and min(seq) to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17654
diff
changeset
|
1094 Py_DECREF(it); |
|
5610
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5471
diff
changeset
|
1095 return NULL; |
|
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5471
diff
changeset
|
1096 } |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1097 else |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1098 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
|
1099 } |
| 86 | 1100 } |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1101 if (w == NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1102 PyErr_SetString(PyExc_ValueError, |
| 15318 | 1103 "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
|
1104 Py_DECREF(it); |
| 86 | 1105 return w; |
| 1106 } | |
| 1107 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1108 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1109 builtin_min(PyObject *self, PyObject *v) |
| 86 | 1110 { |
|
15949
76ad2a9a3e53
Use rich comparisons in min and max.
Guido van Rossum <guido@python.org>
parents:
15832
diff
changeset
|
1111 return min_max(v, Py_LT); |
| 86 | 1112 } |
| 1113 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1114 PyDoc_STRVAR(min_doc, |
| 8561 | 1115 "min(sequence) -> value\n\ |
| 1116 min(a, b, c, ...) -> value\n\ | |
| 1117 \n\ | |
| 1118 With a single sequence argument, return its smallest item.\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1119 With two or more arguments, return the smallest argument."); |
| 8561 | 1120 |
| 1121 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1122 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1123 builtin_max(PyObject *self, PyObject *v) |
| 86 | 1124 { |
|
15949
76ad2a9a3e53
Use rich comparisons in min and max.
Guido van Rossum <guido@python.org>
parents:
15832
diff
changeset
|
1125 return min_max(v, Py_GT); |
| 86 | 1126 } |
| 1127 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1128 PyDoc_STRVAR(max_doc, |
| 8561 | 1129 "max(sequence) -> value\n\ |
| 1130 max(a, b, c, ...) -> value\n\ | |
| 1131 \n\ | |
| 1132 With a single sequence argument, return its largest item.\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1133 With two or more arguments, return the largest argument."); |
| 8561 | 1134 |
| 1135 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1136 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1137 builtin_oct(PyObject *self, 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
|
1138 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1139 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
|
1140 |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
1141 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
|
1142 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
|
1143 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
|
1144 "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
|
1145 return NULL; |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
1146 } |
|
1049
2ed511171809
Made builtins int(), long(), float(), oct() and hex() more generic.
Guido van Rossum <guido@python.org>
parents:
972
diff
changeset
|
1147 return (*nb->nb_oct)(v); |
|
404
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
1148 } |
|
9cd38d1ac391
Made dir() more robust.
Guido van Rossum <guido@python.org>
parents:
385
diff
changeset
|
1149 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1150 PyDoc_STRVAR(oct_doc, |
| 8561 | 1151 "oct(number) -> string\n\ |
| 1152 \n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1153 Return the octal representation of an integer or long integer."); |
| 8561 | 1154 |
| 1155 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1156 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1157 builtin_ord(PyObject *self, PyObject* obj) |
| 86 | 1158 { |
|
11973
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1159 long ord; |
|
12384
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1160 int size; |
|
11973
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1161 |
|
12384
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1162 if (PyString_Check(obj)) { |
|
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1163 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
|
1164 if (size == 1) { |
|
12384
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1165 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
|
1166 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
|
1167 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19301
diff
changeset
|
1168 #ifdef Py_USING_UNICODE |
|
12384
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1169 } else if (PyUnicode_Check(obj)) { |
|
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1170 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
|
1171 if (size == 1) { |
|
12384
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1172 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
|
1173 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
|
1174 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19301
diff
changeset
|
1175 #endif |
|
12384
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1176 } else { |
|
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1177 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
|
1178 "ord() expected string of length 1, but " \ |
|
12384
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1179 "%.200s found", obj->ob_type->tp_name); |
| 86 | 1180 return NULL; |
|
11973
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1181 } |
|
8bdc25d22925
Marc-Andre Lemburg: added new builtin functions unicode() and
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1182 |
|
15829
9308dc8c85e0
(Modified) patch by Ping - SF Patch #102681.
Guido van Rossum <guido@python.org>
parents:
15727
diff
changeset
|
1183 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
|
1184 "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
|
1185 "but string of length %d found", |
|
12384
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1186 size); |
|
aa013f2cf80b
ord: provide better error messages
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12368
diff
changeset
|
1187 return NULL; |
| 86 | 1188 } |
| 1189 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1190 PyDoc_STRVAR(ord_doc, |
| 8561 | 1191 "ord(c) -> integer\n\ |
| 1192 \n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1193 Return the integer ordinal of a one-character string."); |
| 8561 | 1194 |
| 1195 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1196 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1197 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
|
1198 { |
|
8402
0cb0394c2edc
A bunch of functions are now properly implemented in abstract.c, and
Guido van Rossum <guido@python.org>
parents:
8287
diff
changeset
|
1199 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
|
1200 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
1201 if (!PyArg_UnpackTuple(args, "pow", 2, 3, &v, &w, &z)) |
|
2087
65146b52f16b
* Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
1202 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
|
1203 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
|
1204 } |
|
6693c5d87f3a
Added long() and support for longs in int() and float();
Guido van Rossum <guido@python.org>
parents:
182
diff
changeset
|
1205 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1206 PyDoc_STRVAR(pow_doc, |
| 8561 | 1207 "pow(x, y[, z]) -> number\n\ |
| 1208 \n\ | |
| 1209 With two arguments, equivalent to x**y. With three arguments,\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1210 equivalent to (x**y) % z, but may be more efficient (e.g. for longs)."); |
| 8561 | 1211 |
| 1212 | |
|
10279
886ea255f381
Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents:
10020
diff
changeset
|
1213 /* 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
|
1214 * 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
|
1215 * 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
|
1216 */ |
|
886ea255f381
Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents:
10020
diff
changeset
|
1217 static long |
|
13679
61f65de19e1e
Another missed ansification.
Thomas Wouters <thomas@python.org>
parents:
13658
diff
changeset
|
1218 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
|
1219 { |
|
886ea255f381
Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents:
10020
diff
changeset
|
1220 /* ------------------------------------------------------------- |
|
886ea255f381
Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents:
10020
diff
changeset
|
1221 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
|
1222 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
|
1223 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
|
1224 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
|
1225 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
|
1226 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
|
1227 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
|
1228 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
|
1229 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
|
1230 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
|
1231 ---------------------------------------------------------------*/ |
|
886ea255f381
Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents:
10020
diff
changeset
|
1232 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
|
1233 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
|
1234 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
|
1235 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
|
1236 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
|
1237 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
|
1238 } |
|
886ea255f381
Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents:
10020
diff
changeset
|
1239 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
|
1240 } |
|
886ea255f381
Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents:
10020
diff
changeset
|
1241 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1242 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1243 builtin_range(PyObject *self, PyObject *args) |
| 86 | 1244 { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1245 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
|
1246 long bign; |
| 86 | 1247 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
|
1248 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1249 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
|
1250 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1251 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
|
1252 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
|
1253 "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
|
1254 &ihigh)) |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1255 return NULL; |
| 86 | 1256 } |
| 1257 else { | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1258 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
|
1259 "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
|
1260 &ilow, &ihigh, &istep)) |
| 86 | 1261 return NULL; |
| 1262 } | |
| 1263 if (istep == 0) { | |
| 15318 | 1264 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
|
1265 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1266 } |
|
10279
886ea255f381
Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents:
10020
diff
changeset
|
1267 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
|
1268 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
|
1269 else |
|
886ea255f381
Patch by Tim Peters to improve the range checks for range() and
Guido van Rossum <guido@python.org>
parents:
10020
diff
changeset
|
1270 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
|
1271 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
|
1272 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
|
1273 PyErr_SetString(PyExc_OverflowError, |
| 15318 | 1274 "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
|
1275 return NULL; |
|
5e9ef9d8575b
Avoid overflow if possible in calculations for range(); report
Guido van Rossum <guido@python.org>
parents:
9567
diff
changeset
|
1276 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1277 v = PyList_New(n); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1278 if (v == NULL) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1279 return NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1280 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
|
1281 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
|
1282 if (w == NULL) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1283 Py_DECREF(v); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1284 return NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1285 } |
|
8138
9d0310143600
Fred's right -- we need PyList_SET_ITEM().
Guido van Rossum <guido@python.org>
parents:
8132
diff
changeset
|
1286 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
|
1287 ilow += istep; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1288 } |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1289 return v; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1290 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1291 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1292 PyDoc_STRVAR(range_doc, |
| 8561 | 1293 "range([start,] stop[, step]) -> list of integers\n\ |
| 1294 \n\ | |
| 1295 Return a list containing an arithmetic progression of integers.\n\ | |
| 1296 range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.\n\ | |
| 1297 When step is given, it specifies the increment (or decrement).\n\ | |
| 1298 For example, range(4) returns [0, 1, 2, 3]. The end point is omitted!\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1299 These are exactly the valid indices for a list of 4 elements."); |
| 8561 | 1300 |
| 1301 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1302 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1303 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
|
1304 { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1305 PyObject *v = NULL; |
|
24817
3ae8e3ff7e3f
Patch #550192: Set softspace to 0 in raw_input().
Martin v. Löwis <martin@v.loewis.de>
parents:
24737
diff
changeset
|
1306 PyObject *fin = PySys_GetObject("stdin"); |
|
3ae8e3ff7e3f
Patch #550192: Set softspace to 0 in raw_input().
Martin v. Löwis <martin@v.loewis.de>
parents:
24737
diff
changeset
|
1307 PyObject *fout = PySys_GetObject("stdout"); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1308 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
1309 if (!PyArg_UnpackTuple(args, "[raw_]input", 0, 1, &v)) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1310 return NULL; |
|
24817
3ae8e3ff7e3f
Patch #550192: Set softspace to 0 in raw_input().
Martin v. Löwis <martin@v.loewis.de>
parents:
24737
diff
changeset
|
1311 |
|
3ae8e3ff7e3f
Patch #550192: Set softspace to 0 in raw_input().
Martin v. Löwis <martin@v.loewis.de>
parents:
24737
diff
changeset
|
1312 if (fin == NULL) { |
|
3ae8e3ff7e3f
Patch #550192: Set softspace to 0 in raw_input().
Martin v. Löwis <martin@v.loewis.de>
parents:
24737
diff
changeset
|
1313 PyErr_SetString(PyExc_RuntimeError, "lost sys.stdin"); |
|
3ae8e3ff7e3f
Patch #550192: Set softspace to 0 in raw_input().
Martin v. Löwis <martin@v.loewis.de>
parents:
24737
diff
changeset
|
1314 return NULL; |
|
3ae8e3ff7e3f
Patch #550192: Set softspace to 0 in raw_input().
Martin v. Löwis <martin@v.loewis.de>
parents:
24737
diff
changeset
|
1315 } |
|
3ae8e3ff7e3f
Patch #550192: Set softspace to 0 in raw_input().
Martin v. Löwis <martin@v.loewis.de>
parents:
24737
diff
changeset
|
1316 if (fout == NULL) { |
|
3ae8e3ff7e3f
Patch #550192: Set softspace to 0 in raw_input().
Martin v. Löwis <martin@v.loewis.de>
parents:
24737
diff
changeset
|
1317 PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout"); |
|
3ae8e3ff7e3f
Patch #550192: Set softspace to 0 in raw_input().
Martin v. Löwis <martin@v.loewis.de>
parents:
24737
diff
changeset
|
1318 return NULL; |
|
3ae8e3ff7e3f
Patch #550192: Set softspace to 0 in raw_input().
Martin v. Löwis <martin@v.loewis.de>
parents:
24737
diff
changeset
|
1319 } |
|
3ae8e3ff7e3f
Patch #550192: Set softspace to 0 in raw_input().
Martin v. Löwis <martin@v.loewis.de>
parents:
24737
diff
changeset
|
1320 if (PyFile_SoftSpace(fout, 0)) { |
|
3ae8e3ff7e3f
Patch #550192: Set softspace to 0 in raw_input().
Martin v. Löwis <martin@v.loewis.de>
parents:
24737
diff
changeset
|
1321 if (PyFile_WriteString(" ", fout) != 0) |
|
3ae8e3ff7e3f
Patch #550192: Set softspace to 0 in raw_input().
Martin v. Löwis <martin@v.loewis.de>
parents:
24737
diff
changeset
|
1322 return NULL; |
|
3ae8e3ff7e3f
Patch #550192: Set softspace to 0 in raw_input().
Martin v. Löwis <martin@v.loewis.de>
parents:
24737
diff
changeset
|
1323 } |
|
25924
dc4a0336a2a3
Patch #512981: Update readline input stream on sys.stdin/out change.
Martin v. Löwis <martin@v.loewis.de>
parents:
25046
diff
changeset
|
1324 if (PyFile_Check (fin) && PyFile_Check (fout) |
|
dc4a0336a2a3
Patch #512981: Update readline input stream on sys.stdin/out change.
Martin v. Löwis <martin@v.loewis.de>
parents:
25046
diff
changeset
|
1325 && isatty(fileno(PyFile_AsFile(fin))) |
|
dc4a0336a2a3
Patch #512981: Update readline input stream on sys.stdin/out change.
Martin v. Löwis <martin@v.loewis.de>
parents:
25046
diff
changeset
|
1326 && isatty(fileno(PyFile_AsFile(fout)))) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1327 PyObject *po; |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1328 char *prompt; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1329 char *s; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1330 PyObject *result; |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1331 if (v != NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1332 po = PyObject_Str(v); |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1333 if (po == NULL) |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1334 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1335 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
|
1336 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
|
1337 return NULL; |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1338 } |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1339 else { |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1340 po = NULL; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1341 prompt = ""; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1342 } |
|
25924
dc4a0336a2a3
Patch #512981: Update readline input stream on sys.stdin/out change.
Martin v. Löwis <martin@v.loewis.de>
parents:
25046
diff
changeset
|
1343 s = PyOS_Readline(PyFile_AsFile (fin), PyFile_AsFile (fout), |
|
dc4a0336a2a3
Patch #512981: Update readline input stream on sys.stdin/out change.
Martin v. Löwis <martin@v.loewis.de>
parents:
25046
diff
changeset
|
1344 prompt); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1345 Py_XDECREF(po); |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1346 if (s == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1347 PyErr_SetNone(PyExc_KeyboardInterrupt); |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1348 return NULL; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1349 } |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1350 if (*s == '\0') { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1351 PyErr_SetNone(PyExc_EOFError); |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1352 result = NULL; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1353 } |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1354 else { /* strip trailing '\n' */ |
| 13078 | 1355 size_t len = strlen(s); |
| 1356 if (len > INT_MAX) { | |
|
24817
3ae8e3ff7e3f
Patch #550192: Set softspace to 0 in raw_input().
Martin v. Löwis <martin@v.loewis.de>
parents:
24737
diff
changeset
|
1357 PyErr_SetString(PyExc_OverflowError, |
|
3ae8e3ff7e3f
Patch #550192: Set softspace to 0 in raw_input().
Martin v. Löwis <martin@v.loewis.de>
parents:
24737
diff
changeset
|
1358 "input too long"); |
| 13078 | 1359 result = NULL; |
| 1360 } | |
| 1361 else { | |
|
24817
3ae8e3ff7e3f
Patch #550192: Set softspace to 0 in raw_input().
Martin v. Löwis <martin@v.loewis.de>
parents:
24737
diff
changeset
|
1362 result = PyString_FromStringAndSize(s, |
|
3ae8e3ff7e3f
Patch #550192: Set softspace to 0 in raw_input().
Martin v. Löwis <martin@v.loewis.de>
parents:
24737
diff
changeset
|
1363 (int)(len-1)); |
| 13078 | 1364 } |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1365 } |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12572
diff
changeset
|
1366 PyMem_FREE(s); |
|
2808
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1367 return result; |
|
9318ac51691e
added locals() and globals(); [raw_]input() uses readline()
Guido van Rossum <guido@python.org>
parents:
2375
diff
changeset
|
1368 } |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
1369 if (v != NULL) { |
|
24817
3ae8e3ff7e3f
Patch #550192: Set softspace to 0 in raw_input().
Martin v. Löwis <martin@v.loewis.de>
parents:
24737
diff
changeset
|
1370 if (PyFile_WriteObject(v, fout, Py_PRINT_RAW) != 0) |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
1371 return NULL; |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
253
diff
changeset
|
1372 } |
|
24817
3ae8e3ff7e3f
Patch #550192: Set softspace to 0 in raw_input().
Martin v. Löwis <martin@v.loewis.de>
parents:
24737
diff
changeset
|
1373 return PyFile_GetLine(fin, -1); |
| 86 | 1374 } |
| 1375 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1376 PyDoc_STRVAR(raw_input_doc, |
| 8561 | 1377 "raw_input([prompt]) -> string\n\ |
| 1378 \n\ | |
| 1379 Read a string from standard input. The trailing newline is stripped.\n\ | |
| 1380 If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.\n\ | |
| 1381 On Unix, GNU readline is used if enabled. The prompt string, if given,\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1382 is printed without a trailing newline before reading."); |
| 8561 | 1383 |
| 1384 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
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_reduce(PyObject *self, PyObject *args) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1387 { |
|
17677
bf7f166d3c97
Generalize reduce() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17675
diff
changeset
|
1388 PyObject *seq, *func, *result = NULL, *it; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1389 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
1390 if (!PyArg_UnpackTuple(args, "reduce", 2, 3, &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
|
1391 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1392 if (result != NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1393 Py_INCREF(result); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1394 |
|
17677
bf7f166d3c97
Generalize reduce() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17675
diff
changeset
|
1395 it = PyObject_GetIter(seq); |
|
bf7f166d3c97
Generalize reduce() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17675
diff
changeset
|
1396 if (it == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1397 PyErr_SetString(PyExc_TypeError, |
|
17677
bf7f166d3c97
Generalize reduce() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17675
diff
changeset
|
1398 "reduce() arg 2 must support iteration"); |
|
bf7f166d3c97
Generalize reduce() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17675
diff
changeset
|
1399 Py_XDECREF(result); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1400 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1401 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1402 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1403 if ((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
|
1404 goto Fail; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1405 |
|
17677
bf7f166d3c97
Generalize reduce() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17675
diff
changeset
|
1406 for (;;) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1407 PyObject *op2; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1408 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1409 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
|
1410 Py_DECREF(args); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1411 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
|
1412 goto Fail; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1413 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1414 |
|
17677
bf7f166d3c97
Generalize reduce() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17675
diff
changeset
|
1415 op2 = PyIter_Next(it); |
|
bf7f166d3c97
Generalize reduce() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17675
diff
changeset
|
1416 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
|
1417 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
|
1418 goto Fail; |
|
e9a4e27e8d4e
Make PyIter_Next() a little smarter (wrt its knowledge of iterator
Tim Peters <tim.peters@gmail.com>
parents:
17677
diff
changeset
|
1419 break; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1420 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1421 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1422 if (result == NULL) |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1423 result = op2; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1424 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1425 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
|
1426 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
|
1427 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
|
1428 goto Fail; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1429 } |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1430 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1431 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1432 Py_DECREF(args); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1433 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1434 if (result == NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1435 PyErr_SetString(PyExc_TypeError, |
| 15318 | 1436 "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
|
1437 |
|
17677
bf7f166d3c97
Generalize reduce() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17675
diff
changeset
|
1438 Py_DECREF(it); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1439 return result; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1440 |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1441 Fail: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1442 Py_XDECREF(args); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1443 Py_XDECREF(result); |
|
17677
bf7f166d3c97
Generalize reduce() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17675
diff
changeset
|
1444 Py_DECREF(it); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1445 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1446 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1447 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1448 PyDoc_STRVAR(reduce_doc, |
| 8561 | 1449 "reduce(function, sequence[, initial]) -> value\n\ |
| 1450 \n\ | |
| 1451 Apply a function of two arguments cumulatively to the items of a sequence,\n\ | |
| 1452 from left to right, so as to reduce the sequence to a single value.\n\ | |
| 1453 For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates\n\ | |
| 1454 ((((1+2)+3)+4)+5). If initial is present, it is placed before the items\n\ | |
| 1455 of the sequence in the calculation, and serves as a default when the\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1456 sequence is empty."); |
| 8561 | 1457 |
| 1458 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1459 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1460 builtin_reload(PyObject *self, 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
|
1461 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1462 return PyImport_ReloadModule(v); |
| 86 | 1463 } |
| 1464 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1465 PyDoc_STRVAR(reload_doc, |
| 8561 | 1466 "reload(module) -> module\n\ |
| 1467 \n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1468 Reload the module. The module must have been successfully imported before."); |
| 8561 | 1469 |
| 1470 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1471 static PyObject * |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1472 builtin_repr(PyObject *self, PyObject *v) |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1473 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1474 return PyObject_Repr(v); |
|
1094
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1475 } |
|
d2af6bdcb6d0
* config.c: Added audioop to lists.
Guido van Rossum <guido@python.org>
parents:
1079
diff
changeset
|
1476 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1477 PyDoc_STRVAR(repr_doc, |
| 8561 | 1478 "repr(object) -> string\n\ |
| 1479 \n\ | |
| 1480 Return the canonical string representation of the object.\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1481 For most object types, eval(repr(object)) == object."); |
| 8561 | 1482 |
| 1483 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1484 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1485 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
|
1486 { |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1487 double x; |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1488 double f; |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1489 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
|
1490 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
|
1491 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1492 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
|
1493 return NULL; |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1494 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
|
1495 i = abs(ndigits); |
|
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1496 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
|
1497 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
|
1498 if (ndigits < 0) |
|
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1499 x /= f; |
|
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1500 else |
|
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1501 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
|
1502 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
|
1503 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
|
1504 else |
|
8287
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1505 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
|
1506 if (ndigits < 0) |
|
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1507 x *= f; |
|
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1508 else |
|
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1509 x /= f; |
|
d3bf3c2ad75a
Implement round() slightly different, so that for negative ndigits no
Guido van Rossum <guido@python.org>
parents:
8138
diff
changeset
|
1510 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
|
1511 } |
|
9d6cf529bb71
bltinmodule.c: added round(x, [n]); coerce() of two class instances
Guido van Rossum <guido@python.org>
parents:
1096
diff
changeset
|
1512 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1513 PyDoc_STRVAR(round_doc, |
| 8561 | 1514 "round(number[, ndigits]) -> floating point number\n\ |
| 1515 \n\ | |
| 1516 Round a number to a given precision in decimal digits (default 0 digits).\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1517 This always returns a floating point number. Precision may be negative."); |
| 8561 | 1518 |
| 1519 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1520 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1521 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
|
1522 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1523 PyObject *v = NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1524 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
|
1525 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
1526 if (!PyArg_UnpackTuple(args, "vars", 0, 1, &v)) |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2002
diff
changeset
|
1527 return NULL; |
|
1840
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1528 if (v == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1529 d = PyEval_GetLocals(); |
|
2857
eebbdbee54f9
be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
1530 if (d == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1531 if (!PyErr_Occurred()) |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1532 PyErr_SetString(PyExc_SystemError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1533 "no locals!?"); |
|
2857
eebbdbee54f9
be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
1534 } |
|
eebbdbee54f9
be more suspicious of getlocals()
Guido van Rossum <guido@python.org>
parents:
2844
diff
changeset
|
1535 else |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1536 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
|
1537 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1538 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1539 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
|
1540 if (d == NULL) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1541 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
|
1542 "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
|
1543 return NULL; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1544 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1545 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1546 return d; |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1547 } |
|
bfd11620a2d8
* Python/bltinmodule.c (builtin_vars): correct typo in error msg
Guido van Rossum <guido@python.org>
parents:
1444
diff
changeset
|
1548 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1549 PyDoc_STRVAR(vars_doc, |
| 8561 | 1550 "vars([object]) -> dictionary\n\ |
| 1551 \n\ | |
| 1552 Without arguments, equivalent to locals().\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1553 With an argument, equivalent to object.__dict__."); |
| 8561 | 1554 |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1555 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1556 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
|
1557 { |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1558 PyObject *inst; |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1559 PyObject *cls; |
|
17111
bf678a11c21a
Move the code implementing isinstance() and issubclass() to new C
Guido van Rossum <guido@python.org>
parents:
16048
diff
changeset
|
1560 int retval; |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1561 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
1562 if (!PyArg_UnpackTuple(args, "isinstance", 2, 2, &inst, &cls)) |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1563 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
|
1564 |
|
17111
bf678a11c21a
Move the code implementing isinstance() and issubclass() to new C
Guido van Rossum <guido@python.org>
parents:
16048
diff
changeset
|
1565 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
|
1566 if (retval < 0) |
|
15829
9308dc8c85e0
(Modified) patch by Ping - SF Patch #102681.
Guido van Rossum <guido@python.org>
parents:
15727
diff
changeset
|
1567 return NULL; |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22205
diff
changeset
|
1568 return PyBool_FromLong(retval); |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1569 } |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1570 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1571 PyDoc_STRVAR(isinstance_doc, |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22205
diff
changeset
|
1572 "isinstance(object, class-or-type-or-tuple) -> bool\n\ |
| 8561 | 1573 \n\ |
| 1574 Return whether an object is an instance of a class or of a subclass thereof.\n\ | |
|
20307
aa681345bfab
Implement isinstance(x, (A, B, ...)). Note that we only allow tuples,
Guido van Rossum <guido@python.org>
parents:
19903
diff
changeset
|
1575 With a type as second argument, return whether that is the object's type.\n\ |
|
aa681345bfab
Implement isinstance(x, (A, B, ...)). Note that we only allow tuples,
Guido van Rossum <guido@python.org>
parents:
19903
diff
changeset
|
1576 The form using a tuple, isinstance(x, (A, B, ...)), is a shortcut for\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1577 isinstance(x, A) or isinstance(x, B) or ... (etc.)."); |
| 8561 | 1578 |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1579 |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1580 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1581 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
|
1582 { |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1583 PyObject *derived; |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1584 PyObject *cls; |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1585 int retval; |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1586 |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
26612
diff
changeset
|
1587 if (!PyArg_UnpackTuple(args, "issubclass", 2, 2, &derived, &cls)) |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1588 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
|
1589 |
|
17111
bf678a11c21a
Move the code implementing isinstance() and issubclass() to new C
Guido van Rossum <guido@python.org>
parents:
16048
diff
changeset
|
1590 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
|
1591 if (retval < 0) |
|
bf678a11c21a
Move the code implementing isinstance() and issubclass() to new C
Guido van Rossum <guido@python.org>
parents:
16048
diff
changeset
|
1592 return NULL; |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22205
diff
changeset
|
1593 return PyBool_FromLong(retval); |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1594 } |
|
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1595 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1596 PyDoc_STRVAR(issubclass_doc, |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22205
diff
changeset
|
1597 "issubclass(C, B) -> bool\n\ |
| 8561 | 1598 \n\ |
|
26612
97f83542f8ee
Enhance issubclass() and PyObject_IsSubclass() so that a tuple is
Walter Dörwald <walter@livinglogic.de>
parents:
25924
diff
changeset
|
1599 Return whether class C is a subclass (i.e., a derived class) of class B.\n\ |
|
97f83542f8ee
Enhance issubclass() and PyObject_IsSubclass() so that a tuple is
Walter Dörwald <walter@livinglogic.de>
parents:
25924
diff
changeset
|
1600 When using a tuple as the second argument issubclass(X, (A, B, ...)),\n\ |
|
97f83542f8ee
Enhance issubclass() and PyObject_IsSubclass() so that a tuple is
Walter Dörwald <walter@livinglogic.de>
parents:
25924
diff
changeset
|
1601 is a shortcut for issubclass(X, A) or issubclass(X, B) or ... (etc.)."); |
| 8561 | 1602 |
|
6145
341fcb7bad90
Two new built-in functions: issubclass() and isinstance(). Both take
Barry Warsaw <barry@python.org>
parents:
5926
diff
changeset
|
1603 |
|
13822
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
1604 static PyObject* |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
1605 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
|
1606 { |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
1607 PyObject *ret; |
|
23305
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1608 const int itemsize = PySequence_Length(args); |
|
17694
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1609 int i; |
|
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1610 PyObject *itlist; /* tuple of iterators */ |
|
23305
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1611 int len; /* guess at result length */ |
|
13822
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
1612 |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
1613 if (itemsize < 1) { |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
1614 PyErr_SetString(PyExc_TypeError, |
| 15318 | 1615 "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
|
1616 return NULL; |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
1617 } |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
1618 /* 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
|
1619 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
|
1620 |
|
23421
642a453e7a2e
SF bug 555042: zip() may trigger MemoryError.
Tim Peters <tim.peters@gmail.com>
parents:
23305
diff
changeset
|
1621 /* Guess at result length: the shortest of the input lengths. |
|
642a453e7a2e
SF bug 555042: zip() may trigger MemoryError.
Tim Peters <tim.peters@gmail.com>
parents:
23305
diff
changeset
|
1622 If some argument refuses to say, we refuse to guess too, lest |
|
642a453e7a2e
SF bug 555042: zip() may trigger MemoryError.
Tim Peters <tim.peters@gmail.com>
parents:
23305
diff
changeset
|
1623 an argument like xrange(sys.maxint) lead us astray.*/ |
|
23305
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1624 len = -1; /* unknown */ |
|
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1625 for (i = 0; i < itemsize; ++i) { |
|
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1626 PyObject *item = PyTuple_GET_ITEM(args, i); |
|
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1627 int thislen = PySequence_Length(item); |
|
23421
642a453e7a2e
SF bug 555042: zip() may trigger MemoryError.
Tim Peters <tim.peters@gmail.com>
parents:
23305
diff
changeset
|
1628 if (thislen < 0) { |
|
23305
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1629 PyErr_Clear(); |
|
23421
642a453e7a2e
SF bug 555042: zip() may trigger MemoryError.
Tim Peters <tim.peters@gmail.com>
parents:
23305
diff
changeset
|
1630 len = -1; |
|
642a453e7a2e
SF bug 555042: zip() may trigger MemoryError.
Tim Peters <tim.peters@gmail.com>
parents:
23305
diff
changeset
|
1631 break; |
|
642a453e7a2e
SF bug 555042: zip() may trigger MemoryError.
Tim Peters <tim.peters@gmail.com>
parents:
23305
diff
changeset
|
1632 } |
|
23305
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1633 else if (len < 0 || thislen < len) |
|
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1634 len = thislen; |
|
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1635 } |
|
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1636 |
|
17694
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1637 /* allocate result list */ |
|
23305
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1638 if (len < 0) |
|
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1639 len = 10; /* arbitrary */ |
|
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1640 if ((ret = PyList_New(len)) == NULL) |
|
13822
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
1641 return NULL; |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
1642 |
|
17694
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1643 /* obtain iterators */ |
|
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1644 itlist = PyTuple_New(itemsize); |
|
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1645 if (itlist == NULL) |
|
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1646 goto Fail_ret; |
|
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1647 for (i = 0; i < itemsize; ++i) { |
|
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1648 PyObject *item = PyTuple_GET_ITEM(args, i); |
|
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1649 PyObject *it = PyObject_GetIter(item); |
|
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1650 if (it == NULL) { |
|
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1651 if (PyErr_ExceptionMatches(PyExc_TypeError)) |
|
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1652 PyErr_Format(PyExc_TypeError, |
|
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1653 "zip argument #%d must support iteration", |
|
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1654 i+1); |
|
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1655 goto Fail_ret_itlist; |
|
13822
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
1656 } |
|
17694
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1657 PyTuple_SET_ITEM(itlist, i, it); |
|
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1658 } |
|
13822
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
1659 |
|
17694
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1660 /* build result into ret list */ |
|
23305
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1661 for (i = 0; ; ++i) { |
|
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1662 int j; |
|
17694
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1663 PyObject *next = PyTuple_New(itemsize); |
|
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1664 if (!next) |
|
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1665 goto Fail_ret_itlist; |
|
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1666 |
|
23305
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1667 for (j = 0; j < itemsize; j++) { |
|
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1668 PyObject *it = PyTuple_GET_ITEM(itlist, j); |
|
17694
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1669 PyObject *item = PyIter_Next(it); |
|
13822
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
1670 if (!item) { |
|
17694
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1671 if (PyErr_Occurred()) { |
|
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1672 Py_DECREF(ret); |
|
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1673 ret = NULL; |
|
13822
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
1674 } |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
1675 Py_DECREF(next); |
|
17694
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1676 Py_DECREF(itlist); |
|
23305
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1677 goto Done; |
|
13822
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
1678 } |
|
23305
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1679 PyTuple_SET_ITEM(next, j, item); |
|
13822
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
1680 } |
|
17694
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1681 |
|
23305
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1682 if (i < len) |
|
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1683 PyList_SET_ITEM(ret, i, next); |
|
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1684 else { |
|
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1685 int status = PyList_Append(ret, next); |
|
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1686 Py_DECREF(next); |
|
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1687 ++len; |
|
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1688 if (status < 0) |
|
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1689 goto Fail_ret_itlist; |
|
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1690 } |
|
13822
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
1691 } |
|
17694
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1692 |
|
23305
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1693 Done: |
|
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1694 if (ret != NULL && i < len) { |
|
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1695 /* The list is too big. */ |
|
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1696 if (PyList_SetSlice(ret, i, len, NULL) < 0) |
|
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1697 return NULL; |
|
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1698 } |
|
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1699 return ret; |
|
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1700 |
|
17694
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1701 Fail_ret_itlist: |
|
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1702 Py_DECREF(itlist); |
|
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1703 Fail_ret: |
|
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1704 Py_DECREF(ret); |
|
aab6c1f19289
Generalize zip() to work with iterators.
Tim Peters <tim.peters@gmail.com>
parents:
17683
diff
changeset
|
1705 return NULL; |
|
13822
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
1706 } |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
1707 |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
1708 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1709 PyDoc_STRVAR(zip_doc, |
|
13822
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
1710 "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
|
1711 \n\ |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
1712 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
|
1713 from each of the argument sequences. The returned list is truncated\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1714 in length to the length of the shortest argument sequence."); |
|
13822
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
1715 |
|
c57b574e6766
Both PEP 201 Lockstep Iteration and SF patch #101030 have been
Barry Warsaw <barry@python.org>
parents:
13761
diff
changeset
|
1716 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1717 static PyMethodDef builtin_methods[] = { |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1718 {"__import__", builtin___import__, METH_VARARGS, import_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1719 {"abs", builtin_abs, METH_O, abs_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1720 {"apply", builtin_apply, METH_VARARGS, apply_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1721 {"callable", builtin_callable, METH_O, callable_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1722 {"chr", builtin_chr, METH_VARARGS, chr_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1723 {"cmp", builtin_cmp, METH_VARARGS, cmp_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1724 {"coerce", builtin_coerce, METH_VARARGS, coerce_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1725 {"compile", builtin_compile, METH_VARARGS, compile_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1726 {"delattr", builtin_delattr, METH_VARARGS, delattr_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1727 {"dir", builtin_dir, METH_VARARGS, dir_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1728 {"divmod", builtin_divmod, METH_VARARGS, divmod_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1729 {"eval", builtin_eval, METH_VARARGS, eval_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1730 {"execfile", builtin_execfile, METH_VARARGS, execfile_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1731 {"filter", builtin_filter, METH_VARARGS, filter_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1732 {"getattr", builtin_getattr, METH_VARARGS, getattr_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1733 {"globals", (PyCFunction)builtin_globals, METH_NOARGS, globals_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1734 {"hasattr", builtin_hasattr, METH_VARARGS, hasattr_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1735 {"hash", builtin_hash, METH_O, hash_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1736 {"hex", builtin_hex, METH_O, hex_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1737 {"id", builtin_id, METH_O, id_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1738 {"input", builtin_input, METH_VARARGS, input_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1739 {"intern", builtin_intern, METH_VARARGS, intern_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1740 {"isinstance", builtin_isinstance, METH_VARARGS, isinstance_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1741 {"issubclass", builtin_issubclass, METH_VARARGS, issubclass_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1742 {"iter", builtin_iter, METH_VARARGS, iter_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1743 {"len", builtin_len, METH_O, len_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1744 {"locals", (PyCFunction)builtin_locals, METH_NOARGS, locals_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1745 {"map", builtin_map, METH_VARARGS, map_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1746 {"max", builtin_max, METH_VARARGS, max_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1747 {"min", builtin_min, METH_VARARGS, min_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1748 {"oct", builtin_oct, METH_O, oct_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1749 {"ord", builtin_ord, METH_O, ord_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1750 {"pow", builtin_pow, METH_VARARGS, pow_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1751 {"range", builtin_range, METH_VARARGS, range_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1752 {"raw_input", builtin_raw_input, METH_VARARGS, raw_input_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1753 {"reduce", builtin_reduce, METH_VARARGS, reduce_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1754 {"reload", builtin_reload, METH_O, reload_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1755 {"repr", builtin_repr, METH_O, repr_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1756 {"round", builtin_round, METH_VARARGS, round_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1757 {"setattr", builtin_setattr, METH_VARARGS, setattr_doc}, |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19301
diff
changeset
|
1758 #ifdef Py_USING_UNICODE |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1759 {"unichr", builtin_unichr, METH_VARARGS, unichr_doc}, |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19301
diff
changeset
|
1760 #endif |
|
19301
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1761 {"vars", builtin_vars, METH_VARARGS, vars_doc}, |
|
b9701538f827
Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents:
19061
diff
changeset
|
1762 {"zip", builtin_zip, METH_VARARGS, zip_doc}, |
|
480
c64c6702549d
Added "apply"; added "SyntaxError"; changed table lay-out.
Guido van Rossum <guido@python.org>
parents:
463
diff
changeset
|
1763 {NULL, NULL}, |
| 86 | 1764 }; |
| 1765 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1766 PyDoc_STRVAR(builtin_doc, |
| 8561 | 1767 "Built-in functions, exceptions, and other objects.\n\ |
| 1768 \n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23695
diff
changeset
|
1769 Noteworthy: None is the `nil' object; Ellipsis represents `...' in slices."); |
| 8561 | 1770 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1771 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1772 _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
|
1773 { |
|
12961
eb911eca9ee9
Christopher Fandrich <cfandrich@8cs.com>:
Fred Drake <fdrake@acm.org>
parents:
12756
diff
changeset
|
1774 PyObject *mod, *dict, *debug; |
| 8561 | 1775 mod = Py_InitModule4("__builtin__", builtin_methods, |
| 1776 builtin_doc, (PyObject *)NULL, | |
| 1777 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
|
1778 if (mod == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1779 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1780 dict = PyModule_GetDict(mod); |
|
19902
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
1781 |
|
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
1782 #define SETBUILTIN(NAME, OBJECT) \ |
|
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
1783 if (PyDict_SetItemString(dict, NAME, (PyObject *)OBJECT) < 0) \ |
|
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
1784 return NULL |
|
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
1785 |
|
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
1786 SETBUILTIN("None", Py_None); |
|
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
1787 SETBUILTIN("Ellipsis", Py_Ellipsis); |
|
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
1788 SETBUILTIN("NotImplemented", Py_NotImplemented); |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22205
diff
changeset
|
1789 SETBUILTIN("False", Py_False); |
|
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22205
diff
changeset
|
1790 SETBUILTIN("True", Py_True); |
|
23597
ed007e47b3a1
Change name from string to basestring
Neal Norwitz <nnorwitz@gmail.com>
parents:
23542
diff
changeset
|
1791 SETBUILTIN("basestring", &PyBaseString_Type); |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22205
diff
changeset
|
1792 SETBUILTIN("bool", &PyBool_Type); |
|
23868
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23832
diff
changeset
|
1793 SETBUILTIN("buffer", &PyBuffer_Type); |
|
19902
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
1794 SETBUILTIN("classmethod", &PyClassMethod_Type); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18890
diff
changeset
|
1795 #ifndef WITHOUT_COMPLEX |
|
19902
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
1796 SETBUILTIN("complex", &PyComplex_Type); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18890
diff
changeset
|
1797 #endif |
|
20754
272336648d1f
Rename "dictionary" (type and constructor) to "dict".
Tim Peters <tim.peters@gmail.com>
parents:
20654
diff
changeset
|
1798 SETBUILTIN("dict", &PyDict_Type); |
|
23305
ef6e31f0cee1
builtin_zip(): Take a good guess at how big the result list will be,
Tim Peters <tim.peters@gmail.com>
parents:
23295
diff
changeset
|
1799 SETBUILTIN("enumerate", &PyEnum_Type); |
|
19902
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
1800 SETBUILTIN("float", &PyFloat_Type); |
|
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
1801 SETBUILTIN("property", &PyProperty_Type); |
|
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
1802 SETBUILTIN("int", &PyInt_Type); |
|
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
1803 SETBUILTIN("list", &PyList_Type); |
|
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
1804 SETBUILTIN("long", &PyLong_Type); |
|
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
1805 SETBUILTIN("object", &PyBaseObject_Type); |
|
23868
8e6760bf1884
SF patch 568629 by Oren Tirosh: types made callable.
Guido van Rossum <guido@python.org>
parents:
23832
diff
changeset
|
1806 SETBUILTIN("slice", &PySlice_Type); |
|
19902
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
1807 SETBUILTIN("staticmethod", &PyStaticMethod_Type); |
|
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
1808 SETBUILTIN("str", &PyString_Type); |
|
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
1809 SETBUILTIN("super", &PySuper_Type); |
|
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
1810 SETBUILTIN("tuple", &PyTuple_Type); |
|
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
1811 SETBUILTIN("type", &PyType_Type); |
|
23695
6266f1bd1ab9
Skip Montanaro's patch, SF 559833, exposing xrange type in builtins.
Raymond Hettinger <python@rcn.com>
parents:
23597
diff
changeset
|
1812 SETBUILTIN("xrange", &PyRange_Type); |
|
19903
c082971823ce
Get rid of builtin_open() entirely (the C code and docstring, not the
Tim Peters <tim.peters@gmail.com>
parents:
19902
diff
changeset
|
1813 |
|
c082971823ce
Get rid of builtin_open() entirely (the C code and docstring, not the
Tim Peters <tim.peters@gmail.com>
parents:
19902
diff
changeset
|
1814 /* Note that open() is just an alias of file(). */ |
|
c082971823ce
Get rid of builtin_open() entirely (the C code and docstring, not the
Tim Peters <tim.peters@gmail.com>
parents:
19902
diff
changeset
|
1815 SETBUILTIN("open", &PyFile_Type); |
|
19902
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
1816 SETBUILTIN("file", &PyFile_Type); |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19301
diff
changeset
|
1817 #ifdef Py_USING_UNICODE |
|
19902
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
1818 SETBUILTIN("unicode", &PyUnicode_Type); |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19301
diff
changeset
|
1819 #endif |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22205
diff
changeset
|
1820 debug = PyBool_FromLong(Py_OptimizeFlag == 0); |
|
12961
eb911eca9ee9
Christopher Fandrich <cfandrich@8cs.com>:
Fred Drake <fdrake@acm.org>
parents:
12756
diff
changeset
|
1821 if (PyDict_SetItemString(dict, "__debug__", debug) < 0) { |
|
eb911eca9ee9
Christopher Fandrich <cfandrich@8cs.com>:
Fred Drake <fdrake@acm.org>
parents:
12756
diff
changeset
|
1822 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
|
1823 return NULL; |
|
12961
eb911eca9ee9
Christopher Fandrich <cfandrich@8cs.com>:
Fred Drake <fdrake@acm.org>
parents:
12756
diff
changeset
|
1824 } |
|
eb911eca9ee9
Christopher Fandrich <cfandrich@8cs.com>:
Fred Drake <fdrake@acm.org>
parents:
12756
diff
changeset
|
1825 Py_XDECREF(debug); |
|
6198
c43ca8dd0081
Removed obsolete exception PyExc_AccessError.
Barry Warsaw <barry@python.org>
parents:
6145
diff
changeset
|
1826 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
1827 return mod; |
|
19902
de39956b5458
_PyBuiltin_Init(): For clarity, macroize this purely repetitive code.
Tim Peters <tim.peters@gmail.com>
parents:
19894
diff
changeset
|
1828 #undef SETBUILTIN |
| 86 | 1829 } |
| 1830 | |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1387
diff
changeset
|
1831 /* 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
|
1832 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1833 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1834 filtertuple(PyObject *func, PyObject *tuple) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1835 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1836 PyObject *result; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1837 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
|
1838 int len = PyTuple_Size(tuple); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1839 |
|
2890
04e1690fb4d1
avoid resize of 0-length tuple
Guido van Rossum <guido@python.org>
parents:
2857
diff
changeset
|
1840 if (len == 0) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1841 Py_INCREF(tuple); |
|
2890
04e1690fb4d1
avoid resize of 0-length tuple
Guido van Rossum <guido@python.org>
parents:
2857
diff
changeset
|
1842 return tuple; |
|
04e1690fb4d1
avoid resize of 0-length tuple
Guido van Rossum <guido@python.org>
parents:
2857
diff
changeset
|
1843 } |
|
04e1690fb4d1
avoid resize of 0-length tuple
Guido van Rossum <guido@python.org>
parents:
2857
diff
changeset
|
1844 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1845 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
|
1846 return NULL; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1847 |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1848 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
|
1849 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
|
1850 int ok; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1851 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1852 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
|
1853 goto Fail_1; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1854 if (func == Py_None) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1855 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
|
1856 good = item; |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1857 } |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1858 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1859 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
|
1860 if (arg == NULL) |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1861 goto Fail_1; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1862 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
|
1863 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
|
1864 if (good == NULL) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1865 goto Fail_1; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1866 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1867 ok = PyObject_IsTrue(good); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1868 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
|
1869 if (ok) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1870 Py_INCREF(item); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1871 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
|
1872 goto Fail_1; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1873 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1874 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1875 |
|
17976
d579a5d8b3fe
Cruft cleanup: Removed the unused last_is_sticky argument from the internal
Tim Peters <tim.peters@gmail.com>
parents:
17874
diff
changeset
|
1876 if (_PyTuple_Resize(&result, j) < 0) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1877 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1878 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1879 return result; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1880 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1881 Fail_1: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1882 Py_DECREF(result); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1883 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1884 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1885 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1886 |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1387
diff
changeset
|
1887 /* 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
|
1888 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1889 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
1890 filterstring(PyObject *func, PyObject *strobj) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1891 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1892 PyObject *result; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1893 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
|
1894 int len = PyString_Size(strobj); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1895 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1896 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
|
1897 /* 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
|
1898 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
|
1899 return strobj; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1900 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1901 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
|
1902 return NULL; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1903 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1904 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
|
1905 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
|
1906 int ok; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1907 |
|
1375
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1908 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
|
1909 if (item == NULL) |
|
f3a325662d39
* listobject.c (list_ass_slice): XDECREF instead of DECREF so
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
1910 goto Fail_1; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1911 arg = Py_BuildValue("(O)", item); |
|
17337
96ea0eccdb31
SF patch #413552 - Premature decref on object
Tim Peters <tim.peters@gmail.com>
parents:
17125
diff
changeset
|
1912 if (arg == NULL) { |
|
96ea0eccdb31
SF patch #413552 - Premature decref on object
Tim Peters <tim.peters@gmail.com>
parents:
17125
diff
changeset
|
1913 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
|
1914 goto Fail_1; |
|
17337
96ea0eccdb31
SF patch #413552 - Premature decref on object
Tim Peters <tim.peters@gmail.com>
parents:
17125
diff
changeset
|
1915 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1916 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
|
1917 Py_DECREF(arg); |
|
17337
96ea0eccdb31
SF patch #413552 - Premature decref on object
Tim Peters <tim.peters@gmail.com>
parents:
17125
diff
changeset
|
1918 if (good == NULL) { |
|
96ea0eccdb31
SF patch #413552 - Premature decref on object
Tim Peters <tim.peters@gmail.com>
parents:
17125
diff
changeset
|
1919 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
|
1920 goto Fail_1; |
|
17337
96ea0eccdb31
SF patch #413552 - Premature decref on object
Tim Peters <tim.peters@gmail.com>
parents:
17125
diff
changeset
|
1921 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1922 ok = PyObject_IsTrue(good); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1923 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
|
1924 if (ok) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1925 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
|
1926 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
|
1927 Py_DECREF(item); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1928 } |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1929 |
|
23295
6fa76b4e59fe
Repair widespread misuse of _PyString_Resize. Since it's clear people
Tim Peters <tim.peters@gmail.com>
parents:
23285
diff
changeset
|
1930 if (j < len) |
|
6fa76b4e59fe
Repair widespread misuse of _PyString_Resize. Since it's clear people
Tim Peters <tim.peters@gmail.com>
parents:
23285
diff
changeset
|
1931 _PyString_Resize(&result, j); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1932 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1933 return result; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1934 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1935 Fail_1: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
1936 Py_DECREF(result); |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1937 return NULL; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1360
diff
changeset
|
1938 } |
|
27385
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1939 |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1940 #ifdef Py_USING_UNICODE |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1941 /* Helper for filter(): filter a Unicode object through a function */ |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1942 |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1943 static PyObject * |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1944 filterunicode(PyObject *func, PyObject *strobj) |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1945 { |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1946 PyObject *result; |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1947 register int i, j; |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1948 int len = PyUnicode_GetSize(strobj); |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1949 |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1950 if (func == Py_None) { |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1951 /* No character is ever false -- share input string */ |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1952 Py_INCREF(strobj); |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1953 return strobj; |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1954 } |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1955 if ((result = PyUnicode_FromUnicode(NULL, len)) == NULL) |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1956 return NULL; |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1957 |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1958 for (i = j = 0; i < len; ++i) { |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1959 PyObject *item, *arg, *good; |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1960 int ok; |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1961 |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1962 item = (*strobj->ob_type->tp_as_sequence->sq_item)(strobj, i); |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1963 if (item == NULL) |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1964 goto Fail_1; |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1965 arg = Py_BuildValue("(O)", item); |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1966 if (arg == NULL) { |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1967 Py_DECREF(item); |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1968 goto Fail_1; |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1969 } |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1970 good = PyEval_CallObject(func, arg); |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1971 Py_DECREF(arg); |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1972 if (good == NULL) { |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1973 Py_DECREF(item); |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1974 goto Fail_1; |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1975 } |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1976 ok = PyObject_IsTrue(good); |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1977 Py_DECREF(good); |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1978 if (ok) |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1979 PyUnicode_AS_UNICODE((PyStringObject *)result)[j++] = |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1980 PyUnicode_AS_UNICODE((PyStringObject *)item)[0]; |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1981 Py_DECREF(item); |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1982 } |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1983 |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1984 if (j < len) |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1985 PyUnicode_Resize(&result, j); |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1986 |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1987 return result; |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1988 |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1989 Fail_1: |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1990 Py_DECREF(result); |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1991 return NULL; |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1992 } |
|
91a573243d5d
Patch #636005: Filter unicode into unicode.
Martin v. Löwis <martin@v.loewis.de>
parents:
27076
diff
changeset
|
1993 #endif |
