From 5ff6e607908debe9251eb6f58d70302f55bd2d80 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 4 Jul 2024 15:26:48 +0300 Subject: [PATCH 01/12] void* casting --- cutils.c | 4 +- libbf.c | 64 +++---- libregexp.c | 10 +- libunicode.c | 2 +- qjs.c | 10 +- qjsc.c | 4 +- quickjs-libc.c | 90 +++++----- quickjs.c | 476 ++++++++++++++++++++++++------------------------- run-test262.c | 24 +-- unicode_gen.c | 16 +- 10 files changed, 350 insertions(+), 350 deletions(-) diff --git a/cutils.c b/cutils.c index 56982dfa7..25a687159 100644 --- a/cutils.c +++ b/cutils.c @@ -121,7 +121,7 @@ int dbuf_realloc(DynBuf *s, size_t new_size) size = s->allocated_size * 3 / 2; if (size > new_size) new_size = size; - new_buf = s->realloc_func(s->opaque, s->buf, new_size); + new_buf = (uint8_t *)s->realloc_func(s->opaque, s->buf, new_size); if (!new_buf) { s->error = TRUE; return -1; @@ -1039,7 +1039,7 @@ void rqsort(void *base, size_t nmemb, size_t size, cmp_f cmp, void *opaque) /* select median of 3 from 1/4, 1/2, 3/4 positions */ /* should use median of 5 or 9? */ m4 = (nmemb >> 2) * size; - m = med3(ptr + m4, ptr + 2 * m4, ptr + 3 * m4, cmp, opaque); + m = (uint8_t *)med3(ptr + m4, ptr + 2 * m4, ptr + 3 * m4, cmp, opaque); swap(ptr, m, size); /* move the pivot to the start or the array */ i = lt = 1; pi = plt = ptr + size; diff --git a/libbf.c b/libbf.c index 7c5bdb45a..92d6f0b8b 100644 --- a/libbf.c +++ b/libbf.c @@ -211,7 +211,7 @@ int bf_resize(bf_t *r, limb_t len) limb_t *tab; if (len != r->len) { - tab = bf_realloc(r->ctx, r->tab, len * sizeof(limb_t)); + tab = (limb_t *)bf_realloc(r->ctx, r->tab, len * sizeof(limb_t)); if (!tab && len != 0) return -1; r->tab = tab; @@ -1372,8 +1372,8 @@ int mp_recip(bf_context_t *s, limb_t *tabr, const limb_t *taba, limb_t n) if (n <= 2) { /* return ceil(B^(2*n)/a) - 1 */ /* XXX: could avoid allocation */ - tabu = bf_malloc(s, sizeof(limb_t) * (2 * n + 1)); - tabt = bf_malloc(s, sizeof(limb_t) * (n + 2)); + tabu = (limb_t *)bf_malloc(s, sizeof(limb_t) * (2 * n + 1)); + tabt = (limb_t *)bf_malloc(s, sizeof(limb_t) * (n + 2)); if (!tabt || !tabu) goto fail; for(i = 0; i < 2 * n; i++) @@ -1393,8 +1393,8 @@ int mp_recip(bf_context_t *s, limb_t *tabr, const limb_t *taba, limb_t n) /* n=2p -> l=p-1, h = p + 1, k = p + 3 n=2p+1-> l=p, h = p + 1; k = p + 2 */ - tabt = bf_malloc(s, sizeof(limb_t) * (n + h + 1)); - tabu = bf_malloc(s, sizeof(limb_t) * (n + 2 * h - l + 2)); + tabt = (limb_t *)bf_malloc(s, sizeof(limb_t) * (n + h + 1)); + tabu = (limb_t *)bf_malloc(s, sizeof(limb_t) * (n + 2 * h - l + 2)); if (!tabt || !tabu) goto fail; tabxh = tabr + l; @@ -1461,8 +1461,8 @@ static int mp_divnorm_large(bf_context_t *s, n = nq; if (nq < nb) n++; - tabb_inv = bf_malloc(s, sizeof(limb_t) * (n + 1)); - tabt = bf_malloc(s, sizeof(limb_t) * 2 * (n + 1)); + tabb_inv = (limb_t *)bf_malloc(s, sizeof(limb_t) * (n + 1)); + tabt = (limb_t *)bf_malloc(s, sizeof(limb_t) * 2 * (n + 1)); if (!tabb_inv || !tabt) goto fail; @@ -1501,7 +1501,7 @@ static int mp_divnorm_large(bf_context_t *s, tabb_inv = NULL; /* R=A-B*Q */ - tabt = bf_malloc(s, sizeof(limb_t) * (na + 1)); + tabt = (limb_t *)bf_malloc(s, sizeof(limb_t) * (na + 1)); if (!tabt) goto fail; if (mp_mul(s, tabt, tabq, nq + 1, tabb, nb)) @@ -1710,7 +1710,7 @@ static int __bf_div(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec, slimb_t d; na = n + nb; - taba = bf_malloc(s, (na + 1) * sizeof(limb_t)); + taba = (limb_t *)bf_malloc(s, (na + 1) * sizeof(limb_t)); if (!taba) goto fail; d = na - a->len; @@ -2073,7 +2073,7 @@ int mp_sqrtrem(bf_context_t *s, limb_t *tabs, limb_t *taba, limb_t n) if (n2 <= countof(tmp_buf1)) { tmp_buf = tmp_buf1; } else { - tmp_buf = bf_malloc(s, sizeof(limb_t) * n2); + tmp_buf = (limb_t *)bf_malloc(s, sizeof(limb_t) * n2); if (!tmp_buf) return -1; } @@ -2169,7 +2169,7 @@ int bf_sqrt(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags) n = (2 * (prec + 2) + 2 * LIMB_BITS - 1) / (2 * LIMB_BITS); if (bf_resize(r, n)) goto fail; - a1 = bf_malloc(s, sizeof(limb_t) * 2 * n); + a1 = (limb_t *)bf_malloc(s, sizeof(limb_t) * 2 * n); if (!a1) goto fail; n1 = bf_min(2 * n, a->len); @@ -2755,7 +2755,7 @@ static int bf_integer_from_radix(bf_t *r, const limb_t *tab, radixl = get_limb_radix(radix); pow_tab_len = ceil_log2(n) + 2; /* XXX: check */ - pow_tab = bf_malloc(s, sizeof(pow_tab[0]) * pow_tab_len); + pow_tab = (bf_t *)bf_malloc(s, sizeof(pow_tab[0]) * pow_tab_len); if (!pow_tab) return -1; for(i = 0; i < pow_tab_len; i++) @@ -2854,7 +2854,7 @@ static int bf_add_limb(bf_t *a, slimb_t *ppos, limb_t v) if (unlikely(pos < 0)) { limb_t new_size, d, *new_tab; new_size = bf_max(a->len + 1, a->len * 3 / 2); - new_tab = bf_realloc(a->ctx, a->tab, sizeof(limb_t) * new_size); + new_tab = (limb_t *)bf_realloc(a->ctx, a->tab, sizeof(limb_t) * new_size); if (!new_tab) return -1; a->tab = new_tab; @@ -3481,7 +3481,7 @@ static int bf_integer_to_radix(bf_t *r, const bf_t *a, limb_t radixl) r_len = r->len; pow_tab_len = (ceil_log2(r_len) + 2) * 2; /* XXX: check */ - pow_tab = bf_malloc(s, sizeof(pow_tab[0]) * pow_tab_len); + pow_tab = (bf_t *)bf_malloc(s, sizeof(pow_tab[0]) * pow_tab_len); if (!pow_tab) return -1; for(i = 0; i < pow_tab_len; i++) @@ -3708,7 +3708,7 @@ static void output_digits(DynBuf *s, const bf_t *a1, int radix, limb_t n_digits, static void *bf_dbuf_realloc(void *opaque, void *ptr, size_t size) { - bf_context_t *s = opaque; + bf_context_t *s = (bf_context_t *)opaque; return bf_realloc(s, ptr, size); } @@ -4586,7 +4586,7 @@ int bf_log(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags) static int bf_pow_generic(bf_t *r, const bf_t *x, limb_t prec, void *opaque) { bf_context_t *s = r->ctx; - const bf_t *y = opaque; + const bf_t *y = (bf_t *)opaque; bf_t T_s, *T = &T_s; limb_t prec1; @@ -4607,7 +4607,7 @@ static int bf_pow_generic(bf_t *r, const bf_t *x, limb_t prec, void *opaque) static int bf_pow_int(bf_t *r, const bf_t *x, limb_t prec, void *opaque) { bf_context_t *s = r->ctx; - const bf_t *y = opaque; + const bf_t *y = (bf_t *)opaque; bf_t T_s, *T = &T_s; limb_t prec1; int ret; @@ -5196,7 +5196,7 @@ int bf_atan(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags) static int bf_atan2_internal(bf_t *r, const bf_t *y, limb_t prec, void *opaque) { bf_context_t *s = r->ctx; - const bf_t *x = opaque; + const bf_t *x = (bf_t *)opaque; bf_t T_s, *T = &T_s; limb_t prec1; int ret; @@ -5863,7 +5863,7 @@ static int mp_div_dec(bf_context_t *s, limb_t *tabq, if (likely(nb <= DIV_STATIC_ALLOC_LEN)) { tabb = static_tabb; } else { - tabb = bf_malloc(s, sizeof(limb_t) * nb); + tabb = (limb_t *)bf_malloc(s, sizeof(limb_t) * nb); if (!tabb) return -1; } @@ -6065,7 +6065,7 @@ int mp_sqrtrem_dec(bf_context_t *s, limb_t *tabs, limb_t *taba, limb_t n) if (n2 <= countof(tmp_buf1)) { tmp_buf = tmp_buf1; } else { - tmp_buf = bf_malloc(s, sizeof(limb_t) * n2); + tmp_buf = (limb_t *)bf_malloc(s, sizeof(limb_t) * n2); if (!tmp_buf) return -1; } @@ -6636,7 +6636,7 @@ static int bfdec_add_internal(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, li b1_tab = (limb_t *)b->tab; } else { b1_len = b->len + 1; - b1_tab = bf_malloc(s, sizeof(limb_t) * b1_len); + b1_tab = (limb_t *)bf_malloc(s, sizeof(limb_t) * b1_len); if (!b1_tab) goto fail; b1_tab[0] = mp_shr_dec(b1_tab + 1, b->tab, b->len, b_shift, 0) * @@ -6847,7 +6847,7 @@ static int __bfdec_div(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, slimb_t d; na = n + nb; - taba = bf_malloc(r->ctx, (na + 1) * sizeof(limb_t)); + taba = (limb_t *)bf_malloc(r->ctx, (na + 1) * sizeof(limb_t)); if (!taba) goto fail; d = na - a->len; @@ -7071,7 +7071,7 @@ int bfdec_sqrt(bfdec_t *r, const bfdec_t *a, limb_t prec, bf_flags_t flags) n = (2 * (prec1 + 2) + 2 * LIMB_DIGITS - 1) / (2 * LIMB_DIGITS); if (bfdec_resize(r, n)) goto fail; - a1 = bf_malloc(s, sizeof(limb_t) * 2 * n); + a1 = (limb_t *)bf_malloc(s, sizeof(limb_t) * 2 * n); if (!a1) goto fail; n1 = bf_min(2 * n, a->len); @@ -7798,9 +7798,9 @@ static no_inline NTTLimb *get_trig(BFNTTState *s, n2 = (limb_t)1 << (k - 1); m = ntt_mods[m_idx]; #ifdef __AVX2__ - tab = ntt_malloc(s, sizeof(NTTLimb) * n2); + tab = (NTTLimb *)ntt_malloc(s, sizeof(NTTLimb) * n2); #else - tab = ntt_malloc(s, sizeof(NTTLimb) * n2 * 2); + tab = (NTTLimb *)ntt_malloc(s, sizeof(NTTLimb) * n2 * 2); #endif if (!tab) return NULL; @@ -7855,7 +7855,7 @@ static int ntt_fft_partial(BFNTTState *s, NTTLimb *buf1, NTTLimb *buf2, *buf3; buf2 = NULL; - buf3 = ntt_malloc(s, sizeof(NTTLimb) * n1); + buf3 = (NTTLimb *)ntt_malloc(s, sizeof(NTTLimb) * n1); if (!buf3) goto fail; if (k2 == 0) { @@ -7863,7 +7863,7 @@ static int ntt_fft_partial(BFNTTState *s, NTTLimb *buf1, goto fail; } else { strip_len = STRIP_LEN; - buf2 = ntt_malloc(s, sizeof(NTTLimb) * n1 * strip_len); + buf2 = (NTTLimb *)ntt_malloc(s, sizeof(NTTLimb) * n1 * strip_len); if (!buf2) goto fail; m = ntt_mods[m_idx]; @@ -8198,9 +8198,9 @@ static int ntt_static_init(bf_context_t *s1) if (s1->ntt_state) return 0; #if defined(__AVX2__) - s = bf_aligned_malloc(s1, sizeof(*s), 64); + s = (BFNTTState *)bf_aligned_malloc(s1, sizeof(*s), 64); #else - s = bf_malloc(s1, sizeof(*s)); + s = (BFNTTState *)bf_malloc(s1, sizeof(*s)); #endif if (!s) return -1; @@ -8339,7 +8339,7 @@ static no_inline int fft_mul(bf_context_t *s1, a_len = b_len; b_len = tmp_len; } - buf1 = ntt_malloc(s, sizeof(NTTLimb) * fft_len * nb_mods); + buf1 = (NTTLimb *)ntt_malloc(s, sizeof(NTTLimb) * fft_len * nb_mods); if (!buf1) return -1; limb_to_ntt(s, buf1, fft_len, a_tab, a_len, dpl, @@ -8351,7 +8351,7 @@ static no_inline int fft_mul(bf_context_t *s1, } reduced_mem = (fft_len_log2 >= 14); if (!reduced_mem) { - buf2 = ntt_malloc(s, sizeof(NTTLimb) * fft_len * nb_mods); + buf2 = (NTTLimb *)ntt_malloc(s, sizeof(NTTLimb) * fft_len * nb_mods); if (!buf2) goto fail; limb_to_ntt(s, buf2, fft_len, b_tab, b_len, dpl, @@ -8359,7 +8359,7 @@ static no_inline int fft_mul(bf_context_t *s1, if (!(mul_flags & FFT_MUL_R_NORESIZE)) bf_resize(res, 0); /* in case res == b */ } else { - buf2 = ntt_malloc(s, sizeof(NTTLimb) * fft_len); + buf2 = (NTTLimb *)ntt_malloc(s, sizeof(NTTLimb) * fft_len); if (!buf2) goto fail; } diff --git a/libregexp.c b/libregexp.c index e372f2749..eaa9e8319 100644 --- a/libregexp.c +++ b/libregexp.c @@ -1979,7 +1979,7 @@ static BOOL is_word_char(uint32_t c) if (_p < _end) \ if (is_lo_surrogate(*_p)) \ c = from_surrogate(c, *_p++); \ - cptr = (const void *)_p; \ + cptr = (const uint8_t *)_p; \ } \ } while (0) @@ -2029,7 +2029,7 @@ static BOOL is_word_char(uint32_t c) if (_p > _start) \ if (is_hi_surrogate(_p[-1])) \ c = from_surrogate(*--_p, c); \ - cptr = (const void *)_p; \ + cptr = (const uint8_t *)_p; \ } \ } while (0) @@ -2045,7 +2045,7 @@ static BOOL is_word_char(uint32_t c) if (_p > _start) \ if (is_hi_surrogate(_p[-1])) \ _p--; \ - cptr = (const void *)_p; \ + cptr = (const uint8_t *)_p; \ } \ } while (0) @@ -2101,7 +2101,7 @@ static int push_state(REExecContext *s, new_size = s->state_stack_size * 3 / 2; if (new_size < 8) new_size = 8; - new_stack = lre_realloc(s->opaque, s->state_stack, new_size * s->state_size); + new_stack = (uint8_t *)lre_realloc(s->opaque, s->state_stack, new_size * s->state_size); if (!new_stack) return -1; s->state_stack_size = new_size; @@ -2569,7 +2569,7 @@ int lre_exec(uint8_t **capture, for(i = 0; i < s->capture_count * 2; i++) capture[i] = NULL; alloca_size = s->stack_size_max * sizeof(stack_buf[0]); - stack_buf = alloca(alloca_size); + stack_buf = (StackInt *)alloca(alloca_size); ret = lre_exec_backtrack(s, capture, stack_buf, 0, bc_buf + RE_HEADER_LEN, cbuf + (cindex << cbuf_type), FALSE); lre_realloc(s->opaque, s->state_stack, 0); diff --git a/libunicode.c b/libunicode.c index f0b514691..ab5963745 100644 --- a/libunicode.c +++ b/libunicode.c @@ -299,7 +299,7 @@ int cr_realloc(CharRange *cr, int size) if (size > cr->size) { new_size = max_int(size, cr->size * 3 / 2); - new_buf = cr->realloc_func(cr->mem_opaque, cr->points, + new_buf = (uint32_t *)cr->realloc_func(cr->mem_opaque, cr->points, new_size * sizeof(cr->points[0])); if (!new_buf) return -1; diff --git a/qjs.c b/qjs.c index a293a1754..60e28013b 100644 --- a/qjs.c +++ b/qjs.c @@ -52,7 +52,7 @@ static int eval_buf(JSContext *ctx, const void *buf, int buf_len, if ((eval_flags & JS_EVAL_TYPE_MASK) == JS_EVAL_TYPE_MODULE) { /* for the modules, we compile then run to be able to set import.meta */ - val = JS_Eval(ctx, buf, buf_len, filename, + val = JS_Eval(ctx, (const char *)buf, buf_len, filename, eval_flags | JS_EVAL_FLAG_COMPILE_ONLY); if (!JS_IsException(val)) { js_module_set_import_meta(ctx, val, TRUE, TRUE); @@ -60,7 +60,7 @@ static int eval_buf(JSContext *ctx, const void *buf, int buf_len, } val = js_std_await(ctx, val); } else { - val = JS_Eval(ctx, buf, buf_len, filename, eval_flags); + val = JS_Eval(ctx, (const char *)buf, buf_len, filename, eval_flags); } if (JS_IsException(val)) { js_std_dump_error(ctx); @@ -194,12 +194,12 @@ __attribute__((format(printf, 2, 3))) if (c == '%') { /* only handle %p and %zd */ if (*fmt == 'p') { - uint8_t *ptr = va_arg(ap, void *); + uint8_t *ptr = (uint8_t *)va_arg(ap, void *); if (ptr == NULL) { printf("NULL"); } else { printf("H%+06lld.%zd", - js_trace_malloc_ptr_offset(ptr, s->opaque), + js_trace_malloc_ptr_offset(ptr, (struct trace_malloc_data *)s->opaque), js__malloc_usable_size(ptr)); } fmt++; @@ -219,7 +219,7 @@ __attribute__((format(printf, 2, 3))) static void js_trace_malloc_init(struct trace_malloc_data *s) { - free(s->base = malloc(8)); + free(s->base = (uint8_t *)malloc(8)); } static void *js_trace_malloc(JSMallocState *s, size_t size) diff --git a/qjsc.c b/qjsc.c index 33dccce4d..0b079bd16 100644 --- a/qjsc.c +++ b/qjsc.c @@ -72,7 +72,7 @@ void namelist_add(namelist_t *lp, const char *name, const char *short_name, if (lp->count == lp->size) { size_t newsize = lp->size + (lp->size >> 1) + 4; namelist_entry_t *a = - realloc(lp->array, sizeof(lp->array[0]) * newsize); + (namelist_entry_t *)realloc(lp->array, sizeof(lp->array[0]) * newsize); /* XXX: check for realloc failure */ lp->array = a; lp->size = newsize; @@ -264,7 +264,7 @@ JSModuleDef *jsc_module_loader(JSContext *ctx, output_object_code(ctx, outfile, func_val, cname, TRUE); /* the module is already referenced, so we must free it */ - m = JS_VALUE_GET_PTR(func_val); + m = (JSModuleDef *)JS_VALUE_GET_PTR(func_val); JS_FreeValue(ctx, func_val); } return m; diff --git a/quickjs-libc.c b/quickjs-libc.c index a594d742e..f781202e5 100644 --- a/quickjs-libc.c +++ b/quickjs-libc.c @@ -409,9 +409,9 @@ uint8_t *js_load_file(JSContext *ctx, size_t *pbuf_len, const char *filename) if (fseek(f, 0, SEEK_SET) < 0) goto fail; if (ctx) - buf = js_malloc(ctx, buf_len + 1); + buf = (uint8_t *)js_malloc(ctx, buf_len + 1); else - buf = malloc(buf_len + 1); + buf = (uint8_t *)malloc(buf_len + 1); if (!buf) goto fail; if (fread(buf, 1, buf_len, f) != buf_len) { @@ -499,7 +499,7 @@ static JSModuleDef *js_module_loader_so(JSContext *ctx, if (!strchr(module_name, '/')) { /* must add a '/' so that the DLL is not searched in the system library paths */ - filename = js_malloc(ctx, strlen(module_name) + 2 + 1); + filename = (char *)js_malloc(ctx, strlen(module_name) + 2 + 1); if (!filename) return NULL; strcpy(filename, "./"); @@ -548,7 +548,7 @@ int js_module_set_import_meta(JSContext *ctx, JSValue func_val, const char *module_name; assert(JS_VALUE_GET_TAG(func_val) == JS_TAG_MODULE); - m = JS_VALUE_GET_PTR(func_val); + m = (JSModuleDef *)JS_VALUE_GET_PTR(func_val); module_name_atom = JS_GetModuleName(ctx, m); module_name = JS_AtomToCString(ctx, module_name_atom); @@ -619,7 +619,7 @@ JSModuleDef *js_module_loader(JSContext *ctx, /* XXX: could propagate the exception */ js_module_set_import_meta(ctx, func_val, TRUE, FALSE); /* the module is already referenced, so we must free it */ - m = JS_VALUE_GET_PTR(func_val); + m = (JSModuleDef *)JS_VALUE_GET_PTR(func_val); JS_FreeValue(ctx, func_val); } return m; @@ -772,7 +772,7 @@ static JSValue js_evalScript(JSContext *ctx, JSValue this_val, int argc, JSValue *argv) { JSRuntime *rt = JS_GetRuntime(ctx); - JSThreadState *ts = JS_GetRuntimeOpaque(rt); + JSThreadState *ts = (JSThreadState *)JS_GetRuntimeOpaque(rt); const char *str; size_t len; JSValue ret; @@ -827,7 +827,7 @@ typedef struct { static void js_std_file_finalizer(JSRuntime *rt, JSValue val) { - JSSTDFile *s = JS_GetOpaque(val, js_std_file_class_id); + JSSTDFile *s = (JSSTDFile *)JS_GetOpaque(val, js_std_file_class_id); if (s) { if (s->f && s->close_in_finalizer) { #if !defined(__wasi__) @@ -866,7 +866,7 @@ static JSValue js_new_std_file(JSContext *ctx, FILE *f, obj = JS_NewObjectClass(ctx, js_std_file_class_id); if (JS_IsException(obj)) return obj; - s = js_mallocz(ctx, sizeof(*s)); + s = (JSSTDFile *)js_mallocz(ctx, sizeof(*s)); if (!s) { JS_FreeValue(ctx, obj); return JS_EXCEPTION; @@ -1020,7 +1020,7 @@ static JSValue js_std_printf(JSContext *ctx, JSValue this_val, static FILE *js_std_file_get(JSContext *ctx, JSValue obj) { - JSSTDFile *s = JS_GetOpaque2(ctx, obj, js_std_file_class_id); + JSSTDFile *s = (JSSTDFile *)JS_GetOpaque2(ctx, obj, js_std_file_class_id); if (!s) return NULL; if (!s->f) { @@ -1059,7 +1059,7 @@ static JSValue js_std_file_puts(JSContext *ctx, JSValue this_val, static JSValue js_std_file_close(JSContext *ctx, JSValue this_val, int argc, JSValue *argv) { - JSSTDFile *s = JS_GetOpaque2(ctx, this_val, js_std_file_class_id); + JSSTDFile *s = (JSSTDFile *)JS_GetOpaque2(ctx, this_val, js_std_file_class_id); int err; if (!s) return JS_EXCEPTION; @@ -1408,7 +1408,7 @@ static JSValue js_std_urlGet(JSContext *ctx, JSValue this_val, js_std_dbuf_init(ctx, data_buf); js_std_dbuf_init(ctx, header_buf); - buf = js_malloc(ctx, URL_GET_BUF_SIZE); + buf = (char *)js_malloc(ctx, URL_GET_BUF_SIZE); if (!buf) goto fail; @@ -1860,7 +1860,7 @@ static JSValue js_os_rename(JSContext *ctx, JSValue this_val, static BOOL is_main_thread(JSRuntime *rt) { - JSThreadState *ts = JS_GetRuntimeOpaque(rt); + JSThreadState *ts = (JSThreadState *)JS_GetRuntimeOpaque(rt); return !ts->recv_pipe; } @@ -1891,7 +1891,7 @@ static JSValue js_os_setReadHandler(JSContext *ctx, JSValue this_val, int argc, JSValue *argv, int magic) { JSRuntime *rt = JS_GetRuntime(ctx); - JSThreadState *ts = JS_GetRuntimeOpaque(rt); + JSThreadState *ts = (JSThreadState *)JS_GetRuntimeOpaque(rt); JSOSRWHandler *rh; int fd; JSValue func; @@ -1915,7 +1915,7 @@ static JSValue js_os_setReadHandler(JSContext *ctx, JSValue this_val, return JS_ThrowTypeError(ctx, "not a function"); rh = find_rh(ts, fd); if (!rh) { - rh = js_mallocz(ctx, sizeof(*rh)); + rh = (JSOSRWHandler *)js_mallocz(ctx, sizeof(*rh)); if (!rh) return JS_EXCEPTION; rh->fd = fd; @@ -1961,7 +1961,7 @@ static JSValue js_os_signal(JSContext *ctx, JSValue this_val, int argc, JSValue *argv) { JSRuntime *rt = JS_GetRuntime(ctx); - JSThreadState *ts = JS_GetRuntimeOpaque(rt); + JSThreadState *ts = (JSThreadState *)JS_GetRuntimeOpaque(rt); JSOSSignalHandler *sh; uint32_t sig_num; JSValue func; @@ -1991,7 +1991,7 @@ static JSValue js_os_signal(JSContext *ctx, JSValue this_val, return JS_ThrowTypeError(ctx, "not a function"); sh = find_sh(ts, sig_num); if (!sh) { - sh = js_mallocz(ctx, sizeof(*sh)); + sh = (JSOSSignalHandler *)js_mallocz(ctx, sizeof(*sh)); if (!sh) return JS_EXCEPTION; sh->sig_num = sig_num; @@ -2048,7 +2048,7 @@ static JSClassID js_os_timer_class_id; static void js_os_timer_finalizer(JSRuntime *rt, JSValue val) { - JSOSTimer *th = JS_GetOpaque(val, js_os_timer_class_id); + JSOSTimer *th = (JSOSTimer *)JS_GetOpaque(val, js_os_timer_class_id); if (th) { th->has_object = FALSE; if (!th->link.prev) @@ -2059,7 +2059,7 @@ static void js_os_timer_finalizer(JSRuntime *rt, JSValue val) static void js_os_timer_mark(JSRuntime *rt, JSValue val, JS_MarkFunc *mark_func) { - JSOSTimer *th = JS_GetOpaque(val, js_os_timer_class_id); + JSOSTimer *th = (JSOSTimer *)JS_GetOpaque(val, js_os_timer_class_id); if (th) { JS_MarkValue(rt, th->func, mark_func); } @@ -2071,7 +2071,7 @@ static JSValue js_os_setTimeout(JSContext *ctx, JSValue this_val, int argc, JSValue *argv, int magic) { JSRuntime *rt = JS_GetRuntime(ctx); - JSThreadState *ts = JS_GetRuntimeOpaque(rt); + JSThreadState *ts = (JSThreadState *)JS_GetRuntimeOpaque(rt); int64_t delay; JSValue func; JSOSTimer *th; @@ -2087,7 +2087,7 @@ static JSValue js_os_setTimeout(JSContext *ctx, JSValue this_val, obj = JS_NewObjectClass(ctx, js_os_timer_class_id); if (JS_IsException(obj)) return obj; - th = js_mallocz(ctx, sizeof(*th)); + th = (JSOSTimer *)js_mallocz(ctx, sizeof(*th)); if (!th) { JS_FreeValue(ctx, obj); return JS_EXCEPTION; @@ -2105,7 +2105,7 @@ static JSValue js_os_setTimeout(JSContext *ctx, JSValue this_val, static JSValue js_os_clearTimeout(JSContext *ctx, JSValue this_val, int argc, JSValue *argv) { - JSOSTimer *th = JS_GetOpaque2(ctx, argv[0], js_os_timer_class_id); + JSOSTimer *th = (JSOSTimer *)JS_GetOpaque2(ctx, argv[0], js_os_timer_class_id); if (!th) return JS_EXCEPTION; unlink_timer(JS_GetRuntime(ctx), th); @@ -2125,7 +2125,7 @@ static JSValue js_os_sleepAsync(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { JSRuntime *rt = JS_GetRuntime(ctx); - JSThreadState *ts = JS_GetRuntimeOpaque(rt); + JSThreadState *ts = (JSThreadState *)JS_GetRuntimeOpaque(rt); int64_t delay; JSOSTimer *th; JSValue promise, resolving_funcs[2]; @@ -2136,7 +2136,7 @@ static JSValue js_os_sleepAsync(JSContext *ctx, JSValueConst this_val, if (JS_IsException(promise)) return JS_EXCEPTION; - th = js_mallocz(ctx, sizeof(*th)); + th = (JSOSTimer *)js_mallocz(ctx, sizeof(*th)); if (!th) { JS_FreeValue(ctx, promise); JS_FreeValue(ctx, resolving_funcs[0]); @@ -2336,7 +2336,7 @@ static int handle_posted_message(JSRuntime *rt, JSContext *ctx, static int js_os_poll(JSContext *ctx) { JSRuntime *rt = JS_GetRuntime(ctx); - JSThreadState *ts = JS_GetRuntimeOpaque(rt); + JSThreadState *ts = (JSThreadState *)JS_GetRuntimeOpaque(rt); int ret, fd_max, min_delay; fd_set rfds, wfds; JSOSRWHandler *rh; @@ -2815,7 +2815,7 @@ static char **build_envp(JSContext *ctx, JSValue obj) if (JS_GetOwnPropertyNames(ctx, &tab, &len, obj, JS_GPN_STRING_MASK | JS_GPN_ENUM_ONLY) < 0) return NULL; - envp = js_mallocz(ctx, sizeof(envp[0]) * ((size_t)len + 1)); + envp = (char **)js_mallocz(ctx, sizeof(envp[0]) * ((size_t)len + 1)); if (!envp) goto fail; for(i = 0; i < len; i++) { @@ -2833,7 +2833,7 @@ static char **build_envp(JSContext *ctx, JSValue obj) } key_len = strlen(key); str_len = strlen(str); - pair = js_malloc(ctx, key_len + str_len + 2); + pair = (char *)js_malloc(ctx, key_len + str_len + 2); if (!pair) { JS_FreeCString(ctx, key); JS_FreeCString(ctx, str); @@ -2944,7 +2944,7 @@ static JSValue js_os_exec(JSContext *ctx, JSValue this_val, if (exec_argc < 1 || exec_argc > 65535) { return JS_ThrowTypeError(ctx, "invalid number of arguments"); } - exec_argv = js_mallocz(ctx, sizeof(exec_argv[0]) * (exec_argc + 1)); + exec_argv = (const char **)js_mallocz(ctx, sizeof(exec_argv[0]) * (exec_argc + 1)); if (!exec_argv) return JS_EXCEPTION; for(i = 0; i < exec_argc; i++) { @@ -3246,7 +3246,7 @@ static int atomic_add_int(int *ptr, int v) static void *js_sab_alloc(void *opaque, size_t size) { JSSABHeader *sab; - sab = malloc(sizeof(JSSABHeader) + size); + sab = (JSSABHeader *)malloc(sizeof(JSSABHeader) + size); if (!sab) return NULL; sab->ref_count = 1; @@ -3280,7 +3280,7 @@ static JSWorkerMessagePipe *js_new_message_pipe(void) if (pipe(pipe_fds) < 0) return NULL; - ps = malloc(sizeof(*ps)); + ps = (JSWorkerMessagePipe *)malloc(sizeof(*ps)); if (!ps) { close(pipe_fds[0]); close(pipe_fds[1]); @@ -3347,7 +3347,7 @@ static void js_free_port(JSRuntime *rt, JSWorkerMessageHandler *port) static void js_worker_finalizer(JSRuntime *rt, JSValue val) { - JSWorkerData *worker = JS_GetOpaque(val, js_worker_class_id); + JSWorkerData *worker = (JSWorkerData *)JS_GetOpaque(val, js_worker_class_id); if (worker) { js_free_message_pipe(worker->recv_pipe); js_free_message_pipe(worker->send_pipe); @@ -3363,7 +3363,7 @@ static JSClassDef js_worker_class = { static void *worker_func(void *opaque) { - WorkerFuncArgs *args = opaque; + WorkerFuncArgs *args = (WorkerFuncArgs *)opaque; JSRuntime *rt; JSThreadState *ts; JSContext *ctx; @@ -3379,7 +3379,7 @@ static void *worker_func(void *opaque) JS_SetModuleLoaderFunc(rt, NULL, js_module_loader, NULL); /* set the pipe to communicate with the parent */ - ts = JS_GetRuntimeOpaque(rt); + ts = (JSThreadState *)JS_GetRuntimeOpaque(rt); ts->recv_pipe = args->recv_pipe; ts->send_pipe = args->send_pipe; @@ -3430,7 +3430,7 @@ static JSValue js_worker_ctor_internal(JSContext *ctx, JSValue new_target, JS_FreeValue(ctx, proto); if (JS_IsException(obj)) goto fail; - s = js_mallocz(ctx, sizeof(*s)); + s = (JSWorkerData *)js_mallocz(ctx, sizeof(*s)); if (!s) goto fail; s->recv_pipe = js_dup_message_pipe(recv_pipe); @@ -3476,7 +3476,7 @@ static JSValue js_worker_ctor(JSContext *ctx, JSValue new_target, if (!filename) goto fail; - args = malloc(sizeof(*args)); + args = (WorkerFuncArgs *)malloc(sizeof(*args)); if (!args) goto oom_fail; memset(args, 0, sizeof(*args)); @@ -3530,7 +3530,7 @@ static JSValue js_worker_ctor(JSContext *ctx, JSValue new_target, static JSValue js_worker_postMessage(JSContext *ctx, JSValue this_val, int argc, JSValue *argv) { - JSWorkerData *worker = JS_GetOpaque2(ctx, this_val, js_worker_class_id); + JSWorkerData *worker = (JSWorkerData *)JS_GetOpaque2(ctx, this_val, js_worker_class_id); JSWorkerMessagePipe *ps; size_t data_len, sab_tab_len, i; uint8_t *data; @@ -3546,21 +3546,21 @@ static JSValue js_worker_postMessage(JSContext *ctx, JSValue this_val, if (!data) return JS_EXCEPTION; - msg = malloc(sizeof(*msg)); + msg = (JSWorkerMessage *)malloc(sizeof(*msg)); if (!msg) goto fail; msg->data = NULL; msg->sab_tab = NULL; /* must reallocate because the allocator may be different */ - msg->data = malloc(data_len); + msg->data = (uint8_t *)malloc(data_len); if (!msg->data) goto fail; memcpy(msg->data, data, data_len); msg->data_len = data_len; if (sab_tab_len > 0) { - msg->sab_tab = malloc(sizeof(msg->sab_tab[0]) * sab_tab_len); + msg->sab_tab = (uint8_t **)malloc(sizeof(msg->sab_tab[0]) * sab_tab_len); if (!msg->sab_tab) goto fail; memcpy(msg->sab_tab, sab_tab, sizeof(msg->sab_tab[0]) * sab_tab_len); @@ -3608,8 +3608,8 @@ static JSValue js_worker_set_onmessage(JSContext *ctx, JSValue this_val, JSValue func) { JSRuntime *rt = JS_GetRuntime(ctx); - JSThreadState *ts = JS_GetRuntimeOpaque(rt); - JSWorkerData *worker = JS_GetOpaque2(ctx, this_val, js_worker_class_id); + JSThreadState *ts = (JSThreadState *)JS_GetRuntimeOpaque(rt); + JSWorkerData *worker = (JSWorkerData *)JS_GetOpaque2(ctx, this_val, js_worker_class_id); JSWorkerMessageHandler *port; if (!worker) @@ -3625,7 +3625,7 @@ static JSValue js_worker_set_onmessage(JSContext *ctx, JSValue this_val, if (!JS_IsFunction(ctx, func)) return JS_ThrowTypeError(ctx, "not a function"); if (!port) { - port = js_mallocz(ctx, sizeof(*port)); + port = (JSWorkerMessageHandler *)js_mallocz(ctx, sizeof(*port)); if (!port) return JS_EXCEPTION; port->recv_pipe = js_dup_message_pipe(worker->recv_pipe); @@ -3641,7 +3641,7 @@ static JSValue js_worker_set_onmessage(JSContext *ctx, JSValue this_val, static JSValue js_worker_get_onmessage(JSContext *ctx, JSValue this_val) { - JSWorkerData *worker = JS_GetOpaque2(ctx, this_val, js_worker_class_id); + JSWorkerData *worker = (JSWorkerData *)JS_GetOpaque2(ctx, this_val, js_worker_class_id); JSWorkerMessageHandler *port; if (!worker) return JS_EXCEPTION; @@ -3795,7 +3795,7 @@ static int js_os_init(JSContext *ctx, JSModuleDef *m) #ifdef USE_WORKER { - JSThreadState *ts = JS_GetRuntimeOpaque(rt); + JSThreadState *ts = (JSThreadState *)JS_GetRuntimeOpaque(rt); JSValue proto, obj; /* Worker class */ JS_NewClassID(rt, &js_worker_class_id); @@ -3894,7 +3894,7 @@ void js_std_init_handlers(JSRuntime *rt) { JSThreadState *ts; - ts = malloc(sizeof(*ts)); + ts = (JSThreadState *)malloc(sizeof(*ts)); if (!ts) { fprintf(stderr, "Could not allocate memory for the worker"); exit(1); @@ -3922,7 +3922,7 @@ void js_std_init_handlers(JSRuntime *rt) void js_std_free_handlers(JSRuntime *rt) { - JSThreadState *ts = JS_GetRuntimeOpaque(rt); + JSThreadState *ts = (JSThreadState *)JS_GetRuntimeOpaque(rt); struct list_head *el, *el1; list_for_each_safe(el, el1, &ts->os_rw_handlers) { diff --git a/quickjs.c b/quickjs.c index fe774fb4d..37de44ac0 100644 --- a/quickjs.c +++ b/quickjs.c @@ -1137,7 +1137,7 @@ static JSProperty *add_property(JSContext *ctx, static JSValue JS_NewBigInt(JSContext *ctx); static inline bf_t *JS_GetBigInt(JSValue val) { - JSBigInt *p = JS_VALUE_GET_PTR(val); + JSBigInt *p = (JSBigInt *)JS_VALUE_GET_PTR(val); return &p->num; } static JSValue JS_CompactBigInt1(JSContext *ctx, JSValue val); @@ -1390,7 +1390,7 @@ void *js_realloc_rt(JSRuntime *rt, void *ptr, size_t size) static void *js_dbuf_realloc(void *opaque, void *ptr, size_t size) { - JSRuntime *rt = opaque; + JSRuntime *rt = (JSRuntime *)opaque; return js_realloc_rt(rt, ptr, size); } @@ -1411,7 +1411,7 @@ void *js_mallocz_rt(JSRuntime *rt, size_t size) /* called by libbf */ static void *js_bf_realloc(void *opaque, void *ptr, size_t size) { - JSRuntime *rt = opaque; + JSRuntime *rt = (JSRuntime *)opaque; return js_realloc_rt(rt, ptr, size); } @@ -1481,7 +1481,7 @@ size_t js_malloc_usable_size(JSContext *ctx, const void *ptr) char *js_strndup(JSContext *ctx, const char *s, size_t n) { char *ptr; - ptr = js_malloc(ctx, n + 1); + ptr = (char *)js_malloc(ctx, n + 1); if (ptr) { memcpy(ptr, s, n); ptr[n] = '\0'; @@ -1625,7 +1625,7 @@ JSRuntime *JS_NewRuntime2(const JSMallocFunctions *mf, void *opaque) ms.opaque = opaque; ms.malloc_limit = 0; - rt = mf->js_malloc(&ms, sizeof(JSRuntime)); + rt = (JSRuntime *)mf->js_malloc(&ms, sizeof(JSRuntime)); if (!rt) return NULL; memset(rt, 0, sizeof(*rt)); @@ -1812,7 +1812,7 @@ int JS_EnqueueJob(JSContext *ctx, JSJobFunc *job_func, JSJobEntry *e; int i; - e = js_malloc(ctx, sizeof(*e) + argc * sizeof(JSValue)); + e = (JSJobEntry *)js_malloc(ctx, sizeof(*e) + argc * sizeof(JSValue)); if (!e) return -1; e->ctx = ctx; @@ -1880,7 +1880,7 @@ static inline JSAtomStruct *atom_set_free(uint32_t v) static JSString *js_alloc_string_rt(JSRuntime *rt, int max_len, int is_wide_char) { JSString *str; - str = js_malloc_rt(rt, sizeof(JSString) + (max_len << is_wide_char) + 1 - is_wide_char); + str = (JSString *)js_malloc_rt(rt, sizeof(JSString) + (max_len << is_wide_char) + 1 - is_wide_char); if (unlikely(!str)) return NULL; str->header.ref_count = 1; @@ -2118,13 +2118,13 @@ JSContext *JS_NewContextRaw(JSRuntime *rt) JSContext *ctx; int i; - ctx = js_mallocz_rt(rt, sizeof(JSContext)); + ctx = (JSContext *)js_mallocz_rt(rt, sizeof(JSContext)); if (!ctx) return NULL; ctx->header.ref_count = 1; add_gc_object(rt, &ctx->header, JS_GC_OBJ_TYPE_JS_CONTEXT); - ctx->class_proto = js_malloc_rt(rt, sizeof(ctx->class_proto[0]) * + ctx->class_proto = (JSValue *)js_malloc_rt(rt, sizeof(ctx->class_proto[0]) * rt->class_count); if (!ctx->class_proto) { js_free_rt(rt, ctx); @@ -2552,7 +2552,7 @@ static int JS_ResizeAtomHash(JSRuntime *rt, int new_hash_size) assert((new_hash_size & (new_hash_size - 1)) == 0); /* power of two */ new_hash_mask = new_hash_size - 1; - new_hash = js_mallocz_rt(rt, sizeof(rt->atom_hash[0]) * new_hash_size); + new_hash = (uint32_t *)js_mallocz_rt(rt, sizeof(rt->atom_hash[0]) * new_hash_size); if (!new_hash) return -1; for(i = 0; i < rt->atom_hash_size; i++) { @@ -2738,14 +2738,14 @@ static JSAtom __JS_NewAtom(JSRuntime *rt, JSString *str, int atom_type) if (new_size > JS_ATOM_MAX) goto fail; /* XXX: should use realloc2 to use slack space */ - new_array = js_realloc_rt(rt, rt->atom_array, sizeof(*new_array) * new_size); + new_array = (JSAtomStruct **)js_realloc_rt(rt, rt->atom_array, sizeof(*new_array) * new_size); if (!new_array) goto fail; /* Note: the atom 0 is not used */ start = rt->atom_size; if (start == 0) { /* JS_ATOM_NULL entry */ - p = js_mallocz_rt(rt, sizeof(JSAtomStruct)); + p = (JSAtomStruct *)js_mallocz_rt(rt, sizeof(JSAtomStruct)); if (!p) { js_free_rt(rt, new_array); goto fail; @@ -2777,7 +2777,7 @@ static JSAtom __JS_NewAtom(JSRuntime *rt, JSString *str, int atom_type) p = str; p->atom_type = atom_type; } else { - p = js_malloc_rt(rt, sizeof(JSString) + + p = (JSAtomStruct *)js_malloc_rt(rt, sizeof(JSString) + (str->len << str->is_wide_char) + 1 - str->is_wide_char); if (unlikely(!p)) @@ -2793,7 +2793,7 @@ static JSAtom __JS_NewAtom(JSRuntime *rt, JSString *str, int atom_type) js_free_string(rt, str); } } else { - p = js_malloc_rt(rt, sizeof(JSAtomStruct)); /* empty wide string */ + p = (JSAtomStruct *)js_malloc_rt(rt, sizeof(JSAtomStruct)); /* empty wide string */ if (!p) return JS_ATOM_NULL; p->header.ref_count = 1; @@ -3327,7 +3327,7 @@ static JSAtom js_atom_concat_str(JSContext *ctx, JSAtom name, const char *str1) if (!cstr) goto fail; len1 = strlen(str1); - cstr2 = js_malloc(ctx, len + len1 + 1); + cstr2 = (char *)js_malloc(ctx, len + len1 + 1); if (!cstr2) goto fail; memcpy(cstr2, cstr, len); @@ -3407,7 +3407,7 @@ static int JS_NewClass1(JSRuntime *rt, JSClassID class_id, list_for_each(el, &rt->context_list) { JSContext *ctx = list_entry(el, JSContext, link); JSValue *new_tab; - new_tab = js_realloc_rt(rt, ctx->class_proto, + new_tab = (JSValue *)js_realloc_rt(rt, ctx->class_proto, sizeof(ctx->class_proto[0]) * new_size); if (!new_tab) return -1; @@ -3416,7 +3416,7 @@ static int JS_NewClass1(JSRuntime *rt, JSClassID class_id, ctx->class_proto = new_tab; } /* reallocate the class array */ - new_class_array = js_realloc_rt(rt, rt->class_array, + new_class_array = (JSClass *)js_realloc_rt(rt, rt->class_array, sizeof(JSClass) * new_size); if (!new_class_array) return -1; @@ -3588,7 +3588,7 @@ static no_inline int string_buffer_widen(StringBuffer *s, int size) if (s->error_status) return -1; - str = js_realloc2(s->ctx, s->str, sizeof(JSString) + (size << 1), &slack); + str = (JSString *)js_realloc2(s->ctx, s->str, sizeof(JSString) + (size << 1), &slack); if (!str) return string_buffer_set_error(s); size += slack >> 1; @@ -3619,7 +3619,7 @@ static no_inline int string_buffer_realloc(StringBuffer *s, int new_len, int c) return string_buffer_widen(s, new_size); } new_size_bytes = sizeof(JSString) + (new_size << s->is_wide_char) + 1 - s->is_wide_char; - new_str = js_realloc2(s->ctx, s->str, new_size_bytes, &slack); + new_str = (JSString *)js_realloc2(s->ctx, s->str, new_size_bytes, &slack); if (!new_str) return string_buffer_set_error(s); new_size = min_int(new_size + (slack >> s->is_wide_char), JS_STRING_LEN_MAX); @@ -3844,7 +3844,7 @@ static JSValue string_buffer_end(StringBuffer *s) /* smaller size so js_realloc should not fail, but OK if it does */ /* XXX: should add some slack to avoid unnecessary calls */ /* XXX: might need to use malloc+free to ensure smaller size */ - str = js_realloc_rt(s->ctx->rt, str, sizeof(JSString) + + str = (JSString *)js_realloc_rt(s->ctx->rt, str, sizeof(JSString) + (s->len << s->is_wide_char) + 1 - s->is_wide_char); if (str == NULL) str = s->str; @@ -4247,7 +4247,7 @@ static int init_shape_hash(JSRuntime *rt) rt->shape_hash_bits = 4; /* 16 shapes */ rt->shape_hash_size = 1 << rt->shape_hash_bits; rt->shape_hash_count = 0; - rt->shape_hash = js_mallocz_rt(rt, sizeof(rt->shape_hash[0]) * + rt->shape_hash = (JSShape **)js_mallocz_rt(rt, sizeof(rt->shape_hash[0]) * rt->shape_hash_size); if (!rt->shape_hash) return -1; @@ -4282,7 +4282,7 @@ static int resize_shape_hash(JSRuntime *rt, int new_shape_hash_bits) JSShape **new_shape_hash, *sh, *sh_next; new_shape_hash_size = 1 << new_shape_hash_bits; - new_shape_hash = js_mallocz_rt(rt, sizeof(rt->shape_hash[0]) * + new_shape_hash = (JSShape **)js_mallocz_rt(rt, sizeof(rt->shape_hash[0]) * new_shape_hash_size); if (!new_shape_hash) return -1; @@ -4451,7 +4451,7 @@ static no_inline int resize_properties(JSContext *ctx, JSShape **psh, in case of memory allocation failure */ if (p) { JSProperty *new_prop; - new_prop = js_realloc(ctx, p->prop, sizeof(new_prop[0]) * new_size); + new_prop = (JSProperty *)js_realloc(ctx, p->prop, sizeof(new_prop[0]) * new_size); if (unlikely(!new_prop)) return -1; p->prop = new_prop; @@ -4731,7 +4731,7 @@ static JSValue JS_NewObjectFromShape(JSContext *ctx, JSShape *sh, JSClassID clas p->first_weak_ref = NULL; p->u.opaque = NULL; p->shape = sh; - p->prop = js_malloc(ctx, sizeof(JSProperty) * sh->prop_size); + p->prop = (JSProperty *)js_malloc(ctx, sizeof(JSProperty) * sh->prop_size); if (unlikely(!p->prop)) { js_free(ctx, p); fail: @@ -5024,7 +5024,7 @@ typedef struct JSCFunctionDataRecord { static void js_c_function_data_finalizer(JSRuntime *rt, JSValue val) { - JSCFunctionDataRecord *s = JS_GetOpaque(val, JS_CLASS_C_FUNCTION_DATA); + JSCFunctionDataRecord *s = (JSCFunctionDataRecord *)JS_GetOpaque(val, JS_CLASS_C_FUNCTION_DATA); int i; if (s) { @@ -5038,7 +5038,7 @@ static void js_c_function_data_finalizer(JSRuntime *rt, JSValue val) static void js_c_function_data_mark(JSRuntime *rt, JSValue val, JS_MarkFunc *mark_func) { - JSCFunctionDataRecord *s = JS_GetOpaque(val, JS_CLASS_C_FUNCTION_DATA); + JSCFunctionDataRecord *s = (JSCFunctionDataRecord *)JS_GetOpaque(val, JS_CLASS_C_FUNCTION_DATA); int i; if (s) { @@ -5052,13 +5052,13 @@ static JSValue js_c_function_data_call(JSContext *ctx, JSValue func_obj, JSValue this_val, int argc, JSValue *argv, int flags) { - JSCFunctionDataRecord *s = JS_GetOpaque(func_obj, JS_CLASS_C_FUNCTION_DATA); + JSCFunctionDataRecord *s = (JSCFunctionDataRecord *)JS_GetOpaque(func_obj, JS_CLASS_C_FUNCTION_DATA); JSValue *arg_buf; int i; /* XXX: could add the function on the stack for debug */ if (unlikely(argc < s->length)) { - arg_buf = alloca(sizeof(arg_buf[0]) * s->length); + arg_buf = (JSValue *)alloca(sizeof(arg_buf[0]) * s->length); for(i = 0; i < argc; i++) arg_buf[i] = argv[i]; for(i = argc; i < s->length; i++) @@ -5082,7 +5082,7 @@ JSValue JS_NewCFunctionData(JSContext *ctx, JSCFunctionData *func, JS_CLASS_C_FUNCTION_DATA); if (JS_IsException(func_obj)) return func_obj; - s = js_malloc(ctx, sizeof(*s) + data_len * sizeof(JSValue)); + s = (JSCFunctionDataRecord *)js_malloc(ctx, sizeof(*s) + data_len * sizeof(JSValue)); if (!s) { JS_FreeValue(ctx, func_obj); return JS_EXCEPTION; @@ -5490,7 +5490,7 @@ void __JS_FreeValueRT(JSRuntime *rt, JSValue v) case JS_TAG_OBJECT: case JS_TAG_FUNCTION_BYTECODE: { - JSGCObjectHeader *p = JS_VALUE_GET_PTR(v); + JSGCObjectHeader *p = (JSGCObjectHeader *)JS_VALUE_GET_PTR(v); if (rt->gc_phase != JS_GC_PHASE_REMOVE_CYCLES) { list_del(&p->link); list_add(&p->link, &rt->gc_zero_ref_count_list); @@ -5505,14 +5505,14 @@ void __JS_FreeValueRT(JSRuntime *rt, JSValue v) break; case JS_TAG_BIG_INT: { - JSBigInt *bf = JS_VALUE_GET_PTR(v); + JSBigInt *bf = (JSBigInt *)JS_VALUE_GET_PTR(v); bf_delete(&bf->num); js_free_rt(rt, bf); } break; case JS_TAG_SYMBOL: { - JSAtomStruct *p = JS_VALUE_GET_PTR(v); + JSAtomStruct *p = (JSAtomStruct *)JS_VALUE_GET_PTR(v); JS_FreeAtomStruct(rt, p); } break; @@ -5548,7 +5548,7 @@ void JS_MarkValue(JSRuntime *rt, JSValue val, JS_MarkFunc *mark_func) switch(JS_VALUE_GET_TAG(val)) { case JS_TAG_OBJECT: case JS_TAG_FUNCTION_BYTECODE: - mark_func(rt, JS_VALUE_GET_PTR(val)); + mark_func(rt, (JSGCObjectHeader *)JS_VALUE_GET_PTR(val)); break; default: break; @@ -7522,7 +7522,7 @@ static uint32_t js_string_obj_get_length(JSContext *ctx, static int num_keys_cmp(const void *p1, const void *p2, void *opaque) { - JSContext *ctx = opaque; + JSContext *ctx = (JSContext *)opaque; JSAtom atom1 = ((const JSPropertyEnum *)p1)->atom; JSAtom atom2 = ((const JSPropertyEnum *)p2)->atom; uint32_t v1, v2; @@ -7656,7 +7656,7 @@ static int __exception JS_GetOwnPropertyNamesInternal(JSContext *ctx, atom_count = num_keys_count + str_keys_count + sym_keys_count + exotic_keys_count; /* avoid allocating 0 bytes */ - tab_atom = js_malloc(ctx, sizeof(tab_atom[0]) * max_int(atom_count, 1)); + tab_atom = (JSPropertyEnum *)js_malloc(ctx, sizeof(tab_atom[0]) * max_int(atom_count, 1)); if (!tab_atom) { js_free_prop_enum(ctx, tab_exotic, exotic_count); return -1; @@ -7924,7 +7924,7 @@ int JS_HasProperty(JSContext *ctx, JSValue obj, JSAtom prop) /* val must be a symbol */ static JSAtom js_symbol_to_atom(JSContext *ctx, JSValue val) { - JSAtomStruct *p = JS_VALUE_GET_PTR(val); + JSAtomStruct *p = (JSAtomStruct *)JS_VALUE_GET_PTR(val); return js_get_atom_index(ctx->rt, p); } @@ -7939,7 +7939,7 @@ JSAtom JS_ValueToAtom(JSContext *ctx, JSValue val) /* fast path for integer values */ atom = __JS_AtomFromUInt32(JS_VALUE_GET_INT(val)); } else if (tag == JS_TAG_SYMBOL) { - JSAtomStruct *p = JS_VALUE_GET_PTR(val); + JSAtomStruct *p = (JSAtomStruct *)JS_VALUE_GET_PTR(val); atom = JS_DupAtom(ctx, js_get_atom_index(ctx->rt, p)); } else { JSValue str; @@ -8125,7 +8125,7 @@ static JSProperty *add_property(JSContext *ctx, /* the property array may need to be resized */ if (new_sh->prop_size != sh->prop_size) { JSProperty *new_prop; - new_prop = js_realloc(ctx, p->prop, sizeof(p->prop[0]) * + new_prop = (JSProperty *)js_realloc(ctx, p->prop, sizeof(p->prop[0]) * new_sh->prop_size); if (!new_prop) return NULL; @@ -8398,7 +8398,7 @@ static int expand_fast_array(JSContext *ctx, JSObject *p, uint32_t new_len) JSValue *new_array_prop; /* XXX: potential arithmetic overflow */ new_size = max_int(new_len, p->u.array.u1.size * 3 / 2); - new_array_prop = js_realloc2(ctx, p->u.array.u.values, sizeof(JSValue) * new_size, &slack); + new_array_prop = (JSValue *)js_realloc2(ctx, p->u.array.u.values, sizeof(JSValue) * new_size, &slack); if (!new_array_prop) return -1; new_size += slack / sizeof(*new_array_prop); @@ -9911,7 +9911,7 @@ void *JS_GetOpaque(JSValue obj, JSClassID class_id) void *JS_GetOpaque2(JSContext *ctx, JSValue obj, JSClassID class_id) { - void *p = JS_GetOpaque(obj, class_id); + void *p = (void *)JS_GetOpaque(obj, class_id); if (unlikely(!p)) { JS_ThrowTypeErrorInvalidClass(ctx, class_id); } @@ -10047,7 +10047,7 @@ static int JS_ToBoolFree(JSContext *ctx, JSValue val) } case JS_TAG_BIG_INT: { - JSBigInt *p = JS_VALUE_GET_PTR(val); + JSBigInt *p = (JSBigInt *)JS_VALUE_GET_PTR(val); BOOL ret; ret = p->num.expn != BF_EXP_ZERO && p->num.expn != BF_EXP_NAN; JS_FreeValue(ctx, val); @@ -10298,7 +10298,7 @@ static JSValue js_atof(JSContext *ctx, const char *p, size_t len, len = p - p_start; if (unlikely((len + 2) > sizeof(buf1))) { - buf = js_malloc_rt(ctx->rt, len + 2); /* no exception raised */ + buf = (char *)js_malloc_rt(ctx->rt, len + 2); /* no exception raised */ if (!buf) { if (pp) *pp = p; return JS_ThrowOutOfMemory(ctx); @@ -10447,7 +10447,7 @@ static __exception int __JS_ToFloat64Free(JSContext *ctx, double *pres, break; case JS_TAG_BIG_INT: { - JSBigInt *p = JS_VALUE_GET_PTR(val); + JSBigInt *p = (JSBigInt *)JS_VALUE_GET_PTR(val); /* XXX: there can be a double rounding issue with some primitives (such as JS_ToUint8ClampFree()), but it is not critical to fix it. */ @@ -10845,7 +10845,7 @@ static __exception int JS_ToArrayLengthFree(JSContext *ctx, uint32_t *plen, break; case JS_TAG_BIG_INT: { - JSBigInt *p = JS_VALUE_GET_PTR(val); + JSBigInt *p = (JSBigInt *)JS_VALUE_GET_PTR(val); bf_t a; BOOL res; bf_get_int32((int32_t *)&len, &p->num, BF_GET_INT_MOD); @@ -10965,7 +10965,7 @@ static BOOL JS_NumberIsNegativeOrMinusZero(JSContext *ctx, JSValue val) } case JS_TAG_BIG_INT: { - JSBigInt *p = JS_VALUE_GET_PTR(val); + JSBigInt *p = (JSBigInt *)JS_VALUE_GET_PTR(val); /* Note: integer zeros are not necessarily positive */ return p->num.sign && !bf_is_zero(&p->num); } @@ -11753,7 +11753,7 @@ static __maybe_unused void JS_DumpValue(JSRuntime *rt, JSValue val) break; case JS_TAG_BIG_INT: { - JSBigInt *p = JS_VALUE_GET_PTR(val); + JSBigInt *p = (JSBigInt *)JS_VALUE_GET_PTR(val); char *str; str = bf_ftoa(NULL, &p->num, 10, 0, BF_RNDZ | BF_FTOA_FORMAT_FRAC); @@ -11770,7 +11770,7 @@ static __maybe_unused void JS_DumpValue(JSRuntime *rt, JSValue val) break; case JS_TAG_FUNCTION_BYTECODE: { - JSFunctionBytecode *b = JS_VALUE_GET_PTR(val); + JSFunctionBytecode *b = (JSFunctionBytecode *)JS_VALUE_GET_PTR(val); char buf[ATOM_GET_STR_BUF_SIZE]; if (b->func_name) { printf("[bytecode %s]", JS_AtomGetStrRT(rt, buf, sizeof(buf), b->func_name)); @@ -11790,7 +11790,7 @@ static __maybe_unused void JS_DumpValue(JSRuntime *rt, JSValue val) break; case JS_TAG_SYMBOL: { - JSAtomStruct *p = JS_VALUE_GET_PTR(val); + JSAtomStruct *p = (JSAtomStruct *)JS_VALUE_GET_PTR(val); char atom_buf[ATOM_GET_STR_BUF_SIZE]; printf("Symbol(%s)", JS_AtomGetStrRT(rt, atom_buf, sizeof(atom_buf), js_get_atom_index(rt, p))); @@ -11891,7 +11891,7 @@ static bf_t *JS_ToBigInt1(JSContext *ctx, bf_t *buf, JSValue val) } break; case JS_TAG_BIG_INT: - p = JS_VALUE_GET_PTR(val); + p = (JSBigInt *)JS_VALUE_GET_PTR(val); r = &p->num; break; case JS_TAG_UNDEFINED: @@ -11954,7 +11954,7 @@ static bf_t *JS_ToBigIntFree(JSContext *ctx, bf_t *buf, JSValue val) bf_set_si(r, JS_VALUE_GET_INT(val)); break; case JS_TAG_BIG_INT: - p = JS_VALUE_GET_PTR(val); + p = (JSBigInt *)JS_VALUE_GET_PTR(val); r = &p->num; break; case JS_TAG_STRING: @@ -12048,7 +12048,7 @@ int JS_ToBigUint64(JSContext *ctx, uint64_t *pres, JSValue val) static JSValue JS_NewBigInt(JSContext *ctx) { JSBigInt *p; - p = js_malloc(ctx, sizeof(*p)); + p = (JSBigInt *)js_malloc(ctx, sizeof(*p)); if (!p) return JS_EXCEPTION; p->header.ref_count = 1; @@ -12981,8 +12981,8 @@ static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2, if (tag1 != tag2) { res = FALSE; } else { - p1 = JS_VALUE_GET_STRING(op1); - p2 = JS_VALUE_GET_STRING(op2); + p1 = (JSString *)JS_VALUE_GET_STRING(op1); + p2 = (JSString *)JS_VALUE_GET_STRING(op2); res = (js_string_compare(ctx, p1, p2) == 0); } } @@ -12993,8 +12993,8 @@ static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2, if (tag1 != tag2) { res = FALSE; } else { - p1 = JS_VALUE_GET_PTR(op1); - p2 = JS_VALUE_GET_PTR(op2); + p1 = (JSAtomStruct *)JS_VALUE_GET_PTR(op1); + p2 = (JSAtomStruct *)JS_VALUE_GET_PTR(op2); res = (p1 == p2); } } @@ -13309,7 +13309,7 @@ static JSValue js_build_arguments(JSContext *ctx, int argc, JSValue *argv) /* initialize the fast array part */ tab = NULL; if (argc > 0) { - tab = js_malloc(ctx, sizeof(tab[0]) * argc); + tab = (JSValue *)js_malloc(ctx, sizeof(tab[0]) * argc); if (!tab) { JS_FreeValue(ctx, val); return JS_EXCEPTION; @@ -13424,7 +13424,7 @@ static JSValue build_for_in_iterator(JSContext *ctx, JSValue obj) obj = JS_ToObjectFree(ctx, obj); } - it = js_malloc(ctx, sizeof(*it)); + it = (JSForInIterator *)js_malloc(ctx, sizeof(*it)); if (!it) { JS_FreeValue(ctx, obj); return JS_EXCEPTION; @@ -14083,7 +14083,7 @@ static JSVarRef *get_var_ref(JSContext *ctx, JSStackFrame *sf, } } /* create a new one */ - var_ref = js_malloc(ctx, sizeof(JSVarRef)); + var_ref = (JSVarRef *)js_malloc(ctx, sizeof(JSVarRef)); if (!var_ref) return NULL; var_ref->header.ref_count = 1; @@ -14113,7 +14113,7 @@ static JSValue js_closure2(JSContext *ctx, JSValue func_obj, p->u.func.home_object = NULL; p->u.func.var_refs = NULL; if (b->closure_var_count) { - var_refs = js_mallocz(ctx, sizeof(var_refs[0]) * b->closure_var_count); + var_refs = (JSVarRef **)js_mallocz(ctx, sizeof(var_refs[0]) * b->closure_var_count); if (!var_refs) goto fail; p->u.func.var_refs = var_refs; @@ -14175,7 +14175,7 @@ static JSValue js_closure(JSContext *ctx, JSValue bfunc, JSValue func_obj; JSAtom name_atom; - b = JS_VALUE_GET_PTR(bfunc); + b = (JSFunctionBytecode *)JS_VALUE_GET_PTR(bfunc); func_obj = JS_NewObjectClass(ctx, func_kind_to_class_id[b->func_kind]); if (JS_IsException(func_obj)) { JS_FreeValue(ctx, bfunc); @@ -14262,7 +14262,7 @@ static int js_op_define_class(JSContext *ctx, JSValue *sp, if (JS_IsException(proto)) goto fail; - b = JS_VALUE_GET_PTR(bfunc); + b = (JSFunctionBytecode *)JS_VALUE_GET_PTR(bfunc); assert(b->func_kind == JS_FUNC_NORMAL); ctor = JS_NewObjectProtoClass(ctx, parent_class, JS_CLASS_BYTECODE_FUNCTION); @@ -14394,7 +14394,7 @@ static JSValue js_call_c_function(JSContext *ctx, JSValue func_obj, if (unlikely(argc < arg_count)) { /* ensure that at least argc_count arguments are readable */ - arg_buf = alloca(sizeof(arg_buf[0]) * arg_count); + arg_buf = (JSValue *)alloca(sizeof(arg_buf[0]) * arg_count); for(i = 0; i < argc; i++) arg_buf[i] = argv[i]; for(i = argc; i < arg_count; i++) @@ -14505,7 +14505,7 @@ static JSValue js_call_bound_function(JSContext *ctx, JSValue func_obj, arg_count = bf->argc + argc; if (js_check_stack_overflow(ctx->rt, sizeof(JSValue) * arg_count)) return JS_ThrowStackOverflow(ctx); - arg_buf = alloca(sizeof(JSValue) * arg_count); + arg_buf = (JSValue *)alloca(sizeof(JSValue) * arg_count); for(i = 0; i < bf->argc; i++) { arg_buf[i] = bf->argv[i]; } @@ -14600,7 +14600,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj, return JS_EXCEPTION; if (unlikely(JS_VALUE_GET_TAG(func_obj) != JS_TAG_OBJECT)) { if (flags & JS_CALL_FLAG_GENERATOR) { - JSAsyncFunctionState *s = JS_VALUE_GET_PTR(func_obj); + JSAsyncFunctionState *s = (JSAsyncFunctionState *)JS_VALUE_GET_PTR(func_obj); /* func_obj get contains a pointer to JSFuncAsyncState */ /* the stack frame is already allocated */ sf = &s->frame; @@ -14656,7 +14656,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj, init_list_head(&sf->var_ref_list); var_refs = p->u.func.var_refs; - local_buf = alloca(alloca_size); + local_buf = (JSValue *)alloca(alloca_size); if (unlikely(arg_allocated_size)) { int n = min_int(argc, b->arg_count); arg_buf = local_buf; @@ -17172,7 +17172,7 @@ static JSContext *JS_GetFunctionRealm(JSContext *ctx, JSValue func_obj) break; case JS_CLASS_PROXY: { - JSProxyData *s = p->u.opaque; + JSProxyData *s = (JSProxyData *)p->u.opaque; if (!s) return ctx; if (s->is_revoked) { @@ -17323,7 +17323,7 @@ static __exception int async_func_init(JSContext *ctx, JSAsyncFunctionState *s, sf->cur_pc = b->byte_code_buf; arg_buf_len = max_int(b->arg_count, argc); local_count = arg_buf_len + b->var_count + b->stack_size; - sf->arg_buf = js_malloc(ctx, sizeof(JSValue) * max_int(local_count, 1)); + sf->arg_buf = (JSValue *)js_malloc(ctx, sizeof(JSValue) * max_int(local_count, 1)); if (!sf->arg_buf) return -1; sf->cur_func = js_dup(func_obj); @@ -17420,7 +17420,7 @@ static void free_generator_stack_rt(JSRuntime *rt, JSGeneratorData *s) static void js_generator_finalizer(JSRuntime *rt, JSValue obj) { - JSGeneratorData *s = JS_GetOpaque(obj, JS_CLASS_GENERATOR); + JSGeneratorData *s = (JSGeneratorData *)JS_GetOpaque(obj, JS_CLASS_GENERATOR); if (s) { free_generator_stack_rt(rt, s); @@ -17453,7 +17453,7 @@ static JSValue js_generator_next(JSContext *ctx, JSValue this_val, int argc, JSValue *argv, BOOL *pdone, int magic) { - JSGeneratorData *s = JS_GetOpaque(this_val, JS_CLASS_GENERATOR); + JSGeneratorData *s = (JSGeneratorData *)JS_GetOpaque(this_val, JS_CLASS_GENERATOR); JSStackFrame *sf; JSValue ret, func_ret; @@ -17544,7 +17544,7 @@ static JSValue js_generator_function_call(JSContext *ctx, JSValue func_obj, JSValue obj, func_ret; JSGeneratorData *s; - s = js_mallocz(ctx, sizeof(*s)); + s = (JSGeneratorData *)js_mallocz(ctx, sizeof(*s)); if (!s) return JS_EXCEPTION; s->state = JS_GENERATOR_STATE_SUSPENDED_START; @@ -17728,7 +17728,7 @@ static JSValue js_async_function_call(JSContext *ctx, JSValue func_obj, JSValue promise; JSAsyncFunctionData *s; - s = js_mallocz(ctx, sizeof(*s)); + s = (JSAsyncFunctionData *)js_mallocz(ctx, sizeof(*s)); if (!s) return JS_EXCEPTION; s->header.ref_count = 1; @@ -17807,7 +17807,7 @@ static void js_async_generator_free(JSRuntime *rt, static void js_async_generator_finalizer(JSRuntime *rt, JSValue obj) { - JSAsyncGeneratorData *s = JS_GetOpaque(obj, JS_CLASS_ASYNC_GENERATOR); + JSAsyncGeneratorData *s = (JSAsyncGeneratorData *)JS_GetOpaque(obj, JS_CLASS_ASYNC_GENERATOR); if (s) { js_async_generator_free(rt, s); @@ -17817,7 +17817,7 @@ static void js_async_generator_finalizer(JSRuntime *rt, JSValue obj) static void js_async_generator_mark(JSRuntime *rt, JSValue val, JS_MarkFunc *mark_func) { - JSAsyncGeneratorData *s = JS_GetOpaque(val, JS_CLASS_ASYNC_GENERATOR); + JSAsyncGeneratorData *s = (JSAsyncGeneratorData *)JS_GetOpaque(val, JS_CLASS_ASYNC_GENERATOR); struct list_head *el; JSAsyncGeneratorRequest *req; if (s) { @@ -18090,7 +18090,7 @@ static JSValue js_async_generator_resolve_function(JSContext *ctx, int magic, JSValue *func_data) { BOOL is_reject = magic & 1; - JSAsyncGeneratorData *s = JS_GetOpaque(func_data[0], JS_CLASS_ASYNC_GENERATOR); + JSAsyncGeneratorData *s = (JSAsyncGeneratorData *)JS_GetOpaque(func_data[0], JS_CLASS_ASYNC_GENERATOR); JSValue arg = argv[0]; /* XXX: what if s == NULL */ @@ -18125,7 +18125,7 @@ static JSValue js_async_generator_next(JSContext *ctx, JSValue this_val, int argc, JSValue *argv, int magic) { - JSAsyncGeneratorData *s = JS_GetOpaque(this_val, JS_CLASS_ASYNC_GENERATOR); + JSAsyncGeneratorData *s = (JSAsyncGeneratorData *)JS_GetOpaque(this_val, JS_CLASS_ASYNC_GENERATOR); JSValue promise, resolving_funcs[2]; JSAsyncGeneratorRequest *req; @@ -18144,7 +18144,7 @@ static JSValue js_async_generator_next(JSContext *ctx, JSValue this_val, JS_FreeValue(ctx, resolving_funcs[1]); return promise; } - req = js_mallocz(ctx, sizeof(*req)); + req = (JSAsyncGeneratorRequest *)js_mallocz(ctx, sizeof(*req)); if (!req) goto fail; req->completion_type = magic; @@ -18172,7 +18172,7 @@ static JSValue js_async_generator_function_call(JSContext *ctx, JSValue func_obj JSValue obj, func_ret; JSAsyncGeneratorData *s; - s = js_mallocz(ctx, sizeof(*s)); + s = (JSAsyncGeneratorData *)js_mallocz(ctx, sizeof(*s)); if (!s) return JS_EXCEPTION; s->state = JS_ASYNC_GENERATOR_STATE_SUSPENDED_START; @@ -19036,12 +19036,12 @@ static __exception int ident_realloc(JSContext *ctx, char **pbuf, size_t *psize, else new_size = size + (size >> 1); if (buf == static_buf) { - new_buf = js_malloc(ctx, new_size); + new_buf = (char *)js_malloc(ctx, new_size); if (!new_buf) return -1; memcpy(new_buf, buf, size); } else { - new_buf = js_realloc(ctx, buf, new_size); + new_buf = (char *)js_realloc(ctx, buf, new_size); if (!new_buf) return -1; } @@ -20127,7 +20127,7 @@ static void emit_ic(JSParseState *s, JSAtom atom) for (ch = ic->hash[h]; ch != NULL; ch = ch->next) if (ch->atom == atom) return; - ch = js_malloc(ctx, sizeof(*ch)); + ch = (JSInlineCacheHashSlot *)js_malloc(ctx, sizeof(*ch)); if (unlikely(!ch)) return; ch->atom = JS_DupAtom(ctx, atom); @@ -20153,7 +20153,7 @@ static int new_label_fd(JSFunctionDef *fd, int label) LabelSlot *ls; if (label < 0) { - if (js_resize_array(fd->ctx, (void *)&fd->label_slots, + if (js_resize_array(fd->ctx, (void **)&fd->label_slots, sizeof(fd->label_slots[0]), &fd->label_size, fd->label_count + 1)) return -1; @@ -20205,7 +20205,7 @@ static int cpool_add(JSParseState *s, JSValue val) { JSFunctionDef *fd = s->cur_func; - if (js_resize_array(s->ctx, (void *)&fd->cpool, sizeof(fd->cpool[0]), + if (js_resize_array(s->ctx, (void **)&fd->cpool, sizeof(fd->cpool[0]), &fd->cpool_size, fd->cpool_count + 1)) return -1; fd->cpool[fd->cpool_count++] = val; @@ -20356,12 +20356,12 @@ static int push_scope(JSParseState *s) { /* XXX: potential arithmetic overflow */ new_size = max_int(fd->scope_count + 1, fd->scope_size * 3 / 2); if (fd->scopes == fd->def_scope_array) { - new_buf = js_realloc2(s->ctx, NULL, new_size * sizeof(*fd->scopes), &slack); + new_buf = (JSVarScope *)js_realloc2(s->ctx, NULL, new_size * sizeof(*fd->scopes), &slack); if (!new_buf) return -1; memcpy(new_buf, fd->scopes, fd->scope_count * sizeof(*fd->scopes)); } else { - new_buf = js_realloc2(s->ctx, fd->scopes, new_size * sizeof(*fd->scopes), &slack); + new_buf = (JSVarScope *)js_realloc2(s->ctx, fd->scopes, new_size * sizeof(*fd->scopes), &slack); if (!new_buf) return -1; } @@ -25675,7 +25675,7 @@ static __exception int js_parse_statement_or_decl(JSParseState *s, static JSModuleDef *js_new_module_def(JSContext *ctx, JSAtom name) { JSModuleDef *m; - m = js_mallocz(ctx, sizeof(*m)); + m = (JSModuleDef *)js_mallocz(ctx, sizeof(*m)); if (!m) { JS_FreeAtom(ctx, name); return NULL; @@ -25923,14 +25923,14 @@ static char *js_default_module_normalize_name(JSContext *ctx, return js_strdup(ctx, name); } - p = strrchr(base_name, '/'); + p = (char *)strrchr(base_name, '/'); if (p) len = p - base_name; else len = 0; cap = len + strlen(name) + 1 + 1; - filename = js_malloc(ctx, cap); + filename = (char *)js_malloc(ctx, cap); if (!filename) return NULL; memcpy(filename, base_name, len); @@ -26325,9 +26325,9 @@ static const JSClassExoticMethods js_module_ns_exotic_methods = { static int exported_names_cmp(const void *p1, const void *p2, void *opaque) { - JSContext *ctx = opaque; - const ExportedNameEntry *me1 = p1; - const ExportedNameEntry *me2 = p2; + JSContext *ctx = (JSContext *)opaque; + const ExportedNameEntry *me1 = (const ExportedNameEntry *)p1; + const ExportedNameEntry *me2 = (const ExportedNameEntry *)p2; JSValue str1, str2; int ret; @@ -26349,7 +26349,7 @@ static int exported_names_cmp(const void *p1, const void *p2, void *opaque) static JSValue js_module_ns_autoinit(JSContext *ctx, JSObject *p, JSAtom atom, void *opaque) { - JSModuleDef *m = opaque; + JSModuleDef *m = (JSModuleDef *)opaque; return JS_GetModuleNamespace(ctx, m); } @@ -26510,7 +26510,7 @@ static int js_resolve_module(JSContext *ctx, JSModuleDef *m) static JSVarRef *js_create_module_var(JSContext *ctx, BOOL is_lexical) { JSVarRef *var_ref; - var_ref = js_malloc(ctx, sizeof(JSVarRef)); + var_ref = (JSVarRef *)js_malloc(ctx, sizeof(JSVarRef)); if (!var_ref) return NULL; var_ref->header.ref_count = 1; @@ -26539,7 +26539,7 @@ static int js_create_module_bytecode_function(JSContext *ctx, JSModuleDef *m) if (JS_IsException(func_obj)) return -1; - b = JS_VALUE_GET_PTR(bfunc); + b = (JSFunctionBytecode *)JS_VALUE_GET_PTR(bfunc); p = JS_VALUE_GET_OBJ(func_obj); p->u.func.function_bytecode = b; @@ -26547,7 +26547,7 @@ static int js_create_module_bytecode_function(JSContext *ctx, JSModuleDef *m) p->u.func.home_object = NULL; p->u.func.var_refs = NULL; if (b->closure_var_count) { - var_refs = js_mallocz(ctx, sizeof(var_refs[0]) * b->closure_var_count); + var_refs = (JSVarRef **)js_mallocz(ctx, sizeof(var_refs[0]) * b->closure_var_count); if (!var_refs) goto fail; p->u.func.var_refs = var_refs; @@ -26944,7 +26944,7 @@ static JSValue js_load_module_fulfilled(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic, JSValue *func_data) { JSValueConst *resolving_funcs = (JSValueConst *)func_data; - JSModuleDef *m = JS_VALUE_GET_PTR(func_data[2]); + JSModuleDef *m = (JSModuleDef *)JS_VALUE_GET_PTR(func_data[2]); JSValue ret, ns; /* return the module namespace */ @@ -27173,7 +27173,7 @@ static int js_execute_sync_module(JSContext *ctx, JSModuleDef *m, static JSValue js_async_module_execution_rejected(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic, JSValue *func_data) { - JSModuleDef *module = JS_VALUE_GET_PTR(func_data[0]); + JSModuleDef *module = (JSModuleDef *)JS_VALUE_GET_PTR(func_data[0]); JSValueConst error = argv[0]; int i; @@ -27214,7 +27214,7 @@ static JSValue js_async_module_execution_rejected(JSContext *ctx, JSValueConst t static JSValue js_async_module_execution_fulfilled(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic, JSValue *func_data) { - JSModuleDef *module = JS_VALUE_GET_PTR(func_data[0]); + JSModuleDef *module = (JSModuleDef *)JS_VALUE_GET_PTR(func_data[0]); ExecModuleList exec_list_s, *exec_list = &exec_list_s; int i; @@ -27874,7 +27874,7 @@ static JSFunctionDef *js_new_function_def(JSContext *ctx, { JSFunctionDef *fd; - fd = js_mallocz(ctx, sizeof(*fd)); + fd = (JSFunctionDef *)js_mallocz(ctx, sizeof(*fd)); if (!fd) return NULL; @@ -29569,7 +29569,7 @@ static __exception int add_closure_variables(JSContext *ctx, JSFunctionDef *s, s->closure_var_size = count; if (count == 0) return 0; - s->closure_var = js_malloc(ctx, sizeof(s->closure_var[0]) * count); + s->closure_var = (JSClosureVar *)js_malloc(ctx, sizeof(s->closure_var[0]) * count); if (!s->closure_var) return -1; /* Add lexical variables in scope at the point of evaluation */ @@ -30387,7 +30387,7 @@ static void compute_pc2line_info(JSFunctionDef *s) static RelocEntry *add_reloc(JSContext *ctx, LabelSlot *ls, uint32_t addr, int size) { RelocEntry *re; - re = js_malloc(ctx, sizeof(*re)); + re = (RelocEntry *)js_malloc(ctx, sizeof(*re)); if (!re) return NULL; re->addr = addr; @@ -30560,13 +30560,13 @@ static __exception int resolve_labels(JSContext *ctx, JSFunctionDef *s) js_dbuf_init(ctx, &bc_out); if (s->jump_size) { - s->jump_slots = js_mallocz(s->ctx, sizeof(*s->jump_slots) * s->jump_size); + s->jump_slots = (JumpSlot *)js_mallocz(s->ctx, sizeof(*s->jump_slots) * s->jump_size); if (s->jump_slots == NULL) return -1; } if (s->source_loc_size) { - s->source_loc_slots = js_mallocz(s->ctx, sizeof(*s->source_loc_slots) * s->source_loc_size); + s->source_loc_slots = (SourceLocSlot *)js_mallocz(s->ctx, sizeof(*s->source_loc_slots) * s->source_loc_size); if (s->source_loc_slots == NULL) return -1; s->line_number_last = s->line_num; @@ -31484,14 +31484,14 @@ static __exception int compute_stack_size(JSContext *ctx, bc_buf = fd->byte_code.buf; s->bc_len = fd->byte_code.size; /* bc_len > 0 */ - s->stack_level_tab = js_malloc(ctx, sizeof(s->stack_level_tab[0]) * + s->stack_level_tab = (uint16_t *)js_malloc(ctx, sizeof(s->stack_level_tab[0]) * s->bc_len); if (!s->stack_level_tab) return -1; for(i = 0; i < s->bc_len; i++) s->stack_level_tab[i] = 0xffff; s->pc_stack = NULL; - s->catch_pos_tab = js_malloc(ctx, sizeof(s->catch_pos_tab[0]) * s->bc_len); + s->catch_pos_tab = (int32_t *)js_malloc(ctx, sizeof(s->catch_pos_tab[0]) * s->bc_len); if (!s->catch_pos_tab) goto fail; @@ -31812,12 +31812,12 @@ static JSValue js_create_function(JSContext *ctx, JSFunctionDef *fd) byte_code_offset = function_size; function_size += fd->byte_code.size; - b = js_mallocz(ctx, function_size); + b = (JSFunctionBytecode *)js_mallocz(ctx, function_size); if (!b) goto fail; b->header.ref_count = 1; - b->byte_code_buf = (void *)((uint8_t*)b + byte_code_offset); + b->byte_code_buf = (uint8_t *)((uint8_t*)b + byte_code_offset); b->byte_code_len = fd->byte_code.size; memcpy(b->byte_code_buf, fd->byte_code.buf, fd->byte_code.size); js_free(ctx, fd->byte_code.buf); @@ -31825,7 +31825,7 @@ static JSValue js_create_function(JSContext *ctx, JSFunctionDef *fd) b->func_name = fd->func_name; if (fd->arg_count + fd->var_count > 0) { - b->vardefs = (void *)((uint8_t*)b + vardefs_offset); + b->vardefs = (JSVarDef *)((uint8_t*)b + vardefs_offset); if (fd->arg_count > 0) memcpy(b->vardefs, fd->args, fd->arg_count * sizeof(fd->args[0])); if (fd->var_count > 0) @@ -31838,7 +31838,7 @@ static JSValue js_create_function(JSContext *ctx, JSFunctionDef *fd) } b->cpool_count = fd->cpool_count; if (b->cpool_count) { - b->cpool = (void *)((uint8_t*)b + cpool_offset); + b->cpool = (JSValue *)((uint8_t*)b + cpool_offset); memcpy(b->cpool, fd->cpool, b->cpool_count * sizeof(*b->cpool)); } js_free(ctx, fd->cpool); @@ -31853,7 +31853,7 @@ static JSValue js_create_function(JSContext *ctx, JSFunctionDef *fd) b->line_num = fd->line_num; b->col_num = fd->col_num; - b->pc2line_buf = js_realloc(ctx, fd->pc2line.buf, fd->pc2line.size); + b->pc2line_buf = (uint8_t *)js_realloc(ctx, fd->pc2line.buf, fd->pc2line.size); if (!b->pc2line_buf) b->pc2line_buf = fd->pc2line.buf; b->pc2line_len = fd->pc2line.size; @@ -31865,7 +31865,7 @@ static JSValue js_create_function(JSContext *ctx, JSFunctionDef *fd) b->closure_var_count = fd->closure_var_count; if (b->closure_var_count) { - b->closure_var = (void *)((uint8_t*)b + closure_var_offset); + b->closure_var = (JSClosureVar *)((uint8_t*)b + closure_var_offset); memcpy(b->closure_var, fd->closure_var, b->closure_var_count * sizeof(*b->closure_var)); } js_free(ctx, fd->closure_var); @@ -32785,7 +32785,7 @@ static JSValue JS_EvalFunctionInternal(JSContext *ctx, JSValue fun_obj, ret_val = JS_CallFree(ctx, fun_obj, this_obj, 0, NULL); } else if (tag == JS_TAG_MODULE) { JSModuleDef *m; - m = JS_VALUE_GET_PTR(fun_obj); + m = (JSModuleDef *)JS_VALUE_GET_PTR(fun_obj); /* the module refcount should be >= 2 */ JS_FreeValue(ctx, fun_obj); if (js_create_module_function(ctx, m) < 0) @@ -32979,7 +32979,7 @@ JSValue JS_Eval(JSContext *ctx, const char *input, size_t input_len, int JS_ResolveModule(JSContext *ctx, JSValue obj) { if (JS_VALUE_GET_TAG(obj) == JS_TAG_MODULE) { - JSModuleDef *m = JS_VALUE_GET_PTR(obj); + JSModuleDef *m = (JSModuleDef *)JS_VALUE_GET_PTR(obj); if (js_resolve_module(ctx, m) < 0) { js_free_modules(ctx, JS_FREE_MODULE_NOT_RESOLVED); return -1; @@ -33021,7 +33021,7 @@ static int js_object_list_resize_hash(JSContext *ctx, JSObjectList *s, JSObjectListEntry *e; uint32_t i, h, *new_hash_table; - new_hash_table = js_malloc(ctx, sizeof(new_hash_table[0]) * new_hash_size); + new_hash_table = (uint32_t *)js_malloc(ctx, sizeof(new_hash_table[0]) * new_hash_size); if (!new_hash_table) return -1; js_free(ctx, s->hash_table); @@ -33047,7 +33047,7 @@ static int js_object_list_add(JSContext *ctx, JSObjectList *s, JSObject *obj) JSObjectListEntry *e; uint32_t h, new_hash_size; - if (js_resize_array(ctx, (void *)&s->object_tab, + if (js_resize_array(ctx, (void **)&s->object_tab, sizeof(s->object_tab[0]), &s->object_size, s->object_count + 1)) return -1; @@ -33338,7 +33338,7 @@ static int JS_WriteFunctionBytecode(BCWriterState *s, uint32_t val; bc_len = b->byte_code_len; - bc_buf = js_malloc(s->ctx, bc_len); + bc_buf = (uint8_t *)js_malloc(s->ctx, bc_len); if (!bc_buf) return -1; memcpy(bc_buf, b->byte_code_buf, bc_len); @@ -33402,7 +33402,7 @@ static int JS_WriteBigInt(BCWriterState *s, JSValue obj) { uint32_t tag, tag1; int64_t e; - JSBigInt *bf = JS_VALUE_GET_PTR(obj); + JSBigInt *bf = (JSBigInt *)JS_VALUE_GET_PTR(obj); bf_t *a = &bf->num; size_t len, i, n1, j; limb_t v; @@ -33474,7 +33474,7 @@ static int JS_WriteObjectRec(BCWriterState *s, JSValue obj); static int JS_WriteFunctionTag(BCWriterState *s, JSValue obj) { - JSFunctionBytecode *b = JS_VALUE_GET_PTR(obj); + JSFunctionBytecode *b = (JSFunctionBytecode *)JS_VALUE_GET_PTR(obj); uint32_t flags; int idx, i; @@ -33567,7 +33567,7 @@ static int JS_WriteFunctionTag(BCWriterState *s, JSValue obj) static int JS_WriteModule(BCWriterState *s, JSValue obj) { - JSModuleDef *m = JS_VALUE_GET_PTR(obj); + JSModuleDef *m = (JSModuleDef *)JS_VALUE_GET_PTR(obj); int i; bc_put_u8(s, BC_TAG_MODULE); @@ -34373,7 +34373,7 @@ static JSValue JS_ReadObjectRec(BCReaderState *s); static int BC_add_object_ref1(BCReaderState *s, JSObject *p) { if (s->allow_reference) { - if (js_resize_array(s->ctx, (void *)&s->objects, + if (js_resize_array(s->ctx, (void **)&s->objects, sizeof(s->objects[0]), &s->objects_size, s->objects_count + 1)) return -1; @@ -34448,7 +34448,7 @@ static JSValue JS_ReadFunctionTag(BCReaderState *s) byte_code_offset = function_size; function_size += bc.byte_code_len; - b = js_mallocz(ctx, function_size); + b = (JSFunctionBytecode *)js_mallocz(ctx, function_size); if (!b) goto fail; @@ -34456,13 +34456,13 @@ static JSValue JS_ReadFunctionTag(BCReaderState *s) bc.func_name = JS_ATOM_NULL; b->header.ref_count = 1; if (local_count != 0) { - b->vardefs = (void *)((uint8_t*)b + vardefs_offset); + b->vardefs = (JSVarDef *)((uint8_t*)b + vardefs_offset); } if (b->closure_var_count != 0) { - b->closure_var = (void *)((uint8_t*)b + closure_var_offset); + b->closure_var = (JSClosureVar *)((uint8_t*)b + closure_var_offset); } if (b->cpool_count != 0) { - b->cpool = (void *)((uint8_t*)b + cpool_offset); + b->cpool = (JSValue *)((uint8_t*)b + cpool_offset); } add_gc_object(ctx->rt, &b->header, JS_GC_OBJ_TYPE_FUNCTION_BYTECODE); @@ -34592,7 +34592,7 @@ static JSValue JS_ReadFunctionTag(BCReaderState *s) goto fail; if (b->pc2line_len) { bc_read_trace(s, "positions: %d bytes\n", b->pc2line_len); - b->pc2line_buf = js_mallocz(ctx, b->pc2line_len); + b->pc2line_buf = (uint8_t *)js_mallocz(ctx, b->pc2line_len); if (!b->pc2line_buf) goto fail; if (bc_get_buf(s, b->pc2line_buf, b->pc2line_len)) @@ -34604,7 +34604,7 @@ static JSValue JS_ReadFunctionTag(BCReaderState *s) bc_read_trace(s, "source: %d bytes\n", b->source_len); s->ptr_last += b->source_len; // omit source code hex dump /* b->source is a UTF-8 encoded null terminated C string */ - b->source = js_mallocz(ctx, b->source_len + 1); + b->source = (char *)js_mallocz(ctx, b->source_len + 1); if (!b->source) goto fail; if (bc_get_buf(s, b->source, b->source_len)) @@ -34649,7 +34649,7 @@ static JSValue JS_ReadModule(BCReaderState *s) obj = JS_NewModuleValue(ctx, m); if (m->req_module_entries_count != 0) { m->req_module_entries_size = m->req_module_entries_count; - m->req_module_entries = js_mallocz(ctx, sizeof(m->req_module_entries[0]) * m->req_module_entries_size); + m->req_module_entries = (JSReqModuleEntry *)js_mallocz(ctx, sizeof(m->req_module_entries[0]) * m->req_module_entries_size); if (!m->req_module_entries) goto fail; for(i = 0; i < m->req_module_entries_count; i++) { @@ -34663,7 +34663,7 @@ static JSValue JS_ReadModule(BCReaderState *s) goto fail; if (m->export_entries_count != 0) { m->export_entries_size = m->export_entries_count; - m->export_entries = js_mallocz(ctx, sizeof(m->export_entries[0]) * m->export_entries_size); + m->export_entries = (JSExportEntry *)js_mallocz(ctx, sizeof(m->export_entries[0]) * m->export_entries_size); if (!m->export_entries) goto fail; for(i = 0; i < m->export_entries_count; i++) { @@ -34689,7 +34689,7 @@ static JSValue JS_ReadModule(BCReaderState *s) goto fail; if (m->star_export_entries_count != 0) { m->star_export_entries_size = m->star_export_entries_count; - m->star_export_entries = js_mallocz(ctx, sizeof(m->star_export_entries[0]) * m->star_export_entries_size); + m->star_export_entries = (JSStarExportEntry *)js_mallocz(ctx, sizeof(m->star_export_entries[0]) * m->star_export_entries_size); if (!m->star_export_entries) goto fail; for(i = 0; i < m->star_export_entries_count; i++) { @@ -34703,7 +34703,7 @@ static JSValue JS_ReadModule(BCReaderState *s) goto fail; if (m->import_entries_count != 0) { m->import_entries_size = m->import_entries_count; - m->import_entries = js_mallocz(ctx, sizeof(m->import_entries[0]) * m->import_entries_size); + m->import_entries = (JSImportEntry *)js_mallocz(ctx, sizeof(m->import_entries[0]) * m->import_entries_size); if (!m->import_entries) goto fail; for(i = 0; i < m->import_entries_count; i++) { @@ -35124,7 +35124,7 @@ static int JS_ReadObjectAtoms(BCReaderState *s) bc_read_trace(s, "%d atom indexes {\n", s->idx_to_atom_count); if (s->idx_to_atom_count != 0) { - s->idx_to_atom = js_mallocz(s->ctx, s->idx_to_atom_count * + s->idx_to_atom = (JSAtom *)js_mallocz(s->ctx, s->idx_to_atom_count * sizeof(s->idx_to_atom[0])); if (!s->idx_to_atom) return s->error_state = -1; @@ -35235,7 +35235,7 @@ static JSAtom find_atom(JSContext *ctx, const char *name) static JSValue JS_InstantiateFunctionListItem2(JSContext *ctx, JSObject *p, JSAtom atom, void *opaque) { - const JSCFunctionListEntry *e = opaque; + const JSCFunctionListEntry *e = (const JSCFunctionListEntry *)opaque; JSValue val; switch(e->def_type) { @@ -36893,7 +36893,7 @@ static JSValue *build_arg_list(JSContext *ctx, uint32_t *plen, return NULL; } /* avoid allocating 0 bytes */ - tab = js_mallocz(ctx, sizeof(tab[0]) * max_uint32(1, len)); + tab = (JSValue *)js_mallocz(ctx, sizeof(tab[0]) * max_uint32(1, len)); if (!tab) return NULL; p = JS_VALUE_GET_OBJ(array_arg); @@ -36974,7 +36974,7 @@ static JSValue js_function_bind(JSContext *ctx, JSValue this_val, p = JS_VALUE_GET_OBJ(func_obj); p->is_constructor = JS_IsConstructor(ctx, this_val); arg_count = max_int(0, argc - 1); - bf = js_malloc(ctx, sizeof(*bf) + arg_count * sizeof(JSValue)); + bf = (JSBoundFunction *)js_malloc(ctx, sizeof(*bf) + arg_count * sizeof(JSValue)); if (!bf) goto exception; bf->func_obj = js_dup(this_val); @@ -38992,7 +38992,7 @@ struct array_sort_context { }; static int js_array_cmp_generic(const void *a, const void *b, void *opaque) { - struct array_sort_context *psc = opaque; + struct array_sort_context *psc = (struct array_sort_context *)opaque; JSContext *ctx = psc->ctx; JSValue argv[2]; JSValue res; @@ -39077,7 +39077,7 @@ static JSValue js_array_sort(JSContext *ctx, JSValue this_val, size_t new_size, slack; ValueSlot *new_array; new_size = (array_size + (array_size >> 1) + 31) & ~15; - new_array = js_realloc2(ctx, array, new_size * sizeof(*array), &slack); + new_array = (ValueSlot *)js_realloc2(ctx, array, new_size * sizeof(*array), &slack); if (new_array == NULL) goto exception; new_size += slack / sizeof(*new_array); @@ -39274,7 +39274,7 @@ static JSValue js_create_array_iterator(JSContext *ctx, JSValue this_val, enum_obj = JS_NewObjectClass(ctx, class_id); if (JS_IsException(enum_obj)) goto fail; - it = js_malloc(ctx, sizeof(*it)); + it = (JSArrayIteratorData *)js_malloc(ctx, sizeof(*it)); if (!it) goto fail1; it->obj = arr; @@ -39298,7 +39298,7 @@ static JSValue js_array_iterator_next(JSContext *ctx, JSValue this_val, JSValue val, obj; JSObject *p; - it = JS_GetOpaque2(ctx, this_val, JS_CLASS_ARRAY_ITERATOR); + it = (JSArrayIteratorData *)JS_GetOpaque2(ctx, this_val, JS_CLASS_ARRAY_ITERATOR); if (!it) goto fail1; if (JS_IsUndefined(it->obj)) @@ -39422,7 +39422,7 @@ static JSValue js_number_constructor(JSContext *ctx, JSValue new_target, switch(JS_VALUE_GET_TAG(val)) { case JS_TAG_BIG_INT: { - JSBigInt *p = JS_VALUE_GET_PTR(val); + JSBigInt *p = (JSBigInt *)JS_VALUE_GET_PTR(val); double d; bf_get_float64(&p->num, &d, BF_RNDN); JS_FreeValue(ctx, val); @@ -39844,7 +39844,7 @@ static JSValue js_string_constructor(JSContext *ctx, JSValue new_target, val = JS_AtomToString(ctx, JS_ATOM_empty_string); } else { if (JS_IsUndefined(new_target) && JS_IsSymbol(argv[0])) { - JSAtomStruct *p = JS_VALUE_GET_PTR(argv[0]); + JSAtomStruct *p = (JSAtomStruct *)JS_VALUE_GET_PTR(argv[0]); val = JS_ConcatString3(ctx, "Symbol(", JS_AtomToString(ctx, js_get_atom_index(ctx->rt, p)), ")"); } else { val = JS_ToString(ctx, argv[0]); @@ -41087,7 +41087,7 @@ static int to_utf32_buf(JSContext *ctx, JSString *p, uint32_t **pbuf) j = -1; n = p->len; - b = js_malloc(ctx, max_int(1, n) * sizeof(*b)); + b = (uint32_t *)js_malloc(ctx, max_int(1, n) * sizeof(*b)); if (b) for (i = j = 0; i < n;) b[j++] = string_getc(p, &i); @@ -41299,7 +41299,7 @@ static JSValue js_string_iterator_next(JSContext *ctx, JSValue this_val, uint32_t idx, c, start; JSString *p; - it = JS_GetOpaque2(ctx, this_val, JS_CLASS_STRING_ITERATOR); + it = (JSArrayIteratorData *)JS_GetOpaque2(ctx, this_val, JS_CLASS_STRING_ITERATOR); if (!it) { *pdone = FALSE; return JS_EXCEPTION; @@ -42247,13 +42247,13 @@ static JSValue js_regexp_toString(JSContext *ctx, JSValue this_val, BOOL lre_check_stack_overflow(void *opaque, size_t alloca_size) { - JSContext *ctx = opaque; + JSContext *ctx = (JSContext *)opaque; return js_check_stack_overflow(ctx->rt, alloca_size); } void *lre_realloc(void *opaque, void *ptr, size_t size) { - JSContext *ctx = opaque; + JSContext *ctx = (JSContext *)opaque; /* No JS exception is raised here */ return js_realloc_rt(ctx->rt, ptr, size); } @@ -42297,7 +42297,7 @@ static JSValue js_regexp_exec(JSContext *ctx, JSValue this_val, str = JS_VALUE_GET_STRING(str_val); capture_count = lre_get_capture_count(re_bytecode); if (capture_count > 0) { - capture = js_malloc(ctx, sizeof(capture[0]) * capture_count * 2); + capture = (uint8_t **)js_malloc(ctx, sizeof(capture[0]) * capture_count * 2); if (!capture) goto fail; } @@ -42492,7 +42492,7 @@ static JSValue JS_RegExpDelete(JSContext *ctx, JSValue this_val, JSValue arg) } capture_count = lre_get_capture_count(re_bytecode); if (capture_count > 0) { - capture = js_malloc(ctx, sizeof(capture[0]) * capture_count * 2); + capture = (uint8_t **)js_malloc(ctx, sizeof(capture[0]) * capture_count * 2); if (!capture) goto fail; } @@ -42713,7 +42713,7 @@ static JSValue js_regexp_string_iterator_next(JSContext *ctx, JSValue matchStr = JS_UNDEFINED, match = JS_UNDEFINED; JSString *sp; - it = JS_GetOpaque2(ctx, this_val, JS_CLASS_REGEXP_STRING_ITERATOR); + it = (JSRegExpStringIteratorData *)JS_GetOpaque2(ctx, this_val, JS_CLASS_REGEXP_STRING_ITERATOR); if (!it) goto exception; if (it->done) { @@ -42800,7 +42800,7 @@ static JSValue js_regexp_Symbol_matchAll(JSContext *ctx, JSValue this_val, iter = JS_NewObjectClass(ctx, JS_CLASS_REGEXP_STRING_ITERATOR); if (JS_IsException(iter)) goto exception; - it = js_malloc(ctx, sizeof(*it)); + it = (JSRegExpStringIteratorData *)js_malloc(ctx, sizeof(*it)); if (!it) goto exception; it->iterating_regexp = matcher; @@ -42863,11 +42863,11 @@ static int value_buffer_append(ValueBuffer *b, JSValue val) JSValue *new_arr; if (b->arr == b->def) { - new_arr = js_realloc2(b->ctx, NULL, sizeof(*b->arr) * new_size, &slack); + new_arr = (JSValue *)js_realloc2(b->ctx, NULL, sizeof(*b->arr) * new_size, &slack); if (new_arr) memcpy(new_arr, b->def, sizeof b->def); } else { - new_arr = js_realloc2(b->ctx, b->arr, sizeof(*b->arr) * new_size, &slack); + new_arr = (JSValue *)js_realloc2(b->ctx, b->arr, sizeof(*b->arr) * new_size, &slack); } if (!new_arr) { value_buffer_free(b); @@ -44176,7 +44176,7 @@ static const JSCFunctionListEntry js_reflect_obj[] = { static void js_proxy_finalizer(JSRuntime *rt, JSValue val) { - JSProxyData *s = JS_GetOpaque(val, JS_CLASS_PROXY); + JSProxyData *s = (JSProxyData *)JS_GetOpaque(val, JS_CLASS_PROXY); if (s) { JS_FreeValueRT(rt, s->target); JS_FreeValueRT(rt, s->handler); @@ -44187,7 +44187,7 @@ static void js_proxy_finalizer(JSRuntime *rt, JSValue val) static void js_proxy_mark(JSRuntime *rt, JSValue val, JS_MarkFunc *mark_func) { - JSProxyData *s = JS_GetOpaque(val, JS_CLASS_PROXY); + JSProxyData *s = (JSProxyData *)JS_GetOpaque(val, JS_CLASS_PROXY); if (s) { JS_MarkValue(rt, s->target, mark_func); JS_MarkValue(rt, s->handler, mark_func); @@ -44202,7 +44202,7 @@ static JSValue JS_ThrowTypeErrorRevokedProxy(JSContext *ctx) static JSProxyData *get_proxy_method(JSContext *ctx, JSValue *pmethod, JSValue obj, JSAtom name) { - JSProxyData *s = JS_GetOpaque(obj, JS_CLASS_PROXY); + JSProxyData *s = (JSProxyData *)JS_GetOpaque(obj, JS_CLASS_PROXY); JSValue method; /* safer to test recursion in all proxy methods */ @@ -44843,7 +44843,7 @@ static int js_proxy_get_own_property_names(JSContext *ctx, if (js_get_length32(ctx, &len, prop_array)) goto fail; if (len > 0) { - tab = js_mallocz(ctx, sizeof(tab[0]) * len); + tab = (JSPropertyEnum *)js_mallocz(ctx, sizeof(tab[0]) * len); if (!tab) goto fail; } @@ -45001,7 +45001,7 @@ static JSValue js_proxy_call(JSContext *ctx, JSValue func_obj, static int js_proxy_isArray(JSContext *ctx, JSValue obj) { - JSProxyData *s = JS_GetOpaque(obj, JS_CLASS_PROXY); + JSProxyData *s = (JSProxyData *)JS_GetOpaque(obj, JS_CLASS_PROXY); if (!s) return FALSE; @@ -45043,7 +45043,7 @@ static JSValue js_proxy_constructor(JSContext *ctx, JSValue this_val, obj = JS_NewObjectProtoClass(ctx, JS_NULL, JS_CLASS_PROXY); if (JS_IsException(obj)) return obj; - s = js_malloc(ctx, sizeof(JSProxyData)); + s = (JSProxyData *)js_malloc(ctx, sizeof(JSProxyData)); if (!s) { JS_FreeValue(ctx, obj); return JS_EXCEPTION; @@ -45061,7 +45061,7 @@ static JSValue js_proxy_revoke(JSContext *ctx, JSValue this_val, int argc, JSValue *argv, int magic, JSValue *func_data) { - JSProxyData *s = JS_GetOpaque(func_data[0], JS_CLASS_PROXY); + JSProxyData *s = (JSProxyData *)JS_GetOpaque(func_data[0], JS_CLASS_PROXY); if (s) { /* We do not free the handler and target in case they are referenced as constants in the C call stack */ @@ -45194,7 +45194,7 @@ static JSValue js_symbol_get_description(JSContext *ctx, JSValue this_val) val = js_thisSymbolValue(ctx, this_val); if (JS_IsException(val)) return val; - p = JS_VALUE_GET_PTR(val); + p = (JSAtomStruct *)JS_VALUE_GET_PTR(val); if (p->len == 0 && p->is_wide_char != 0) { ret = JS_UNDEFINED; } else { @@ -45231,7 +45231,7 @@ static JSValue js_symbol_keyFor(JSContext *ctx, JSValue this_val, if (!JS_IsSymbol(argv[0])) return JS_ThrowTypeError(ctx, "not a symbol"); - p = JS_VALUE_GET_PTR(argv[0]); + p = (JSAtomStruct *)JS_VALUE_GET_PTR(argv[0]); if (p->atom_type != JS_ATOM_TYPE_GLOBAL_SYMBOL) return JS_UNDEFINED; return js_dup(JS_MKPTR(JS_TAG_STRING, p)); @@ -45280,14 +45280,14 @@ static JSValue js_map_constructor(JSContext *ctx, JSValue new_target, obj = js_create_from_ctor(ctx, new_target, JS_CLASS_MAP + magic); if (JS_IsException(obj)) return JS_EXCEPTION; - s = js_mallocz(ctx, sizeof(*s)); + s = (JSMapState *)js_mallocz(ctx, sizeof(*s)); if (!s) goto fail; init_list_head(&s->records); s->is_weak = is_weak; JS_SetOpaque(obj, s); s->hash_size = 1; - s->hash_table = js_malloc(ctx, sizeof(s->hash_table[0]) * s->hash_size); + s->hash_table = (struct list_head *)js_malloc(ctx, sizeof(s->hash_table[0]) * s->hash_size); if (!s->hash_table) goto fail; init_list_head(&s->hash_table[0]); @@ -45413,7 +45413,7 @@ static uint32_t map_hash_key(JSContext *ctx, JSValue key) goto hash_float64; case JS_TAG_BIG_INT: a = JS_GetBigInt(key); - h = hash_string8((void *)a->tab, a->len * sizeof(*a->tab), 0); + h = hash_string8((const uint8_t *)a->tab, a->len * sizeof(*a->tab), 0); break; case JS_TAG_FLOAT64: d = JS_VALUE_GET_FLOAT64(key); @@ -45459,7 +45459,7 @@ static void map_hash_resize(JSContext *ctx, JSMapState *s) new_hash_size = 4; else new_hash_size = s->hash_size * 2; - new_hash_table = js_realloc2(ctx, s->hash_table, + new_hash_table = (struct list_head *)js_realloc2(ctx, s->hash_table, sizeof(new_hash_table[0]) * new_hash_size, &slack); if (!new_hash_table) return; @@ -45491,7 +45491,7 @@ static JSWeakRefRecord **get_first_weak_ref(JSValue key) break; case JS_TAG_SYMBOL: { - JSAtomStruct *p = JS_VALUE_GET_PTR(key); + JSAtomStruct *p = (JSAtomStruct *)JS_VALUE_GET_PTR(key); return &p->first_weak_ref; } break; @@ -45507,14 +45507,14 @@ static JSMapRecord *map_add_record(JSContext *ctx, JSMapState *s, uint32_t h; JSMapRecord *mr; - mr = js_malloc(ctx, sizeof(*mr)); + mr = (JSMapRecord *)js_malloc(ctx, sizeof(*mr)); if (!mr) return NULL; mr->ref_count = 1; mr->map = s; mr->empty = FALSE; if (s->is_weak) { - JSWeakRefRecord *wr = js_malloc(ctx, sizeof(*wr)); + JSWeakRefRecord *wr = (JSWeakRefRecord *)js_malloc(ctx, sizeof(*wr)); if (!wr) { js_free(ctx, mr); return NULL; @@ -45592,7 +45592,7 @@ static void map_decref_record(JSRuntime *rt, JSMapRecord *mr) static JSValue js_map_set(JSContext *ctx, JSValue this_val, int argc, JSValue *argv, int magic) { - JSMapState *s = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic); + JSMapState *s = (JSMapState *)JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic); JSMapRecord *mr; JSValue key, value; int is_set; @@ -45622,7 +45622,7 @@ static JSValue js_map_set(JSContext *ctx, JSValue this_val, static JSValue js_map_get(JSContext *ctx, JSValue this_val, int argc, JSValue *argv, int magic) { - JSMapState *s = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic); + JSMapState *s = (JSMapState *)JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic); JSMapRecord *mr; JSValue key; @@ -45639,7 +45639,7 @@ static JSValue js_map_get(JSContext *ctx, JSValue this_val, static JSValue js_map_has(JSContext *ctx, JSValue this_val, int argc, JSValue *argv, int magic) { - JSMapState *s = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic); + JSMapState *s = (JSMapState *)JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic); JSMapRecord *mr; JSValue key; @@ -45653,7 +45653,7 @@ static JSValue js_map_has(JSContext *ctx, JSValue this_val, static JSValue js_map_delete(JSContext *ctx, JSValue this_val, int argc, JSValue *argv, int magic) { - JSMapState *s = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic); + JSMapState *s = (JSMapState *)JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic); JSMapRecord *mr; JSValue key; @@ -45670,7 +45670,7 @@ static JSValue js_map_delete(JSContext *ctx, JSValue this_val, static JSValue js_map_clear(JSContext *ctx, JSValue this_val, int argc, JSValue *argv, int magic) { - JSMapState *s = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic); + JSMapState *s = (JSMapState *)JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic); struct list_head *el, *el1; JSMapRecord *mr; @@ -45685,7 +45685,7 @@ static JSValue js_map_clear(JSContext *ctx, JSValue this_val, static JSValue js_map_get_size(JSContext *ctx, JSValue this_val, int magic) { - JSMapState *s = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic); + JSMapState *s = (JSMapState *)JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic); if (!s) return JS_EXCEPTION; return js_uint32(s->record_count); @@ -45694,7 +45694,7 @@ static JSValue js_map_get_size(JSContext *ctx, JSValue this_val, int magic) static JSValue js_map_forEach(JSContext *ctx, JSValue this_val, int argc, JSValue *argv, int magic) { - JSMapState *s = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic); + JSMapState *s = (JSMapState *)JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic); JSValue func, this_arg; JSValue ret, args[3]; struct list_head *el; @@ -45919,13 +45919,13 @@ static JSValue js_create_map_iterator(JSContext *ctx, JSValue this_val, kind = magic >> 2; magic &= 3; - s = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic); + s = (JSMapState *)JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic); if (!s) return JS_EXCEPTION; enum_obj = JS_NewObjectClass(ctx, JS_CLASS_MAP_ITERATOR + magic); if (JS_IsException(enum_obj)) goto fail; - it = js_malloc(ctx, sizeof(*it)); + it = (JSMapIteratorData *)js_malloc(ctx, sizeof(*it)); if (!it) { JS_FreeValue(ctx, enum_obj); goto fail; @@ -45948,14 +45948,14 @@ static JSValue js_map_iterator_next(JSContext *ctx, JSValue this_val, JSMapRecord *mr; struct list_head *el; - it = JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP_ITERATOR + magic); + it = (JSMapIteratorData *)JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP_ITERATOR + magic); if (!it) { *pdone = FALSE; return JS_EXCEPTION; } if (JS_IsUndefined(it->obj)) goto done; - s = JS_GetOpaque(it->obj, JS_CLASS_MAP + magic); + s = (JSMapState *)JS_GetOpaque(it->obj, JS_CLASS_MAP + magic); assert(s != NULL); if (!it->cur_record) { el = s->records.next; @@ -46152,7 +46152,7 @@ typedef struct JSPromiseReactionData { JSPromiseStateEnum JS_PromiseState(JSContext *ctx, JSValue promise) { - JSPromiseData *s = JS_GetOpaque(promise, JS_CLASS_PROMISE); + JSPromiseData *s = (JSPromiseData *)JS_GetOpaque(promise, JS_CLASS_PROMISE); if (!s) return -1; return s->promise_state; @@ -46160,7 +46160,7 @@ typedef struct JSPromiseReactionData { JSValue JS_PromiseResult(JSContext *ctx, JSValue promise) { - JSPromiseData *s = JS_GetOpaque(promise, JS_CLASS_PROMISE); + JSPromiseData *s = (JSPromiseData *)JS_GetOpaque(promise, JS_CLASS_PROMISE); if (!s) return JS_UNDEFINED; return JS_DupValue(ctx, s->promise_result); @@ -46238,7 +46238,7 @@ void JS_SetHostPromiseRejectionTracker(JSRuntime *rt, static void fulfill_or_reject_promise(JSContext *ctx, JSValue promise, JSValue value, BOOL is_reject) { - JSPromiseData *s = JS_GetOpaque(promise, JS_CLASS_PROMISE); + JSPromiseData *s = (JSPromiseData *)JS_GetOpaque(promise, JS_CLASS_PROMISE); struct list_head *el, *el1; JSPromiseReactionData *rd; JSValue args[5]; @@ -46326,7 +46326,7 @@ static int js_create_resolving_functions(JSContext *ctx, JSPromiseFunctionDataResolved *sr; int i, ret; - sr = js_malloc(ctx, sizeof(*sr)); + sr = (JSPromiseFunctionDataResolved *)js_malloc(ctx, sizeof(*sr)); if (!sr) return -1; sr->ref_count = 1; @@ -46337,7 +46337,7 @@ static int js_create_resolving_functions(JSContext *ctx, JS_CLASS_PROMISE_RESOLVE_FUNCTION + i); if (JS_IsException(obj)) goto fail; - s = js_malloc(ctx, sizeof(*s)); + s = (JSPromiseFunctionData *)js_malloc(ctx, sizeof(*s)); if (!s) { JS_FreeValue(ctx, obj); fail: @@ -46434,7 +46434,7 @@ static JSValue js_promise_resolve_function_call(JSContext *ctx, static void js_promise_finalizer(JSRuntime *rt, JSValue val) { - JSPromiseData *s = JS_GetOpaque(val, JS_CLASS_PROMISE); + JSPromiseData *s = (JSPromiseData *)JS_GetOpaque(val, JS_CLASS_PROMISE); struct list_head *el, *el1; int i; @@ -46454,7 +46454,7 @@ static void js_promise_finalizer(JSRuntime *rt, JSValue val) static void js_promise_mark(JSRuntime *rt, JSValue val, JS_MarkFunc *mark_func) { - JSPromiseData *s = JS_GetOpaque(val, JS_CLASS_PROMISE); + JSPromiseData *s = (JSPromiseData *)JS_GetOpaque(val, JS_CLASS_PROMISE); struct list_head *el; int i; @@ -46487,7 +46487,7 @@ static JSValue js_promise_constructor(JSContext *ctx, JSValue new_target, obj = js_create_from_ctor(ctx, new_target, JS_CLASS_PROMISE); if (JS_IsException(obj)) return JS_EXCEPTION; - s = js_mallocz(ctx, sizeof(*s)); + s = (JSPromiseData *)js_mallocz(ctx, sizeof(*s)); if (!s) goto fail; s->promise_state = JS_PROMISE_PENDING; @@ -46566,7 +46566,7 @@ static JSValue js_new_promise_capability(JSContext *ctx, } if (JS_IsException(result_promise)) goto fail; - s = JS_GetOpaque(executor, JS_CLASS_C_FUNCTION_DATA); + s = (JSCFunctionDataRecord *)JS_GetOpaque(executor, JS_CLASS_C_FUNCTION_DATA); for(i = 0; i < 2; i++) { if (check_function(ctx, s->data[i])) goto fail; @@ -46954,7 +46954,7 @@ static __exception int perform_promise_then(JSContext *ctx, JSValue *resolve_reject, JSValue *cap_resolving_funcs) { - JSPromiseData *s = JS_GetOpaque(promise, JS_CLASS_PROMISE); + JSPromiseData *s = (JSPromiseData *)JS_GetOpaque(promise, JS_CLASS_PROMISE); JSPromiseReactionData *rd_array[2], *rd; int i, j; @@ -46962,7 +46962,7 @@ static __exception int perform_promise_then(JSContext *ctx, rd_array[1] = NULL; for(i = 0; i < 2; i++) { JSValue handler; - rd = js_mallocz(ctx, sizeof(*rd)); + rd = (JSPromiseReactionData *)js_mallocz(ctx, sizeof(*rd)); if (!rd) { if (i == 1) promise_reaction_data_free(ctx->rt, rd_array[0]); @@ -47011,7 +47011,7 @@ static JSValue js_promise_then(JSContext *ctx, JSValue this_val, JSPromiseData *s; int i, ret; - s = JS_GetOpaque2(ctx, this_val, JS_CLASS_PROMISE); + s = (JSPromiseData *)JS_GetOpaque2(ctx, this_val, JS_CLASS_PROMISE); if (!s) return JS_EXCEPTION; @@ -47180,7 +47180,7 @@ typedef struct JSAsyncFromSyncIteratorData { static void js_async_from_sync_iterator_finalizer(JSRuntime *rt, JSValue val) { JSAsyncFromSyncIteratorData *s = - JS_GetOpaque(val, JS_CLASS_ASYNC_FROM_SYNC_ITERATOR); + (JSAsyncFromSyncIteratorData *)JS_GetOpaque(val, JS_CLASS_ASYNC_FROM_SYNC_ITERATOR); if (s) { JS_FreeValueRT(rt, s->sync_iter); JS_FreeValueRT(rt, s->next_method); @@ -47192,7 +47192,7 @@ static void js_async_from_sync_iterator_mark(JSRuntime *rt, JSValue val, JS_MarkFunc *mark_func) { JSAsyncFromSyncIteratorData *s = - JS_GetOpaque(val, JS_CLASS_ASYNC_FROM_SYNC_ITERATOR); + (JSAsyncFromSyncIteratorData *)JS_GetOpaque(val, JS_CLASS_ASYNC_FROM_SYNC_ITERATOR); if (s) { JS_MarkValue(rt, s->sync_iter, mark_func); JS_MarkValue(rt, s->next_method, mark_func); @@ -47213,7 +47213,7 @@ static JSValue JS_CreateAsyncFromSyncIterator(JSContext *ctx, JS_FreeValue(ctx, next_method); return async_iter; } - s = js_mallocz(ctx, sizeof(*s)); + s = (JSAsyncFromSyncIteratorData *)js_mallocz(ctx, sizeof(*s)); if (!s) { JS_FreeValue(ctx, async_iter); JS_FreeValue(ctx, next_method); @@ -47237,7 +47237,7 @@ static JSValue js_async_from_sync_iterator_next(JSContext *ctx, JSValue this_val promise = JS_NewPromiseCapability(ctx, resolving_funcs); if (JS_IsException(promise)) return JS_EXCEPTION; - s = JS_GetOpaque(this_val, JS_CLASS_ASYNC_FROM_SYNC_ITERATOR); + s = (JSAsyncFromSyncIteratorData *)JS_GetOpaque(this_val, JS_CLASS_ASYNC_FROM_SYNC_ITERATOR); if (!s) { JS_ThrowTypeError(ctx, "not an Async-from-Sync Iterator"); goto reject; @@ -49371,21 +49371,21 @@ static JSValue js_array_buffer_constructor3(JSContext *ctx, JS_ThrowRangeError(ctx, "invalid array buffer length"); goto fail; } - abuf = js_malloc(ctx, sizeof(*abuf)); + abuf = (JSArrayBuffer *)js_malloc(ctx, sizeof(*abuf)); if (!abuf) goto fail; abuf->byte_length = len; if (alloc_flag) { if (class_id == JS_CLASS_SHARED_ARRAY_BUFFER && rt->sab_funcs.sab_alloc) { - abuf->data = rt->sab_funcs.sab_alloc(rt->sab_funcs.sab_opaque, + abuf->data = (uint8_t *)rt->sab_funcs.sab_alloc(rt->sab_funcs.sab_opaque, max_int(len, 1)); if (!abuf->data) goto fail; memset(abuf->data, 0, len); } else { /* the allocation must be done after the object creation */ - abuf->data = js_mallocz(ctx, max_int(len, 1)); + abuf->data = (uint8_t *)js_mallocz(ctx, max_int(len, 1)); if (!abuf->data) goto fail; } @@ -49543,7 +49543,7 @@ static JSValue JS_ThrowTypeErrorDetachedArrayBuffer(JSContext *ctx) static JSValue js_array_buffer_get_detached(JSContext *ctx, JSValue this_val) { - JSArrayBuffer *abuf = JS_GetOpaque2(ctx, this_val, JS_CLASS_ARRAY_BUFFER); + JSArrayBuffer *abuf = (JSArrayBuffer *)JS_GetOpaque2(ctx, this_val, JS_CLASS_ARRAY_BUFFER); if (!abuf) return JS_EXCEPTION; if (abuf->shared) @@ -49555,7 +49555,7 @@ static JSValue js_array_buffer_get_byteLength(JSContext *ctx, JSValue this_val, int class_id) { - JSArrayBuffer *abuf = JS_GetOpaque2(ctx, this_val, class_id); + JSArrayBuffer *abuf = (JSArrayBuffer *)JS_GetOpaque2(ctx, this_val, class_id); if (!abuf) return JS_EXCEPTION; /* return 0 if detached */ @@ -49564,7 +49564,7 @@ static JSValue js_array_buffer_get_byteLength(JSContext *ctx, void JS_DetachArrayBuffer(JSContext *ctx, JSValue obj) { - JSArrayBuffer *abuf = JS_GetOpaque(obj, JS_CLASS_ARRAY_BUFFER); + JSArrayBuffer *abuf = (JSArrayBuffer *)JS_GetOpaque(obj, JS_CLASS_ARRAY_BUFFER); struct list_head *el; if (!abuf || abuf->detached) @@ -49632,7 +49632,7 @@ static JSValue js_array_buffer_transfer(JSContext *ctx, uint64_t new_len, old_len; uint8_t *bs, *new_bs; - abuf = JS_GetOpaque2(ctx, this_val, JS_CLASS_ARRAY_BUFFER); + abuf = (JSArrayBuffer *)JS_GetOpaque2(ctx, this_val, JS_CLASS_ARRAY_BUFFER); if (!abuf) return JS_EXCEPTION; if (abuf->shared) @@ -49652,7 +49652,7 @@ static JSValue js_array_buffer_transfer(JSContext *ctx, old_len = abuf->byte_length; /* if length mismatch, realloc. Otherwise, use the same backing buffer. */ if (new_len != old_len) { - new_bs = js_realloc(ctx, bs, new_len); + new_bs = (uint8_t *)js_realloc(ctx, bs, new_len); if (!new_bs) return JS_EXCEPTION; bs = new_bs; @@ -49677,7 +49677,7 @@ static JSValue js_array_buffer_slice(JSContext *ctx, int64_t len, start, end, new_len; JSValue ctor, new_obj; - abuf = JS_GetOpaque2(ctx, this_val, class_id); + abuf = (JSArrayBuffer *)JS_GetOpaque2(ctx, this_val, class_id); if (!abuf) return JS_EXCEPTION; if (abuf->detached) @@ -49708,7 +49708,7 @@ static JSValue js_array_buffer_slice(JSContext *ctx, } if (JS_IsException(new_obj)) return new_obj; - new_abuf = JS_GetOpaque2(ctx, new_obj, class_id); + new_abuf = (JSArrayBuffer *)JS_GetOpaque2(ctx, new_obj, class_id); if (!new_abuf) goto fail; if (js_same_value(ctx, new_obj, this_val)) { @@ -50578,7 +50578,7 @@ static JSValue js_typed_array_indexOf(JSContext *ctx, JSValue this_val, } } else if (tag == JS_TAG_BIG_INT) { - JSBigInt *p1 = JS_VALUE_GET_PTR(argv[0]); + JSBigInt *p1 = (JSBigInt *)JS_VALUE_GET_PTR(argv[0]); if (p->class_id == JS_CLASS_BIG_INT64_ARRAY) { if (bf_get_int64(&v64, &p1->num, 0) != 0) @@ -50609,7 +50609,7 @@ static JSValue js_typed_array_indexOf(JSContext *ctx, JSValue this_val, pv = p->u.array.u.uint8_ptr; v = v64; if (inc > 0) { - pp = memchr(pv + k, v, len - k); + pp = (const uint8_t *)memchr(pv + k, v, len - k); if (pp) res = pp - pv; } else { @@ -51097,7 +51097,7 @@ struct TA_sort_context { }; static int js_TA_cmp_generic(const void *a, const void *b, void *opaque) { - struct TA_sort_context *psc = opaque; + struct TA_sort_context *psc = (struct TA_sort_context *)opaque; JSContext *ctx = psc->ctx; uint32_t a_idx, b_idx; JSValue argv[2]; @@ -51221,12 +51221,12 @@ static JSValue js_typed_array_sort(JSContext *ctx, JSValue this_val, size_t i, j; /* XXX: a stable sort would use less memory */ - array_idx = js_malloc(ctx, len * sizeof(array_idx[0])); + array_idx = (uint32_t *)js_malloc(ctx, len * sizeof(array_idx[0])); if (!array_idx) return JS_EXCEPTION; for(i = 0; i < len; i++) array_idx[i] = i; - tsc.array_ptr = array_ptr; + tsc.array_ptr = (uint8_t *)array_ptr; tsc.elt_size = elt_size; rqsort(array_idx, len, sizeof(array_idx[0]), js_TA_cmp_generic, &tsc); @@ -51364,7 +51364,7 @@ static int typed_array_init(JSContext *ctx, JSValue obj, p = JS_VALUE_GET_OBJ(obj); size_log2 = typed_array_size_log2(p->class_id); - ta = js_malloc(ctx, sizeof(*ta)); + ta = (JSTypedArray *)js_malloc(ctx, sizeof(*ta)); if (!ta) { JS_FreeValue(ctx, buffer); return -1; @@ -51512,7 +51512,7 @@ static JSValue js_typed_array_constructor_ta(JSContext *ctx, JS_ThrowTypeErrorDetachedArrayBuffer(ctx); goto fail; } - abuf = JS_GetOpaque(buffer, JS_CLASS_ARRAY_BUFFER); + abuf = (JSArrayBuffer *)JS_GetOpaque(buffer, JS_CLASS_ARRAY_BUFFER); if (typed_array_init(ctx, obj, buffer, 0, len)) goto fail; if (p->class_id == classid) { @@ -51670,7 +51670,7 @@ static JSValue js_dataview_constructor(JSContext *ctx, JS_ThrowTypeErrorDetachedArrayBuffer(ctx); goto fail; } - ta = js_malloc(ctx, sizeof(*ta)); + ta = (JSTypedArray *)js_malloc(ctx, sizeof(*ta)); if (!ta) { fail: JS_FreeValue(ctx, obj); @@ -51698,7 +51698,7 @@ static JSValue js_dataview_getValue(JSContext *ctx, uint32_t v; uint64_t pos; - ta = JS_GetOpaque2(ctx, this_obj, JS_CLASS_DATAVIEW); + ta = (JSTypedArray *)JS_GetOpaque2(ctx, this_obj, JS_CLASS_DATAVIEW); if (!ta) return JS_EXCEPTION; size = 1 << typed_array_size_log2(class_id); @@ -51799,7 +51799,7 @@ static JSValue js_dataview_setValue(JSContext *ctx, uint64_t pos; JSValue val; - ta = JS_GetOpaque2(ctx, this_obj, JS_CLASS_DATAVIEW); + ta = (JSTypedArray *)JS_GetOpaque2(ctx, this_obj, JS_CLASS_DATAVIEW); if (!ta) return JS_EXCEPTION; size = 1 << typed_array_size_log2(class_id); @@ -52284,7 +52284,7 @@ static JSValue js_atomics_wait(JSContext *ctx, } waiter = &waiter_s; - waiter->ptr = ptr; + waiter->ptr = (int32_t *)ptr; js_cond_init(&waiter->cond); waiter->linked = TRUE; list_add_tail(&waiter->link, &js_atomics_waiter_list); @@ -52540,7 +52540,7 @@ typedef struct JSWeakRefData { static void js_weakref_finalizer(JSRuntime *rt, JSValue val) { - JSWeakRefData *wrd = JS_GetOpaque(val, JS_CLASS_WEAK_REF); + JSWeakRefData *wrd = (JSWeakRefData *)JS_GetOpaque(val, JS_CLASS_WEAK_REF); if (!wrd) return; @@ -52571,12 +52571,12 @@ static JSValue js_weakref_constructor(JSContext *ctx, JSValue new_target, int ar JSValue obj = js_create_from_ctor(ctx, new_target, JS_CLASS_WEAK_REF); if (JS_IsException(obj)) return JS_EXCEPTION; - JSWeakRefData *wrd = js_malloc(ctx, sizeof(*wrd)); + JSWeakRefData *wrd = (JSWeakRefData *)js_malloc(ctx, sizeof(*wrd)); if (!wrd) { JS_FreeValue(ctx, obj); return JS_EXCEPTION; } - JSWeakRefRecord *wr = js_malloc(ctx, sizeof(*wr)); + JSWeakRefRecord *wr = (JSWeakRefRecord *)js_malloc(ctx, sizeof(*wr)); if (!wr) { JS_FreeValue(ctx, obj); js_free(ctx, wrd); @@ -52594,7 +52594,7 @@ static JSValue js_weakref_constructor(JSContext *ctx, JSValue new_target, int ar static JSValue js_weakref_deref(JSContext *ctx, JSValue this_val, int argc, JSValue *argv) { - JSWeakRefData *wrd = JS_GetOpaque2(ctx, this_val, JS_CLASS_WEAK_REF); + JSWeakRefData *wrd = (JSWeakRefData *)JS_GetOpaque2(ctx, this_val, JS_CLASS_WEAK_REF); if (!wrd) return JS_EXCEPTION; return js_dup(wrd->target); @@ -52641,7 +52641,7 @@ static void delete_finrec_weakref(JSRuntime *rt, JSFinRecEntry *fre) static void js_finrec_finalizer(JSRuntime *rt, JSValue val) { - JSFinalizationRegistryData *frd = JS_GetOpaque(val, JS_CLASS_FINALIZATION_REGISTRY); + JSFinalizationRegistryData *frd = (JSFinalizationRegistryData *)JS_GetOpaque(val, JS_CLASS_FINALIZATION_REGISTRY); if (frd) { struct list_head *el, *el1; /* first pass to remove the weak ref entries and avoid having them modified @@ -52665,7 +52665,7 @@ static void js_finrec_finalizer(JSRuntime *rt, JSValue val) static void js_finrec_mark(JSRuntime *rt, JSValue val, JS_MarkFunc *mark_func) { - JSFinalizationRegistryData *frd = JS_GetOpaque(val, JS_CLASS_FINALIZATION_REGISTRY); + JSFinalizationRegistryData *frd = (JSFinalizationRegistryData *)JS_GetOpaque(val, JS_CLASS_FINALIZATION_REGISTRY); if (frd) { JS_MarkValue(rt, frd->cb, mark_func); struct list_head *el; @@ -52688,7 +52688,7 @@ static JSValue js_finrec_constructor(JSContext *ctx, JSValue new_target, int arg JSValue obj = js_create_from_ctor(ctx, new_target, JS_CLASS_FINALIZATION_REGISTRY); if (JS_IsException(obj)) return JS_EXCEPTION; - JSFinalizationRegistryData *frd = js_malloc(ctx, sizeof(*frd)); + JSFinalizationRegistryData *frd = (JSFinalizationRegistryData *)js_malloc(ctx, sizeof(*frd)); if (!frd) { JS_FreeValue(ctx, obj); return JS_EXCEPTION; @@ -52702,7 +52702,7 @@ static JSValue js_finrec_constructor(JSContext *ctx, JSValue new_target, int arg static JSValue js_finrec_register(JSContext *ctx, JSValue this_val, int argc, JSValue *argv) { - JSFinalizationRegistryData *frd = JS_GetOpaque2(ctx, this_val, JS_CLASS_FINALIZATION_REGISTRY); + JSFinalizationRegistryData *frd = (JSFinalizationRegistryData *)JS_GetOpaque2(ctx, this_val, JS_CLASS_FINALIZATION_REGISTRY); if (!frd) return JS_EXCEPTION; @@ -52720,10 +52720,10 @@ static JSValue js_finrec_register(JSContext *ctx, JSValue this_val, int argc, JS if (!JS_IsUndefined(token) && !is_valid_weakref_target(token)) return JS_ThrowTypeError(ctx, "invalid unregister token"); - JSFinRecEntry *fre = js_malloc(ctx, sizeof(*fre)); + JSFinRecEntry *fre = (JSFinRecEntry *)js_malloc(ctx, sizeof(*fre)); if (!fre) return JS_EXCEPTION; - JSWeakRefRecord *wr = js_malloc(ctx, sizeof(*wr)); + JSWeakRefRecord *wr = (JSWeakRefRecord *)js_malloc(ctx, sizeof(*wr)); if (!wr) { js_free(ctx, fre); return JS_EXCEPTION; @@ -52742,7 +52742,7 @@ static JSValue js_finrec_register(JSContext *ctx, JSValue this_val, int argc, JS static JSValue js_finrec_unregister(JSContext *ctx, JSValue this_val, int argc, JSValue *argv) { - JSFinalizationRegistryData *frd = JS_GetOpaque2(ctx, this_val, JS_CLASS_FINALIZATION_REGISTRY); + JSFinalizationRegistryData *frd = (JSFinalizationRegistryData *)JS_GetOpaque2(ctx, this_val, JS_CLASS_FINALIZATION_REGISTRY); if (!frd) return JS_EXCEPTION; @@ -52854,7 +52854,7 @@ static void reset_weak_ref(JSRuntime *rt, JSWeakRefRecord **first_weak_ref) break; case JS_WEAK_REF_KIND_FINALIZATION_REGISTRY_ENTRY: { fre = wr->u.fin_rec_entry; - JSFinalizationRegistryData *frd = JS_GetOpaque(fre->obj, JS_CLASS_FINALIZATION_REGISTRY); + JSFinalizationRegistryData *frd = (JSFinalizationRegistryData *)JS_GetOpaque(fre->obj, JS_CLASS_FINALIZATION_REGISTRY); assert(frd != NULL); /** * During the GC sweep phase the held object might be collected first. @@ -52886,7 +52886,7 @@ static BOOL is_valid_weakref_target(JSValue val) break; case JS_TAG_SYMBOL: { // Per spec: prohibit symbols registered with Symbol.for() - JSAtomStruct *p = JS_VALUE_GET_PTR(val); + JSAtomStruct *p = (JSAtomStruct *)JS_VALUE_GET_PTR(val); if (p->atom_type != JS_ATOM_TYPE_GLOBAL_SYMBOL) break; // fallthru @@ -52911,13 +52911,13 @@ static void insert_weakref_record(JSValue target, struct JSWeakRefRecord *wr) JSInlineCache *init_ic(JSContext *ctx) { JSInlineCache *ic; - ic = js_malloc(ctx, sizeof(JSInlineCache)); + ic = (JSInlineCache *)js_malloc(ctx, sizeof(JSInlineCache)); if (unlikely(!ic)) goto fail; ic->count = 0; ic->hash_bits = 2; ic->capacity = 1 << ic->hash_bits; - ic->hash = js_mallocz(ctx, sizeof(ic->hash[0]) * ic->capacity); + ic->hash = (JSInlineCacheHashSlot **)js_mallocz(ctx, sizeof(ic->hash[0]) * ic->capacity); if (unlikely(!ic->hash)) goto fail; ic->cache = NULL; @@ -52936,7 +52936,7 @@ int rebuild_ic(JSContext *ctx, JSInlineCache *ic) if (ic->count == 0) goto end; count = 0; - ic->cache = js_mallocz(ctx, sizeof(JSInlineCacheRingSlot) * ic->count); + ic->cache = (JSInlineCacheRingSlot *)js_mallocz(ctx, sizeof(JSInlineCacheRingSlot) * ic->count); if (unlikely(!ic->cache)) goto fail; for (i = 0; i < ic->capacity; i++) { @@ -52958,7 +52958,7 @@ int resize_ic_hash(JSContext *ctx, JSInlineCache *ic) JSInlineCacheHashSlot *ch, *ch_next; JSInlineCacheHashSlot **new_hash; new_capacity = 1 << (ic->hash_bits + 1); - new_hash = js_mallocz(ctx, sizeof(ic->hash[0]) * new_capacity); + new_hash = (JSInlineCacheHashSlot **)js_mallocz(ctx, sizeof(ic->hash[0]) * new_capacity); if (unlikely(!new_hash)) goto fail; ic->hash_bits += 1; @@ -53045,7 +53045,7 @@ uint32_t add_ic_slot(JSContext *ctx, JSInlineCache *ic, JSAtom atom, JSObject *o static void js_callsite_finalizer(JSRuntime *rt, JSValue val) { - JSCallSiteData *csd = JS_GetOpaque(val, JS_CLASS_CALL_SITE); + JSCallSiteData *csd = (JSCallSiteData *)JS_GetOpaque(val, JS_CLASS_CALL_SITE); if (csd) { JS_FreeValueRT(rt, csd->filename); JS_FreeValueRT(rt, csd->func); @@ -53056,7 +53056,7 @@ static void js_callsite_finalizer(JSRuntime *rt, JSValue val) static void js_callsite_mark(JSRuntime *rt, JSValue val, JS_MarkFunc *mark_func) { - JSCallSiteData *csd = JS_GetOpaque(val, JS_CLASS_CALL_SITE); + JSCallSiteData *csd = (JSCallSiteData *)JS_GetOpaque(val, JS_CLASS_CALL_SITE); if (csd) { JS_MarkValue(rt, csd->filename, mark_func); JS_MarkValue(rt, csd->func, mark_func); @@ -53069,7 +53069,7 @@ static JSValue js_new_callsite(JSContext *ctx, JSCallSiteData *csd) { if (JS_IsException(obj)) return JS_EXCEPTION; - JSCallSiteData *csd1 = js_malloc(ctx, sizeof(*csd)); + JSCallSiteData *csd1 = (JSCallSiteData *)js_malloc(ctx, sizeof(*csd)); if (!csd1) { JS_FreeValue(ctx, obj); return JS_EXCEPTION; @@ -53138,16 +53138,16 @@ static void js_new_callsite_data2(JSContext *ctx, JSCallSiteData *csd, const cha static JSValue js_callsite_getfield(JSContext *ctx, JSValue this_val, int argc, JSValue *argv, int magic) { - JSCallSiteData *csd = JS_GetOpaque2(ctx, this_val, JS_CLASS_CALL_SITE); + JSCallSiteData *csd = (JSCallSiteData *)JS_GetOpaque2(ctx, this_val, JS_CLASS_CALL_SITE); if (!csd) return JS_EXCEPTION; - JSValue *field = (void *)((char *)csd + magic); + JSValue *field = (JSValue *)((char *)csd + magic); return js_dup(*field); } static JSValue js_callsite_isnative(JSContext *ctx, JSValue this_val, int argc, JSValue *argv) { - JSCallSiteData *csd = JS_GetOpaque2(ctx, this_val, JS_CLASS_CALL_SITE); + JSCallSiteData *csd = (JSCallSiteData *)JS_GetOpaque2(ctx, this_val, JS_CLASS_CALL_SITE); if (!csd) return JS_EXCEPTION; return JS_NewBool(ctx, csd->native); @@ -53155,10 +53155,10 @@ static JSValue js_callsite_isnative(JSContext *ctx, JSValue this_val, int argc, static JSValue js_callsite_getnumber(JSContext *ctx, JSValue this_val, int argc, JSValue *argv, int magic) { - JSCallSiteData *csd = JS_GetOpaque2(ctx, this_val, JS_CLASS_CALL_SITE); + JSCallSiteData *csd = (JSCallSiteData *)JS_GetOpaque2(ctx, this_val, JS_CLASS_CALL_SITE); if (!csd) return JS_EXCEPTION; - int *field = (void *)((char *)csd + magic); + int *field = (int *)((char *)csd + magic); return JS_NewInt32(ctx, *field); } diff --git a/run-test262.c b/run-test262.c index 9c6475ae3..1cf51a5df 100644 --- a/run-test262.c +++ b/run-test262.c @@ -125,7 +125,7 @@ void perror_exit(int errcode, const char *s) char *strdup_len(const char *str, int len) { - char *p = malloc(len + 1); + char *p = (char *)malloc(len + 1); memcpy(p, str, len); p[len] = '\0'; return p; @@ -142,7 +142,7 @@ char *str_append(char **pp, const char *sep, const char *str) { if (p) { len = strlen(p) + strlen(sep); } - res = malloc(len + strlen(str) + 1); + res = (char *)malloc(len + strlen(str) + 1); if (p) { strcpy(res, p); strcat(res, sep); @@ -201,7 +201,7 @@ char *compose_path(const char *path, const char *name) } else { path_len = strlen(path); name_len = strlen(name); - d = malloc(path_len + 1 + name_len + 1); + d = (char *)malloc(path_len + 1 + name_len + 1); if (d) { q = d; memcpy(q, path, path_len); @@ -293,7 +293,7 @@ void namelist_add(namelist_t *lp, const char *base, const char *name) goto fail; if (lp->count == lp->size) { size_t newsize = lp->size + (lp->size >> 1) + 4; - char **a = realloc(lp->array, sizeof(lp->array[0]) * newsize); + char **a = (char **)realloc(lp->array, sizeof(lp->array[0]) * newsize); if (!a) goto fail; lp->array = a; @@ -453,7 +453,7 @@ static struct list_head report_list = LIST_HEAD_INIT(report_list); static void *agent_start(void *arg) { - Test262Agent *agent = arg; + Test262Agent *agent = (Test262Agent *)arg; JSRuntime *rt; JSContext *ctx; JSValue ret_val; @@ -539,7 +539,7 @@ static JSValue js_agent_start(JSContext *ctx, JSValue this_val, script = JS_ToCString(ctx, argv[0]); if (!script) return JS_EXCEPTION; - agent = malloc(sizeof(*agent)); + agent = (Test262Agent *)malloc(sizeof(*agent)); memset(agent, 0, sizeof(*agent)); agent->broadcast_func = JS_UNDEFINED; agent->broadcast_sab = JS_UNDEFINED; @@ -572,7 +572,7 @@ static void js_agent_free(JSContext *ctx) static JSValue js_agent_leaving(JSContext *ctx, JSValue this_val, int argc, JSValue *argv) { - Test262Agent *agent = JS_GetContextOpaque(ctx); + Test262Agent *agent = (Test262Agent *)JS_GetContextOpaque(ctx); if (!agent) return JS_ThrowTypeError(ctx, "must be called inside an agent"); /* nothing to do */ @@ -635,7 +635,7 @@ static JSValue js_agent_broadcast(JSContext *ctx, JSValue this_val, static JSValue js_agent_receiveBroadcast(JSContext *ctx, JSValue this_val, int argc, JSValue *argv) { - Test262Agent *agent = JS_GetContextOpaque(ctx); + Test262Agent *agent = (Test262Agent *)JS_GetContextOpaque(ctx); if (!agent) return JS_ThrowTypeError(ctx, "must be called inside an agent"); if (!JS_IsFunction(ctx, argv[0])) @@ -701,7 +701,7 @@ static JSValue js_agent_report(JSContext *ctx, JSValue this_val, str = JS_ToCString(ctx, argv[0]); if (!str) return JS_EXCEPTION; - rep = malloc(sizeof(*rep)); + rep = (AgentReport *)malloc(sizeof(*rep)); rep->str = strdup(str); JS_FreeCString(ctx, str); @@ -824,7 +824,7 @@ static JSModuleDef *js_module_loader_test(JSContext *ctx, // interpret import("bar.js") from path/to/foo.js as // import("path/to/bar.js") but leave import("./bar.js") untouched - filename = opaque; + filename = (char *)opaque; if (!strchr(module_name, '/')) { slash = strrchr(filename, '/'); if (slash) { @@ -848,7 +848,7 @@ static JSModuleDef *js_module_loader_test(JSContext *ctx, if (JS_IsException(func_val)) return NULL; /* the module is already referenced, so we must free it */ - m = JS_VALUE_GET_PTR(func_val); + m = (JSModuleDef *)JS_VALUE_GET_PTR(func_val); JS_FreeValue(ctx, func_val); return m; } @@ -1434,7 +1434,7 @@ char *extract_desc(const char *buf, char style) return NULL; } len = p - desc_start; - desc = malloc(len + 1); + desc = (char *)malloc(len + 1); memcpy(desc, desc_start, len); desc[len] = '\0'; return desc; diff --git a/unicode_gen.c b/unicode_gen.c index d94ec64bb..583fa6e02 100644 --- a/unicode_gen.c +++ b/unicode_gen.c @@ -108,7 +108,7 @@ void add_char(int **pbuf, int *psize, int *plen, int c) if (len >= size) { size = *psize; size = max_int(len + 1, size * 3 / 2); - buf = realloc(buf, sizeof(buf[0]) * size); + buf = (int *)realloc(buf, sizeof(buf[0]) * size); *pbuf = buf; *psize = size; } @@ -827,7 +827,7 @@ void parse_script_extensions(const char *filename) for(c = c0; c <= c1; c++) { CCInfo *ci = &unicode_db[c]; ci->script_ext_len = script_ext_len; - ci->script_ext = malloc(sizeof(ci->script_ext[0]) * script_ext_len); + ci->script_ext = (uint8_t *)malloc(sizeof(ci->script_ext[0]) * script_ext_len); for(i = 0; i < script_ext_len; i++) ci->script_ext[i] = script_ext[i]; } @@ -2565,14 +2565,14 @@ void build_decompose_table(FILE *f) code_max = CHARCODE_MAX; - tab_de = mallocz((code_max + 2) * sizeof(*tab_de)); + tab_de = (DecompEntry *)mallocz((code_max + 2) * sizeof(*tab_de)); for(i = code_max; i >= 0; i--) { find_decomp_run(tab_de, i); } /* build the data buffer */ - data_buf = malloc(100000); + data_buf = (uint8_t *)malloc(100000); data_len = 0; array_len = 0; for(i = 0; i <= code_max; i++) { @@ -2666,8 +2666,8 @@ typedef struct { static int ce_cmp(const void *p1, const void *p2) { - const ComposeEntry *ce1 = p1; - const ComposeEntry *ce2 = p2; + const ComposeEntry *ce1 = (ComposeEntry *)p1; + const ComposeEntry *ce2 = (ComposeEntry *)p2; int i; for(i = 0; i < 2; i++) { @@ -2708,7 +2708,7 @@ void build_compose_table(FILE *f, const DecompEntry *tab_de) int i, v, tab_ce_len; ComposeEntry *ce, *tab_ce; - tab_ce = malloc(sizeof(*tab_ce) * COMPOSE_LEN_MAX); + tab_ce = (ComposeEntry *)malloc(sizeof(*tab_ce) * COMPOSE_LEN_MAX); tab_ce_len = 0; for(i = 0; i <= CHARCODE_MAX; i++) { CCInfo *ci = &unicode_db[i]; @@ -2916,7 +2916,7 @@ int main(int argc, char **argv) if (argc >= 3) outfilename = argv[2]; - unicode_db = mallocz(sizeof(unicode_db[0]) * (CHARCODE_MAX + 1)); + unicode_db = (CCInfo *)mallocz(sizeof(unicode_db[0]) * (CHARCODE_MAX + 1)); snprintf(filename, sizeof(filename), "%s/UnicodeData.txt", unicode_db_path); From 15f7838843cd25661b93e7075b8758cd8bec45c3 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 4 Jul 2024 15:29:00 +0300 Subject: [PATCH 02/12] Wrong length array --- cutils.c | 2 +- cutils.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cutils.c b/cutils.c index 25a687159..cf0687d63 100644 --- a/cutils.c +++ b/cutils.c @@ -588,7 +588,7 @@ size_t utf8_encode_buf16(char *dest, size_t dest_len, const uint16_t *src, size_ */ /* 2 <= base <= 36 */ -char const digits36[36] = "0123456789abcdefghijklmnopqrstuvwxyz"; +char const digits36[37] = "0123456789abcdefghijklmnopqrstuvwxyz"; #define USE_SPECIAL_RADIX_10 1 // special case base 10 radix conversions #define USE_SINGLE_CASE_FAST 1 // special case single digit numbers diff --git a/cutils.h b/cutils.h index 26436d4f2..21847d4a4 100644 --- a/cutils.h +++ b/cutils.h @@ -212,7 +212,7 @@ static inline int clz64(uint64_t a) return clz32((unsigned)(a >> 32)); else return clz32((unsigned)a) + 32; -#endif +#endif #else return __builtin_clzll(a); #endif @@ -465,7 +465,7 @@ static inline uint8_t to_upper_ascii(uint8_t c) { return c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c; } -extern char const digits36[36]; +extern char const digits36[37]; size_t u32toa(char buf[minimum_length(11)], uint32_t n); size_t i32toa(char buf[minimum_length(12)], int32_t n); size_t u64toa(char buf[minimum_length(21)], uint64_t n); From 797b85c181cbdb6e0d492eb6665bd80aa369a8b9 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 4 Jul 2024 15:49:56 +0300 Subject: [PATCH 03/12] Enum int types --- libbf.c | 12 ++++---- libregexp.c | 2 +- quickjs.c | 86 ++++++++++++++++++++++++++--------------------------- 3 files changed, 50 insertions(+), 50 deletions(-) diff --git a/libbf.c b/libbf.c index 92d6f0b8b..a2083c0d3 100644 --- a/libbf.c +++ b/libbf.c @@ -2817,7 +2817,7 @@ int bf_mul_pow_radix(bf_t *r, const bf_t *T, limb_t radix, if (ret & BF_ST_MEM_ERROR) break; if ((ret & BF_ST_INEXACT) && - !bf_can_round(r, prec, flags & BF_RND_MASK, prec1) && + !bf_can_round(r, prec, (bf_rnd_t)(flags & BF_RND_MASK), prec1) && !overflow) { /* and more precision and retry */ ziv_extra_bits = ziv_extra_bits + (ziv_extra_bits / 2); @@ -3807,7 +3807,7 @@ static char *bf_ftoa_internal(size_t *plen, const bf_t *a2, int radix, n_digits = n + prec; n1 = n; if (bf_convert_to_radix(a1, &n1, a, radix, n_digits, - flags & BF_RND_MASK, TRUE)) + (bf_rnd_t)(flags & BF_RND_MASK), TRUE)) goto fail1; start = s->size; output_digits(s, a1, radix, n_digits, n, is_dec); @@ -3907,7 +3907,7 @@ static char *bf_ftoa_internal(size_t *plen, const bf_t *a2, int radix, while (n_digits_min < n_digits_max) { n_digits = (n_digits_min + n_digits_max) / 2; if (bf_convert_to_radix(a1, &n, a, radix, n_digits, - flags & BF_RND_MASK, FALSE)) { + (bf_rnd_t)(flags & BF_RND_MASK), FALSE)) { bf_delete(b); goto fail1; } @@ -3931,7 +3931,7 @@ static char *bf_ftoa_internal(size_t *plen, const bf_t *a2, int radix, } } if (bf_convert_to_radix(a1, &n, a, radix, n_digits, - flags & BF_RND_MASK, FALSE)) { + (bf_rnd_t)(flags & BF_RND_MASK), FALSE)) { fail1: bf_delete(a1); goto fail; @@ -4184,7 +4184,7 @@ static int bf_const_get(bf_t *T, limb_t prec, bf_flags_t flags, } bf_set(T, &c->val); T->sign = sign; - if (!bf_can_round(T, prec, flags & BF_RND_MASK, prec1)) { + if (!bf_can_round(T, prec, (bf_rnd_t)(flags & BF_RND_MASK), prec1)) { /* and more precision and retry */ ziv_extra_bits = ziv_extra_bits + (ziv_extra_bits / 2); } else { @@ -4261,7 +4261,7 @@ static int bf_ziv_rounding(bf_t *r, const bf_t *a, ret = 0; break; } - if (bf_can_round(r, prec, rnd_mode, prec1)) { + if (bf_can_round(r, prec, (bf_rnd_t)rnd_mode, prec1)) { ret = BF_ST_INEXACT; break; } diff --git a/libregexp.c b/libregexp.c index eaa9e8319..86de2860d 100644 --- a/libregexp.c +++ b/libregexp.c @@ -2256,7 +2256,7 @@ static intptr_t lre_exec_backtrack(REExecContext *s, uint8_t **capture, pc += 4; ret = push_state(s, capture, stack, stack_len, pc + (int)val, cptr, - RE_EXEC_STATE_LOOKAHEAD + opcode - REOP_lookahead, + (REExecStateEnum)(RE_EXEC_STATE_LOOKAHEAD + opcode - REOP_lookahead), 0); if (ret < 0) return -1; diff --git a/quickjs.c b/quickjs.c index 37de44ac0..545da4aaa 100644 --- a/quickjs.c +++ b/quickjs.c @@ -2654,7 +2654,7 @@ static JSAtomKindEnum JS_AtomGetKind(JSContext *ctx, JSAtom v) default: abort(); } - return (JSAtomKindEnum){-1}; // pacify compiler + return (JSAtomKindEnum)(-1); // pacify compiler } static BOOL JS_AtomIsString(JSContext *ctx, JSAtom v) @@ -4564,7 +4564,7 @@ static int compact_properties(JSContext *ctx, JSObject *p) js_free(ctx, get_alloc_from_shape(old_sh)); /* reduce the size of the object properties */ - new_prop = js_realloc(ctx, p->prop, sizeof(new_prop[0]) * new_size); + new_prop = (JSProperty *)js_realloc(ctx, p->prop, sizeof(new_prop[0]) * new_size); if (new_prop) p->prop = new_prop; return 0; @@ -4716,7 +4716,7 @@ static JSValue JS_NewObjectFromShape(JSContext *ctx, JSShape *sh, JSClassID clas JSObject *p; js_trigger_gc(ctx->rt, sizeof(JSObject)); - p = js_malloc(ctx, sizeof(JSObject)); + p = (JSObject *)js_malloc(ctx, sizeof(JSObject)); if (unlikely(!p)) goto fail; p->class_id = class_id; @@ -5106,7 +5106,7 @@ static JSContext *js_autoinit_get_realm(JSProperty *pr) static JSAutoInitIDEnum js_autoinit_get_id(JSProperty *pr) { - return pr->u.init.realm_and_id & 3; + return (JSAutoInitIDEnum)(pr->u.init.realm_and_id & 3); } static void js_autoinit_free(JSRuntime *rt, JSProperty *pr) @@ -12232,7 +12232,7 @@ static __exception int js_post_inc_slow(JSContext *ctx, } sp[-1] = op1; sp[0] = js_dup(op1); - return js_unary_arith_slow(ctx, sp + 1, op - OP_post_dec + OP_dec); + return js_unary_arith_slow(ctx, sp + 1, (OPCodeEnum)(op - OP_post_dec + OP_dec)); } static no_inline int js_not_slow(JSContext *ctx, JSValue *sp) @@ -14375,7 +14375,7 @@ static JSValue js_call_c_function(JSContext *ctx, JSValue func_obj, JSCFunctionEnum cproto; p = JS_VALUE_GET_OBJ(func_obj); - cproto = p->u.cfunc.cproto; + cproto = (JSCFunctionEnum)p->u.cfunc.cproto; arg_count = p->u.cfunc.length; /* better to always check stack overflow */ @@ -16541,7 +16541,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj, CASE(OP_pow): binary_arith_slow: sf->cur_pc = pc; - if (js_binary_arith_slow(ctx, sp, opcode)) + if (js_binary_arith_slow(ctx, sp, (OPCodeEnum)opcode)) goto exception; sp--; BREAK; @@ -16555,7 +16555,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj, if (tag == JS_TAG_INT || JS_TAG_IS_FLOAT64(tag)) { } else { sf->cur_pc = pc; - if (js_unary_arith_slow(ctx, sp, opcode)) + if (js_unary_arith_slow(ctx, sp, (OPCodeEnum)opcode)) goto exception; } } @@ -16586,7 +16586,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj, sp[-1] = js_float64(d); } else { sf->cur_pc = pc; - if (js_unary_arith_slow(ctx, sp, opcode)) + if (js_unary_arith_slow(ctx, sp, (OPCodeEnum)opcode)) goto exception; } } @@ -16604,7 +16604,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj, } else { inc_slow: sf->cur_pc = pc; - if (js_unary_arith_slow(ctx, sp, opcode)) + if (js_unary_arith_slow(ctx, sp, (OPCodeEnum)opcode)) goto exception; } } @@ -16622,7 +16622,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj, } else { dec_slow: sf->cur_pc = pc; - if (js_unary_arith_slow(ctx, sp, opcode)) + if (js_unary_arith_slow(ctx, sp, (OPCodeEnum)opcode)) goto exception; } } @@ -16630,7 +16630,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj, CASE(OP_post_inc): CASE(OP_post_dec): sf->cur_pc = pc; - if (js_post_inc_slow(ctx, sp, opcode)) + if (js_post_inc_slow(ctx, sp, (OPCodeEnum)opcode)) goto exception; sp++; BREAK; @@ -16713,7 +16713,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj, sp--; } else { sf->cur_pc = pc; - if (js_binary_logic_slow(ctx, sp, opcode)) + if (js_binary_logic_slow(ctx, sp, (OPCodeEnum)opcode)) goto exception; sp--; } @@ -16753,7 +16753,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj, sp--; } else { sf->cur_pc = pc; - if (js_binary_logic_slow(ctx, sp, opcode)) + if (js_binary_logic_slow(ctx, sp, (OPCodeEnum)opcode)) goto exception; sp--; } @@ -16769,7 +16769,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj, sp--; } else { sf->cur_pc = pc; - if (js_binary_logic_slow(ctx, sp, opcode)) + if (js_binary_logic_slow(ctx, sp, (OPCodeEnum)opcode)) goto exception; sp--; } @@ -16785,7 +16785,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj, sp--; } else { sf->cur_pc = pc; - if (js_binary_logic_slow(ctx, sp, opcode)) + if (js_binary_logic_slow(ctx, sp, (OPCodeEnum)opcode)) goto exception; sp--; } @@ -16801,7 +16801,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj, sp--; } else { sf->cur_pc = pc; - if (js_binary_logic_slow(ctx, sp, opcode)) + if (js_binary_logic_slow(ctx, sp, (OPCodeEnum)opcode)) goto exception; sp--; } @@ -16827,14 +16827,14 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj, } \ BREAK - OP_CMP(OP_lt, <, js_relational_slow(ctx, sp, opcode)); - OP_CMP(OP_lte, <=, js_relational_slow(ctx, sp, opcode)); - OP_CMP(OP_gt, >, js_relational_slow(ctx, sp, opcode)); - OP_CMP(OP_gte, >=, js_relational_slow(ctx, sp, opcode)); - OP_CMP(OP_eq, ==, js_eq_slow(ctx, sp, 0)); - OP_CMP(OP_neq, !=, js_eq_slow(ctx, sp, 1)); - OP_CMP(OP_strict_eq, ==, js_strict_eq_slow(ctx, sp, 0)); - OP_CMP(OP_strict_neq, !=, js_strict_eq_slow(ctx, sp, 1)); + OP_CMP(OP_lt, <, js_relational_slow(ctx, sp, (OPCodeEnum)opcode)); + OP_CMP(OP_lte, <=, js_relational_slow(ctx, sp, (OPCodeEnum)opcode)); + OP_CMP(OP_gt, >, js_relational_slow(ctx, sp, (OPCodeEnum)opcode)); + OP_CMP(OP_gte, >=, js_relational_slow(ctx, sp, (OPCodeEnum)opcode)); + OP_CMP(OP_eq, ==, js_eq_slow(ctx, sp, (OPCodeEnum)0)); + OP_CMP(OP_neq, !=, js_eq_slow(ctx, sp, (OPCodeEnum)1)); + OP_CMP(OP_strict_eq, ==, js_strict_eq_slow(ctx, sp, (OPCodeEnum)0)); + OP_CMP(OP_strict_neq, !=, js_strict_eq_slow(ctx, sp, (OPCodeEnum)1)); CASE(OP_in): sf->cur_pc = pc; @@ -21268,7 +21268,7 @@ static __exception int js_parse_object_literal(JSParseState *s) func_kind = JS_FUNC_NORMAL; if (is_getset) { - func_type = JS_PARSE_FUNC_GETTER + prop_type - PROP_TYPE_GET; + func_type = (JSParseFunctionEnum)(JS_PARSE_FUNC_GETTER + prop_type - PROP_TYPE_GET); } else { func_type = JS_PARSE_FUNC_METHOD; if (prop_type == PROP_TYPE_STAR) @@ -21758,14 +21758,14 @@ static __exception int js_parse_class(JSParseState *s, BOOL is_class_expr, fd->vars[idx].var_kind = JS_VAR_PRIVATE_GETTER_SETTER; } else { if (add_private_class_field(s, fd, name, - JS_VAR_PRIVATE_GETTER + is_set, is_static) < 0) + (JSVarKindEnum)(JS_VAR_PRIVATE_GETTER + is_set), is_static) < 0) goto fail; } if (add_brand(s, &class_fields[is_static]) < 0) goto fail; } - if (js_parse_function_decl2(s, JS_PARSE_FUNC_GETTER + is_set, + if (js_parse_function_decl2(s, (JSParseFunctionEnum)(JS_PARSE_FUNC_GETTER + is_set), JS_FUNC_NORMAL, JS_ATOM_NULL, start_ptr, s->token.line_num, @@ -29034,7 +29034,7 @@ static int resolve_scope_var(JSContext *ctx, JSFunctionDef *s, FALSE, cv->is_arg, idx1, cv->var_name, cv->is_const, - cv->is_lexical, cv->var_kind); + cv->is_lexical, (JSVarKindEnum)cv->var_kind); } else { idx = idx1; } @@ -29073,7 +29073,7 @@ static int resolve_scope_var(JSContext *ctx, JSFunctionDef *s, var_name, fd->vars[var_idx].is_const, fd->vars[var_idx].is_lexical, - fd->vars[var_idx].var_kind); + (JSVarKindEnum)fd->vars[var_idx].var_kind); } if (idx >= 0) { has_idx: @@ -29263,7 +29263,7 @@ static int resolve_scope_private_field1(JSContext *ctx, cv->is_arg, idx, cv->var_name, cv->is_const, cv->is_lexical, - cv->var_kind); + (JSVarKindEnum)cv->var_kind); if (idx < 0) return -1; } @@ -29490,7 +29490,7 @@ static void add_eval_variables(JSContext *ctx, JSFunctionDef *s) vd = &fd->vars[scope_idx]; vd->is_captured = 1; get_closure_var(ctx, s, fd, FALSE, scope_idx, - vd->var_name, vd->is_const, vd->is_lexical, vd->var_kind); + vd->var_name, vd->is_const, vd->is_lexical, (JSVarKindEnum)vd->var_kind); scope_idx = vd->scope_next; } is_arg_scope = (scope_idx == ARG_SCOPE_END); @@ -29536,7 +29536,7 @@ static void add_eval_variables(JSContext *ctx, JSFunctionDef *s) get_closure_var2(ctx, s, fd, FALSE, cv->is_arg, idx, cv->var_name, cv->is_const, - cv->is_lexical, cv->var_kind); + cv->is_lexical, (JSVarKindEnum)cv->var_kind); } } } @@ -32165,7 +32165,7 @@ static __exception int js_parse_function_decl2(JSParseState *s, if (s->token.val == '*') { if (next_token(s)) return -1; - func_kind |= JS_FUNC_GENERATOR; + func_kind = (JSFunctionKindEnum)(func_kind | JS_FUNC_GENERATOR); } if (s->token.val == TOK_IDENT) { @@ -34670,7 +34670,7 @@ static JSValue JS_ReadModule(BCReaderState *s) JSExportEntry *me = &m->export_entries[i]; if (bc_get_u8(s, &v8)) goto fail; - me->export_type = v8; + me->export_type = (JSExportTypeEnum)v8; if (me->export_type == JS_EXPORT_TYPE_LOCAL) { if (bc_get_leb128_int(s, &me->u.local.var_idx)) goto fail; @@ -35241,7 +35241,7 @@ static JSValue JS_InstantiateFunctionListItem2(JSContext *ctx, JSObject *p, switch(e->def_type) { case JS_DEF_CFUNC: val = JS_NewCFunction2(ctx, e->u.func.cfunc.generic, - e->name, e->u.func.length, e->u.func.cproto, e->magic); + e->name, e->u.func.length, (JSCFunctionEnum)e->u.func.cproto, e->magic); break; case JS_DEF_PROP_STRING: val = JS_NewAtomString(ctx, e->u.str); @@ -35384,7 +35384,7 @@ int JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m, switch(e->def_type) { case JS_DEF_CFUNC: val = JS_NewCFunction2(ctx, e->u.func.cfunc.generic, - e->name, e->u.func.length, e->u.func.cproto, e->magic); + e->name, e->u.func.length, (JSCFunctionEnum)e->u.func.cproto, e->magic); break; case JS_DEF_PROP_STRING: /* `e->u.str` may be pure ASCII or UTF-8 encoded */ @@ -36772,7 +36772,7 @@ static JSValue js_function_proto(JSContext *ctx, JSValue this_val, static JSValue js_function_constructor(JSContext *ctx, JSValue new_target, int argc, JSValue *argv, int magic) { - JSFunctionKindEnum func_kind = magic; + JSFunctionKindEnum func_kind = (JSFunctionKindEnum)magic; int i, n, ret; JSValue s, proto, obj = JS_UNDEFINED; StringBuffer b_s, *b = &b_s; @@ -39260,7 +39260,7 @@ static JSValue js_create_array_iterator(JSContext *ctx, JSValue this_val, JSIteratorKindEnum kind; int class_id; - kind = magic & 3; + kind = (JSIteratorKindEnum)(magic & 3); if (magic & 4) { /* string iterator case */ arr = JS_ToStringCheckObject(ctx, this_val); @@ -41258,7 +41258,7 @@ static JSValue js_string_normalize(JSContext *ctx, JSValue this_val, p++; } if (*p == 'C' || *p == 'D') { - n_type = UNICODE_NFC + is_compat * 2 + (*p - 'C'); + n_type = (UnicodeNormalizationEnum)(UNICODE_NFC + is_compat * 2 + (*p - 'C')); if ((p + 1 - form) != form_len) goto bad_form; } else { @@ -45917,7 +45917,7 @@ static JSValue js_create_map_iterator(JSContext *ctx, JSValue this_val, JSMapIteratorData *it; JSValue enum_obj; - kind = magic >> 2; + kind = (JSIteratorKindEnum)(magic >> 2); magic &= 3; s = (JSMapState *)JS_GetOpaque2(ctx, this_val, JS_CLASS_MAP + magic); if (!s) @@ -46154,7 +46154,7 @@ typedef struct JSPromiseReactionData { { JSPromiseData *s = (JSPromiseData *)JS_GetOpaque(promise, JS_CLASS_PROMISE); if (!s) - return -1; + return (JSPromiseStateEnum)(-1); return s->promise_state; } @@ -46246,7 +46246,7 @@ static void fulfill_or_reject_promise(JSContext *ctx, JSValue promise, if (!s || s->promise_state != JS_PROMISE_PENDING) return; /* should never happen */ set_value(ctx, &s->promise_result, js_dup(value)); - s->promise_state = JS_PROMISE_FULFILLED + is_reject; + s->promise_state = (JSPromiseStateEnum)(JS_PROMISE_FULFILLED + is_reject); promise_trace(ctx, "fulfill_or_reject_promise: is_reject=%d\n", is_reject); From e8db885173edd8cc9d51a43f6a44fd5e64c35fa1 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 4 Jul 2024 16:07:19 +0300 Subject: [PATCH 04/12] Goto skipping initialising --- libbf.c | 3 +-- libregexp.c | 6 ++++-- quickjs.c | 5 ++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/libbf.c b/libbf.c index a2083c0d3..334ebe7a5 100644 --- a/libbf.c +++ b/libbf.c @@ -3718,6 +3718,7 @@ static char *bf_ftoa_internal(size_t *plen, const bf_t *a2, int radix, { bf_context_t *ctx = a2->ctx; DynBuf s_s, *s = &s_s; + bf_t a_s, *a = &a_s; int radix_bits; // bf_print_str("ftoa", a2); @@ -3875,8 +3876,6 @@ static char *bf_ftoa_internal(size_t *plen, const bf_t *a2, int radix, } n = ceil_div(a1->expn, radix_bits); } else { - bf_t a_s, *a = &a_s; - /* make a positive number */ a->tab = a2->tab; a->len = a2->len; diff --git a/libregexp.c b/libregexp.c index 86de2860d..14f0e80c7 100644 --- a/libregexp.c +++ b/libregexp.c @@ -870,6 +870,7 @@ static int re_parse_char_class(REParseState *s, const uint8_t **pp) CharRange cr_s, *cr = &cr_s; CharRange cr1_s, *cr1 = &cr1_s; BOOL invert; + const uint8_t *p0; cr_init(cr, s->opaque, lre_realloc); p = *pp; @@ -912,7 +913,7 @@ static int re_parse_char_class(REParseState *s, const uint8_t **pp) goto invalid_class_range; } if (*p == '-' && p[1] != ']') { - const uint8_t *p0 = p + 1; + p0 = p + 1; if (c1 >= CLASS_RANGE_BASE) { if (s->is_unicode) { cr_free(cr1); @@ -1255,6 +1256,7 @@ static int re_parse_disjunction(REParseState *s, BOOL is_backward_dir); static int re_parse_term(REParseState *s, BOOL is_backward_dir) { const uint8_t *p; + const uint8_t *q; int c, last_atom_start, quant_min, quant_max, last_capture_count; BOOL greedy, add_zero_advance_check, is_neg, is_backward_lookahead; CharRange cr_s, *cr = &cr_s; @@ -1460,7 +1462,7 @@ static int re_parse_term(REParseState *s, BOOL is_backward_dir) case '5': case '6': case '7': case '8': case '9': { - const uint8_t *q = ++p; + q = ++p; c = parse_digits(&p, FALSE); if (c < 0 || (c >= s->capture_count && c >= re_count_captures(s))) { diff --git a/quickjs.c b/quickjs.c index 545da4aaa..d805c35b9 100644 --- a/quickjs.c +++ b/quickjs.c @@ -3153,6 +3153,8 @@ static JSValue JS_AtomIsNumericIndex1(JSContext *ctx, JSAtom atom) return JS_UNDEFINED; p = p1; len = p->len; + const uint8_t *r; + const uint8_t *r_end; if (p->is_wide_char) { const uint16_t *r = p->u.str16, *r_end = p->u.str16 + len; if (r >= r_end) @@ -3176,7 +3178,8 @@ static JSValue JS_AtomIsNumericIndex1(JSContext *ctx, JSAtom atom) return JS_UNDEFINED; } } else { - const uint8_t *r = p->u.str8, *r_end = p->u.str8 + len; + r = p->u.str8; + r_end = p->u.str8 + len; if (r >= r_end) return JS_UNDEFINED; c = *r; From 8744411c999fcc3243c832a9f2aca4e52b1ed0d2 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 4 Jul 2024 16:10:33 +0300 Subject: [PATCH 05/12] Const casting --- qjs.c | 2 +- run-test262.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/qjs.c b/qjs.c index 60e28013b..13aa9fe14 100644 --- a/qjs.c +++ b/qjs.c @@ -348,7 +348,7 @@ int main(int argc, char **argv) optind++; if (*arg == '-') { longopt = arg + 1; - opt_arg = strchr(longopt, '='); + opt_arg = (char *)strchr(longopt, '='); if (opt_arg) *opt_arg++ = '\0'; arg += strlen(arg); diff --git a/run-test262.c b/run-test262.c index 1cf51a5df..12e543766 100644 --- a/run-test262.c +++ b/run-test262.c @@ -185,7 +185,7 @@ char *get_basename(const char *filename) { char *p; - p = strrchr(filename, '/'); + p = (char *)strrchr(filename, '/'); if (!p) return NULL; return strdup_len(filename, p - filename); @@ -1626,7 +1626,7 @@ int run_test(const char *filename, int index) if (new_style) { if (!harness) { - p = strstr(filename, "test/"); + p = (char *)strstr(filename, "test/"); if (p) { snprintf(harnessbuf, sizeof(harnessbuf), "%.*s%s", (int)(p - filename), filename, "harness"); @@ -1713,7 +1713,7 @@ int run_test(const char *filename, int index) char *ifile; if (!harness) { - p = strstr(filename, "test/"); + p = (char *)strstr(filename, "test/"); if (p) { snprintf(harnessbuf, sizeof(harnessbuf), "%.*s%s", (int)(p - filename), filename, "test/harness"); From e0f0a17356a174b1f420f286f6fee97def1f447f Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 4 Jul 2024 16:12:59 +0300 Subject: [PATCH 06/12] Function pointer casting --- quickjs-libc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quickjs-libc.c b/quickjs-libc.c index f781202e5..98741c1ef 100644 --- a/quickjs-libc.c +++ b/quickjs-libc.c @@ -185,7 +185,7 @@ static JSValue js_printf_internal(JSContext *ctx, double double_arg; const char *string_arg; /* Use indirect call to dbuf_printf to prevent gcc warning */ - int (*dbuf_printf_fun)(DynBuf *s, const char *fmt, ...) = (void*)dbuf_printf; + int (*dbuf_printf_fun)(DynBuf *s, const char *fmt, ...) = dbuf_printf; js_std_dbuf_init(ctx, &dbuf); @@ -518,7 +518,7 @@ static JSModuleDef *js_module_loader_so(JSContext *ctx, goto fail; } - init = dlsym(hd, "js_init_module"); + *(void **) (&init) = dlsym(hd, "js_init_module"); if (!init) { JS_ThrowReferenceError(ctx, "could not load module filename '%s': js_init_module not found", module_name); From fe70fe2aeb5a2e0977774e7a6f32c33acd9557de Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 4 Jul 2024 16:19:52 +0300 Subject: [PATCH 07/12] Class redefinitions --- quickjs.c | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/quickjs.c b/quickjs.c index d805c35b9..a93c67028 100644 --- a/quickjs.c +++ b/quickjs.c @@ -174,7 +174,11 @@ enum { /* number of typed array types */ #define JS_TYPED_ARRAY_COUNT (JS_CLASS_FLOAT64_ARRAY - JS_CLASS_UINT8C_ARRAY + 1) -static uint8_t const typed_array_size_log2[JS_TYPED_ARRAY_COUNT]; +static uint8_t const typed_array_size_log2[JS_TYPED_ARRAY_COUNT] = { + 0, 0, 0, 1, 1, 2, 2, + 3, 3, /* BigInt64Array, BigUint64Array */ + 2, 3 +}; #define typed_array_size_log2(classid) (typed_array_size_log2[(classid)- JS_CLASS_UINT8C_ARRAY]) typedef enum JSErrorEnum { @@ -1262,10 +1266,23 @@ static void js_new_callsite_data(JSContext *ctx, JSCallSiteData *csd, JSStackFra static void js_new_callsite_data2(JSContext *ctx, JSCallSiteData *csd, const char *filename, int line_num, int col_num); static void _JS_AddIntrinsicCallSite(JSContext *ctx); -static const JSClassExoticMethods js_arguments_exotic_methods; -static const JSClassExoticMethods js_string_exotic_methods; -static const JSClassExoticMethods js_proxy_exotic_methods; -static const JSClassExoticMethods js_module_ns_exotic_methods; +static int js_string_get_own_property(JSContext *ctx, JSPropertyDescriptor *desc, JSValue obj, JSAtom prop); +static int js_string_define_own_property(JSContext *ctx, JSValue this_obj, JSAtom prop, JSValue val, JSValue getter, JSValue setter, int flags); +static int js_string_delete_property(JSContext *ctx, JSValue obj, JSAtom prop); +static int js_arguments_define_own_property(JSContext *ctx, JSValue this_obj, JSAtom prop, JSValue val, JSValue getter, JSValue setter, int flags); +static int js_module_ns_has(JSContext *ctx, JSValue obj, JSAtom atom); + +static const JSClassExoticMethods js_arguments_exotic_methods = { + .define_own_property = js_arguments_define_own_property, +}; +static const JSClassExoticMethods js_string_exotic_methods = { + .get_own_property = js_string_get_own_property, + .define_own_property = js_string_define_own_property, + .delete_property = js_string_delete_property, +}; +static const JSClassExoticMethods js_module_ns_exotic_methods = { + .has_property = js_module_ns_has, +}; static inline BOOL double_is_int32(double d) { @@ -13287,9 +13304,6 @@ static int js_arguments_define_own_property(JSContext *ctx, flags | JS_PROP_NO_EXOTIC); } -static const JSClassExoticMethods js_arguments_exotic_methods = { - .define_own_property = js_arguments_define_own_property, -}; static JSValue js_build_arguments(JSContext *ctx, int argc, JSValue *argv) { @@ -26322,10 +26336,6 @@ static int js_module_ns_has(JSContext *ctx, JSValue obj, JSAtom atom) return (find_own_property1(JS_VALUE_GET_OBJ(obj), atom) != NULL); } -static const JSClassExoticMethods js_module_ns_exotic_methods = { - .has_property = js_module_ns_has, -}; - static int exported_names_cmp(const void *p1, const void *p2, void *opaque) { JSContext *ctx = (JSContext *)opaque; @@ -39833,12 +39843,6 @@ static int js_string_delete_property(JSContext *ctx, return TRUE; } -static const JSClassExoticMethods js_string_exotic_methods = { - .get_own_property = js_string_get_own_property, - .define_own_property = js_string_define_own_property, - .delete_property = js_string_delete_property, -}; - static JSValue js_string_constructor(JSContext *ctx, JSValue new_target, int argc, JSValue *argv) { @@ -49349,12 +49353,6 @@ void JS_AddIntrinsicBaseObjects(JSContext *ctx) /* Typed Arrays */ -static uint8_t const typed_array_size_log2[JS_TYPED_ARRAY_COUNT] = { - 0, 0, 0, 1, 1, 2, 2, - 3, 3, /* BigInt64Array, BigUint64Array */ - 2, 3 -}; - static JSValue js_array_buffer_constructor3(JSContext *ctx, JSValue new_target, uint64_t len, JSClassID class_id, From 9e1146eb7a8f073f165f3875b96b77e656570c0c Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 4 Jul 2024 16:20:45 +0300 Subject: [PATCH 08/12] Forward declaration enum --- quickjs.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/quickjs.c b/quickjs.c index a93c67028..60c4314db 100644 --- a/quickjs.c +++ b/quickjs.c @@ -213,8 +213,6 @@ typedef enum { JS_GC_PHASE_REMOVE_CYCLES, } JSGCPhaseEnum; -typedef enum OPCodeEnum OPCodeEnum; - struct JSRuntime { JSMallocFunctions mf; JSMallocState malloc_state; @@ -994,7 +992,7 @@ typedef enum OPCodeFormat { #undef FMT } OPCodeFormat; -enum OPCodeEnum { +typedef enum OPCodeEnum { #define FMT(f) #define DEF(id, size, n_pop, n_push, f) OP_ ## id, #define def(id, size, n_pop, n_push, f) @@ -1014,7 +1012,7 @@ enum OPCodeEnum { #undef DEF #undef FMT OP_TEMP_END, -}; +} OPCodeEnum; static int JS_InitAtoms(JSRuntime *rt); static JSAtom __JS_NewAtomInit(JSRuntime *rt, const char *str, int len, From 4cff3c3cdf3eac1101623e26dc95f064afd39421 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 4 Jul 2024 16:39:57 +0300 Subject: [PATCH 09/12] repl/test c++ fixes --- gen/repl.c | 5 ++--- tests/test_conv.c | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/gen/repl.c b/gen/repl.c index 2757a668f..8fdd72ed5 100644 --- a/gen/repl.c +++ b/gen/repl.c @@ -2,9 +2,9 @@ #include -const uint32_t qjsc_repl_size = 22701; +extern const uint32_t qjsc_repl_size = 22701; -const uint8_t qjsc_repl[22701] = { +extern const uint8_t qjsc_repl[22701] = { 0x0c, 0x91, 0x04, 0x0e, 0x72, 0x65, 0x70, 0x6c, 0x2e, 0x6a, 0x73, 0x06, 0x73, 0x74, 0x64, 0x04, 0x6f, 0x73, 0x02, 0x67, 0x10, 0x69, 0x73, 0x46, @@ -2844,4 +2844,3 @@ const uint8_t qjsc_repl[22701] = { 0x02, 0x29, 0xbe, 0x00, 0x38, 0x8a, 0x00, 0x00, 0x00, 0xee, 0x0e, 0x06, 0x2e, }; - diff --git a/tests/test_conv.c b/tests/test_conv.c index b0678ae5c..4ca78c7dd 100644 --- a/tests/test_conv.c +++ b/tests/test_conv.c @@ -103,13 +103,13 @@ static inline int clz64(uint64_t a) return clz32((unsigned)(a >> 32)); else return clz32((unsigned)a) + 32; -#endif +#endif #else return __builtin_clzll(a); #endif } // prototypes for final functions -extern char const digits36[36]; +extern char const digits36[37]; size_t u32toa(char buf[minimum_length(11)], uint32_t n); size_t i32toa(char buf[minimum_length(12)], int32_t n); size_t u64toa(char buf[minimum_length(21)], uint64_t n); @@ -129,7 +129,7 @@ size_t i64toa_radix(char buf[minimum_length(66)], int64_t n, unsigned base); */ /* 2 <= base <= 36 */ -char const digits36[36] = "0123456789abcdefghijklmnopqrstuvwxyz"; +char const digits36[37] = "0123456789abcdefghijklmnopqrstuvwxyz"; /*---- variants ----*/ @@ -234,7 +234,7 @@ define_i64toa(shift) #endif /* TEST_SHIFTBUF */ #if defined(TEST_DIGIT_PAIRS) || defined(TEST_DIGIT_1PASS) -static char const digits100[200] = +static char const digits100[201] = "00010203040506070809" "10111213141516171819" "20212223242526272829" From 50301ffbc0929ea5003d2af6a7d0d5a3a6d85c34 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 4 Jul 2024 16:48:13 +0300 Subject: [PATCH 10/12] Add CONFIG_CPP flag --- CMakeLists.txt | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 373bb1f59..84363d8a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,14 +1,30 @@ cmake_minimum_required(VERSION 3.9) -project(quickjs LANGUAGES C) +project(quickjs LANGUAGES C CXX) include(CheckCCompilerFlag) include(GNUInstallDirs) set(CMAKE_C_VISIBILITY_PRESET hidden) -set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_C_EXTENSIONS ON) -set(CMAKE_C_STANDARD 11) + +macro(xoption OPTION_NAME OPTION_TEXT OPTION_DEFAULT) + option(${OPTION_NAME} ${OPTION_TEXT} ${OPTION_DEFAULT}) + if(DEFINED ENV{${OPTION_NAME}}) + # Allow setting the option through an environment variable. + set(${OPTION_NAME} $ENV{${OPTION_NAME}}) + endif() + if(${OPTION_NAME}) + add_definitions(-D${OPTION_NAME}) + endif() + message(STATUS " ${OPTION_NAME}: ${${OPTION_NAME}}") +endmacro() +xoption(CONFIG_CPP "Compile as C++" OFF) + +if (NOT CONFIG_CPP) + set(CMAKE_C_STANDARD_REQUIRED ON) + set(CMAKE_C_EXTENSIONS ON) + set(CMAKE_C_STANDARD 11) +endif() if(NOT CMAKE_BUILD_TYPE) message(STATUS "No build type selected, default to Release") @@ -76,17 +92,6 @@ if(CMAKE_BUILD_TYPE MATCHES "Debug") xcheck_add_c_compiler_flag(-fno-omit-frame-pointer) endif() -macro(xoption OPTION_NAME OPTION_TEXT OPTION_DEFAULT) - option(${OPTION_NAME} ${OPTION_TEXT} ${OPTION_DEFAULT}) - if(DEFINED ENV{${OPTION_NAME}}) - # Allow setting the option through an environment variable. - set(${OPTION_NAME} $ENV{${OPTION_NAME}}) - endif() - if(${OPTION_NAME}) - add_definitions(-D${OPTION_NAME}) - endif() - message(STATUS " ${OPTION_NAME}: ${${OPTION_NAME}}") -endmacro() xoption(BUILD_SHARED_LIBS "Build a shared library" OFF) if(BUILD_SHARED_LIBS) @@ -159,6 +164,14 @@ set(qjs_sources quickjs.c ) +if (CONFIG_CPP) + file(GLOB_RECURSE CFILES "*.c") + set_source_files_properties(${CFILES} PROPERTIES LANGUAGE CXX) + add_compile_options( + -x c++ + ) +endif() + if(BUILD_QJS_LIBC) list(APPEND qjs_sources quickjs-libc.c) endif() From 12b61f2dc28c09c4ddcbb4616ab3c663cf2e16da Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 4 Jul 2024 16:48:29 +0300 Subject: [PATCH 11/12] Repl c/c++ compat --- gen/repl.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gen/repl.c b/gen/repl.c index 8fdd72ed5..667181cd1 100644 --- a/gen/repl.c +++ b/gen/repl.c @@ -2,9 +2,15 @@ #include -extern const uint32_t qjsc_repl_size = 22701; +#ifdef __cplusplus +extern +#endif +const uint32_t qjsc_repl_size = 22701; -extern const uint8_t qjsc_repl[22701] = { +#ifdef __cplusplus +extern +#endif +const uint8_t qjsc_repl[22701] = { 0x0c, 0x91, 0x04, 0x0e, 0x72, 0x65, 0x70, 0x6c, 0x2e, 0x6a, 0x73, 0x06, 0x73, 0x74, 0x64, 0x04, 0x6f, 0x73, 0x02, 0x67, 0x10, 0x69, 0x73, 0x46, From 684ab7926de63566a6fb9ea8dadd326e52ba8662 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 4 Jul 2024 16:50:35 +0300 Subject: [PATCH 12/12] Add CI step --- .github/workflows/ci.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2fd5d8523..fb0c8c5a5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,6 +48,7 @@ jobs: - { os: ubuntu-latest, configType: ubsan, runTest262: true } - { os: ubuntu-latest, configType: msan } - { os: ubuntu-latest, configType: tcc } + - { os: ubuntu-latest, configType: cpp } - { os: ubuntu-latest, arch: x86 } - { os: ubuntu-latest, arch: riscv64 } - { os: ubuntu-latest, arch: s390x } @@ -58,6 +59,7 @@ jobs: - { os: macos-14, configType: shared } - { os: macos-14, configType: asan } - { os: macos-14, configType: ubsan } + - { os: macos-14, configType: cpp } - { os: macos-12, configType: Debug } - { os: macos-12, configType: Release } @@ -65,6 +67,7 @@ jobs: - { os: macos-12, configType: shared } - { os: macos-12, configType: asan } - { os: macos-12, configType: ubsan } + - { os: macos-12, configType: cpp } steps: - uses: actions/checkout@v4 with: @@ -109,6 +112,8 @@ jobs: echo "CONFIG_ASAN=ON" >> $GITHUB_ENV; elif [ "${{ matrix.config.configType }}" = "ubsan" ]; then echo "CONFIG_UBSAN=ON" >> $GITHUB_ENV; + elif [ "${{ matrix.config.configType }}" = "cpp" ]; then + echo "CONFIG_CPP=ON" >> $GITHUB_ENV; elif [ "${{ matrix.config.configType }}" = "msan" ]; then echo "CONFIG_MSAN=ON" >> $GITHUB_ENV; echo "CC=clang" >> $GITHUB_ENV; @@ -122,7 +127,8 @@ jobs: BUILD_SHARED_LIBS=$BUILD_SHARED_LIBS \ CONFIG_ASAN=$CONFIG_ASAN \ CONFIG_UBSAN=$CONFIG_UBSAN \ - CONFIG_MSAN=$CONFIG_MSAN + CONFIG_MSAN=$CONFIG_MSAN \ + CONFIG_CPP=$CONFIG_CPP - name: stats if: ${{ matrix.config.configType != 'examples' }}