diff options
author | R David Murray <rdmurray@bitdance.com> | 2012-04-13 21:27:19 -0400 |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2012-04-13 21:27:19 -0400 |
commit | ea7bc055b08fb442986e0735b1b5b325b0b51ecc (patch) | |
tree | 20c2b837c787daf7e95ece075e6544627b17625a /Objects/fileobject.c | |
parent | c32365d2ce552d1d17279e30a564509235ffb1db (diff) | |
parent | c2c9c905706160bf34aea12f2348210aac3e0da2 (diff) | |
download | cpython-ea7bc055b08fb442986e0735b1b5b325b0b51ecc.tar.gz |
Merge #14399: corrected news item
Diffstat (limited to 'Objects/fileobject.c')
-rw-r--r-- | Objects/fileobject.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c index d20f196b27..e1c47ce372 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -30,11 +30,12 @@ PyFile_FromFd(int fd, char *name, char *mode, int buffering, char *encoding, char *errors, char *newline, int closefd) { PyObject *io, *stream; + _Py_IDENTIFIER(open); io = PyImport_ImportModule("io"); if (io == NULL) return NULL; - stream = PyObject_CallMethod(io, "open", "isisssi", fd, mode, + stream = _PyObject_CallMethodId(io, &PyId_open, "isisssi", fd, mode, buffering, encoding, errors, newline, closefd); Py_DECREF(io); @@ -58,8 +59,9 @@ PyFile_GetLine(PyObject *f, int n) { PyObject *reader; PyObject *args; + _Py_IDENTIFIER(readline); - reader = PyObject_GetAttrString(f, "readline"); + reader = _PyObject_GetAttrId(f, &PyId_readline); if (reader == NULL) return NULL; if (n <= 0) @@ -103,23 +105,18 @@ PyFile_GetLine(PyObject *f, int n) } } if (n < 0 && result != NULL && PyUnicode_Check(result)) { - Py_UNICODE *s = PyUnicode_AS_UNICODE(result); - Py_ssize_t len = PyUnicode_GET_SIZE(result); + Py_ssize_t len = PyUnicode_GET_LENGTH(result); if (len == 0) { Py_DECREF(result); result = NULL; PyErr_SetString(PyExc_EOFError, "EOF when reading a line"); } - else if (s[len-1] == '\n') { - if (result->ob_refcnt == 1) - PyUnicode_Resize(&result, len-1); - else { - PyObject *v; - v = PyUnicode_FromUnicode(s, len-1); - Py_DECREF(result); - result = v; - } + else if (PyUnicode_READ_CHAR(result, len-1) == '\n') { + PyObject *v; + v = PyUnicode_Substring(result, 0, len-1); + Py_DECREF(result); + result = v; } } return result; @@ -131,11 +128,13 @@ int PyFile_WriteObject(PyObject *v, PyObject *f, int flags) { PyObject *writer, *value, *args, *result; + _Py_IDENTIFIER(write); + if (f == NULL) { PyErr_SetString(PyExc_TypeError, "writeobject with NULL file"); return -1; } - writer = PyObject_GetAttrString(f, "write"); + writer = _PyObject_GetAttrId(f, &PyId_write); if (writer == NULL) return -1; if (flags & Py_PRINT_RAW) { @@ -198,11 +197,12 @@ PyObject_AsFileDescriptor(PyObject *o) { int fd; PyObject *meth; + _Py_IDENTIFIER(fileno); if (PyLong_Check(o)) { fd = PyLong_AsLong(o); } - else if ((meth = PyObject_GetAttrString(o, "fileno")) != NULL) + else if ((meth = _PyObject_GetAttrId(o, &PyId_fileno)) != NULL) { PyObject *fno = PyEval_CallObject(meth, NULL); Py_DECREF(meth); @@ -297,8 +297,8 @@ Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj) *p++ = c; if (c == '\n') break; } - if ( c == EOF && skipnextlf ) - newlinetypes |= NEWLINE_CR; + /* if ( c == EOF && skipnextlf ) + newlinetypes |= NEWLINE_CR; */ FUNLOCKFILE(stream); *p = '\0'; if ( skipnextlf ) { |