annotate Objects/fileobject.c @ 57114:d3a81051663b

importlib.test.source.util referenced variables in the 'finally' part of a try/finally which may not have been set.
author Brett Cannon <bcannon@gmail.com>
date Thu, 05 Nov 2009 01:17:22 +0000
parents 87fbbf22adf3
children f197407bdba2 774230078926
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42071
825041fc8e2c Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents: 42054
diff changeset
1 /* File object implementation (what's left of it -- see io.py) */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36485
diff changeset
3 #define PY_SSIZE_T_CLEAN
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4585
diff changeset
4 #include "Python.h"
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
23029
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
6 #ifdef HAVE_GETC_UNLOCKED
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
7 #define GETC(f) getc_unlocked(f)
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
8 #define FLOCKFILE(f) flockfile(f)
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
9 #define FUNLOCKFILE(f) funlockfile(f)
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
10 #else
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
11 #define GETC(f) getc(f)
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
12 #define FLOCKFILE(f)
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
13 #define FUNLOCKFILE(f)
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
14 #endif
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
15
42071
825041fc8e2c Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents: 42054
diff changeset
16 /* Newline flags */
23029
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
17 #define NEWLINE_UNKNOWN 0 /* No newline seen, yet */
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
18 #define NEWLINE_CR 1 /* \r newline seen */
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
19 #define NEWLINE_LF 2 /* \n newline seen */
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
20 #define NEWLINE_CRLF 4 /* \r\n newline seen */
13924
ddf302d69211 Add largefile support for Linux64 and WIn64. Add test_largefile and some minor
Trent Mick <trentm@activestate.com>
parents: 13591
diff changeset
21
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37053
diff changeset
22 #ifdef __cplusplus
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37053
diff changeset
23 extern "C" {
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37053
diff changeset
24 #endif
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37053
diff changeset
25
42071
825041fc8e2c Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents: 42054
diff changeset
26 /* External C interface */
19894
51cc82605d32 SF bug [#460467] file objects should be subclassable.
Tim Peters <tim.peters@gmail.com>
parents: 19836
diff changeset
27
51cc82605d32 SF bug [#460467] file objects should be subclassable.
Tim Peters <tim.peters@gmail.com>
parents: 19836
diff changeset
28 PyObject *
43632
0067a6ab4854 Issue 1267, continued.
Guido van Rossum <guido@python.org>
parents: 43605
diff changeset
29 PyFile_FromFd(int fd, char *name, char *mode, int buffering, char *encoding,
44134
e08b12c3b913 Add an errors parameter to open() and TextIOWrapper() to specify error handling.
Guido van Rossum <guido@python.org>
parents: 44099
diff changeset
30 char *errors, char *newline, int closefd)
19894
51cc82605d32 SF bug [#460467] file objects should be subclassable.
Tim Peters <tim.peters@gmail.com>
parents: 19836
diff changeset
31 {
43632
0067a6ab4854 Issue 1267, continued.
Guido van Rossum <guido@python.org>
parents: 43605
diff changeset
32 PyObject *io, *stream, *nameobj = NULL;
42054
063530fcc32e Minimal changes to make the "freeze" tool work again.
Guido van Rossum <guido@python.org>
parents: 41846
diff changeset
33
063530fcc32e Minimal changes to make the "freeze" tool work again.
Guido van Rossum <guido@python.org>
parents: 41846
diff changeset
34 io = PyImport_ImportModule("io");
063530fcc32e Minimal changes to make the "freeze" tool work again.
Guido van Rossum <guido@python.org>
parents: 41846
diff changeset
35 if (io == NULL)
063530fcc32e Minimal changes to make the "freeze" tool work again.
Guido van Rossum <guido@python.org>
parents: 41846
diff changeset
36 return NULL;
44134
e08b12c3b913 Add an errors parameter to open() and TextIOWrapper() to specify error handling.
Guido van Rossum <guido@python.org>
parents: 44099
diff changeset
37 stream = PyObject_CallMethod(io, "open", "isisssi", fd, mode,
e08b12c3b913 Add an errors parameter to open() and TextIOWrapper() to specify error handling.
Guido van Rossum <guido@python.org>
parents: 44099
diff changeset
38 buffering, encoding, errors,
e08b12c3b913 Add an errors parameter to open() and TextIOWrapper() to specify error handling.
Guido van Rossum <guido@python.org>
parents: 44099
diff changeset
39 newline, closefd);
43605
a2bb76d11d66 Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43513
diff changeset
40 Py_DECREF(io);
42071
825041fc8e2c Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents: 42054
diff changeset
41 if (stream == NULL)
42054
063530fcc32e Minimal changes to make the "freeze" tool work again.
Guido van Rossum <guido@python.org>
parents: 41846
diff changeset
42 return NULL;
43605
a2bb76d11d66 Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43513
diff changeset
43 if (name != NULL) {
a2bb76d11d66 Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43513
diff changeset
44 nameobj = PyUnicode_FromString(name);
a2bb76d11d66 Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43513
diff changeset
45 if (nameobj == NULL)
42071
825041fc8e2c Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents: 42054
diff changeset
46 PyErr_Clear();
43605
a2bb76d11d66 Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43513
diff changeset
47 else {
a2bb76d11d66 Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43513
diff changeset
48 if (PyObject_SetAttrString(stream, "name", nameobj) < 0)
a2bb76d11d66 Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43513
diff changeset
49 PyErr_Clear();
a2bb76d11d66 Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43513
diff changeset
50 Py_DECREF(nameobj);
a2bb76d11d66 Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43513
diff changeset
51 }
19894
51cc82605d32 SF bug [#460467] file objects should be subclassable.
Tim Peters <tim.peters@gmail.com>
parents: 19836
diff changeset
52 }
42054
063530fcc32e Minimal changes to make the "freeze" tool work again.
Guido van Rossum <guido@python.org>
parents: 41846
diff changeset
53 return stream;
19894
51cc82605d32 SF bug [#460467] file objects should be subclassable.
Tim Peters <tim.peters@gmail.com>
parents: 19836
diff changeset
54 }
51cc82605d32 SF bug [#460467] file objects should be subclassable.
Tim Peters <tim.peters@gmail.com>
parents: 19836
diff changeset
55
51cc82605d32 SF bug [#460467] file objects should be subclassable.
Tim Peters <tim.peters@gmail.com>
parents: 19836
diff changeset
56 PyObject *
13454
fcc75a3748f5 ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents: 13447
diff changeset
57 PyFile_GetLine(PyObject *f, int n)
183
c9168afe23dd Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents: 177
diff changeset
58 {
15753
8d00f7555eec Tim noticed that I had botched get_line_raw(). Looking again, I
Guido van Rossum <guido@python.org>
parents: 15745
diff changeset
59 PyObject *result;
8d00f7555eec Tim noticed that I had botched get_line_raw(). Looking again, I
Guido van Rossum <guido@python.org>
parents: 15745
diff changeset
60
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
61 if (f == NULL) {
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4585
diff changeset
62 PyErr_BadInternalCall();
183
c9168afe23dd Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents: 177
diff changeset
63 return NULL;
c9168afe23dd Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents: 177
diff changeset
64 }
15753
8d00f7555eec Tim noticed that I had botched get_line_raw(). Looking again, I
Guido van Rossum <guido@python.org>
parents: 15745
diff changeset
65
42071
825041fc8e2c Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents: 42054
diff changeset
66 {
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4585
diff changeset
67 PyObject *reader;
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4585
diff changeset
68 PyObject *args;
15753
8d00f7555eec Tim noticed that I had botched get_line_raw(). Looking again, I
Guido van Rossum <guido@python.org>
parents: 15745
diff changeset
69
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4585
diff changeset
70 reader = PyObject_GetAttrString(f, "readline");
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
71 if (reader == NULL)
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
72 return NULL;
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
73 if (n <= 0)
30683
3b59fa5d25b1 Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents: 30366
diff changeset
74 args = PyTuple_New(0);
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
75 else
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4585
diff changeset
76 args = Py_BuildValue("(i)", n);
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
77 if (args == NULL) {
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4585
diff changeset
78 Py_DECREF(reader);
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
79 return NULL;
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
80 }
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4585
diff changeset
81 result = PyEval_CallObject(reader, args);
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4585
diff changeset
82 Py_DECREF(reader);
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4585
diff changeset
83 Py_DECREF(args);
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 44134
diff changeset
84 if (result != NULL && !PyBytes_Check(result) &&
27060
cf90309efeee Allow PyFile_GetLine() to return Unicode objects. Fixes #660165.
Martin v. Löwis <martin@v.loewis.de>
parents: 26818
diff changeset
85 !PyUnicode_Check(result)) {
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4585
diff changeset
86 Py_DECREF(result);
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
87 result = NULL;
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4585
diff changeset
88 PyErr_SetString(PyExc_TypeError,
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
89 "object.readline() returned non-string");
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
90 }
15753
8d00f7555eec Tim noticed that I had botched get_line_raw(). Looking again, I
Guido van Rossum <guido@python.org>
parents: 15745
diff changeset
91 }
8d00f7555eec Tim noticed that I had botched get_line_raw(). Looking again, I
Guido van Rossum <guido@python.org>
parents: 15745
diff changeset
92
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 44134
diff changeset
93 if (n < 0 && result != NULL && PyBytes_Check(result)) {
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 44134
diff changeset
94 char *s = PyBytes_AS_STRING(result);
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 44134
diff changeset
95 Py_ssize_t len = PyBytes_GET_SIZE(result);
15753
8d00f7555eec Tim noticed that I had botched get_line_raw(). Looking again, I
Guido van Rossum <guido@python.org>
parents: 15745
diff changeset
96 if (len == 0) {
8d00f7555eec Tim noticed that I had botched get_line_raw(). Looking again, I
Guido van Rossum <guido@python.org>
parents: 15745
diff changeset
97 Py_DECREF(result);
8d00f7555eec Tim noticed that I had botched get_line_raw(). Looking again, I
Guido van Rossum <guido@python.org>
parents: 15745
diff changeset
98 result = NULL;
8d00f7555eec Tim noticed that I had botched get_line_raw(). Looking again, I
Guido van Rossum <guido@python.org>
parents: 15745
diff changeset
99 PyErr_SetString(PyExc_EOFError,
8d00f7555eec Tim noticed that I had botched get_line_raw(). Looking again, I
Guido van Rossum <guido@python.org>
parents: 15745
diff changeset
100 "EOF when reading a line");
8d00f7555eec Tim noticed that I had botched get_line_raw(). Looking again, I
Guido van Rossum <guido@python.org>
parents: 15745
diff changeset
101 }
8d00f7555eec Tim noticed that I had botched get_line_raw(). Looking again, I
Guido van Rossum <guido@python.org>
parents: 15745
diff changeset
102 else if (s[len-1] == '\n') {
8d00f7555eec Tim noticed that I had botched get_line_raw(). Looking again, I
Guido van Rossum <guido@python.org>
parents: 15745
diff changeset
103 if (result->ob_refcnt == 1)
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 44134
diff changeset
104 _PyBytes_Resize(&result, len-1);
15753
8d00f7555eec Tim noticed that I had botched get_line_raw(). Looking again, I
Guido van Rossum <guido@python.org>
parents: 15745
diff changeset
105 else {
8d00f7555eec Tim noticed that I had botched get_line_raw(). Looking again, I
Guido van Rossum <guido@python.org>
parents: 15745
diff changeset
106 PyObject *v;
47301
23ab586c427a Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents: 44134
diff changeset
107 v = PyBytes_FromStringAndSize(s, len-1);
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4585
diff changeset
108 Py_DECREF(result);
15753
8d00f7555eec Tim noticed that I had botched get_line_raw(). Looking again, I
Guido van Rossum <guido@python.org>
parents: 15745
diff changeset
109 result = v;
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
110 }
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
111 }
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
112 }
27060
cf90309efeee Allow PyFile_GetLine() to return Unicode objects. Fixes #660165.
Martin v. Löwis <martin@v.loewis.de>
parents: 26818
diff changeset
113 if (n < 0 && result != NULL && PyUnicode_Check(result)) {
cf90309efeee Allow PyFile_GetLine() to return Unicode objects. Fixes #660165.
Martin v. Löwis <martin@v.loewis.de>
parents: 26818
diff changeset
114 Py_UNICODE *s = PyUnicode_AS_UNICODE(result);
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36485
diff changeset
115 Py_ssize_t len = PyUnicode_GET_SIZE(result);
27060
cf90309efeee Allow PyFile_GetLine() to return Unicode objects. Fixes #660165.
Martin v. Löwis <martin@v.loewis.de>
parents: 26818
diff changeset
116 if (len == 0) {
cf90309efeee Allow PyFile_GetLine() to return Unicode objects. Fixes #660165.
Martin v. Löwis <martin@v.loewis.de>
parents: 26818
diff changeset
117 Py_DECREF(result);
cf90309efeee Allow PyFile_GetLine() to return Unicode objects. Fixes #660165.
Martin v. Löwis <martin@v.loewis.de>
parents: 26818
diff changeset
118 result = NULL;
cf90309efeee Allow PyFile_GetLine() to return Unicode objects. Fixes #660165.
Martin v. Löwis <martin@v.loewis.de>
parents: 26818
diff changeset
119 PyErr_SetString(PyExc_EOFError,
cf90309efeee Allow PyFile_GetLine() to return Unicode objects. Fixes #660165.
Martin v. Löwis <martin@v.loewis.de>
parents: 26818
diff changeset
120 "EOF when reading a line");
cf90309efeee Allow PyFile_GetLine() to return Unicode objects. Fixes #660165.
Martin v. Löwis <martin@v.loewis.de>
parents: 26818
diff changeset
121 }
cf90309efeee Allow PyFile_GetLine() to return Unicode objects. Fixes #660165.
Martin v. Löwis <martin@v.loewis.de>
parents: 26818
diff changeset
122 else if (s[len-1] == '\n') {
cf90309efeee Allow PyFile_GetLine() to return Unicode objects. Fixes #660165.
Martin v. Löwis <martin@v.loewis.de>
parents: 26818
diff changeset
123 if (result->ob_refcnt == 1)
cf90309efeee Allow PyFile_GetLine() to return Unicode objects. Fixes #660165.
Martin v. Löwis <martin@v.loewis.de>
parents: 26818
diff changeset
124 PyUnicode_Resize(&result, len-1);
cf90309efeee Allow PyFile_GetLine() to return Unicode objects. Fixes #660165.
Martin v. Löwis <martin@v.loewis.de>
parents: 26818
diff changeset
125 else {
cf90309efeee Allow PyFile_GetLine() to return Unicode objects. Fixes #660165.
Martin v. Löwis <martin@v.loewis.de>
parents: 26818
diff changeset
126 PyObject *v;
cf90309efeee Allow PyFile_GetLine() to return Unicode objects. Fixes #660165.
Martin v. Löwis <martin@v.loewis.de>
parents: 26818
diff changeset
127 v = PyUnicode_FromUnicode(s, len-1);
cf90309efeee Allow PyFile_GetLine() to return Unicode objects. Fixes #660165.
Martin v. Löwis <martin@v.loewis.de>
parents: 26818
diff changeset
128 Py_DECREF(result);
cf90309efeee Allow PyFile_GetLine() to return Unicode objects. Fixes #660165.
Martin v. Löwis <martin@v.loewis.de>
parents: 26818
diff changeset
129 result = v;
cf90309efeee Allow PyFile_GetLine() to return Unicode objects. Fixes #660165.
Martin v. Löwis <martin@v.loewis.de>
parents: 26818
diff changeset
130 }
cf90309efeee Allow PyFile_GetLine() to return Unicode objects. Fixes #660165.
Martin v. Löwis <martin@v.loewis.de>
parents: 26818
diff changeset
131 }
cf90309efeee Allow PyFile_GetLine() to return Unicode objects. Fixes #660165.
Martin v. Löwis <martin@v.loewis.de>
parents: 26818
diff changeset
132 }
15753
8d00f7555eec Tim noticed that I had botched get_line_raw(). Looking again, I
Guido van Rossum <guido@python.org>
parents: 15745
diff changeset
133 return result;
183
c9168afe23dd Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents: 177
diff changeset
134 }
c9168afe23dd Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents: 177
diff changeset
135
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
136 /* Interfaces to write objects/strings to file-like objects */
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
137
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
138 int
13454
fcc75a3748f5 ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents: 13447
diff changeset
139 PyFile_WriteObject(PyObject *v, PyObject *f, int flags)
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
140 {
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4585
diff changeset
141 PyObject *writer, *value, *args, *result;
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
142 if (f == NULL) {
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4585
diff changeset
143 PyErr_SetString(PyExc_TypeError, "writeobject with NULL file");
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
144 return -1;
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
145 }
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4585
diff changeset
146 writer = PyObject_GetAttrString(f, "write");
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
147 if (writer == NULL)
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
148 return -1;
19985
712afdae1123 Patch #462849: Pass Unicode objects to file's .write method.
Martin v. Löwis <martin@v.loewis.de>
parents: 19905
diff changeset
149 if (flags & Py_PRINT_RAW) {
43777
0d462d789b18 Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents: 43719
diff changeset
150 value = PyObject_Str(v);
19985
712afdae1123 Patch #462849: Pass Unicode objects to file's .write method.
Martin v. Löwis <martin@v.loewis.de>
parents: 19905
diff changeset
151 }
42184
bf5d04e0da4c Make test_descr.py pass. Had to disable a few tests, remove references
Guido van Rossum <guido@python.org>
parents: 42071
diff changeset
152 else
43513
340e6fd5d75f PyFile_WriteObject() should use PyObject_Repr(), not _ReprStr8().
Guido van Rossum <guido@python.org>
parents: 42552
diff changeset
153 value = PyObject_Repr(v);
1400
aac8231a715c * mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents: 1389
diff changeset
154 if (value == NULL) {
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4585
diff changeset
155 Py_DECREF(writer);
1400
aac8231a715c * mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents: 1389
diff changeset
156 return -1;
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
157 }
30683
3b59fa5d25b1 Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents: 30366
diff changeset
158 args = PyTuple_Pack(1, value);
5582
87d5d7fa8d07 Fix typo in error checking spotted by Just...
Guido van Rossum <guido@python.org>
parents: 5479
diff changeset
159 if (args == NULL) {
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4585
diff changeset
160 Py_DECREF(value);
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4585
diff changeset
161 Py_DECREF(writer);
2825
bebb0ea7de20 fix read(0), readline(0); make tuple for call_object args
Guido van Rossum <guido@python.org>
parents: 2667
diff changeset
162 return -1;
bebb0ea7de20 fix read(0), readline(0); make tuple for call_object args
Guido van Rossum <guido@python.org>
parents: 2667
diff changeset
163 }
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4585
diff changeset
164 result = PyEval_CallObject(writer, args);
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4585
diff changeset
165 Py_DECREF(args);
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4585
diff changeset
166 Py_DECREF(value);
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4585
diff changeset
167 Py_DECREF(writer);
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
168 if (result == NULL)
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
169 return -1;
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4585
diff changeset
170 Py_DECREF(result);
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
171 return 0;
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
172 }
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
173
5605
89af5bf8f873 PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5582
diff changeset
174 int
21095
b1280cba79b5 PyFile_WriteString(): change prototype so that the string arg is
Tim Peters <tim.peters@gmail.com>
parents: 20942
diff changeset
175 PyFile_WriteString(const char *s, PyObject *f)
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
176 {
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
177 if (f == NULL) {
5605
89af5bf8f873 PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5582
diff changeset
178 /* Should be caused by a pre-existing error */
13454
fcc75a3748f5 ANSI-fication of the sources.
Fred Drake <fdrake@acm.org>
parents: 13447
diff changeset
179 if (!PyErr_Occurred())
5605
89af5bf8f873 PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5582
diff changeset
180 PyErr_SetString(PyExc_SystemError,
89af5bf8f873 PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5582
diff changeset
181 "null file for PyFile_WriteString");
89af5bf8f873 PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5582
diff changeset
182 return -1;
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
183 }
5396
d1447950fa04 Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents: 4585
diff changeset
184 else if (!PyErr_Occurred()) {
42513
a24e27f05e48 In PyFile_WriteString(), call PyUnicode_FromString() instead of
Guido van Rossum <guido@python.org>
parents: 42184
diff changeset
185 PyObject *v = PyUnicode_FromString(s);
5605
89af5bf8f873 PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5582
diff changeset
186 int err;
89af5bf8f873 PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5582
diff changeset
187 if (v == NULL)
89af5bf8f873 PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5582
diff changeset
188 return -1;
89af5bf8f873 PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5582
diff changeset
189 err = PyFile_WriteObject(v, f, Py_PRINT_RAW);
89af5bf8f873 PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5582
diff changeset
190 Py_DECREF(v);
89af5bf8f873 PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5582
diff changeset
191 return err;
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
192 }
5783
9cfbc9bb6423 Reordered list of methods to hopefully put the most frequently used
Guido van Rossum <guido@python.org>
parents: 5605
diff changeset
193 else
9cfbc9bb6423 Reordered list of methods to hopefully put the most frequently used
Guido van Rossum <guido@python.org>
parents: 5605
diff changeset
194 return -1;
1073
2c0432fcc270 Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
195 }
13591
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
196
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
197 /* Try to get a file-descriptor from a Python object. If the object
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
198 is an integer or long integer, its value is returned. If not, the
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
199 object's fileno() method is called if it exists; the method must return
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
200 an integer or long integer, which is returned as the file descriptor value.
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
201 -1 is returned on failure.
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
202 */
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
203
42071
825041fc8e2c Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents: 42054
diff changeset
204 int
825041fc8e2c Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents: 42054
diff changeset
205 PyObject_AsFileDescriptor(PyObject *o)
13591
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
206 {
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
207 int fd;
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
208 PyObject *meth;
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
209
43649
da8230faf2ae Remove redundant PyInt/PyLong checks.
Georg Brandl <georg@python.org>
parents: 43632
diff changeset
210 if (PyLong_Check(o)) {
13591
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
211 fd = PyLong_AsLong(o);
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
212 }
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
213 else if ((meth = PyObject_GetAttrString(o, "fileno")) != NULL)
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
214 {
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
215 PyObject *fno = PyEval_CallObject(meth, NULL);
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
216 Py_DECREF(meth);
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
217 if (fno == NULL)
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
218 return -1;
15754
7c8fac4ac31a MS Win32 .readline() speedup, as discussed on Python-Dev. This is a tricky
Tim Peters <tim.peters@gmail.com>
parents: 15753
diff changeset
219
43649
da8230faf2ae Remove redundant PyInt/PyLong checks.
Georg Brandl <georg@python.org>
parents: 43632
diff changeset
220 if (PyLong_Check(fno)) {
13591
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
221 fd = PyLong_AsLong(fno);
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
222 Py_DECREF(fno);
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
223 }
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
224 else {
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
225 PyErr_SetString(PyExc_TypeError,
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
226 "fileno() returned a non-integer");
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
227 Py_DECREF(fno);
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
228 return -1;
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
229 }
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
230 }
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
231 else {
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
232 PyErr_SetString(PyExc_TypeError,
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
233 "argument must be an int, or have a fileno() method.");
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
234 return -1;
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
235 }
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
236
40626
4aee3f672f77 Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
237 if (fd == -1 && PyErr_Occurred())
4aee3f672f77 Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
238 return -1;
13591
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
239 if (fd < 0) {
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
240 PyErr_Format(PyExc_ValueError,
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
241 "file descriptor cannot be a negative integer (%i)",
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
242 fd);
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
243 return -1;
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
244 }
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
245 return fd;
2077bf141b37 Added PyObject_AsFileDescriptor, which checks for integer, long integer,
Andrew M. Kuchling <amk@amk.ca>
parents: 13454
diff changeset
246 }
23029
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
247
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
248 /*
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
249 ** Py_UniversalNewlineFgets is an fgets variation that understands
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
250 ** all of \r, \n and \r\n conventions.
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
251 ** The stream should be opened in binary mode.
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
252 ** If fobj is NULL the routine always does newline conversion, and
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
253 ** it may peek one char ahead to gobble the second char in \r\n.
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
254 ** If fobj is non-NULL it must be a PyFileObject. In this case there
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
255 ** is no readahead but in stead a flag is used to skip a following
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
256 ** \n on the next read. Also, if the file is open in binary mode
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
257 ** the whole conversion is skipped. Finally, the routine keeps track of
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
258 ** the different types of newlines seen.
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
259 ** Note that we need no error handling: fgets() treats error and eof
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
260 ** identically.
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
261 */
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
262 char *
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
263 Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj)
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
264 {
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
265 char *p = buf;
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
266 int c;
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
267 int newlinetypes = 0;
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
268 int skipnextlf = 0;
23201
c408e8b2675a Py_UniversalNewlineFread(): Many changes.
Tim Peters <tim.peters@gmail.com>
parents: 23029
diff changeset
269
23029
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
270 if (fobj) {
42071
825041fc8e2c Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents: 42054
diff changeset
271 errno = ENXIO; /* What can you do... */
825041fc8e2c Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents: 42054
diff changeset
272 return NULL;
23029
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
273 }
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
274 FLOCKFILE(stream);
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
275 c = 'x'; /* Shut up gcc warning */
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
276 while (--n > 0 && (c = GETC(stream)) != EOF ) {
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
277 if (skipnextlf ) {
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
278 skipnextlf = 0;
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
279 if (c == '\n') {
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
280 /* Seeing a \n here with skipnextlf true
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
281 ** means we saw a \r before.
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
282 */
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
283 newlinetypes |= NEWLINE_CRLF;
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
284 c = GETC(stream);
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
285 if (c == EOF) break;
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
286 } else {
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
287 /*
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
288 ** Note that c == EOF also brings us here,
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
289 ** so we're okay if the last char in the file
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
290 ** is a CR.
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
291 */
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
292 newlinetypes |= NEWLINE_CR;
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
293 }
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
294 }
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
295 if (c == '\r') {
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
296 /* A \r is translated into a \n, and we skip
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
297 ** an adjacent \n, if any. We don't set the
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
298 ** newlinetypes flag until we've seen the next char.
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
299 */
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
300 skipnextlf = 1;
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
301 c = '\n';
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
302 } else if ( c == '\n') {
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
303 newlinetypes |= NEWLINE_LF;
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
304 }
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
305 *p++ = c;
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
306 if (c == '\n') break;
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
307 }
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
308 if ( c == EOF && skipnextlf )
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
309 newlinetypes |= NEWLINE_CR;
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
310 FUNLOCKFILE(stream);
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
311 *p = '\0';
42071
825041fc8e2c Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents: 42054
diff changeset
312 if ( skipnextlf ) {
23029
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
313 /* If we have no file object we cannot save the
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
314 ** skipnextlf flag. We have to readahead, which
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
315 ** will cause a pause if we're reading from an
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
316 ** interactive stream, but that is very unlikely
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
317 ** unless we're doing something silly like
42552
ac192f89c109 Kill execfile(), use exec() instead
Neal Norwitz <nnorwitz@gmail.com>
parents: 42513
diff changeset
318 ** exec(open("/dev/tty").read()).
23029
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
319 */
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
320 c = GETC(stream);
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
321 if ( c != '\n' )
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
322 ungetc(c, stream);
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
323 }
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
324 if (p == buf)
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
325 return NULL;
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
326 return buf;
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
327 }
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22974
diff changeset
328
43830
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
329 /* **************************** std printer ****************************
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
330 * The stdprinter is used during the boot strapping phase as a preliminary
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
331 * file like object for sys.stderr.
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
332 */
43718
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
333
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
334 typedef struct {
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
335 PyObject_HEAD
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
336 int fd;
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
337 } PyStdPrinter_Object;
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
338
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
339 static PyObject *
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
340 stdprinter_new(PyTypeObject *type, PyObject *args, PyObject *kews)
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
341 {
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
342 PyStdPrinter_Object *self;
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
343
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
344 assert(type != NULL && type->tp_alloc != NULL);
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
345
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
346 self = (PyStdPrinter_Object *) type->tp_alloc(type, 0);
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
347 if (self != NULL) {
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
348 self->fd = -1;
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
349 }
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
350
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
351 return (PyObject *) self;
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
352 }
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
353
43830
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
354 static int
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
355 fileio_init(PyObject *self, PyObject *args, PyObject *kwds)
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
356 {
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
357 PyErr_SetString(PyExc_TypeError,
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
358 "cannot create 'stderrprinter' instances");
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
359 return -1;
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
360 }
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
361
43718
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
362 PyObject *
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
363 PyFile_NewStdPrinter(int fd)
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
364 {
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
365 PyStdPrinter_Object *self;
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
366
43841
ccceaec11442 Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents: 43831
diff changeset
367 if (fd != fileno(stdout) && fd != fileno(stderr)) {
43811
20dc6786f9ac Bug #1415
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
368 /* not enough infrastructure for PyErr_BadInternalCall() */
43718
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
369 return NULL;
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
370 }
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
371
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
372 self = PyObject_New(PyStdPrinter_Object,
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
373 &PyStdPrinter_Type);
43719
04682687817e Minor correction to the stdprinter object.
Guido van Rossum <guido@python.org>
parents: 43718
diff changeset
374 if (self != NULL) {
04682687817e Minor correction to the stdprinter object.
Guido van Rossum <guido@python.org>
parents: 43718
diff changeset
375 self->fd = fd;
04682687817e Minor correction to the stdprinter object.
Guido van Rossum <guido@python.org>
parents: 43718
diff changeset
376 }
43718
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
377 return (PyObject*)self;
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
378 }
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
379
47677
7a8ee05c697f Make stdprinter_write static.
Martin v. Löwis <martin@v.loewis.de>
parents: 47301
diff changeset
380 static PyObject *
43718
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
381 stdprinter_write(PyStdPrinter_Object *self, PyObject *args)
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
382 {
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
383 char *c;
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
384 Py_ssize_t n;
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
385
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
386 if (self->fd < 0) {
43830
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
387 /* fd might be invalid on Windows
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
388 * I can't raise an exception here. It may lead to an
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
389 * unlimited recursion in the case stderr is invalid.
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
390 */
43831
164a6ac94d3c Let's do as Guido says and return None instead of -1
Christian Heimes <christian@cheimes.de>
parents: 43830
diff changeset
391 Py_RETURN_NONE;
43830
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
392 }
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
393
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
394 if (!PyArg_ParseTuple(args, "s", &c)) {
43718
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
395 return NULL;
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
396 }
43830
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
397 n = strlen(c);
43718
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
398
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
399 Py_BEGIN_ALLOW_THREADS
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
400 errno = 0;
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
401 n = write(self->fd, c, n);
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
402 Py_END_ALLOW_THREADS
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
403
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
404 if (n < 0) {
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
405 if (errno == EAGAIN)
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
406 Py_RETURN_NONE;
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
407 PyErr_SetFromErrno(PyExc_IOError);
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
408 return NULL;
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
409 }
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
410
43830
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
411 return PyLong_FromSsize_t(n);
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
412 }
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
413
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
414 static PyObject *
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
415 stdprinter_fileno(PyStdPrinter_Object *self)
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
416 {
44099
f324631462a2 Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents: 43841
diff changeset
417 return PyLong_FromLong((long) self->fd);
43830
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
418 }
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
419
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
420 static PyObject *
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
421 stdprinter_repr(PyStdPrinter_Object *self)
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
422 {
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
423 return PyUnicode_FromFormat("<stdprinter(fd=%d) object at 0x%x>",
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
424 self->fd, self);
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
425 }
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
426
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
427 static PyObject *
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
428 stdprinter_noop(PyStdPrinter_Object *self)
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
429 {
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
430 Py_RETURN_NONE;
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
431 }
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
432
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
433 static PyObject *
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
434 stdprinter_isatty(PyStdPrinter_Object *self)
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
435 {
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
436 long res;
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
437 if (self->fd < 0) {
43831
164a6ac94d3c Let's do as Guido says and return None instead of -1
Christian Heimes <christian@cheimes.de>
parents: 43830
diff changeset
438 Py_RETURN_FALSE;
43830
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
439 }
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
440
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
441 Py_BEGIN_ALLOW_THREADS
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
442 res = isatty(self->fd);
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
443 Py_END_ALLOW_THREADS
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
444
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
445 return PyBool_FromLong(res);
43718
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
446 }
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
447
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
448 static PyMethodDef stdprinter_methods[] = {
43830
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
449 {"close", (PyCFunction)stdprinter_noop, METH_NOARGS, ""},
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
450 {"flush", (PyCFunction)stdprinter_noop, METH_NOARGS, ""},
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
451 {"fileno", (PyCFunction)stdprinter_fileno, METH_NOARGS, ""},
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
452 {"isatty", (PyCFunction)stdprinter_isatty, METH_NOARGS, ""},
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
453 {"write", (PyCFunction)stdprinter_write, METH_VARARGS, ""},
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
454 {NULL, NULL} /*sentinel */
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
455 };
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
456
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
457 static PyObject *
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
458 get_closed(PyStdPrinter_Object *self, void *closure)
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
459 {
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
460 Py_INCREF(Py_False);
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
461 return Py_False;
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
462 }
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
463
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
464 static PyObject *
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
465 get_mode(PyStdPrinter_Object *self, void *closure)
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
466 {
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
467 return PyUnicode_FromString("w");
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
468 }
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
469
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
470 static PyObject *
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
471 get_encoding(PyStdPrinter_Object *self, void *closure)
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
472 {
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
473 Py_RETURN_NONE;
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
474 }
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
475
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
476 static PyGetSetDef stdprinter_getsetlist[] = {
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
477 {"closed", (getter)get_closed, NULL, "True if the file is closed"},
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
478 {"encoding", (getter)get_encoding, NULL, "Encoding of the file"},
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
479 {"mode", (getter)get_mode, NULL, "String giving the file mode"},
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
480 {0},
43718
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
481 };
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
482
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
483 PyTypeObject PyStdPrinter_Type = {
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
484 PyVarObject_HEAD_INIT(&PyType_Type, 0)
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
485 "stderrprinter", /* tp_name */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
486 sizeof(PyStdPrinter_Object), /* tp_basicsize */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
487 0, /* tp_itemsize */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
488 /* methods */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
489 0, /* tp_dealloc */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
490 0, /* tp_print */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
491 0, /* tp_getattr */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
492 0, /* tp_setattr */
51271
87fbbf22adf3 Merged revisions 69214 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 47677
diff changeset
493 0, /* tp_reserved */
43830
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
494 (reprfunc)stdprinter_repr, /* tp_repr */
43718
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
495 0, /* tp_as_number */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
496 0, /* tp_as_sequence */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
497 0, /* tp_as_mapping */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
498 0, /* tp_hash */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
499 0, /* tp_call */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
500 0, /* tp_str */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
501 PyObject_GenericGetAttr, /* tp_getattro */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
502 0, /* tp_setattro */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
503 0, /* tp_as_buffer */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
504 Py_TPFLAGS_DEFAULT, /* tp_flags */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
505 0, /* tp_doc */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
506 0, /* tp_traverse */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
507 0, /* tp_clear */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
508 0, /* tp_richcompare */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
509 0, /* tp_weaklistoffset */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
510 0, /* tp_iter */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
511 0, /* tp_iternext */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
512 stdprinter_methods, /* tp_methods */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
513 0, /* tp_members */
43830
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
514 stdprinter_getsetlist, /* tp_getset */
43718
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
515 0, /* tp_base */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
516 0, /* tp_dict */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
517 0, /* tp_descr_get */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
518 0, /* tp_descr_set */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
519 0, /* tp_dictoffset */
43830
8ed3a95ca114 Stop Python code from instantiating a new stdprinter with sys.stderr.__class__()
Christian Heimes <christian@cheimes.de>
parents: 43811
diff changeset
520 fileio_init, /* tp_init */
43718
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
521 PyType_GenericAlloc, /* tp_alloc */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
522 stdprinter_new, /* tp_new */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
523 PyObject_Del, /* tp_free */
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
524 };
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
525
e510b716bd80 Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents: 43712
diff changeset
526
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37053
diff changeset
527 #ifdef __cplusplus
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37053
diff changeset
528 }
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37053
diff changeset
529 #endif