From 49c3a65a64c05d149fbaf103b769272f7c0b4942 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 17 Sep 2017 14:02:50 +0100 Subject: [PATCH] Windows fixes after rebase --- README.md | 2 +- configure.ac | 12 +++++++++--- src/rt/jit.c | 2 ++ src/util.c | 34 ++++++++++++++++++++-------------- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index b0ea87be..52eeadf8 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ If you do not already have Cygwin it is easiest to build for MinGW using [MSYS2](https://msys2.github.io/). Install the following dependencies using `pacman`. For 64-bit MSYS2 replace `i686` below with `x86_64`. - pacman -S base-devel mingw-w64-i686-{llvm,ncurses,libffi,dlfcn,check,pkg-config} + pacman -S base-devel mingw-w64-i686-{llvm,ncurses,libffi,check,pkg-config} export PATH=/mingw32/bin:$PATH # Or mingw64 for 64-bit mkdir build && cd build ../configure diff --git a/configure.ac b/configure.ac index 875ebd52..e6d25dcf 100644 --- a/configure.ac +++ b/configure.ac @@ -77,9 +77,15 @@ esac AC_DEFINE_UNQUOTED([EXEEXT], ["$EXEEXT"], [Executable file extension]) -AC_SEARCH_LIBS([dlopen], [dl dld], [], [ - AC_MSG_ERROR([unable to find the dlopen() function]) -]) +case $host_os in + msys*|mingw32*) + ;; + *) + AC_SEARCH_LIBS([dlopen], [dl dld], [], [ + AC_MSG_ERROR([unable to find the dlopen() function]) + ]) + ;; +esac AC_SEARCH_LIBS([pow], [m], [], [ AC_MSG_ERROR([unable to find the pow() function]) diff --git a/src/rt/jit.c b/src/rt/jit.c index c86e4c5f..6d0b483b 100644 --- a/src/rt/jit.c +++ b/src/rt/jit.c @@ -101,6 +101,8 @@ static void *jit_search_loaded_syms(const char *name, bool required) return NULL; +#else // __MINGW32__ + dlerror(); // Clear any previous error void *sym = dlsym(NULL, name); diff --git a/src/util.c b/src/util.c index 976d8aa6..62596ee1 100644 --- a/src/util.c +++ b/src/util.c @@ -62,7 +62,7 @@ #endif #ifdef __CYGWIN__ -#include +#include #endif #if defined(HAVE_UCONTEXT_H) @@ -1533,14 +1533,16 @@ void run_program(const char *const *args, size_t n_args) void file_read_lock(int fd) { #ifdef __MINGW32__ - HANDLE hf; + HANDLE hf = (HANDLE)_get_osfhandle(fd); + LARGE_INTEGER li; + li.QuadPart = _filelengthi64(fd); + OVERLAPPED ovlp; - hf = (HANDLE) _get_osfhandle (fd); - li.QuadPart = _filelengthi64 (fd); memset(&ovlp, 0, sizeof ovlp); - if (!LockFileEx (hf, 0, 0, li.LowPart, li.HighPart, &ovlp)) - fatal_errno("LockFileEx"); + + if (!LockFileEx(hf, 0, 0, li.LowPart, li.HighPart, &ovlp)) + fatal_errno("LockFileEx"); #else if (flock(fd, LOCK_SH) < 0) fatal_errno("flock"); @@ -1550,14 +1552,17 @@ void file_read_lock(int fd) void file_write_lock(int fd) { #ifdef __MINGW32__ - HANDLE hf; + HANDLE hf = (HANDLE)_get_osfhandle(fd); + LARGE_INTEGER li; + li.QuadPart = _filelengthi64(fd); + OVERLAPPED ovlp; - hf = (HANDLE) _get_osfhandle (fd); - li.QuadPart = _filelengthi64 (fd); memset(&ovlp, 0, sizeof ovlp); - if (!LockFileEx (hf, LOCKFILE_EXCLUSIVE_LOCK, 0, li.LowPart, li.HighPart, &ovlp)) - fatal_errno("LockFileEx"); + + if (!LockFileEx(hf, LOCKFILE_EXCLUSIVE_LOCK, 0, + li.LowPart, li.HighPart, &ovlp)) + fatal_errno("LockFileEx"); #else if (flock(fd, LOCK_EX) < 0) fatal_errno("flock"); @@ -1567,11 +1572,12 @@ void file_write_lock(int fd) void file_unlock(int fd) { #ifdef __MINGW32__ - HANDLE hf; + HANDLE hf = (HANDLE)_get_osfhandle(fd); + LARGE_INTEGER li; - hf = (HANDLE) _get_osfhandle (fd); li.QuadPart = _filelengthi64 (fd); - UnlockFile (hf, 0, 0, li.LowPart, li.HighPart); + + UnlockFile(hf, 0, 0, li.LowPart, li.HighPart); #else if (flock(fd, LOCK_UN) < 0) fatal_errno("flock"); -- 2.39.2