1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-10 18:59:54 +00:00

fix: Fix some windows warnings

This commit is contained in:
GrayJack 2024-04-18 19:37:09 -03:00
parent 09c384a2e9
commit 6eb371e076
14 changed files with 39 additions and 41 deletions

View File

@ -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

View File

@ -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;

View File

@ -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. */

View File

@ -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))

View File

@ -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]);

View File

@ -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;

View File

@ -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;

View File

@ -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 */

View File

@ -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 '"':

View File

@ -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)) {

View File

@ -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);

View File

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

View File

@ -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);

View File

@ -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 */