mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
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.
This commit is contained in:
parent
75a902db78
commit
ce3a72aec6
11 changed files with 175 additions and 31 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue