Skip to content

Commit

Permalink
posixmodule.c: Define necessary headers for compiling on MINGW
Browse files Browse the repository at this point in the history
Also, build `nt` module instead of `posix` when compiling
with MINGW.

Co-authored-by: Naveen M K <[email protected]>
Co-authored-by: Алексей <[email protected]>
  • Loading branch information
2 people authored and lazka committed Aug 25, 2023
1 parent 02755c9 commit b971ecc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Modules/Setup.bootstrap.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# module C APIs are used in core
atexit atexitmodule.c
faulthandler faulthandler.c
posix posixmodule.c
@INITSYS@ posixmodule.c
_signal signalmodule.c
_tracemalloc _tracemalloc.c

Expand Down
28 changes: 24 additions & 4 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,26 @@ corresponding Unix manual entries for more information on calls.");
# define HAVE_CWAIT 1
# define HAVE_FSYNC 1
# define fsync _commit
# elif defined(__MINGW32__) /* GCC for windows hosts */
/* getlogin is detected by configure on mingw-w64 */
# undef HAVE_GETLOGIN
/*# define HAVE_GETCWD 1 - detected by configure*/
# define HAVE_GETPPID 1
# define HAVE_GETLOGIN 1
# define HAVE_SPAWNV 1
# define HAVE_WSPAWNV 1
# define HAVE_WEXECV 1
/*# define HAVE_EXECV 1 - detected by configure*/
# define HAVE_PIPE 1
# define HAVE_POPEN 1
# define HAVE_SYSTEM 1
# define HAVE_CWAIT 1
# define HAVE_FSYNC 1
# define fsync _commit
# include <winioctl.h>
# ifndef _MAX_ENV
# define _MAX_ENV 32767
# endif
# endif /* _MSC_VER */
#endif /* ! __WATCOMC__ || __QNX__ */

Expand Down Expand Up @@ -428,7 +448,7 @@ extern char *ctermid_r(char *);
# endif
#endif

#ifdef _MSC_VER
#ifdef MS_WINDOWS
# ifdef HAVE_DIRECT_H
# include <direct.h>
# endif
Expand All @@ -439,7 +459,7 @@ extern char *ctermid_r(char *);
# include <process.h>
# endif
# include <malloc.h>
#endif /* _MSC_VER */
#endif /* MS_WINDOWS */

#ifndef MAXPATHLEN
# if defined(PATH_MAX) && PATH_MAX > 1024
Expand Down Expand Up @@ -1593,9 +1613,9 @@ win32_get_reparse_tag(HANDLE reparse_point_handle, ULONG *reparse_tag)
** man environ(7).
*/
#include <crt_externs.h>
#elif !defined(_MSC_VER) && (!defined(__WATCOMC__) || defined(__QNX__) || defined(__VXWORKS__))
#elif !defined(MS_WINDOWS) && (!defined(__WATCOMC__) || defined(__QNX__) || defined(__VXWORKS__))
extern char **environ;
#endif /* !_MSC_VER */
#endif /* !MS_WINDOWS */

static PyObject *
convertenviron(void)
Expand Down
8 changes: 8 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,14 @@ then
AC_DEFINE(_INCLUDE__STDC_A1_SOURCE, 1, Define to include mbstate_t for mbrtowc)
fi

AC_MSG_CHECKING([for init system calls])
AC_SUBST(INITSYS)
case $host in
*-*-mingw*) INITSYS=nt;;
*) INITSYS=posix;;
esac
AC_MSG_RESULT([$INITSYS])

# Record the configure-time value of MACOSX_DEPLOYMENT_TARGET,
# it may influence the way we can build extensions, so distutils
# needs to check it
Expand Down

0 comments on commit b971ecc

Please sign in to comment.