Commits

Armin Rigo  committed af978ad

Windows: don't muck with LastError in b_get_errno()
and b_set_errno()

  • Participants
  • Parent commits 6b188ac

Comments (0)

Files changed (2)

File c/_cffi_backend.c

 # else
 #  include "misc_thread.h"
 # endif
+# define save_errno_only      save_errno
+# define restore_errno_only   restore_errno
 #endif
 
 #ifdef HAVE_WCHAR_H
 static PyObject *b_get_errno(PyObject *self, PyObject *noarg)
 {
     int err;
-    restore_errno();
+    restore_errno_only();
     err = errno;
     errno = 0;
     return PyInt_FromLong(err);
     if (!PyArg_ParseTuple(args, "i:set_errno", &i))
         return NULL;
     errno = i;
-    save_errno();
+    save_errno_only();
     errno = 0;
     Py_INCREF(Py_None);
     return Py_None;

File c/misc_win32.h

     /* else: cannot report the error */
 }
 
+static void save_errno_only(void)
+{
+    int current_err = errno;
+    struct cffi_errno_s *p;
+
+    p = _geterrno_object();
+    if (p != NULL) {
+        p->saved_errno = current_err;
+    }
+    /* else: cannot report the error */
+}
+
 static void restore_errno(void)
 {
     struct cffi_errno_s *p;
     /* else: cannot report the error */
 }
 
+static void restore_errno_only(void)
+{
+    struct cffi_errno_s *p;
+
+    p = _geterrno_object();
+    if (p != NULL) {
+        errno = p->saved_errno;
+    }
+    /* else: cannot report the error */
+}
 
 /************************************************************/
 /* Emulate dlopen()&co. from the Windows API */