From 1f5ae4a8da0a794b436743087760162d80fd1fe7 Mon Sep 17 00:00:00 2001 From: Bo Date: Tue, 22 Oct 2024 15:35:29 +0300 Subject: [PATCH] small fixes + windows compatibility --- ext/iodine/fio-stl.h | 15 +++++++-------- ext/iodine/iodine_cli.h | 4 ++++ ext/iodine/iodine_connection.h | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ext/iodine/fio-stl.h b/ext/iodine/fio-stl.h index a03ddb4..5047585 100644 --- a/ext/iodine/fio-stl.h +++ b/ext/iodine/fio-stl.h @@ -3136,7 +3136,7 @@ Memory allocation macros /** Frees allocated memory. */ #define FIO_MEM_FREE(ptr, size) fio_free((ptr)) /** Set to true of internall allocator is used (memory returned set to zero). */ -#define FIO_MEM_REALLOC_IS_SAFE 1 +#define FIO_MEM_REALLOC_IS_SAFE fio_realloc_is_safe() #else /* H___FIO_MALLOC___H */ /** Reallocates memory, copying (at least) `copy_len` if necessary. */ @@ -10791,12 +10791,12 @@ SFUNC int fio_sock_open2(const char *url, uint16_t flags) { /** Sets a file descriptor / socket to non blocking state. */ SFUNC int fio_sock_set_non_block(int fd) { /* If they have O_NONBLOCK, use the Posix way to do it */ -#if defined(O_NONBLOCK) +#if defined(O_NONBLOCK) && defined(F_GETFL) && defined(F_SETFL) /* Fixme: O_NONBLOCK is defined but broken on SunOS 4.1.x and AIX 3.2.5. */ int flags; if (-1 == (flags = fcntl(fd, F_GETFL, 0))) flags = 0; -#ifdef O_CLOEXEC +#if defined(O_CLOEXEC) return fcntl(fd, F_SETFL, flags | O_NONBLOCK | O_CLOEXEC); #else return fcntl(fd, F_SETFL, flags | O_NONBLOCK); @@ -26479,8 +26479,8 @@ FIO_IFUNC int FIO_NAME(FIO_MAP_NAME, (FIO_NAME(FIO_MAP_NAME, node_s) *)FIO_MEM_REALLOC_(NULL, 0, s, 0); if (!n) return -1; - // if (!FIO_MEM_REALLOC_IS_SAFE_) /* set only imap to zero */ - FIO_MEMSET((n + (1ULL << bits)), 0, (1ULL << bits)); + if (!FIO_MEM_REALLOC_IS_SAFE_) /* set only imap to zero */ + FIO_MEMSET((n + (1ULL << bits)), 0, (1ULL << bits)); *o = (FIO_NAME(FIO_MAP_NAME, s)){.map = n, .bits = bits}; FIO_LEAK_COUNTER_ON_ALLOC(FIO_NAME(FIO_MAP_NAME, destroy)); return 0; @@ -27250,7 +27250,7 @@ SFUNC void FIO_NAME(FIO_MAP_NAME, compact)(FIO_MAP_PTR map) { FIO_NAME(FIO_MAP_NAME, s) *o = FIO_PTR_TAG_GET_UNTAGGED(FIO_MAP_T, map); if (!o->map || !o->count) return; - FIO_NAME(FIO_MAP_NAME, s) cpy = {0}, tmp; + FIO_NAME(FIO_MAP_NAME, s) cpy = {0}; uint32_t bits = o->bits; while (FIO_MAP_CAPA(bits >> 1) > o->count) bits >>= 1; @@ -27268,9 +27268,8 @@ SFUNC void FIO_NAME(FIO_MAP_NAME, compact)(FIO_MAP_PTR map) { return; finish: - tmp = o[0]; + FIO_NAME(FIO_MAP_NAME, __free_map)(o, 0); o[0] = cpy; - FIO_NAME(FIO_MAP_NAME, __free_map)(&tmp, 0); return; } diff --git a/ext/iodine/iodine_cli.h b/ext/iodine/iodine_cli.h index 120cc61..e4b6e73 100644 --- a/ext/iodine/iodine_cli.h +++ b/ext/iodine/iodine_cli.h @@ -228,7 +228,11 @@ static VALUE iodine_cli_parse(VALUE self, VALUE required) { FIO_STRING_WRITE_STR2(u.query.buf, u.query.len)); fio_cli_set("-b", url.buf); } else { +#if FIO_OS_WIN + SetEnvironmentVariable("PORT", fio_cli_get("-p")); +#else setenv("PORT", fio_cli_get("-p"), 1); +#endif } } diff --git a/ext/iodine/iodine_connection.h b/ext/iodine/iodine_connection.h index bb1267d..4efadff 100644 --- a/ext/iodine/iodine_connection.h +++ b/ext/iodine/iodine_connection.h @@ -947,7 +947,7 @@ static VALUE iodine_handler_deafult_on_http(VALUE handler, VALUE client) { .copy = 1, .finish = 1); } else if (rb_respond_to(bd, IODINE_TO_PATH_ID)) { /* named file body... */ - VALUE p = rb_funcall(bd, IODINE_TO_PATH_ID, 0, NULL); + VALUE p = rb_funcallv(bd, IODINE_TO_PATH_ID, 0, NULL); if (!RB_TYPE_P(p, RUBY_T_STRING)) goto rack_error; /* FIXME? something else? */ if (fio_http_static_file_response(c->http,