[pypy-svn] r76221 - in pypy/branch/unicode_filename-2/pypy: module/posix rlib rpython/module
afa at codespeak.net
afa at codespeak.net
Thu Jul 15 01:21:20 CEST 2010
Author: afa
Date: Thu Jul 15 01:21:18 2010
New Revision: 76221
Modified:
pypy/branch/unicode_filename-2/pypy/module/posix/interp_posix.py
pypy/branch/unicode_filename-2/pypy/rlib/rposix.py
pypy/branch/unicode_filename-2/pypy/rlib/rwin32.py
pypy/branch/unicode_filename-2/pypy/rpython/module/ll_os.py
Log:
unicode version of nt._getfullpathname()
Modified: pypy/branch/unicode_filename-2/pypy/module/posix/interp_posix.py
==============================================================================
--- pypy/branch/unicode_filename-2/pypy/module/posix/interp_posix.py (original)
+++ pypy/branch/unicode_filename-2/pypy/module/posix/interp_posix.py Thu Jul 15 01:21:18 2010
@@ -320,14 +320,13 @@
def _getfullpathname(space, path):
"""helper for ntpath.abspath """
- posix = __import__(os.name) # nt specific
try:
- fullpath = posix._getfullpathname(path)
+ dispatch_filename(rposix._getfullpathname)(space, w_path)
except OSError, e:
- raise wrap_oserror(space, e, path)
- else:
+ raise wrap_oserror2(space, e, w_path)
+ else:
return space.wrap(fullpath)
-_getfullpathname.unwrap_spec = [ObjSpace, str]
+_getfullpathname.unwrap_spec = [ObjSpace, W_Root]
def getcwd(space):
"""Return the current working directory."""
Modified: pypy/branch/unicode_filename-2/pypy/rlib/rposix.py
==============================================================================
--- pypy/branch/unicode_filename-2/pypy/rlib/rposix.py (original)
+++ pypy/branch/unicode_filename-2/pypy/rlib/rposix.py Thu Jul 15 01:21:18 2010
@@ -109,3 +109,11 @@
return os.rmdir(path)
else:
return os.rmdir(path.encode())
+
+if os.name == 'nt':
+ import nt
+ def _getfullpathname(path):
+ if isinstance(path, str):
+ return nt._getfullpathname(path)
+ else:
+ return nt._getfullpathname(path.encode())
Modified: pypy/branch/unicode_filename-2/pypy/rlib/rwin32.py
==============================================================================
--- pypy/branch/unicode_filename-2/pypy/rlib/rwin32.py (original)
+++ pypy/branch/unicode_filename-2/pypy/rlib/rwin32.py Thu Jul 15 01:21:18 2010
@@ -39,6 +39,7 @@
LPCVOID = rffi_platform.SimpleType("LPCVOID", rffi.VOIDP)
LPSTR = rffi_platform.SimpleType("LPSTR", rffi.CCHARP)
LPCSTR = rffi_platform.SimpleType("LPCSTR", rffi.CCHARP)
+ LPWSTR = rffi_platform.SimpleType("LPWSTR", rffi.CWCHARP)
LPCWSTR = rffi_platform.SimpleType("LPCWSTR", rffi.CWCHARP)
LPDWORD = rffi_platform.SimpleType("LPDWORD", rffi.INTP)
SIZE_T = rffi_platform.SimpleType("SIZE_T", rffi.SIZE_T)
Modified: pypy/branch/unicode_filename-2/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/branch/unicode_filename-2/pypy/rpython/module/ll_os.py (original)
+++ pypy/branch/unicode_filename-2/pypy/rpython/module/ll_os.py Thu Jul 15 01:21:18 2010
@@ -968,7 +968,6 @@
# to get a correct implementation of os.abspath
# XXX why do we ignore WINAPI conventions everywhere?
LPSTRP = rffi.CArrayPtr(rwin32.LPSTR)
- # XXX unicode?
GetFullPathName = self.llexternal(
'GetFullPathNameA',
[rwin32.LPCSTR,
@@ -996,6 +995,41 @@
"ll_os.posix__getfullpathname",
llimpl=_getfullpathname_llimpl)
+ @registering_unicode_version(getattr(posix, '_getfullpathname', None),
+ 1, [0], sys.platform=='win32')
+ def register_posix__getfullpathname_unicode(self):
+ from pypy.rlib import rwin32
+ # this nt function is not exposed via os, but needed
+ # to get a correct implementation of os.abspath
+ # XXX why do we ignore WINAPI conventions everywhere?
+ LPWSTRP = rffi.CArrayPtr(rwin32.LPWSTR)
+ GetFullPathName = self.llexternal(
+ 'GetFullPathNameW',
+ [rwin32.LPCWSTR,
+ rwin32.DWORD,
+ rwin32.LPSTR,
+ rffi.CArrayPtr(rwin32.LPWSTR)],
+ rwin32.DWORD)
+
+ def _getfullpathname_llimpl(lpFileName):
+ nBufferLength = rwin32.MAX_PATH + 1
+ lpBuffer = lltype.malloc(rwin32.LPWSTR.TO, nBufferLength, flavor='raw')
+ try:
+ res = GetFullPathName(
+ lpFileName, rffi.cast(rwin32.DWORD, nBufferLength),
+ lpBuffer, lltype.nullptr(LPWSTRP.TO))
+ if res == 0:
+ raise rwin32.lastWindowsError("_getfullpathname failed")
+ result = rffi.wcharp2unicode(lpBuffer)
+ return result
+ finally:
+ lltype.free(lpBuffer, flavor='raw')
+
+ return extdef([unicode], # a single argument which is a str
+ unicode, # returns a string
+ "ll_os.posix__wgetfullpathname",
+ llimpl=_getfullpathname_llimpl)
+
@registering(os.getcwd)
def register_os_getcwd(self):
os_getcwd = self.llexternal(underscore_on_windows + 'getcwd',
More information about the Pypy-commit
mailing list