From aaee576929e1baa4259c69a6655c1527dff49655 Mon Sep 17 00:00:00 2001
From: Naveen M K <naveen521kk@gmail.com>
Date: Mon, 1 Jan 2024 14:14:45 +0530
Subject: [PATCH 105/N] selectmodule: add support for MINGW

---
 Modules/selectmodule.c | 6 +++---
 configure.ac           | 7 ++++++-
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 50788e5..89396f3 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -169,9 +169,9 @@ seq2set(PyObject *seq, fd_set *set, pylist fd2obj[FD_SETSIZE + 1])
         v = PyObject_AsFileDescriptor( o );
         if (v == -1) goto finally;
 
-#if defined(_MSC_VER)
+#if defined(MS_WIN32)
         max = 0;                             /* not used for Win32 */
-#else  /* !_MSC_VER */
+#else  /* !MS_WIN32 */
         if (!_PyIsSelectable_fd(v)) {
             PyErr_SetString(PyExc_ValueError,
                         "filedescriptor out of range in select()");
@@ -179,7 +179,7 @@ seq2set(PyObject *seq, fd_set *set, pylist fd2obj[FD_SETSIZE + 1])
         }
         if (v > max)
             max = v;
-#endif /* _MSC_VER */
+#endif /* MS_WIN32 */
         FD_SET(v, set);
 
         /* add object and its file descriptor to the list */
diff --git a/configure.ac b/configure.ac
index 0a82add..353ff02 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4288,6 +4288,11 @@ AS_CASE([$MACHDEP],
   [MULTIPROCESSING_LIBS=""]
 )
 
+dnl On MINGW, you need to link againt ws2_32 for selectmodule
+AS_CASE([$MACHDEP],
+  [win32], [SELECTMODULE_LIBS="-lws2_32"],
+  [SELECTMODULE_LIBS=""]
+)
 
 dnl detect sqlite3 from Emscripten emport
 PY_CHECK_EMSCRIPTEN_PORT([LIBSQLITE3], [-sUSE_SQLITE3])
@@ -7896,7 +7901,7 @@ PY_STDLIB_MOD_SIMPLE([_opcode])
 PY_STDLIB_MOD_SIMPLE([_pickle])
 PY_STDLIB_MOD_SIMPLE([_queue])
 PY_STDLIB_MOD_SIMPLE([_random])
-PY_STDLIB_MOD_SIMPLE([select])
+PY_STDLIB_MOD_SIMPLE([select], [], [$SELECTMODULE_LIBS])
 PY_STDLIB_MOD_SIMPLE([_struct])
 PY_STDLIB_MOD_SIMPLE([_typing])
 PY_STDLIB_MOD_SIMPLE([_xxsubinterpreters])
