diff --git a/src/core/buffer.c b/src/core/buffer.c index 3a56d5b92..dfe1859ff 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 b4e8fa921..d4cb74046 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/compile.c b/src/core/compile.c index 2d9a3ebba..8d6613cb3 100644 --- a/src/core/compile.c +++ b/src/core/compile.c @@ -418,12 +418,11 @@ JanetSlot janetc_gettarget(JanetFopts opts) { } /* Get a bunch of slots for function arguments */ -JanetSlot *janetc_toslots(JanetCompiler *c, const Janet *vals, int32_t len) { - int32_t i; +JanetSlot *janetc_toslots(JanetCompiler *c, const Janet *vals, size_t len) { JanetSlot *ret = NULL; JanetFopts subopts = janetc_fopts_default(c); subopts.flags |= JANET_FOPTS_ACCEPT_SPLICE; - for (i = 0; i < len; i++) { + for (size_t i = 0; i < len; i++) { janet_v_push(ret, janetc_value(subopts, vals[i])); } return ret; diff --git a/src/core/compile.h b/src/core/compile.h index 05e6f39b7..e372fb9f4 100644 --- a/src/core/compile.h +++ b/src/core/compile.h @@ -232,7 +232,7 @@ void janetc_throwaway(JanetFopts opts, Janet x); JanetSlot janetc_gettarget(JanetFopts opts); /* Get a bunch of slots for function arguments */ -JanetSlot *janetc_toslots(JanetCompiler *c, const Janet *vals, int32_t len); +JanetSlot *janetc_toslots(JanetCompiler *c, const Janet *vals, size_t len); /* Get a bunch of slots for function arguments */ JanetSlot *janetc_toslotskv(JanetCompiler *c, Janet ds); diff --git a/src/core/debug.c b/src/core/debug.c index 35b2b3316..0a3215e38 100644 --- a/src/core/debug.c +++ b/src/core/debug.c @@ -120,7 +120,7 @@ void janet_stacktrace_ext(JanetFiber *fiber, Janet err, const char *prefix) { for (fi = janet_v_count(fibers) - 1; fi >= 0; fi--) { fiber = fibers[fi]; - int32_t i = fiber->frame; + size_t i = fiber->frame; while (i > 0) { JanetCFunRegistry *reg = NULL; JanetStackFrame *frame = (JanetStackFrame *)(fiber->data + i - JANET_FRAME_SIZE); @@ -374,7 +374,7 @@ JANET_CORE_FN(cfun_debug_stack, JanetFiber *fiber = janet_getfiber(argv, 0); JanetArray *array = janet_array(0); { - int32_t i = fiber->frame; + size_t i = fiber->frame; JanetStackFrame *frame; while (i > 0) { frame = (JanetStackFrame *)(fiber->data + i - JANET_FRAME_SIZE); diff --git a/src/core/ev.c b/src/core/ev.c index f20da22f1..9e43c2324 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/fiber.c b/src/core/fiber.c index 33a945eb3..5660ce091 100644 --- a/src/core/fiber.c +++ b/src/core/fiber.c @@ -288,10 +288,10 @@ int janet_env_valid(JanetFuncEnv *env) { if (env->offset < 0) { int32_t real_offset = -(env->offset); JanetFiber *fiber = env->as.fiber; - int32_t i = fiber->frame; + size_t i = fiber->frame; while (i > 0) { JanetStackFrame *frame = (JanetStackFrame *)(fiber->data + i - JANET_FRAME_SIZE); - if (real_offset == i && + if ((size_t) real_offset == i && frame->env == env && frame->func && frame->func->def->slotcount == env->length) { diff --git a/src/core/gc.c b/src/core/gc.c index 462a5b49b..1145d576b 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 20825d088..8eda892bb 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 1fedd8ce5..0715d1839 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 6821f51bd..2c6eea9e5 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 72d2ddf9f..39fb82632 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 569d49dac..9bfcb76b7 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 db343f716..bf2f75177 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 824da2f5f..a4badf8f4 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 41ce036e7..43ce6cbd2 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 @@ static const uint8_t **janet_symcache_findmem( 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 df255cfa1..2d6a73251 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 3ac69a694..0a8cbf88b 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 */ diff --git a/src/include/janet.h b/src/include/janet.h index bb50bdc46..d4729f5c8 100644 --- a/src/include/janet.h +++ b/src/include/janet.h @@ -975,7 +975,7 @@ struct JanetStackFrame { JanetFunction *func; uint32_t *pc; JanetFuncEnv *env; - int32_t prevframe; + size_t prevframe; int32_t flags; };