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