diff options
| author | 2023-01-21 10:37:34 -0600 | |
|---|---|---|
| committer | 2023-01-21 10:37:34 -0600 | |
| commit | 93b469885a145d4e917bc29e5ac72a17b5aaba4c (patch) | |
| tree | fa60d8d1ddf3605f175ff8f226a6dc40d48f1bc9 | |
| parent | Don't compile library loading code on windows if it is disabled. (diff) | |
Initial Mingw support with Makefile.
Also add a macro JANET_MSVC to distinguish between
a windows build (JANET_WINDOWS) and a build with msvc.
| -rw-r--r-- | Makefile | 6 | ||||
| -rw-r--r-- | src/core/abstract.c | 4 | ||||
| -rw-r--r-- | src/core/ev.c | 8 | ||||
| -rw-r--r-- | src/core/ffi.c | 1 | ||||
| -rw-r--r-- | src/core/net.c | 7 | ||||
| -rw-r--r-- | src/core/os.c | 11 | ||||
| -rw-r--r-- | src/core/util.c | 4 | ||||
| -rw-r--r-- | src/include/janet.h | 5 | ||||
| -rw-r--r-- | src/mainclient/shell.c | 2 | ||||
| -rw-r--r--[-rwxr-xr-x] | tools/format.sh | 0 |
10 files changed, 33 insertions, 15 deletions
@@ -77,6 +77,12 @@ ifeq ($(shell uname -o), Android) endif endif +# Mingw +ifeq ($(findstring MINGW,$(UNAME)), MINGW) + CLIBS:=-lws2_32 -lpsapi -lwsock32 + LDFLAGS:= +endif + $(shell mkdir -p build/core build/c build/boot) all: $(JANET_TARGET) $(JANET_LIBRARY) $(JANET_STATIC_LIBRARY) build/janet.h diff --git a/src/core/abstract.c b/src/core/abstract.c index 9c4740e8..84879801 100644 --- a/src/core/abstract.c +++ b/src/core/abstract.c @@ -98,11 +98,11 @@ size_t janet_os_rwlock_size(void) { } static int32_t janet_incref(JanetAbstractHead *ab) { - return InterlockedIncrement(&ab->gc.data.refcount); + return InterlockedIncrement((LONG volatile *) &ab->gc.data.refcount); } static int32_t janet_decref(JanetAbstractHead *ab) { - return InterlockedDecrement(&ab->gc.data.refcount); + return InterlockedDecrement((LONG volatile *) &ab->gc.data.refcount); } void janet_os_mutex_init(JanetOSMutex *mutex) { diff --git a/src/core/ev.c b/src/core/ev.c index 5ceb075b..5726949b 100644 --- a/src/core/ev.c +++ b/src/core/ev.c @@ -2273,7 +2273,7 @@ JanetAsyncStatus ev_machine_read(JanetListenerState *s, JanetAsyncEvent event) { #ifdef JANET_NET if (state->mode == JANET_ASYNC_READMODE_RECVFROM) { state->wbuf.len = (ULONG) chunk_size; - state->wbuf.buf = state->chunk_buf; + state->wbuf.buf = (char *) state->chunk_buf; status = WSARecvFrom((SOCKET) s->stream->handle, &state->wbuf, 1, NULL, &state->flags, &state->from, &state->fromlen, &state->overlapped, NULL); if (status && (WSA_IO_PENDING != WSAGetLastError())) { @@ -2664,15 +2664,15 @@ int janet_make_pipe(JanetHandle handles[2], int mode) { * so we lift from the windows source code and modify for our own version. */ JanetHandle shandle, chandle; - UCHAR PipeNameBuffer[MAX_PATH]; + CHAR PipeNameBuffer[MAX_PATH]; SECURITY_ATTRIBUTES saAttr; memset(&saAttr, 0, sizeof(saAttr)); saAttr.nLength = sizeof(saAttr); saAttr.bInheritHandle = TRUE; sprintf(PipeNameBuffer, "\\\\.\\Pipe\\JanetPipeFile.%08x.%08x", - GetCurrentProcessId(), - InterlockedIncrement(&PipeSerialNumber)); + (unsigned int) GetCurrentProcessId(), + (unsigned int) InterlockedIncrement(&PipeSerialNumber)); /* server handle goes to subprocess */ shandle = CreateNamedPipeA( diff --git a/src/core/ffi.c b/src/core/ffi.c index 8b578ad7..f48d1ba5 100644 --- a/src/core/ffi.c +++ b/src/core/ffi.c @@ -838,7 +838,6 @@ JANET_CORE_FN(cfun_ffi_signature, } /* Add reference items */ - size_t old_stack_count = stack_count; stack_count += 2 * ref_stack_count; if (stack_count & 0x1) { stack_count++; diff --git a/src/core/net.c b/src/core/net.c index 9ce53cbf..badb0524 100644 --- a/src/core/net.c +++ b/src/core/net.c @@ -34,9 +34,11 @@ #include <windows.h> #include <ws2tcpip.h> #include <mswsock.h> +#ifdef JANET_MSVC #pragma comment (lib, "Ws2_32.lib") #pragma comment (lib, "Mswsock.lib") #pragma comment (lib, "Advapi32.lib") +#endif #else #include <arpa/inet.h> #include <unistd.h> @@ -173,7 +175,6 @@ JanetAsyncStatus net_machine_accept(JanetListenerState *s, JanetAsyncEvent event JANET_NO_RETURN static void janet_sched_accept(JanetStream *stream, JanetFunction *fun) { Janet err; - SOCKET lsock = (SOCKET) stream->handle; JanetListenerState *s = janet_listen(stream, net_machine_accept, JANET_ASYNC_LISTEN_READ, sizeof(NetStateAccept), NULL); NetStateAccept *state = (NetStateAccept *)s; memset(&state->overlapped, 0, sizeof(WSAOVERLAPPED)); @@ -706,7 +707,7 @@ JANET_CORE_FN(cfun_net_getsockname, if (getsockname((JSock)js->handle, (struct sockaddr *) &ss, &slen)) { janet_panicf("Failed to get localname on %v: %V", argv[0], janet_ev_lasterr()); } - janet_assert(slen <= sizeof(ss), "socket address truncated"); + janet_assert(slen <= (socklen_t) sizeof(ss), "socket address truncated"); return janet_so_getname(&ss); } @@ -722,7 +723,7 @@ JANET_CORE_FN(cfun_net_getpeername, if (getpeername((JSock)js->handle, (struct sockaddr *)&ss, &slen)) { janet_panicf("Failed to get peername on %v: %V", argv[0], janet_ev_lasterr()); } - janet_assert(slen <= sizeof(ss), "socket address truncated"); + janet_assert(slen <= (socklen_t) sizeof(ss), "socket address truncated"); return janet_so_getname(&ss); } diff --git a/src/core/os.c b/src/core/os.c index 88422a4c..4d5c8772 100644 --- a/src/core/os.c +++ b/src/core/os.c @@ -445,7 +445,7 @@ typedef struct { static JanetEVGenericMessage janet_proc_wait_subr(JanetEVGenericMessage args) { JanetProc *proc = (JanetProc *) args.argp; WaitForSingleObject(proc->pHandle, INFINITE); - GetExitCodeProcess(proc->pHandle, &args.tag); + GetExitCodeProcess(proc->pHandle, (LPDWORD) &args.tag); return args; } @@ -902,9 +902,6 @@ static Janet os_execute_impl(int32_t argc, Janet *argv, int is_spawn) { janet_panic("failed to create pipes"); } - /* Result */ - int status = 0; - #ifdef JANET_WINDOWS HANDLE pHandle, tHandle; @@ -983,6 +980,9 @@ static Janet os_execute_impl(int32_t argc, Janet *argv, int is_spawn) { #else + /* Result */ + int status = 0; + const char **child_argv = janet_smalloc(sizeof(char *) * ((size_t) exargs.len + 1)); for (int32_t i = 0; i < exargs.len; i++) child_argv[i] = janet_getcstring(exargs.items, i); @@ -1769,9 +1769,11 @@ static Janet os_stat_changed(jstat_t *st) { } #ifdef JANET_WINDOWS static Janet os_stat_blocks(jstat_t *st) { + (void) st; return janet_wrap_number(0); } static Janet os_stat_blocksize(jstat_t *st) { + (void) st; return janet_wrap_number(0); } #else @@ -2047,6 +2049,7 @@ JANET_CORE_FN(os_open, uint32_t stream_flags = 0; JanetHandle fd; #ifdef JANET_WINDOWS + (void) mode; DWORD desiredAccess = 0; DWORD shareMode = 0; DWORD creationDisp = 0; diff --git a/src/core/util.c b/src/core/util.c index 585f0923..4fb4c4ca 100644 --- a/src/core/util.c +++ b/src/core/util.c @@ -39,9 +39,11 @@ #ifdef JANET_WINDOWS #ifdef JANET_DYNAMIC_MODULES #include <psapi.h> +#ifdef JANET_MSVC #pragma comment (lib, "Psapi.lib") #endif #endif +#endif #ifdef JANET_APPLE #include <AvailabilityMacros.h> @@ -863,7 +865,7 @@ int janet_cryptorand(uint8_t *out, size_t n) { unsigned int v; if (rand_s(&v)) return -1; - for (int32_t j = 0; (j < sizeof(unsigned int)) && (i + j < n); j++) { + for (int32_t j = 0; (j < (int32_t) sizeof(unsigned int)) && (i + j < n); j++) { out[i + j] = v & 0xff; v = v >> 8; } diff --git a/src/include/janet.h b/src/include/janet.h index 00a354e8..0eaa2178 100644 --- a/src/include/janet.h +++ b/src/include/janet.h @@ -92,6 +92,11 @@ extern "C" { #define JANET_WINDOWS 1 #endif +/* Check if compiling with MSVC - else assume a GCC-like compiler by default */ +#ifdef _MSC_VER +#define JANET_MSVC +#endif + /* Check 64-bit vs 32-bit */ #if ((defined(__x86_64__) || defined(_M_X64)) \ && (defined(JANET_POSIX) || defined(JANET_WINDOWS))) \ diff --git a/src/mainclient/shell.c b/src/mainclient/shell.c index 34b33956..74fda913 100644 --- a/src/mainclient/shell.c +++ b/src/mainclient/shell.c @@ -296,6 +296,7 @@ static char *sdup(const char *s) { return memcpy(mem, s, len); } +#ifndef _WIN32 static int curpos(void) { char buf[32]; int cols, rows; @@ -311,6 +312,7 @@ static int curpos(void) { if (sscanf(buf + 2, "%d;%d", &rows, &cols) != 2) return -1; return cols; } +#endif static int getcols(void) { #ifdef _WIN32 diff --git a/tools/format.sh b/tools/format.sh index 37e03f26..37e03f26 100755..100644 --- a/tools/format.sh +++ b/tools/format.sh |
