[Python-Dev] Assign to errno allowed?

Thomas Heller thomas.heller@ion-tof.com
Tue, 24 Sep 2002 15:24:41 +0200


I'm trying to fix selectmodule.c on Windows (it raises
bogus exceptions, because select() on Windows does not
set errno).
The first patch I had was this:
  
   if (n < 0) {
+ #ifdef MS_WINDOWS
+   PyErr_SetExcFromWindowsErr(SelectError, WSAGetLastError());
+ #else
    PyErr_SetFromErrno(SelectError);
+ #endif
   }
   else if (n == 0) {
                  /* optimization */

but PyErr_SetExcFromWindowsErr is not present in the 2.2
maintainance branch. An easier fix would be this one, but
I wonder if it is allowed/good style to set 'errno':

*** 274,279 ****
--- 274,282 ----
   Py_END_ALLOW_THREADS
  
   if (n < 0) {
+ #ifdef MS_WINDOWS
+   errno = WSAGetLastError();
+ #endif
    PyErr_SetFromErrno(SelectError);
   }
   else if (n == 0) {

Thomas