diff options
Diffstat (limited to 'Objects/fileobject.c')
-rw-r--r-- | Objects/fileobject.c | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c index b36aa02f0c..500883edf6 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -29,7 +29,7 @@ PyObject * PyFile_FromFd(int fd, char *name, char *mode, int buffering, char *encoding, char *errors, char *newline, int closefd) { - PyObject *io, *stream, *nameobj = NULL; + PyObject *io, *stream; io = PyImport_ImportModule("io"); if (io == NULL) @@ -40,16 +40,8 @@ PyFile_FromFd(int fd, char *name, char *mode, int buffering, char *encoding, Py_DECREF(io); if (stream == NULL) return NULL; - if (name != NULL) { - nameobj = PyUnicode_FromString(name); - if (nameobj == NULL) - PyErr_Clear(); - else { - if (PyObject_SetAttrString(stream, "name", nameobj) < 0) - PyErr_Clear(); - Py_DECREF(nameobj); - } - } + /* ignore name attribute because the name attribute of _BufferedIOMixin + and TextIOWrapper is read only */ return stream; } @@ -208,7 +200,7 @@ PyObject_AsFileDescriptor(PyObject *o) PyObject *meth; if (PyLong_Check(o)) { - fd = PyLong_AsLong(o); + fd = _PyLong_AsInt(o); } else if ((meth = PyObject_GetAttrString(o, "fileno")) != NULL) { @@ -218,7 +210,7 @@ PyObject_AsFileDescriptor(PyObject *o) return -1; if (PyLong_Check(fno)) { - fd = PyLong_AsLong(fno); + fd = _PyLong_AsInt(fno); Py_DECREF(fno); } else { @@ -352,7 +344,7 @@ stdprinter_new(PyTypeObject *type, PyObject *args, PyObject *kews) } static int -fileio_init(PyObject *self, PyObject *args, PyObject *kwds) +stdprinter_init(PyObject *self, PyObject *args, PyObject *kwds) { PyErr_SetString(PyExc_TypeError, "cannot create 'stderrprinter' instances"); @@ -398,7 +390,13 @@ stdprinter_write(PyStdPrinter_Object *self, PyObject *args) Py_BEGIN_ALLOW_THREADS errno = 0; +#if defined(MS_WIN64) || defined(MS_WINDOWS) + if (n > INT_MAX) + n = INT_MAX; + n = write(self->fd, c, (int)n); +#else n = write(self->fd, c, n); +#endif Py_END_ALLOW_THREADS if (n < 0) { @@ -517,7 +515,7 @@ PyTypeObject PyStdPrinter_Type = { 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - fileio_init, /* tp_init */ + stdprinter_init, /* tp_init */ PyType_GenericAlloc, /* tp_alloc */ stdprinter_new, /* tp_new */ PyObject_Del, /* tp_free */ |