[pypy-commit] pypy default: #2895 Test and fix for rposix.getfullpathname()

arigo pypy.commits at gmail.com
Fri Sep 28 05:52:42 EDT 2018


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r95170:94d034975108
Date: 2018-09-28 11:50 +0200
http://bitbucket.org/pypy/pypy/changeset/94d034975108/

Log:	#2895 Test and fix for rposix.getfullpathname()

diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -730,16 +730,21 @@
     length = rwin32.MAX_PATH + 1
     traits = _preferred_traits(path)
     win32traits = make_win32_traits(traits)
-    with traits.scoped_alloc_buffer(length) as buf:
-        res = win32traits.GetFullPathName(
-            traits.as_str0(path), rffi.cast(rwin32.DWORD, length),
-            buf.raw, lltype.nullptr(win32traits.LPSTRP.TO))
-        if res == 0:
-            raise rwin32.lastSavedWindowsError("_getfullpathname failed")
-        result = buf.str(intmask(res))
-        assert result is not None
-        result = rstring.assert_str0(result)
-        return result
+    while True:      # should run the loop body maximum twice
+        with traits.scoped_alloc_buffer(length) as buf:
+            res = win32traits.GetFullPathName(
+                traits.as_str0(path), rffi.cast(rwin32.DWORD, length),
+                buf.raw, lltype.nullptr(win32traits.LPSTRP.TO))
+            res = intmask(res)
+            if res == 0:
+                raise rwin32.lastSavedWindowsError("_getfullpathname failed")
+            if res >= length:
+                length = res + 1
+                continue
+            result = buf.str(res)
+            assert result is not None
+            result = rstring.assert_str0(result)
+            return result
 
 c_getcwd = external(UNDERSCORE_ON_WIN32 + 'getcwd',
                     [rffi.CCHARP, rffi.SIZE_T], rffi.CCHARP,
diff --git a/rpython/rlib/test/test_rposix.py b/rpython/rlib/test/test_rposix.py
--- a/rpython/rlib/test/test_rposix.py
+++ b/rpython/rlib/test/test_rposix.py
@@ -83,6 +83,14 @@
         # the most intriguing failure of ntpath.py should not repeat, here:
         assert not data.endswith(stuff)
 
+    @win_only
+    def test__getfullpathname_long(self):
+        stuff = "C:" + "\\abcd" * 100
+        py.test.raises(WindowsError, rposix.getfullpathname, stuff)
+        ustuff = u"C:" + u"\\abcd" * 100
+        res = rposix.getfullpathname(ustuff)
+        assert res == ustuff
+
     def test_getcwd(self):
         assert rposix.getcwd() == os.getcwd()
 


More information about the pypy-commit mailing list