[Python-checkins] cpython: os.statvfs() encodes the filename to the filesystem encoding

victor.stinner python-checkins at python.org
Tue Sep 20 04:04:41 CEST 2011


http://hg.python.org/cpython/rev/e14e70e1a390
changeset:   72420:e14e70e1a390
parent:      72418:2dbd5870de0b
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Tue Sep 20 04:04:33 2011 +0200
summary:
  os.statvfs() encodes the filename to the filesystem encoding

files:
  Modules/posixmodule.c |  20 ++++++++++++--------
  1 files changed, 12 insertions(+), 8 deletions(-)


diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -8071,16 +8071,20 @@
 static PyObject *
 posix_statvfs(PyObject *self, PyObject *args)
 {
-    char *path;
+    PyObject *path;
     int res;
     struct statvfs st;
-    if (!PyArg_ParseTuple(args, "s:statvfs", &path))
-        return NULL;
-    Py_BEGIN_ALLOW_THREADS
-    res = statvfs(path, &st);
-    Py_END_ALLOW_THREADS
-    if (res != 0)
-        return posix_error_with_filename(path);
+    if (!PyArg_ParseTuple(args, "O&:statvfs", PyUnicode_FSConverter, &path))
+        return NULL;
+    Py_BEGIN_ALLOW_THREADS
+    res = statvfs(PyBytes_AS_STRING(path), &st);
+    Py_END_ALLOW_THREADS
+    if (res != 0) {
+        posix_error_with_filename(PyBytes_AS_STRING(path));
+        Py_DECREF(path);
+        return NULL;
+    }
+    Py_DECREF(path);
 
     return _pystatvfs_fromstructstatvfs(st);
 }

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list