Commits

Amaury Forgeot d'Arc committed af5fc29

After win32-kill branch merge:
- don't import rwin32 on posix platforms
- simplify TerminateProcess error handling

Comments (0)

Files changed (3)

pypy/module/posix/interp_posix.py

 from pypy.interpreter.error import operationerrfmt
 from pypy.rpython.module.ll_os import RegisterOs
 from pypy.rpython.module import ll_os_stat
-from pypy.rlib import rwin32
 from pypy.rpython.lltypesystem import rffi, lltype
 from pypy.rpython.tool import rffi_platform
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
 def kill(space, pid, sig):
     "Kill a process with a signal."
     try:
-        rwin32.os_kill(pid, sig)
+        rposix.os_kill(pid, sig)
     except OSError, e:
         raise wrap_oserror(space, e)
 
     """Abort the interpreter immediately.  This 'dumps core' or otherwise fails
 in the hardest way possible on the hosting operating system."""
     import signal
-    rwin32.os_kill(os.getpid(), signal.SIGABRT)
+    rposix.os_kill(os.getpid(), signal.SIGABRT)
 
 @unwrap_spec(src='str0', dst='str0')
 def link(space, src, dst):

pypy/rlib/rposix.py

             return nt._getfullpathname(path)
         else:
             return nt._getfullpathname(path.as_bytes())
+
+if os.name == 'nt':
+    from rlib import rwin32
+    os_kill = rwin32.os_kill
+else:
+    os_kill = os.kill
+    

pypy/rlib/rwin32.py

 from pypy.translator.platform import CompilationError
 from pypy.rpython.lltypesystem import lltype, rffi
 from pypy.rlib.rarithmetic import intmask
-from pypy.rlib.rposix import validate_fd
 from pypy.rlib import jit
 import os, sys, errno
 
     _get_osfhandle = rffi.llexternal('_get_osfhandle', [rffi.INT], HANDLE)
 
     def get_osfhandle(fd):
+        from pypy.rlib.rposix import validate_fd
         validate_fd(fd)
         handle = _get_osfhandle(fd)
         if handle == INVALID_HANDLE_VALUE:
         handle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
         if handle == NULL_HANDLE:
             raise lastWindowsError('os_kill failed opening process')
-        t = TerminateProcess(handle, sig)
-        if t == 0:
-            err = lastWindowsError('os_kill failed to terminate process')
+        try:
+            if TerminateProcess(handle, sig) == 0:
+                raise lastWindowsError('os_kill failed to terminate process')
+        finally:
             CloseHandle(handle)
-            raise err
-        t = CloseHandle(handle)
-        if t == 0:
-            raise lastWindowsError('os_kill after terminating process,'
-                     ' while closing handle') 
-else:
-    #not win32
-    os_kill = os.kill