summaryrefslogtreecommitdiffstats
path: root/Objects/fileobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-10-19 23:16:50 (GMT)
committerGuido van Rossum <guido@python.org>2007-10-19 23:16:50 (GMT)
commitce3a72aec6eaa0293c397c8d0407f7afe0072b2f (patch)
tree646cf27667087a48b908f330759fb94271b43f60 /Objects/fileobject.c
parent75a902db7859a4751743e98530c5d96a672641be (diff)
downloadcpython-ce3a72aec6eaa0293c397c8d0407f7afe0072b2f.zip
cpython-ce3a72aec6eaa0293c397c8d0407f7afe0072b2f.tar.gz
cpython-ce3a72aec6eaa0293c397c8d0407f7afe0072b2f.tar.bz2
Patch 1267 by Christian Heimes.
Move the initialization of sys.std{in,out,err} and __builtin__.open to C code. This solves the problem that "python -S" wouldn't work.
Diffstat (limited to 'Objects/fileobject.c')
-rw-r--r--Objects/fileobject.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index 02675f5..b6d200d 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -28,22 +28,32 @@ extern "C" {
PyObject *
PyFile_FromFile(FILE *fp, char *name, char *mode, int (*close)(FILE *))
{
- PyObject *io, *stream, *nameobj;
+ return PyFile_FromFileEx(fp, name, mode, close, -1, NULL, NULL);
+}
+
+PyObject *
+PyFile_FromFileEx(FILE *fp, char *name, char *mode, int (*close)(FILE *),
+ int buffering, char *encoding, char *newline)
+{
+ PyObject *io, *stream, *nameobj=NULL;
io = PyImport_ImportModule("io");
if (io == NULL)
return NULL;
- stream = PyObject_CallMethod(io, "open", "is", fileno(fp), mode);
- Py_DECREF(io);
+ stream = PyObject_CallMethod(io, "open", "isiss", fileno(fp), mode,
+ buffering, encoding, newline);
+ Py_DECREF(io);
if (stream == NULL)
return NULL;
- nameobj = PyUnicode_FromString(name);
- if (nameobj == NULL)
- PyErr_Clear();
- else {
- if (PyObject_SetAttrString(stream, "name", nameobj) < 0)
+ if (name != NULL) {
+ nameobj = PyUnicode_FromString(name);
+ if (nameobj == NULL)
PyErr_Clear();
- Py_DECREF(nameobj);
+ else {
+ if (PyObject_SetAttrString(stream, "name", nameobj) < 0)
+ PyErr_Clear();
+ Py_DECREF(nameobj);
+ }
}
return stream;
}