Skip to content

Commit 30061bb

Browse files
Alexpuxnaveen521kk
authored andcommitted
posixmodule.c: Define necessary headers for compiling on MINGW
Also, build `nt` module instead of `posix` when compiling with MINGW. Co-authored-by: Naveen M K <[email protected]> Co-authored-by: Алексей <[email protected]>
1 parent 0a64353 commit 30061bb

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

Modules/Setup.bootstrap.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# module C APIs are used in core
99
atexit atexitmodule.c
1010
faulthandler faulthandler.c
11-
posix posixmodule.c
11+
@INITSYS@ posixmodule.c
1212
_signal signalmodule.c
1313
_tracemalloc _tracemalloc.c
1414

Modules/posixmodule.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,26 @@ corresponding Unix manual entries for more information on calls.");
350350
# define HAVE_CWAIT 1
351351
# define HAVE_FSYNC 1
352352
# define fsync _commit
353+
# elif defined(__MINGW32__) /* GCC for windows hosts */
354+
/* getlogin is detected by configure on mingw-w64 */
355+
# undef HAVE_GETLOGIN
356+
/*# define HAVE_GETCWD 1 - detected by configure*/
357+
# define HAVE_GETPPID 1
358+
# define HAVE_GETLOGIN 1
359+
# define HAVE_SPAWNV 1
360+
# define HAVE_WSPAWNV 1
361+
# define HAVE_WEXECV 1
362+
/*# define HAVE_EXECV 1 - detected by configure*/
363+
# define HAVE_PIPE 1
364+
# define HAVE_POPEN 1
365+
# define HAVE_SYSTEM 1
366+
# define HAVE_CWAIT 1
367+
# define HAVE_FSYNC 1
368+
# define fsync _commit
369+
# include <winioctl.h>
370+
# ifndef _MAX_ENV
371+
# define _MAX_ENV 32767
372+
# endif
353373
# endif /* _MSC_VER */
354374
#endif /* ! __WATCOMC__ || __QNX__ */
355375

@@ -428,7 +448,7 @@ extern char *ctermid_r(char *);
428448
# endif
429449
#endif
430450

431-
#ifdef _MSC_VER
451+
#ifdef MS_WINDOWS
432452
# ifdef HAVE_DIRECT_H
433453
# include <direct.h>
434454
# endif
@@ -439,7 +459,7 @@ extern char *ctermid_r(char *);
439459
# include <process.h>
440460
# endif
441461
# include <malloc.h>
442-
#endif /* _MSC_VER */
462+
#endif /* MS_WINDOWS */
443463

444464
#ifndef MAXPATHLEN
445465
# if defined(PATH_MAX) && PATH_MAX > 1024
@@ -1593,9 +1613,9 @@ win32_get_reparse_tag(HANDLE reparse_point_handle, ULONG *reparse_tag)
15931613
** man environ(7).
15941614
*/
15951615
#include <crt_externs.h>
1596-
#elif !defined(_MSC_VER) && (!defined(__WATCOMC__) || defined(__QNX__) || defined(__VXWORKS__))
1616+
#elif !defined(MS_WINDOWS) && (!defined(__WATCOMC__) || defined(__QNX__) || defined(__VXWORKS__))
15971617
extern char **environ;
1598-
#endif /* !_MSC_VER */
1618+
#endif /* !MS_WINDOWS */
15991619

16001620
static PyObject *
16011621
convertenviron(void)

configure.ac

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,14 @@ then
738738
AC_DEFINE(_INCLUDE__STDC_A1_SOURCE, 1, Define to include mbstate_t for mbrtowc)
739739
fi
740740

741+
AC_MSG_CHECKING([for init system calls])
742+
AC_SUBST(INITSYS)
743+
case $host in
744+
*-*-mingw*) INITSYS=nt;;
745+
*) INITSYS=posix;;
746+
esac
747+
AC_MSG_RESULT([$INITSYS])
748+
741749
# Record the configure-time value of MACOSX_DEPLOYMENT_TARGET,
742750
# it may influence the way we can build extensions, so distutils
743751
# needs to check it

0 commit comments

Comments
 (0)