Skip to content

Commit d0ea0b6

Browse files
committed
Merge branch 'js/msys2' into next
Beginning of the upstreaming process of Git for Windows effort. * js/msys2: mingw: uglify (a, 0) definitions to shut up warnings mingw: squash another warning about a cast mingw: avoid warnings when casting HANDLEs to int mingw: avoid redefining S_* constants compat/winansi: support compiling with MSys2 compat/mingw: support MSys2-based MinGW build nedmalloc: allow compiling with MSys2's compiler config.mak.uname: supporting 64-bit MSys2 config.mak.uname: support MSys2
2 parents 5463f64 + 3a2c0a1 commit d0ea0b6

File tree

7 files changed

+77
-12
lines changed

7 files changed

+77
-12
lines changed

compat/mingw.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "../run-command.h"
77
#include "../cache.h"
88

9+
#define HCAST(type, handle) ((type)(intptr_t)handle)
10+
911
static const int delay[] = { 0, 1, 10, 20, 40 };
1012

1113
int err_win_to_posix(DWORD winerr)
@@ -691,13 +693,13 @@ int pipe(int filedes[2])
691693
errno = err_win_to_posix(GetLastError());
692694
return -1;
693695
}
694-
filedes[0] = _open_osfhandle((int)h[0], O_NOINHERIT);
696+
filedes[0] = _open_osfhandle(HCAST(int, h[0]), O_NOINHERIT);
695697
if (filedes[0] < 0) {
696698
CloseHandle(h[0]);
697699
CloseHandle(h[1]);
698700
return -1;
699701
}
700-
filedes[1] = _open_osfhandle((int)h[1], O_NOINHERIT);
702+
filedes[1] = _open_osfhandle(HCAST(int, h[1]), O_NOINHERIT);
701703
if (filedes[1] < 0) {
702704
close(filedes[0]);
703705
CloseHandle(h[1]);
@@ -1846,7 +1848,8 @@ void mingw_open_html(const char *unixpath)
18461848
die("cannot run browser");
18471849

18481850
printf("Launching default browser to display HTML ...\n");
1849-
r = (int)ShellExecute(NULL, "open", htmlpath, NULL, "\\", SW_SHOWNORMAL);
1851+
r = HCAST(int, ShellExecute(NULL, "open", htmlpath,
1852+
NULL, "\\", SW_SHOWNORMAL));
18501853
FreeLibrary(shell32);
18511854
/* see the MSDN documentation referring to the result codes here */
18521855
if (r <= 32) {

compat/mingw.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,43 @@
1+
#ifdef __MINGW64_VERSION_MAJOR
2+
#include <stdint.h>
3+
#include <wchar.h>
4+
typedef _sigset_t sigset_t;
5+
#endif
16
#include <winsock2.h>
27
#include <ws2tcpip.h>
38

9+
/* MinGW-w64 reports to have flockfile, but it does not actually have it. */
10+
#ifdef __MINGW64_VERSION_MAJOR
11+
#undef _POSIX_THREAD_SAFE_FUNCTIONS
12+
#endif
13+
414
/*
515
* things that are not available in header files
616
*/
717

8-
typedef int pid_t;
918
typedef int uid_t;
1019
typedef int socklen_t;
20+
#ifndef __MINGW64_VERSION_MAJOR
21+
typedef int pid_t;
1122
#define hstrerror strerror
23+
#endif
1224

1325
#define S_IFLNK 0120000 /* Symbolic link */
1426
#define S_ISLNK(x) (((x) & S_IFMT) == S_IFLNK)
1527
#define S_ISSOCK(x) 0
1628

29+
#ifndef S_IRWXG
1730
#define S_IRGRP 0
1831
#define S_IWGRP 0
1932
#define S_IXGRP 0
2033
#define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
34+
#endif
35+
#ifndef S_IRWXO
2136
#define S_IROTH 0
2237
#define S_IWOTH 0
2338
#define S_IXOTH 0
2439
#define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
40+
#endif
2541

2642
#define S_ISUID 0004000
2743
#define S_ISGID 0002000
@@ -100,8 +116,10 @@ static inline int symlink(const char *oldpath, const char *newpath)
100116
{ errno = ENOSYS; return -1; }
101117
static inline int fchmod(int fildes, mode_t mode)
102118
{ errno = ENOSYS; return -1; }
119+
#ifndef __MINGW64_VERSION_MAJOR
103120
static inline pid_t fork(void)
104121
{ errno = ENOSYS; return -1; }
122+
#endif
105123
static inline unsigned int alarm(unsigned int seconds)
106124
{ return 0; }
107125
static inline int fsync(int fd)
@@ -176,8 +194,10 @@ int pipe(int filedes[2]);
176194
unsigned int sleep (unsigned int seconds);
177195
int mkstemp(char *template);
178196
int gettimeofday(struct timeval *tv, void *tz);
197+
#ifndef __MINGW64_VERSION_MAJOR
179198
struct tm *gmtime_r(const time_t *timep, struct tm *result);
180199
struct tm *localtime_r(const time_t *timep, struct tm *result);
200+
#endif
181201
int getpagesize(void); /* defined in MinGW's libgcc.a */
182202
struct passwd *getpwuid(uid_t uid);
183203
int setitimer(int type, struct itimerval *in, struct itimerval *out);
@@ -301,8 +321,10 @@ static inline int getrlimit(int resource, struct rlimit *rlp)
301321
/*
302322
* Use mingw specific stat()/lstat()/fstat() implementations on Windows.
303323
*/
324+
#ifndef __MINGW64_VERSION_MAJOR
304325
#define off_t off64_t
305326
#define lseek _lseeki64
327+
#endif
306328

307329
/* use struct stat with 64 bit st_size */
308330
#ifdef stat
@@ -378,8 +400,12 @@ static inline char *mingw_find_last_dir_sep(const char *path)
378400
int mingw_offset_1st_component(const char *path);
379401
#define offset_1st_component mingw_offset_1st_component
380402
#define PATH_SEP ';'
403+
#ifndef __MINGW64_VERSION_MAJOR
381404
#define PRIuMAX "I64u"
382405
#define PRId64 "I64d"
406+
#else
407+
#include <inttypes.h>
408+
#endif
383409

384410
void mingw_open_html(const char *path);
385411
#define open_html mingw_open_html

compat/nedmalloc/malloc.c.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,9 @@ struct mallinfo {
720720
inlining are defined as macros, so these aren't used for them.
721721
*/
722722

723+
#ifdef __MINGW64_VERSION_MAJOR
724+
#undef FORCEINLINE
725+
#endif
723726
#ifndef FORCEINLINE
724727
#if defined(__GNUC__)
725728
#define FORCEINLINE __inline __attribute__ ((always_inline))
@@ -1382,6 +1385,7 @@ LONG __cdecl _InterlockedExchange(LONG volatile *Target, LONG Value);
13821385

13831386
/*** Atomic operations ***/
13841387
#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) > 40100
1388+
#undef _ReadWriteBarrier
13851389
#define _ReadWriteBarrier() __sync_synchronize()
13861390
#else
13871391
static __inline__ __attribute__((always_inline)) long __sync_lock_test_and_set(volatile long * const Target, const long Value)
@@ -1798,9 +1802,10 @@ struct win32_mlock_t
17981802
volatile long threadid;
17991803
};
18001804

1805+
static inline int return_0(int i) { return 0; }
18011806
#define MLOCK_T struct win32_mlock_t
18021807
#define CURRENT_THREAD win32_getcurrentthreadid()
1803-
#define INITIAL_LOCK(sl) (memset(sl, 0, sizeof(MLOCK_T)), 0)
1808+
#define INITIAL_LOCK(sl) (memset(sl, 0, sizeof(MLOCK_T)), return_0(0))
18041809
#define ACQUIRE_LOCK(sl) win32_acquire_lock(sl)
18051810
#define RELEASE_LOCK(sl) win32_release_lock(sl)
18061811
#define TRY_LOCK(sl) win32_try_lock(sl)

compat/poll/poll.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676

7777
#ifdef WIN32_NATIVE
7878

79-
#define IsConsoleHandle(h) (((long) (h) & 3) == 3)
79+
#define IsConsoleHandle(h) (((long) (intptr_t) (h) & 3) == 3)
8080

8181
static BOOL
8282
IsSocketHandle (HANDLE h)

compat/win32/pthread.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
*/
1919
#define pthread_mutex_t CRITICAL_SECTION
2020

21-
#define pthread_mutex_init(a,b) (InitializeCriticalSection((a)), 0)
21+
static inline int return_0(int i) {
22+
return 0;
23+
}
24+
#define pthread_mutex_init(a,b) return_0((InitializeCriticalSection((a)), 0))
2225
#define pthread_mutex_destroy(a) DeleteCriticalSection((a))
2326
#define pthread_mutex_lock EnterCriticalSection
2427
#define pthread_mutex_unlock LeaveCriticalSection
@@ -77,7 +80,7 @@ extern pthread_t pthread_self(void);
7780

7881
static inline int pthread_exit(void *ret)
7982
{
80-
ExitThread((DWORD)ret);
83+
ExitThread((DWORD)(intptr_t)ret);
8184
}
8285

8386
typedef DWORD pthread_key_t;

compat/winansi.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ static HANDLE hthread, hread, hwrite;
2323
static HANDLE hconsole1, hconsole2;
2424

2525
#ifdef __MINGW32__
26+
#if !defined(__MINGW64_VERSION_MAJOR) || __MINGW64_VERSION_MAJOR < 5
2627
typedef struct _CONSOLE_FONT_INFOEX {
2728
ULONG cbSize;
2829
DWORD nFont;
@@ -32,6 +33,7 @@ typedef struct _CONSOLE_FONT_INFOEX {
3233
WCHAR FaceName[LF_FACESIZE];
3334
} CONSOLE_FONT_INFOEX, *PCONSOLE_FONT_INFOEX;
3435
#endif
36+
#endif
3537

3638
typedef BOOL (WINAPI *PGETCURRENTCONSOLEFONTEX)(HANDLE, BOOL,
3739
PCONSOLE_FONT_INFOEX);
@@ -452,7 +454,8 @@ static HANDLE duplicate_handle(HANDLE hnd)
452454
HANDLE hresult, hproc = GetCurrentProcess();
453455
if (!DuplicateHandle(hproc, hnd, hproc, &hresult, 0, TRUE,
454456
DUPLICATE_SAME_ACCESS))
455-
die_lasterr("DuplicateHandle(%li) failed", (long) hnd);
457+
die_lasterr("DuplicateHandle(%li) failed",
458+
(long) (intptr_t) hnd);
456459
return hresult;
457460
}
458461

config.mak.uname

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,13 +518,12 @@ ifneq (,$(findstring MINGW,$(uname_S)))
518518
NO_INET_NTOP = YesPlease
519519
NO_POSIX_GOODIES = UnfortunatelyYes
520520
DEFAULT_HELP_FORMAT = html
521-
COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -D_USE_32BIT_TIME_T -DNOGDI -Icompat -Icompat/win32
521+
COMPAT_CFLAGS += -DNOGDI -Icompat -Icompat/win32
522522
COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
523523
COMPAT_OBJS += compat/mingw.o compat/winansi.o \
524524
compat/win32/pthread.o compat/win32/syslog.o \
525525
compat/win32/dirent.o
526526
BASIC_CFLAGS += -DPROTECT_NTFS_DEFAULT=1
527-
BASIC_LDFLAGS += -Wl,--large-address-aware
528527
EXTLIBS += -lws2_32
529528
GITLIBS += git.res
530529
PTHREAD_LIBS =
@@ -541,8 +540,34 @@ ifneq (,$(wildcard ../THIS_IS_MSYSGIT))
541540
INTERNAL_QSORT = YesPlease
542541
HAVE_LIBCHARSET_H = YesPlease
543542
NO_GETTEXT = YesPlease
543+
COMPAT_CLFAGS += -D__USE_MINGW_ACCESS
544544
else
545-
NO_CURL = YesPlease
545+
ifeq ($(shell expr "$(uname_R)" : '2\.'),2)
546+
# MSys2
547+
prefix = /usr/
548+
ifeq (MINGW32,$(MSYSTEM))
549+
prefix = /mingw32
550+
endif
551+
ifeq (MINGW64,$(MSYSTEM))
552+
prefix = /mingw64
553+
else
554+
COMPAT_CFLAGS += -D_USE_32BIT_TIME_T
555+
BASIC_LDFLAGS += -Wl,--large-address-aware
556+
endif
557+
CC = gcc
558+
COMPAT_CFLAGS += -D__USE_MINGW_ANSI_STDIO=0
559+
INSTALL = /bin/install
560+
NO_R_TO_GCC_LINKER = YesPlease
561+
INTERNAL_QSORT = YesPlease
562+
HAVE_LIBCHARSET_H = YesPlease
563+
NO_GETTEXT = YesPlease
564+
USE_LIBPCRE= YesPlease
565+
NO_CURL =
566+
USE_NED_ALLOCATOR = YesPlease
567+
else
568+
COMPAT_CFLAGS += -D__USE_MINGW_ANSI_STDIO
569+
NO_CURL = YesPlease
570+
endif
546571
endif
547572
endif
548573
ifeq ($(uname_S),QNX)

0 commit comments

Comments
 (0)