Skip to content

Commit

Permalink
fix: Fix some windows warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
GrayJack committed Apr 18, 2024
1 parent 2f62f02 commit 6fd6eef
Show file tree
Hide file tree
Showing 19 changed files with 47 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/core/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/core/capi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions src/core/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/core/compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/core/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/core/ev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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. */
Expand Down
4 changes: 2 additions & 2 deletions src/core/fiber.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down
7 changes: 3 additions & 4 deletions src/core/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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]);
Expand Down Expand Up @@ -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]);
Expand Down
5 changes: 2 additions & 3 deletions src/core/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/core/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/core/peg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions src/core/pp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 '"':
Expand Down
2 changes: 1 addition & 1 deletion src/core/specials.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
12 changes: 6 additions & 6 deletions src/core/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/core/symcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/core/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/include/janet.h
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ struct JanetStackFrame {
JanetFunction *func;
uint32_t *pc;
JanetFuncEnv *env;
int32_t prevframe;
size_t prevframe;
int32_t flags;
};

Expand Down

0 comments on commit 6fd6eef

Please sign in to comment.