From 6eb371e076758f198c100b31ae2f69db57b29235 Mon Sep 17 00:00:00 2001 From: GrayJack Date: Thu, 18 Apr 2024 19:37:09 -0300 Subject: [PATCH] fix: Fix some windows warnings --- src/core/buffer.c | 2 +- src/core/capi.c | 12 ++++++------ src/core/ev.c | 8 ++++---- src/core/gc.c | 4 ++-- src/core/io.c | 7 +++---- src/core/os.c | 5 ++--- src/core/parse.c | 6 +++--- src/core/peg.c | 6 +++--- src/core/pp.c | 4 ++-- src/core/specials.c | 2 +- src/core/string.c | 12 ++++++------ src/core/symcache.c | 8 ++++---- src/core/util.c | 2 +- src/core/util.h | 2 +- 14 files changed, 39 insertions(+), 41 deletions(-) diff --git a/src/core/buffer.c b/src/core/buffer.c index 3a56d5b9..dfe1859f 100644 --- a/src/core/buffer.c +++ b/src/core/buffer.c @@ -314,7 +314,7 @@ JANET_CORE_FN(cfun_buffer_chars, return argv[0]; } -static int should_reverse_bytes(const Janet *argv, size_t argc) { +static int should_reverse_bytes(const Janet *argv, int32_t argc) { JanetKeyword order_kw = janet_getkeyword(argv, argc); if (!janet_cstrcmp(order_kw, "le")) { #if JANET_BIG_ENDIAN diff --git a/src/core/capi.c b/src/core/capi.c index b4e8fa92..d4cb7404 100644 --- a/src/core/capi.c +++ b/src/core/capi.c @@ -353,7 +353,7 @@ size_t janet_gethalfrange(const Janet *argv, int32_t n, size_t length, const cha ssize_t not_raw = raw; if (not_raw < 0) not_raw += length + 1; if (not_raw < 0 || (size_t) not_raw > length) - janet_panicf("%s index %d out of range [%o,%o]", which, (int64_t) raw, -(uint64_t)length - 1, (uint64_t) length); + janet_panicf("%s index %d out of range [%d,%d]", which, (int64_t) raw, -(int64_t)length - 1, (int64_t) length); return (size_t) not_raw; } @@ -376,7 +376,7 @@ size_t janet_getargindex(const Janet *argv, int32_t n, size_t length, const char ssize_t not_raw = raw; if (not_raw < 0) not_raw += length; if (not_raw < 0 || (size_t) not_raw > length) - janet_panicf("%s index %d out of range [%o,%o)", which, (int64_t)raw, -(uint64_t)length, (uint64_t)length); + janet_panicf("%s index %d out of range [%d,%d)", which, (int64_t)raw, -(int64_t)length, (int64_t)length); return (size_t) not_raw; } @@ -457,13 +457,13 @@ void janet_setdyn(const char *name, Janet value) { uint64_t janet_getflags(const Janet *argv, int32_t n, const char *flags) { uint64_t ret = 0; const uint8_t *keyw = janet_getkeyword(argv, n); - int32_t klen = janet_string_length(keyw); - int32_t flen = (int32_t) strlen(flags); + size_t klen = janet_string_length(keyw); + size_t flen = strlen(flags); if (flen > 64) { flen = 64; } - for (int32_t j = 0; j < klen; j++) { - for (int32_t i = 0; i < flen; i++) { + for (size_t j = 0; j < klen; j++) { + for (size_t i = 0; i < flen; i++) { if (((uint8_t) flags[i]) == keyw[j]) { ret |= 1ULL << i; goto found; diff --git a/src/core/ev.c b/src/core/ev.c index f20da22f..9e43c232 100644 --- a/src/core/ev.c +++ b/src/core/ev.c @@ -1246,9 +1246,9 @@ static void janet_chanat_marshal(void *p, JanetMarshalContext *ctx) { janet_marshal_byte(ctx, channel->is_threaded); janet_marshal_abstract(ctx, channel); janet_marshal_byte(ctx, channel->closed); - janet_marshal_int(ctx, channel->limit); - int32_t count = janet_q_count(&channel->items); - janet_marshal_int(ctx, count); + janet_marshal_size(ctx, channel->limit); + size_t count = janet_q_count(&channel->items); + janet_marshal_size(ctx, count); JanetQueue *items = &channel->items; Janet *data = channel->items.data; if (items->head <= items->tail) { @@ -2475,7 +2475,7 @@ void ev_callback_write(JanetFiber *fiber, JanetAsyncEvent event) { break; case JANET_ASYNC_EVENT_INIT: { /* Begin write */ - int32_t len; + size_t len; const uint8_t *bytes; if (state->is_buffer) { /* If buffer, convert to string. */ diff --git a/src/core/gc.c b/src/core/gc.c index 462a5b49..1145d576 100644 --- a/src/core/gc.c +++ b/src/core/gc.c @@ -122,7 +122,7 @@ static void janet_mark_abstract(void *adata) { } /* Mark a bunch of items in memory */ -static void janet_mark_many(const Janet *values, int32_t n) { +static void janet_mark_many(const Janet *values, size_t n) { if (values == NULL) return; const Janet *end = values + n; @@ -262,7 +262,7 @@ static void janet_mark_function(JanetFunction *func) { } static void janet_mark_fiber(JanetFiber *fiber) { - int32_t i, j; + size_t i, j; JanetStackFrame *frame; recur: if (janet_gc_reachable(fiber)) diff --git a/src/core/io.c b/src/core/io.c index 20825d08..8eda892b 100644 --- a/src/core/io.c +++ b/src/core/io.c @@ -59,8 +59,7 @@ const JanetAbstractType janet_file_type = { /* Check arguments to fopen */ static int32_t checkflags(const uint8_t *str) { int32_t flags = 0; - int32_t i; - int32_t len = janet_string_length(str); + size_t len = janet_string_length(str); if (!len || len > 10) janet_panic("file mode must have a length between 1 and 10"); switch (*str) { @@ -80,7 +79,7 @@ static int32_t checkflags(const uint8_t *str) { janet_sandbox_assert(JANET_SANDBOX_FS_READ); break; } - for (i = 1; i < len; i++) { + for (size_t i = 1; i < len; i++) { switch (str[i]) { default: janet_panicf("invalid flag %c, expected +, b, or n", str[i]); @@ -489,7 +488,7 @@ static Janet cfun_io_print_impl_x(int32_t argc, Janet *argv, int newline, } } for (int32_t i = offset; i < argc; ++i) { - int32_t len; + size_t len; const uint8_t *vstr; if (janet_checktype(argv[i], JANET_BUFFER)) { JanetBuffer *b = janet_unwrap_buffer(argv[i]); diff --git a/src/core/os.c b/src/core/os.c index a0e626e2..b285192a 100644 --- a/src/core/os.c +++ b/src/core/os.c @@ -1670,9 +1670,8 @@ JANET_CORE_FN(os_cryptorand, "Get or append `n` bytes of good quality random data provided by the OS. Returns a new buffer or `buf`.") { JanetBuffer *buffer; janet_arity(argc, 1, 2); - int32_t offset; - int32_t n = janet_getinteger(argv, 0); - if (n < 0) janet_panic("expected positive integer"); + size_t offset; + size_t n = janet_getsize(argv, 0); if (argc == 2) { buffer = janet_getbuffer(argv, 1); offset = buffer->count; diff --git a/src/core/parse.c b/src/core/parse.c index 6821f51b..2c6eea9e 100644 --- a/src/core/parse.c +++ b/src/core/parse.c @@ -434,8 +434,8 @@ static int stringchar(JanetParser *p, JanetParseState *state, uint8_t c) { } /* Check for string equality in the buffer */ -static int check_str_const(const char *cstr, const uint8_t *str, int32_t len) { - int32_t index; +static int check_str_const(const char *cstr, const uint8_t *str, size_t len) { + size_t index; for (index = 0; index < len; index++) { uint8_t c = str[index]; uint8_t k = ((const uint8_t *)cstr)[index]; @@ -974,7 +974,7 @@ JANET_CORE_FN(cfun_parse_insert, } } else if (s->flags & (PFLAG_STRING | PFLAG_LONGSTRING)) { const uint8_t *str = janet_to_string(argv[1]); - int32_t slen = janet_string_length(str); + size_t slen = janet_string_length(str); size_t newcount = p->bufcount + slen; if (p->bufcap < newcount) { size_t newcap = 2 * newcount; diff --git a/src/core/peg.c b/src/core/peg.c index 72d2ddf9..39fb8263 100644 --- a/src/core/peg.c +++ b/src/core/peg.c @@ -65,9 +65,9 @@ typedef struct { * to save state at branches, and then reload * if one branch fails and try a new branch. */ typedef struct { - int32_t cap; - int32_t tcap; - int32_t scratch; + size_t cap; + size_t tcap; + size_t scratch; } CapState; /* Save the current capture state */ diff --git a/src/core/pp.c b/src/core/pp.c index 569d49da..9bfcb76b 100644 --- a/src/core/pp.c +++ b/src/core/pp.c @@ -134,9 +134,9 @@ static void string_description_b(JanetBuffer *buffer, const char *title, void *p #undef POINTSIZE } -static void janet_escape_string_impl(JanetBuffer *buffer, const uint8_t *str, int32_t len) { +static void janet_escape_string_impl(JanetBuffer *buffer, const uint8_t *str, size_t len) { janet_buffer_push_u8(buffer, '"'); - for (int32_t i = 0; i < len; ++i) { + for (size_t i = 0; i < len; ++i) { uint8_t c = str[i]; switch (c) { case '"': diff --git a/src/core/specials.c b/src/core/specials.c index db343f71..bf2f7517 100644 --- a/src/core/specials.c +++ b/src/core/specials.c @@ -72,7 +72,7 @@ static JanetSlot quasiquote(JanetFopts opts, Janet x, int depth, int level) { default: return janetc_cslot(x); case JANET_TUPLE: { - int32_t i, len; + size_t i, len; const Janet *tup = janet_unwrap_tuple(x); len = janet_tuple_length(tup); if (len > 1 && janet_checktype(tup[0], JANET_SYMBOL)) { diff --git a/src/core/string.c b/src/core/string.c index 824da2f5..a4badf8f 100644 --- a/src/core/string.c +++ b/src/core/string.c @@ -58,8 +58,8 @@ const uint8_t *janet_string(const uint8_t *buf, size_t len) { /* Compare two strings */ int janet_string_compare(const uint8_t *lhs, const uint8_t *rhs) { - int32_t xlen = janet_string_length(lhs); - int32_t ylen = janet_string_length(rhs); + size_t xlen = janet_string_length(lhs); + size_t ylen = janet_string_length(rhs); size_t len = xlen > ylen ? ylen : xlen; int res = memcmp(lhs, rhs, len); if (res) return res > 0 ? 1 : -1; @@ -574,14 +574,14 @@ static int trim_help_checkset(JanetByteView set, uint8_t x) { return 0; } -static int32_t trim_help_leftedge(JanetByteView str, JanetByteView set) { +static size_t trim_help_leftedge(JanetByteView str, JanetByteView set) { for (size_t i = 0; i < str.len; i++) if (!trim_help_checkset(set, str.bytes[i])) return i; return str.len; } -static int32_t trim_help_rightedge(JanetByteView str, JanetByteView set) { +static size_t trim_help_rightedge(JanetByteView str, JanetByteView set) { for (size_t i = str.len - 1; i > 0; i--) if (!trim_help_checkset(set, str.bytes[i])) return i + 1; @@ -605,8 +605,8 @@ JANET_CORE_FN(cfun_string_trim, "`set` is provided, consider only characters in `set` to be whitespace.") { JanetByteView str, set; trim_help_args(argc, argv, &str, &set); - int32_t left_edge = trim_help_leftedge(str, set); - int32_t right_edge = trim_help_rightedge(str, set); + size_t left_edge = trim_help_leftedge(str, set); + size_t right_edge = trim_help_rightedge(str, set); if (right_edge < left_edge) return janet_stringv(NULL, 0); return janet_stringv(str.bytes + left_edge, right_edge - left_edge); diff --git a/src/core/symcache.c b/src/core/symcache.c index 41ce036e..43ce6cbd 100644 --- a/src/core/symcache.c +++ b/src/core/symcache.c @@ -66,7 +66,7 @@ static const uint8_t JANET_SYMCACHE_DELETED[1] = {0}; * where one would put it. */ static const uint8_t **janet_symcache_findmem( const uint8_t *str, - int32_t len, + size_t len, int32_t hash, int *success) { uint32_t bounds[4]; @@ -116,10 +116,10 @@ notfound: janet_symcache_findmem((str), janet_string_length(str), janet_string_hash(str), (success)) /* Resize the cache. */ -static void janet_cache_resize(uint32_t newCapacity) { - uint32_t i, oldCapacity; +static void janet_cache_resize(size_t newCapacity) { + size_t i, oldCapacity; const uint8_t **oldCache = janet_vm.cache; - const uint8_t **newCache = janet_calloc(1, (size_t) newCapacity * sizeof(const uint8_t *)); + const uint8_t **newCache = janet_calloc(1, newCapacity * sizeof(const uint8_t *)); if (newCache == NULL) { JANET_OUT_OF_MEMORY; } diff --git a/src/core/util.c b/src/core/util.c index df255cfa..2d6a7325 100644 --- a/src/core/util.c +++ b/src/core/util.c @@ -690,7 +690,7 @@ static JanetByteView to_byte_view(Janet value) { JanetByteView janet_text_substitution( Janet *subst, const uint8_t *bytes, - uint32_t len, + size_t len, JanetArray *extra_argv) { int32_t extra_argc = extra_argv == NULL ? 0 : extra_argv->count; JanetType type = janet_type(*subst); diff --git a/src/core/util.h b/src/core/util.h index 3ac69a69..0a8cbf88 100644 --- a/src/core/util.h +++ b/src/core/util.h @@ -96,7 +96,7 @@ JanetBinding janet_binding_from_entry(Janet entry); JanetByteView janet_text_substitution( Janet *subst, const uint8_t *bytes, - uint32_t len, + size_t len, JanetArray *extra_args); /* Registry functions */