summaryrefslogtreecommitdiff
path: root/Objects/fileobject.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2011-09-28 07:41:54 +0200
committerMartin v. Löwis <martin@v.loewis.de>2011-09-28 07:41:54 +0200
commitd63a3b8beb4a0841cb59fb3515347ccaab34b733 (patch)
tree3b4e3cc63151c5a5a910c3550a190aefaea96ad4 /Objects/fileobject.c
parent48d49497c50e79d14e9df9527d766ca3a0a38be5 (diff)
downloadcpython-git-d63a3b8beb4a0841cb59fb3515347ccaab34b733.tar.gz
Implement PEP 393.
Diffstat (limited to 'Objects/fileobject.c')
-rw-r--r--Objects/fileobject.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index cffa5de068..64215430c5 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -103,23 +103,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;