Author: andrewjlawrence
Branch: winoverlapped
Changeset: r96422:afa98536e149
Date: 2019-04-06 14:36 +0100
http://bitbucket.org/pypy/pypy/changeset/afa98536e149/
Log: Replaced calls to _WinError with SetFromWindowsErr
diff --git a/lib_pypy/_overlapped.py b/lib_pypy/_overlapped.py
--- a/lib_pypy/_overlapped.py
+++ b/lib_pypy/_overlapped.py
@@ -20,7 +20,7 @@
GetVersion = _kernel32.GetVersion
NULL = _ffi.NULL
-from _winapi import INVALID_HANDLE_VALUE, _MAX_PATH , _Z
+from _winapi import INVALID_HANDLE_VALUE, _MAX_PATH , _Z, SetFromWindowsErr
import _winapi
#
@@ -181,7 +181,7 @@
if err != _winapi.ERROR_SUCCESS and \
err != _winapi.ERROR_NOT_FOUND and \
err != _winapi.ERROR_OPERATION_ABORTED:
- raise _winapi._WinError()
+ SetFromWindowsErr(err)
if self.overlapped[0].hEvent != 0:
_winapi.CloseHandle(self.overlapped[0].hEvent)
@@ -226,7 +226,7 @@
### If we are to support xp we will need to dynamically load the
below method
result = _kernel32.CancelIoEx(self.handle, self.overlapped)
if (not result and _kernel32.GetLastError() !=
_winapi.ERROR_NOT_FOUND):
- raise _winapi._WinError()
+ SetFromWindowsErr(0)
def WSARecv(self ,handle, size, flags):
handle = _int2handle(handle)
@@ -257,12 +257,12 @@
if self.error == _winapi.ERROR_BROKEN_PIPE:
mark_as_completed(self.overlapped)
- raise _winapi._WinError()
+ SetFromWindowsErr(self.error)
elif self.error in [_winapi.ERROR_SUCCESS, _winapi.ERROR_MORE_DATA,
_winapi.ERROR_IO_PENDING] :
return None
else:
self.type = OverlappedType.TYPE_NOT_STARTED
- raise _winapi._WinError()
+ SetFromWindowsErr(self.error)
def WSASend(self ,handle, bufobj, flags):
handle = _int2handle(handle)
@@ -289,7 +289,7 @@
return None
else:
self.type = OverlappedType.TYPE_NOT_STARTED
- raise _winapi._WinError()
+ SetFromWindowsErr(self.error)
def getresult(self, wait=False):
return self.GetOverlappedResult(wait)
@@ -313,7 +313,7 @@
mark_as_completed(self.overlapped)
return True
else:
- raise _winapi._WinError()
+ SetFromWindowsErr(err)
def ReadFile(self, handle, size):
self.type = OverlappedType.TYPE_READ
@@ -333,12 +333,12 @@
if err == _winapi.ERROR_BROKEN_PIPE:
mark_as_completed(self.overlapped)
- raise _winapi._WinError()
+ SetFromWindowsErr(err)
elif err in [_winapi.ERROR_SUCCESS, _winapi.ERROR_MORE_DATA,
_winapi.ERROR_IO_PENDING]:
return None
else:
self.type = OverlappedType.TYPE_NOT_STARTED
- raise _winapi._WinError()
+ SetFromWindowsErr(err)
def WriteFile(self, handle, buffer):
self.handle = _int2handle(handle)
@@ -362,7 +362,7 @@
return None
else:
self.type = OverlappedType.TYPE_NOT_STARTED
- raise _winapi.WinError()
+ SetFromWindowsErr(self.error)
def AcceptEx(self, listensocket, acceptsocket):
listensocket = _int2handle(listensocket)
@@ -393,7 +393,7 @@
return None
else:
self.type = OverlappedType.TYPE_NOT_STARTED
- raise _winapi.WinError()
+ SetFromWindowsErr(0)
def DisconnectEx(self, socket, flags):
xxx
@@ -428,7 +428,7 @@
return None
else:
self.type = OverlappedType.TYPE_NOT_STARTED
- raise _winapi.WinError()
+ SetFromWindowsErr(0)
@property
def pending(self):
@@ -465,7 +465,7 @@
completionkey,
numberofconcurrentthreads)
if result == _ffi.NULL:
- raise _winapi._WinError()
+ raise SetFromWindowsErr(0)
return result
@@ -516,7 +516,7 @@
miliseconds,
_kernel32.WT_EXECUTEINWAITTHREAD | _kernel32.WT_EXECUTEONLYONCE)
if not ret:
- raise _winapi._WinError()
+ SetFromWindowsErr(0)
return _handle2int(newwaitobject[0])
@@ -533,7 +533,7 @@
err = _kernel32.GetLastError()
if handle == INVALID_HANDLE_VALUE or err == _winapi.ERROR_PIPE_BUSY:
- raise _winapi._WinError()
+ SetFromWindowsErr(err)
return _handle2int(handle)
@@ -542,9 +542,9 @@
waitevent = _int2handle(event)
ret = _kernel32.UnregisterWaitEx(waithandle, waitevent)
-
+
if not ret:
- raise _winapi._WinError()
+ SetFromWindowsErr(0)
def UnregisterWait(handle):
handle = _int2handle(handle)
@@ -552,7 +552,7 @@
ret = _kernel32.UnregisterWait(handle)
if not ret:
- raise _winapi._WinError()
+ SetFromWindowsErr(0)
def BindLocal(socket, family):
socket = _int2handle(socket)
@@ -573,21 +573,7 @@
raise ValueError()
if result == SOCKET_ERROR:
- raise _winapi._WinError()
-
-
-# In CPython this function converts a windows error into a python object
-# Not sure what we should do here.
-def SetFromWindowsErr(err):
- if err == _winapi.ERROR_CONNECTION_REFUSED:
- type = ConnectionRefusedError;
- elif err == _winapi.ERROR_CONNECTION_ABORTED:
- type = ConnectionAbortedError;
- else:
- type = WindowsError;
-
- return _winapi._WinError(type);
-
+ SetFromWindowsErr(0)
def HasOverlappedIoCompleted(overlapped):
return (overlapped.Internal != STATUS_PENDING)
diff --git a/lib_pypy/_winapi.py b/lib_pypy/_winapi.py
--- a/lib_pypy/_winapi.py
+++ b/lib_pypy/_winapi.py
@@ -17,13 +17,26 @@
NULL = _ffi.NULL
# Now the _subprocess module implementation
-
-
def _WinError(type=WindowsError):
code, message = _ffi.getwinerror()
excep = type(None, message, None ,code)
raise excep
+# In CPython this function converts a windows error into a python object
+# Not sure what we should do here.
+def SetFromWindowsErr(err):
+ if err == 0:
+ err = _kernel32.GetLastError()
+
+ if err == ERROR_CONNECTION_REFUSED:
+ type = ConnectionRefusedError
+ elif err == ERROR_CONNECTION_ABORTED:
+ type = ConnectionAbortedError
+ else:
+ type = WindowsError
+
+ return _WinError(type)
+
def _int2handle(val):
return _ffi.cast("HANDLE", val)
@@ -38,20 +51,20 @@
res = _kernel32.CreatePipe(handles, handles + 1, NULL, size)
if not res:
- raise _WinError()
+ SetFromWindowsErr(0)
return _handle2int(handles[0]), _handle2int(handles[1])
def CreateNamedPipe(*args):
handle = _kernel32.CreateNamedPipeW(*args)
if handle == INVALID_HANDLE_VALUE:
- raise _WinError()
+ SetFromWindowsErr(0)
return _handle2int(handle)
def CreateFile(*args):
handle = _kernel32.CreateFileW(*args)
if handle == INVALID_HANDLE_VALUE:
- raise _WinError()
+ SetFromWindowsErr(0)
return _handle2int(handle)
def SetNamedPipeHandleState(namedpipe, mode, max_collection_count,
collect_data_timeout):
@@ -93,7 +106,8 @@
raise RuntimeError('deleting an overlapped struct with a
pending operation not supported')
@property
- def event(self):
+ def event(self):
+ xxx
return None
def GetOverlappedResult(self, wait):
@@ -142,10 +156,10 @@
_kernel32.SetEvent(ov.overlapped[0].hEvent)
else:
del ov
- raise _WinError()
+ SetFromWindowsErr(err)
return ov
elif not success:
- raise _WinError()
+ SetFromWindowsErr(0)
def GetCurrentProcess():
return _handle2int(_kernel32.GetCurrentProcess())
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit