summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-05-14 16:39:10 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-05-14 16:39:10 (GMT)
commit26a968d8feceb1a331b800d3e0c0e28a164b9971 (patch)
treeb6262d12be36c209981545603da8aae9d3799d9a /Modules/posixmodule.c
parent9076f9e187c4a0620b52bff7f3c4659647141783 (diff)
downloadcpython-26a968d8feceb1a331b800d3e0c0e28a164b9971.zip
cpython-26a968d8feceb1a331b800d3e0c0e28a164b9971.tar.gz
cpython-26a968d8feceb1a331b800d3e0c0e28a164b9971.tar.bz2
Merged revisions 81170 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r81170 | victor.stinner | 2010-05-14 18:35:39 +0200 (ven., 14 mai 2010) | 6 lines posix_listdir(), posix_readlink(): avoid temporary PyBytes object Use directly PyUnicode_DecodeFSDefaultAndSize() instead of PyBytes_FromStringAndSize() + PyUnicode_FromEncodedObject() if the argument is unicode. ........
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c48
1 files changed, 10 insertions, 38 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 590a47b..9ce8966 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -2515,33 +2515,17 @@ posix_listdir(PyObject *self, PyObject *args)
(NAMLEN(ep) == 1 ||
(ep->d_name[1] == '.' && NAMLEN(ep) == 2)))
continue;
- v = PyBytes_FromStringAndSize(ep->d_name, NAMLEN(ep));
+ if (arg_is_unicode)
+ v = PyUnicode_DecodeFSDefaultAndSize(ep->d_name, NAMLEN(ep));
+ else
+ v = PyBytes_FromStringAndSize(ep->d_name, NAMLEN(ep));
if (v == NULL) {
- Py_DECREF(d);
- d = NULL;
+ Py_CLEAR(d);
break;
}
- if (arg_is_unicode) {
- PyObject *w;
-
- w = PyUnicode_FromEncodedObject(v,
- Py_FileSystemDefaultEncoding,
- "surrogateescape");
- Py_DECREF(v);
- if (w != NULL)
- v = w;
- else {
- /* Encoding failed to decode ASCII bytes.
- Raise exception. */
- Py_DECREF(d);
- d = NULL;
- break;
- }
- }
if (PyList_Append(d, v) != 0) {
Py_DECREF(v);
- Py_DECREF(d);
- d = NULL;
+ Py_CLEAR(d);
break;
}
Py_DECREF(v);
@@ -4676,22 +4660,10 @@ posix_readlink(PyObject *self, PyObject *args)
return posix_error_with_allocated_filename(opath);
release_bytes(opath);
- v = PyBytes_FromStringAndSize(buf, n);
- if (arg_is_unicode) {
- PyObject *w;
-
- w = PyUnicode_FromEncodedObject(v,
- Py_FileSystemDefaultEncoding,
- "surrogateescape");
- if (w != NULL) {
- Py_DECREF(v);
- v = w;
- }
- else {
- v = NULL;
- }
- }
- return v;
+ if (arg_is_unicode)
+ return PyUnicode_DecodeFSDefaultAndSize(buf, n);
+ else
+ return PyBytes_FromStringAndSize(buf, n);
}
#endif /* HAVE_READLINK */