[Python-checkins] r86854 - in python/branches/py3k: Lib/test/test_os.py Modules/posixmodule.c

brian.curtin python-checkins at python.org
Mon Nov 29 00:59:46 CET 2010


Author: brian.curtin
Date: Mon Nov 29 00:59:46 2010
New Revision: 86854

Log:
Fix for #8879.
Amaury noticed that this was originally written in a way that would fail on
names that can't be encoded with the mbcs codec. Restructured the function
to work with wide names first then narrow names second, to fall in line
with the way other functions are written in posixmodule.c.


Modified:
   python/branches/py3k/Lib/test/test_os.py
   python/branches/py3k/Modules/posixmodule.c

Modified: python/branches/py3k/Lib/test/test_os.py
==============================================================================
--- python/branches/py3k/Lib/test/test_os.py	(original)
+++ python/branches/py3k/Lib/test/test_os.py	Mon Nov 29 00:59:46 2010
@@ -887,6 +887,11 @@
         self._test_link(bytes(self.file1, sys.getfilesystemencoding()),
                         bytes(self.file2, sys.getfilesystemencoding()))
 
+    def test_mbcs_name(self):
+        self.file1 += "\u65e5\u672c"
+        self.file2 = self.file1 + "2"
+        self._test_link(self.file1, self.file2)
+
 if sys.platform != 'win32':
     class Win32ErrorTests(unittest.TestCase):
         pass

Modified: python/branches/py3k/Modules/posixmodule.c
==============================================================================
--- python/branches/py3k/Modules/posixmodule.c	(original)
+++ python/branches/py3k/Modules/posixmodule.c	Mon Nov 29 00:59:46 2010
@@ -2252,6 +2252,22 @@
     char *src, *dst;
     BOOL rslt;
 
+    PyUnicodeObject *usrc, *udst;
+    if (PyArg_ParseTuple(args, "UU:link", &usrc, &udst)) {
+        Py_BEGIN_ALLOW_THREADS
+        rslt = CreateHardLinkW(PyUnicode_AS_UNICODE(udst),
+                               PyUnicode_AS_UNICODE(usrc), NULL);
+        Py_END_ALLOW_THREADS
+
+        if (rslt == 0)
+            return win32_error("link", NULL);
+
+        Py_RETURN_NONE;
+    }
+
+    /* Narrow strings also valid. */
+    PyErr_Clear();
+
     if (!PyArg_ParseTuple(args, "O&O&:link", PyUnicode_FSConverter, &osrc,
                           PyUnicode_FSConverter, &odst))
         return NULL;
@@ -2260,13 +2276,13 @@
     dst = PyBytes_AsString(odst);
 
     Py_BEGIN_ALLOW_THREADS
-    rslt = CreateHardLink(dst, src, NULL);
+    rslt = CreateHardLinkA(dst, src, NULL);
     Py_END_ALLOW_THREADS
 
     Py_DECREF(osrc);
     Py_DECREF(odst);
     if (rslt == 0)
-        return posix_error();
+        return win32_error("link", NULL);
 
     Py_RETURN_NONE;
 }


More information about the Python-checkins mailing list