[pypy-commit] pypy release-2.2.x: Use getwinerror() here

arigo noreply at buildbot.pypy.org
Tue Nov 12 13:59:34 CET 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: release-2.2.x
Changeset: r67976:7341987b8055
Date: 2013-11-12 13:58 +0100
http://bitbucket.org/pypy/pypy/changeset/7341987b8055/

Log:	Use getwinerror() here

diff --git a/pypy/module/posix/app_startfile.py b/pypy/module/posix/app_startfile.py
--- a/pypy/module/posix/app_startfile.py
+++ b/pypy/module/posix/app_startfile.py
@@ -11,9 +11,9 @@
         """)
         self.NULL = ffi.NULL
         self.cast = ffi.cast
-        self.libK = ffi.dlopen("Kernel32.dll")
-        self.libS = ffi.dlopen("Shell32.dll")
+        self.lib = ffi.dlopen("Shell32.dll")
         self.SW_SHOWNORMAL = 1
+        self.getwinerror = ffi.getwinerror
 
 _cffi_wrapper = None
 
@@ -29,21 +29,16 @@
     if isinstance(filepath, str):
         if isinstance(operation, unicode):
             operation = operation.encode("ascii")
-        rc = w.libS.ShellExecuteA(w.NULL, operation, filepath,
-                                  w.NULL, w.NULL, w.SW_SHOWNORMAL)
+        rc = w.lib.ShellExecuteA(w.NULL, operation, filepath,
+                                 w.NULL, w.NULL, w.SW_SHOWNORMAL)
     elif isinstance(filepath, unicode):
         if isinstance(operation, str):
             operation = operation.decode("ascii")
-        rc = w.libS.ShellExecuteW(w.NULL, operation, filepath,
-                                  w.NULL, w.NULL, w.SW_SHOWNORMAL)
+        rc = w.lib.ShellExecuteW(w.NULL, operation, filepath,
+                                 w.NULL, w.NULL, w.SW_SHOWNORMAL)
     else:
         raise TypeError("argument 1 must be str or unicode")
     rc = int(w.cast("uintptr_t", rc))
     if rc <= 32:
-        code = w.libK.GetLastError()
-        try:
-            import _rawffi
-            msg = _rawffi.FormatError(code)
-        except ImportError:
-            msg = 'Error %s' % code
+        code, msg = w.getwinerror()
         raise WindowsError(code, msg, filepath)


More information about the pypy-commit mailing list