Browse Source

debug log call wrappers

pull/7/head
Sami Vaarala 11 years ago
parent
commit
3714ea26ac
  1. 10
      src/duk_alloc_default.c
  2. 10
      src/duk_alloc_torture.c
  3. 78
      src/duk_api.c
  4. 28
      src/duk_api_call.c
  5. 4
      src/duk_api_memory.c
  6. 8
      src/duk_api_string.c
  7. 60
      src/duk_bi_array.c
  8. 100
      src/duk_bi_date.c
  9. 24
      src/duk_bi_function.c
  10. 32
      src/duk_bi_global.c
  11. 92
      src/duk_bi_json.c
  12. 4
      src/duk_bi_logger.c
  13. 4
      src/duk_regexp_compiler.c
  14. 88
      src/duk_regexp_executor.c
  15. 28
      src/duk_unicode_support.c
  16. 8
      src/duk_util_bitdecoder.c
  17. 2
      src/duk_util_hashprime.c

10
src/duk_alloc_default.c

@ -11,8 +11,8 @@ void *duk_default_alloc_function(void *udata, size_t size) {
void *res;
DUK_UNREF(udata);
res = DUK_ANSI_MALLOC(size);
DUK_DDDPRINT("default alloc function: %d -> %p",
(int) size, (void *) res);
DUK_DDD(DUK_DDDPRINT("default alloc function: %d -> %p",
(int) size, (void *) res));
return res;
}
@ -20,13 +20,13 @@ void *duk_default_realloc_function(void *udata, void *ptr, size_t newsize) {
void *res;
DUK_UNREF(udata);
res = DUK_ANSI_REALLOC(ptr, newsize);
DUK_DDDPRINT("default realloc function: %p %d -> %p",
(void *) ptr, (int) newsize, (void *) res);
DUK_DDD(DUK_DDDPRINT("default realloc function: %p %d -> %p",
(void *) ptr, (int) newsize, (void *) res));
return res;
}
void duk_default_free_function(void *udata, void *ptr) {
DUK_DDDPRINT("default free function: %p", (void *) ptr);
DUK_DDD(DUK_DDDPRINT("default free function: %p", (void *) ptr));
DUK_UNREF(udata);
DUK_ANSI_FREE(ptr);
}

10
src/duk_alloc_torture.c

@ -18,8 +18,8 @@ void *duk_torture_alloc_function(void *udata, size_t size) {
void *res;
DUK_UNREF(udata);
res = DUK_ANSI_MALLOC(size);
DUK_DDDPRINT("torture alloc function: %d -> %p",
(int) size, (void *) res);
DUK_DDD(DUK_DDDPRINT("torture alloc function: %d -> %p",
(int) size, (void *) res));
return res;
}
@ -27,13 +27,13 @@ void *duk_torture_realloc_function(void *udata, void *ptr, size_t newsize) {
void *res;
DUK_UNREF(udata);
res = DUK_ANSI_REALLOC(ptr, newsize);
DUK_DDDPRINT("torture realloc function: %p %d -> %p",
(void *) ptr, (int) newsize, (void *) res);
DUK_DDD(DUK_DDDPRINT("torture realloc function: %p %d -> %p",
(void *) ptr, (int) newsize, (void *) res));
return res;
}
void duk_torture_free_function(void *udata, void *ptr) {
DUK_DDDPRINT("torture free function: %p", (void *) ptr);
DUK_DDD(DUK_DDDPRINT("torture free function: %p", (void *) ptr));
DUK_UNREF(udata);
DUK_ANSI_FREE(ptr);
}

78
src/duk_api.c

@ -284,8 +284,8 @@ static int duk__resize_valstack(duk_context *ctx, size_t new_size) {
new_alloc_size = sizeof(duk_tval) * new_size;
new_valstack = (duk_tval *) DUK_REALLOC_INDIRECT(thr->heap, duk_hthread_get_valstack_ptr, (void *) thr, new_alloc_size);
if (!new_valstack) {
DUK_DPRINT("failed to resize valstack to %d entries (%d bytes)",
new_size, new_alloc_size);
DUK_D(DUK_DPRINT("failed to resize valstack to %d entries (%d bytes)",
new_size, new_alloc_size));
return 0;
}
@ -326,25 +326,25 @@ static int duk__resize_valstack(duk_context *ctx, size_t new_size) {
/* useful for debugging */
#ifdef DUK_USE_DEBUG
if (old_end_offset_pre != old_end_offset_post) {
DUK_DPRINT("valstack was resized during valstack_resize(), probably by mark-and-sweep; "
"end offset changed: %d -> %d",
old_end_offset_pre,
old_end_offset_post);
DUK_D(DUK_DPRINT("valstack was resized during valstack_resize(), probably by mark-and-sweep; "
"end offset changed: %d -> %d",
old_end_offset_pre,
old_end_offset_post));
}
if (old_valstack_pre != old_valstack_post) {
DUK_DPRINT("valstack pointer changed during valstack_resize(), probably by mark-and-sweep: %p -> %p",
(void *) old_valstack_pre,
(void *) old_valstack_post);
DUK_D(DUK_DPRINT("valstack pointer changed during valstack_resize(), probably by mark-and-sweep: %p -> %p",
(void *) old_valstack_pre,
(void *) old_valstack_post));
}
#endif
DUK_DDPRINT("resized valstack to %d elements (%d bytes), bottom=%d, top=%d, "
"new pointers: start=%p end=%p bottom=%p top=%p",
(int) new_size, (int) new_alloc_size,
(int) (thr->valstack_bottom - thr->valstack),
(int) (thr->valstack_top - thr->valstack),
(void *) thr->valstack, (void *) thr->valstack_end,
(void *) thr->valstack_bottom, (void *) thr->valstack_top);
DUK_DD(DUK_DDPRINT("resized valstack to %d elements (%d bytes), bottom=%d, top=%d, "
"new pointers: start=%p end=%p bottom=%p top=%p",
(int) new_size, (int) new_alloc_size,
(int) (thr->valstack_bottom - thr->valstack),
(int) (thr->valstack_top - thr->valstack),
(void *) thr->valstack, (void *) thr->valstack_end,
(void *) thr->valstack_bottom, (void *) thr->valstack_top));
/* init newly allocated slots (only) */
p = (duk_tval *) ((duk_uint8_t *) thr->valstack + old_end_offset_post);
@ -376,13 +376,13 @@ static int duk__check_valstack_resize_helper(duk_context *ctx,
size_t new_size;
int is_shrink = 0;
DUK_DDDPRINT("check valstack resize: min_new_size=%d, curr_size=%d, curr_top=%d, "
"curr_bottom=%d, shrink=%d, compact=%d, throw=%d",
(int) min_new_size,
(int) (thr->valstack_end - thr->valstack),
(int) (thr->valstack_top - thr->valstack),
(int) (thr->valstack_bottom - thr->valstack),
shrink_flag, compact_flag, throw_flag);
DUK_DDD(DUK_DDDPRINT("check valstack resize: min_new_size=%d, curr_size=%d, curr_top=%d, "
"curr_bottom=%d, shrink=%d, compact=%d, throw=%d",
(int) min_new_size,
(int) (thr->valstack_end - thr->valstack),
(int) (thr->valstack_top - thr->valstack),
(int) (thr->valstack_bottom - thr->valstack),
shrink_flag, compact_flag, throw_flag));
DUK_ASSERT(ctx != NULL);
DUK_ASSERT(thr != NULL);
@ -396,7 +396,7 @@ static int duk__check_valstack_resize_helper(duk_context *ctx,
is_shrink = 1;
if (!shrink_flag ||
old_size - min_new_size < DUK_VALSTACK_SHRINK_THRESHOLD) {
DUK_DDDPRINT("no need to grow or shrink valstack");
DUK_DDD(DUK_DDDPRINT("no need to grow or shrink valstack"));
return 1;
}
}
@ -412,9 +412,9 @@ static int duk__check_valstack_resize_helper(duk_context *ctx,
new_size = (new_size / DUK_VALSTACK_GROW_STEP + 1) * DUK_VALSTACK_GROW_STEP;
}
DUK_DDPRINT("want to %s valstack: %d -> %d elements (min_new_size %d)",
(new_size > old_size ? "grow" : "shrink"),
old_size, new_size, min_new_size);
DUK_DD(DUK_DDPRINT("want to %s valstack: %d -> %d elements (min_new_size %d)",
(new_size > old_size ? "grow" : "shrink"),
old_size, new_size, min_new_size));
if (new_size >= thr->valstack_max) {
/* Note: may be triggered even if minimal new_size would not reach the limit,
@ -439,11 +439,11 @@ static int duk__check_valstack_resize_helper(duk_context *ctx,
if (!duk__resize_valstack(ctx, new_size)) {
if (is_shrink) {
DUK_DDPRINT("valstack resize failed, but is a shrink, ignore");
DUK_DD(DUK_DDPRINT("valstack resize failed, but is a shrink, ignore"));
return 1;
}
DUK_DDPRINT("valstack resize failed");
DUK_DD(DUK_DDPRINT("valstack resize failed"));
if (throw_flag) {
DUK_ERROR(thr, DUK_ERR_ALLOC_ERROR, "failed to extend valstack");
@ -452,7 +452,7 @@ static int duk__check_valstack_resize_helper(duk_context *ctx,
}
}
DUK_DDDPRINT("valstack resize successful");
DUK_DDD(DUK_DDDPRINT("valstack resize successful"));
return 1;
}
@ -597,7 +597,7 @@ void duk_insert(duk_context *ctx, int to_index) {
nbytes = (size_t) (((duk_uint8_t *) q) - ((duk_uint8_t *) p)); /* Note: 'q' is top-1 */
DUK_DDDPRINT("duk_insert: to_index=%p, p=%p, q=%p, nbytes=%d", to_index, p, q, nbytes);
DUK_DDD(DUK_DDDPRINT("duk_insert: to_index=%p, p=%p, q=%p, nbytes=%d", to_index, p, q, nbytes));
if (nbytes > 0) {
DUK_TVAL_SET_TVAL(&tv, q);
DUK_MEMMOVE((void *) (p + 1), (void *) p, nbytes);
@ -2591,7 +2591,7 @@ void duk_push_global_object(duk_context *ctx) {
static void duk__push_stash(duk_context *ctx) {
DUK_ASSERT(ctx != NULL);
if (!duk_get_prop_stridx(ctx, -1, DUK_STRIDX_INT_VALUE)) {
DUK_DDDPRINT("creating heap/global/thread stash on first use");
DUK_DDD(DUK_DDDPRINT("creating heap/global/thread stash on first use"));
duk_pop(ctx);
duk_push_object_internal(ctx);
duk_dup_top(ctx);
@ -2723,7 +2723,7 @@ int duk_push_object_helper(duk_context *ctx, int hobject_flags_and_class, int pr
DUK_ERROR(thr, DUK_ERR_ALLOC_ERROR, "failed to allocate an object");
}
DUK_DDDPRINT("created object with flags: 0x%08x", h->hdr.h_flags);
DUK_DDD(DUK_DDDPRINT("created object with flags: 0x%08x", h->hdr.h_flags));
tv_slot = thr->valstack_top;
DUK_TVAL_SET_OBJECT(tv_slot, h);
@ -2814,7 +2814,7 @@ int duk_push_thread_raw(duk_context *ctx, int flags) {
}
obj->state = DUK_HTHREAD_STATE_INACTIVE;
obj->strs = thr->strs;
DUK_DDDPRINT("created thread object with flags: 0x%08x", obj->obj.hdr.h_flags);
DUK_DDD(DUK_DDDPRINT("created thread object with flags: 0x%08x", obj->obj.hdr.h_flags));
/* make the new thread reachable */
tv_slot = thr->valstack_top;
@ -2873,7 +2873,7 @@ int duk_push_compiledfunction(duk_context *ctx) {
DUK_ERROR(thr, DUK_ERR_ALLOC_ERROR, "failed to allocate a function object");
}
DUK_DDDPRINT("created compiled function object with flags: 0x%08x", obj->obj.hdr.h_flags);
DUK_DDD(DUK_DDDPRINT("created compiled function object with flags: 0x%08x", obj->obj.hdr.h_flags));
tv_slot = thr->valstack_top;
DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) obj);
@ -2926,7 +2926,7 @@ static int duk__push_c_function_raw(duk_context *ctx, duk_c_function func, int n
obj->func = func;
obj->nargs = func_nargs;
DUK_DDDPRINT("created native function object with flags: 0x%08x, nargs=%d", obj->obj.hdr.h_flags, obj->nargs);
DUK_DDD(DUK_DDDPRINT("created native function object with flags: 0x%08x, nargs=%d", obj->obj.hdr.h_flags, obj->nargs));
tv_slot = thr->valstack_top;
DUK_TVAL_SET_OBJECT(tv_slot, (duk_hobject *) obj);
@ -3237,10 +3237,10 @@ void duk_throw(duk_context *ctx) {
*/
#if defined(DUK_USE_AUGMENT_ERROR_THROW)
DUK_DDDPRINT("THROW ERROR (API): %!dT (before throw augment)", duk_get_tval(ctx, -1));
DUK_DDD(DUK_DDDPRINT("THROW ERROR (API): %!dT (before throw augment)", duk_get_tval(ctx, -1)));
duk_err_augment_error_throw(thr);
#endif
DUK_DDDPRINT("THROW ERROR (API): %!dT (after throw augment)", duk_get_tval(ctx, -1));
DUK_DDD(DUK_DDDPRINT("THROW ERROR (API): %!dT (after throw augment)", duk_get_tval(ctx, -1)));
duk_err_setup_heap_ljstate(thr, DUK_LJ_TYPE_THROW);
@ -3261,7 +3261,7 @@ void duk_fatal(duk_context *ctx, int err_code, const char *err_msg) {
DUK_ASSERT(thr->heap != NULL);
DUK_ASSERT(thr->heap->fatal_func != NULL);
DUK_DPRINT("fatal error occurred, code %d, message %s", err_code, err_msg);
DUK_D(DUK_DPRINT("fatal error occurred, code %d, message %s", err_code, err_msg));
/* fatal_func should be noreturn, but noreturn declarations on function
* pointers has a very spotty support apparently so it's not currently

28
src/duk_api_call.c

@ -10,8 +10,8 @@
* May currently throw an error e.g. when getting the property.
*/
static void duk__call_prop_prep_stack(duk_context *ctx, int normalized_obj_index, int nargs) {
DUK_DDDPRINT("duk__call_prop_prep_stack, normalized_obj_index=%d, nargs=%d, stacktop=%d",
normalized_obj_index, nargs, duk_get_top(ctx));
DUK_DDD(DUK_DDDPRINT("duk__call_prop_prep_stack, normalized_obj_index=%d, nargs=%d, stacktop=%d",
normalized_obj_index, nargs, duk_get_top(ctx)));
/* [... key arg1 ... argN] */
@ -19,7 +19,7 @@ static void duk__call_prop_prep_stack(duk_context *ctx, int normalized_obj_index
duk_dup(ctx, -nargs - 1); /* Note: -nargs alone would fail for nargs == 0, this is OK */
duk_get_prop(ctx, normalized_obj_index);
DUK_DDDPRINT("func: %!T", duk_get_tval(ctx, -1));
DUK_DDD(DUK_DDDPRINT("func: %!T", duk_get_tval(ctx, -1)));
/* [... key arg1 ... argN func] */
@ -265,7 +265,7 @@ void duk_new(duk_context *ctx, int nargs) {
idx_cons = duk_require_normalize_index(ctx, -nargs - 1);
DUK_DDDPRINT("top=%d, nargs=%d, idx_cons=%d", duk_get_top(ctx), nargs, idx_cons);
DUK_DDD(DUK_DDDPRINT("top=%d, nargs=%d, idx_cons=%d", duk_get_top(ctx), nargs, idx_cons));
/* FIXME: code duplication */
@ -308,11 +308,11 @@ void duk_new(duk_context *ctx, int nargs) {
duk_get_prop_stridx(ctx, -2, DUK_STRIDX_PROTOTYPE);
proto = duk_get_hobject(ctx, -1);
if (!proto) {
DUK_DDDPRINT("constructor has no 'prototype' property, or value not an object "
"-> leave standard Object prototype as fallback prototype");
DUK_DDD(DUK_DDDPRINT("constructor has no 'prototype' property, or value not an object "
"-> leave standard Object prototype as fallback prototype"));
} else {
DUK_DDDPRINT("constructor has 'prototype' property with object value "
"-> set fallback prototype to that value: %!iO", proto);
DUK_DDD(DUK_DDDPRINT("constructor has 'prototype' property with object value "
"-> set fallback prototype to that value: %!iO", proto));
fallback = duk_get_hobject(ctx, -2);
DUK_ASSERT(fallback != NULL);
DUK_HOBJECT_SET_PROTOTYPE_UPDREF(thr, fallback, proto);
@ -337,10 +337,10 @@ void duk_new(duk_context *ctx, int nargs) {
* Note: idx_cons points to first 'fallback', not 'constructor'.
*/
DUK_DDDPRINT("before call, idx_cons+1 (constructor) -> %!T, idx_cons+2 (fallback/this) -> %!T, "
"nargs=%d, top=%d",
duk_get_tval(ctx, idx_cons + 1), duk_get_tval(ctx, idx_cons + 2),
nargs, duk_get_top(ctx));
DUK_DDD(DUK_DDDPRINT("before call, idx_cons+1 (constructor) -> %!T, idx_cons+2 (fallback/this) -> %!T, "
"nargs=%d, top=%d",
duk_get_tval(ctx, idx_cons + 1), duk_get_tval(ctx, idx_cons + 2),
nargs, duk_get_top(ctx)));
/*
* Call the constructor function (called in "constructor mode").
@ -355,8 +355,8 @@ void duk_new(duk_context *ctx, int nargs) {
/* [... fallback retval] */
DUK_DDDPRINT("constructor call finished, rc=%d, fallback=%!iT, retval=%!iT",
rc, duk_get_tval(ctx, -2), duk_get_tval(ctx, -1));
DUK_DDD(DUK_DDDPRINT("constructor call finished, rc=%d, fallback=%!iT, retval=%!iT",
rc, duk_get_tval(ctx, -2), duk_get_tval(ctx, -1)));
/*
* Determine whether to use the constructor return value as the created

4
src/duk_api_memory.c

@ -91,10 +91,10 @@ void duk_gc(duk_context *ctx, int flags) {
heap = thr->heap;
DUK_ASSERT(heap != NULL);
DUK_DPRINT("mark-and-sweep requested by application");
DUK_D(DUK_DPRINT("mark-and-sweep requested by application"));
duk_heap_mark_and_sweep(heap, 0);
#else
DUK_DPRINT("mark-and-sweep requested by application but mark-and-sweep not enabled, ignoring");
DUK_D(DUK_DPRINT("mark-and-sweep requested by application but mark-and-sweep not enabled, ignoring"));
DUK_UNREF(ctx);
DUK_UNREF(flags);
#endif

8
src/duk_api_string.c

@ -53,7 +53,7 @@ static void duk__concat_and_join_helper(duk_context *ctx, unsigned int count, in
len = new_len;
}
DUK_DDDPRINT("join/concat %d strings, total length %d bytes", (int) count, (int) len);
DUK_DDD(DUK_DDDPRINT("join/concat %d strings, total length %d bytes", (int) count, (int) len));
/* use stack allocated buffer to ensure reachability in errors (e.g. intern error) */
buf = (duk_uint8_t *) duk_push_fixed_buffer(ctx, len);
@ -270,11 +270,11 @@ void duk_trim(duk_context *ctx, int index) {
DUK_ASSERT(q_end >= p_start && q_end <= p_end);
DUK_ASSERT(q_end >= q_start);
DUK_DDDPRINT("trim: p_start=%p, p_end=%p, q_start=%p, q_end=%p",
(void *) p_start, (void *) p_end, (void *) q_start, (void *) q_end);
DUK_DDD(DUK_DDDPRINT("trim: p_start=%p, p_end=%p, q_start=%p, q_end=%p",
(void *) p_start, (void *) p_end, (void *) q_start, (void *) q_end));
if (q_start == p_start && q_end == p_end) {
DUK_DDDPRINT("nothing was trimmed: avoid interning (hashing etc)");
DUK_DDD(DUK_DDDPRINT("nothing was trimmed: avoid interning (hashing etc)"));
return;
}

60
src/duk_bi_array.c

@ -126,7 +126,7 @@ int duk_bi_array_prototype_to_string(duk_context *ctx) {
/* XXX: 'this' will be ToObject() coerced twice, which is incorrect
* but should have no visible side effects.
*/
DUK_DDDPRINT("this.join is not callable, fall back to (original) Object.toString");
DUK_DDD(DUK_DDDPRINT("this.join is not callable, fall back to (original) Object.toString"));
duk_set_top(ctx, 0);
return duk_bi_object_prototype_to_string(ctx);
}
@ -137,7 +137,7 @@ int duk_bi_array_prototype_to_string(duk_context *ctx) {
/* [ ... func this ] */
DUK_DDDPRINT("calling: func=%!iT, this=%!iT", duk_get_tval(ctx, -2), duk_get_tval(ctx, -1));
DUK_DDD(DUK_DDDPRINT("calling: func=%!iT, this=%!iT", duk_get_tval(ctx, -2), duk_get_tval(ctx, -1)));
duk_call_method(ctx, 0);
return 1;
@ -250,8 +250,8 @@ int duk_bi_array_prototype_join_shared(duk_context *ctx) {
/* [ sep ToObject(this) len ] */
DUK_DDDPRINT("sep=%!T, this=%!T, len=%d",
duk_get_tval(ctx, 0), duk_get_tval(ctx, 1), (int) len);
DUK_DDD(DUK_DDDPRINT("sep=%!T, this=%!T, len=%d",
duk_get_tval(ctx, 0), duk_get_tval(ctx, 1), (int) len));
valstack_required = (len >= DUK__ARRAY_MID_JOIN_LIMIT ?
DUK__ARRAY_MID_JOIN_LIMIT : len);
@ -268,8 +268,8 @@ int duk_bi_array_prototype_join_shared(duk_context *ctx) {
if (count >= DUK__ARRAY_MID_JOIN_LIMIT || /* intermediate join to avoid valstack overflow */
idx >= len) { /* end of loop (careful with len==0) */
/* [ sep ToObject(this) len sep str0 ... str(count-1) ] */
DUK_DDDPRINT("mid/final join, count=%d, idx=%d, len=%d",
(int) count, (int) idx, (int) len);
DUK_DDD(DUK_DDDPRINT("mid/final join, count=%d, idx=%d, len=%d",
(int) count, (int) idx, (int) len));
duk_join(ctx, count); /* -> [ sep ToObject(this) len str ] */
duk_dup(ctx, 0); /* -> [ sep ToObject(this) len str sep ] */
duk_insert(ctx, -2); /* -> [ sep ToObject(this) len sep str ] */
@ -394,15 +394,15 @@ static int duk__array_sort_compare(duk_context *ctx, int idx1, int idx2) {
*/
if (idx1 == idx2) {
DUK_DDDPRINT("duk__array_sort_compare: idx1=%d, idx2=%d -> indices identical, quick exit", idx1, idx2);
DUK_DDD(DUK_DDDPRINT("duk__array_sort_compare: idx1=%d, idx2=%d -> indices identical, quick exit", idx1, idx2));
return 0;
}
have1 = duk_get_prop_index(ctx, idx_obj, idx1);
have2 = duk_get_prop_index(ctx, idx_obj, idx2);
DUK_DDDPRINT("duk__array_sort_compare: idx1=%d, idx2=%d, have1=%d, have2=%d, val1=%!T, val2=%!T",
idx1, idx2, have1, have2, duk_get_tval(ctx, -2), duk_get_tval(ctx, -1));
DUK_DDD(DUK_DDDPRINT("duk__array_sort_compare: idx1=%d, idx2=%d, have1=%d, have2=%d, val1=%!T, val2=%!T",
idx1, idx2, have1, have2, duk_get_tval(ctx, -2), duk_get_tval(ctx, -1)));
if (have1) {
if (have2) {
@ -466,7 +466,7 @@ static int duk__array_sort_compare(duk_context *ctx, int idx1, int idx2) {
}
duk_pop(ctx);
DUK_DDDPRINT("-> result %d (from comparefn, after coercion)", ret);
DUK_DDD(DUK_DDDPRINT("-> result %d (from comparefn, after coercion)", ret));
return ret;
}
@ -482,7 +482,7 @@ static int duk__array_sort_compare(duk_context *ctx, int idx1, int idx2) {
pop_ret:
duk_pop_2(ctx);
DUK_DDDPRINT("-> result %d", ret);
DUK_DDD(DUK_DDDPRINT("-> result %d", ret));
return ret;
}
@ -541,7 +541,7 @@ static void duk__debuglog_qsort_state(duk_context *ctx, int lo, int hi, int pivo
*ptr++ = ']';
*ptr++ = '\0';
DUK_DDDPRINT("%s (lo=%d, hi=%d, pivot=%d)", buf, lo, hi, pivot);
DUK_DDD(DUK_DDDPRINT("%s (lo=%d, hi=%d, pivot=%d)", buf, lo, hi, pivot));
}
#endif
@ -549,7 +549,7 @@ static void duk__array_qsort(duk_context *ctx, int lo, int hi) {
duk_hthread *thr = (duk_hthread *) ctx;
int p, l, r;
DUK_DDDPRINT("duk__array_qsort: lo=%d, hi=%d, obj=%!T", lo, hi, duk_get_tval(ctx, 1));
DUK_DDD(DUK_DDDPRINT("duk__array_qsort: lo=%d, hi=%d, obj=%!T", lo, hi, duk_get_tval(ctx, 1)));
DUK_ASSERT_TOP(ctx, 3);
@ -560,7 +560,7 @@ static void duk__array_qsort(duk_context *ctx, int lo, int hi) {
/* trivial cases */
if (hi - lo < 1) {
DUK_DDDPRINT("degenerate case, return immediately");
DUK_DDD(DUK_DDDPRINT("degenerate case, return immediately"));
return;
}
DUK_ASSERT(hi > lo);
@ -569,19 +569,19 @@ static void duk__array_qsort(duk_context *ctx, int lo, int hi) {
/* randomized pivot selection */
p = lo + (duk_util_tinyrandom_get_bits(thr, 30) % (hi - lo + 1)); /* rnd in [lo,hi] */
DUK_ASSERT(p >= lo && p <= hi);
DUK_DDDPRINT("lo=%d, hi=%d, chose pivot p=%d", lo, hi, p);
DUK_DDD(DUK_DDDPRINT("lo=%d, hi=%d, chose pivot p=%d", lo, hi, p));
/* move pivot out of the way */
duk__array_sort_swap(ctx, p, lo);
p = lo;
DUK_DDDPRINT("pivot moved out of the way: %!T", duk_get_tval(ctx, 1));
DUK_DDD(DUK_DDDPRINT("pivot moved out of the way: %!T", duk_get_tval(ctx, 1)));
l = lo + 1;
r = hi;
for (;;) {
/* find elements to swap */
for (;;) {
DUK_DDDPRINT("left scan: l=%d, r=%d, p=%d", l, r, p);
DUK_DDD(DUK_DDDPRINT("left scan: l=%d, r=%d, p=%d", l, r, p));
if (l >= hi) {
break;
}
@ -591,7 +591,7 @@ static void duk__array_qsort(duk_context *ctx, int lo, int hi) {
l++;
}
for (;;) {
DUK_DDDPRINT("right scan: l=%d, r=%d, p=%d", l, r, p);
DUK_DDD(DUK_DDDPRINT("right scan: l=%d, r=%d, p=%d", l, r, p));
if (r <= lo) {
break;
}
@ -605,11 +605,11 @@ static void duk__array_qsort(duk_context *ctx, int lo, int hi) {
}
DUK_ASSERT(l < r);
DUK_DDDPRINT("swap %d and %d", l, r);
DUK_DDD(DUK_DDDPRINT("swap %d and %d", l, r));
duk__array_sort_swap(ctx, l, r);
DUK_DDDPRINT("after swap: %!T", duk_get_tval(ctx, 1));
DUK_DDD(DUK_DDDPRINT("after swap: %!T", duk_get_tval(ctx, 1)));
l++;
r--;
}
@ -625,14 +625,14 @@ static void duk__array_qsort(duk_context *ctx, int lo, int hi) {
*/
/* move pivot to its final place */
DUK_DDDPRINT("before final pivot swap: %!T", duk_get_tval(ctx, 1));
DUK_DDD(DUK_DDDPRINT("before final pivot swap: %!T", duk_get_tval(ctx, 1)));
duk__array_sort_swap(ctx, lo, r);
#ifdef DUK_USE_DDDPRINT
duk__debuglog_qsort_state(ctx, lo, hi, r);
#endif
DUK_DDDPRINT("recurse: pivot=%d, obj=%!T", r, duk_get_tval(ctx, 1));
DUK_DDD(DUK_DDDPRINT("recurse: pivot=%d, obj=%!T", r, duk_get_tval(ctx, 1)));
duk__array_qsort(ctx, lo, r - 1);
duk__array_qsort(ctx, r + 1, hi);
}
@ -1259,7 +1259,7 @@ int duk_bi_array_prototype_reduce_shared(duk_context *ctx) {
* initialValue was given or not.
*/
nargs = duk_get_top(ctx);
DUK_DPRINT("nargs=%d", nargs);
DUK_DDD(DUK_DDDPRINT("nargs=%d", nargs));
duk_set_top(ctx, 2);
len = duk__push_this_obj_len_u32(ctx);
@ -1279,13 +1279,13 @@ int duk_bi_array_prototype_reduce_shared(duk_context *ctx) {
duk_dup(ctx, 1);
have_acc = 1;
}
DUK_DPRINT("have_acc=%d, acc=%!T", have_acc, duk_get_tval(ctx, 3));
DUK_DDD(DUK_DDDPRINT("have_acc=%d, acc=%!T", have_acc, duk_get_tval(ctx, 3)));
for (i = (idx_step >= 0 ? 0 : len - 1);
i >= 0 && i < len;
i += idx_step) {
DUK_DPRINT("i=%d, len=%d, have_acc=%d, top=%d, acc=%!T",
i, len, have_acc, duk_get_top(ctx), duk_get_tval(ctx, 4));
DUK_DDD(DUK_DDDPRINT("i=%d, len=%d, have_acc=%d, top=%d, acc=%!T",
i, len, have_acc, duk_get_top(ctx), duk_get_tval(ctx, 4)));
DUK_ASSERT((have_acc && duk_get_top(ctx) == 5) ||
(!have_acc && duk_get_top(ctx) == 4));
@ -1306,11 +1306,11 @@ int duk_bi_array_prototype_reduce_shared(duk_context *ctx) {
duk_get_prop_index(ctx, 2, i);
duk_push_int(ctx, i); /* FIXME: type */
duk_dup(ctx, 2);
DUK_DPRINT("calling reduce function: func=%!T, prev=%!T, curr=%!T, idx=%!T, obj=%!T",
duk_get_tval(ctx, -5), duk_get_tval(ctx, -4), duk_get_tval(ctx, -3),
duk_get_tval(ctx, -2), duk_get_tval(ctx, -1));
DUK_DDD(DUK_DDDPRINT("calling reduce function: func=%!T, prev=%!T, curr=%!T, idx=%!T, obj=%!T",
duk_get_tval(ctx, -5), duk_get_tval(ctx, -4), duk_get_tval(ctx, -3),
duk_get_tval(ctx, -2), duk_get_tval(ctx, -1)));
duk_call(ctx, 4);
DUK_DPRINT("-> result: %!T", duk_get_tval(ctx, -1));
DUK_DDD(DUK_DDDPRINT("-> result: %!T", duk_get_tval(ctx, -1)));
duk_replace(ctx, 4);
DUK_ASSERT_TOP(ctx, 5);
}

100
src/duk_bi_date.c

@ -124,7 +124,7 @@ duk_double_t duk_bi_date_get_now(duk_context *ctx) {
static void duk__convert_systime_to_ularge(const SYSTEMTIME *st, ULARGE_INTEGER *res) {
FILETIME ft;
if (SystemTimeToFileTime(st, &ft) == 0) {
DUK_DPRINT("SystemTimeToFileTime() failed, returning 0");
DUK_D(DUK_DPRINT("SystemTimeToFileTime() failed, returning 0"));
res->QuadPart = 0;
} else {
res->LowPart = ft.dwLowDateTime;
@ -216,7 +216,7 @@ static int duk__get_local_tzoffset(double d) {
d = duk__get_timeval_from_dparts(dparts, 0 /*flags*/);
DUK_ASSERT(d >= 0 && d < 2147483648.0 * 1000.0); /* unsigned 31-bit range */
t = (size_t) (d / 1000.0);
DUK_DDDPRINT("timeval: %lf -> time_t %d", d, (int) t);
DUK_DDD(DUK_DDDPRINT("timeval: %lf -> time_t %d", d, (int) t));
t1 = t;
@ -232,11 +232,11 @@ static int duk__get_local_tzoffset(double d) {
#endif
DUK_MEMCPY((void *) &tms[1], &tms[0], sizeof(struct tm));
DUK_DDDPRINT("before mktime: tm={sec:%d,min:%d,hour:%d,mday:%d,mon:%d,year:%d,"
"wday:%d,yday:%d,isdst:%d}",
(int) tms[0].tm_sec, (int) tms[0].tm_min, (int) tms[0].tm_hour,
(int) tms[0].tm_mday, (int) tms[0].tm_mon, (int) tms[0].tm_year,
(int) tms[0].tm_wday, (int) tms[0].tm_yday, (int) tms[0].tm_isdst);
DUK_DDD(DUK_DDDPRINT("before mktime: tm={sec:%d,min:%d,hour:%d,mday:%d,mon:%d,year:%d,"
"wday:%d,yday:%d,isdst:%d}",
(int) tms[0].tm_sec, (int) tms[0].tm_min, (int) tms[0].tm_hour,
(int) tms[0].tm_mday, (int) tms[0].tm_mon, (int) tms[0].tm_year,
(int) tms[0].tm_wday, (int) tms[0].tm_yday, (int) tms[0].tm_isdst));
(void) mktime(&tms[0]);
tms[1].tm_isdst = tms[0].tm_isdst;
@ -251,12 +251,12 @@ static int duk__get_local_tzoffset(double d) {
goto error;
}
DUK_DDDPRINT("after mktime: tm={sec:%d,min:%d,hour:%d,mday:%d,mon:%d,year:%d,"
"wday:%d,yday:%d,isdst:%d}",
(int) tms[1].tm_sec, (int) tms[1].tm_min, (int) tms[1].tm_hour,
(int) tms[1].tm_mday, (int) tms[1].tm_mon, (int) tms[1].tm_year,
(int) tms[1].tm_wday, (int) tms[1].tm_yday, (int) tms[1].tm_isdst);
DUK_DDDPRINT("t2=%d", (int) t2);
DUK_DDD(DUK_DDDPRINT("after mktime: tm={sec:%d,min:%d,hour:%d,mday:%d,mon:%d,year:%d,"
"wday:%d,yday:%d,isdst:%d}",
(int) tms[1].tm_sec, (int) tms[1].tm_min, (int) tms[1].tm_hour,
(int) tms[1].tm_mday, (int) tms[1].tm_mon, (int) tms[1].tm_year,
(int) tms[1].tm_wday, (int) tms[1].tm_yday, (int) tms[1].tm_isdst));
DUK_DDD(DUK_DDDPRINT("t2=%d", (int) t2));
/* Positive if local time ahead of UTC. */
@ -272,7 +272,7 @@ static int duk__get_local_tzoffset(double d) {
error:
/* FIXME: return something more useful, so that caller can throw? */
DUK_DPRINT("mktime() failed, d=%lf", d);
DUK_D(DUK_DPRINT("mktime() failed, d=%lf", d));
return 0;
}
#endif /* DUK_USE_DATE_TZO_GMTIME */
@ -300,7 +300,7 @@ static int duk__get_local_tzoffset(double d) {
ft1.dwHighDateTime = tmp2.HighPart;
FileTimeToSystemTime((const FILETIME *) &ft1, &st2);
if (SystemTimeToTzSpecificLocalTime((LPTIME_ZONE_INFORMATION) NULL, &st2, &st3) == 0) {
DUK_DPRINT("SystemTimeToTzSpecificLocalTime() failed, return tzoffset 0");
DUK_D(DUK_DPRINT("SystemTimeToTzSpecificLocalTime() failed, return tzoffset 0"));
return 0;
}
duk__convert_systime_to_ularge((const SYSTEMTIME *) &st3, &tmp3);
@ -322,19 +322,19 @@ static int duk__parse_string_strptime(duk_context *ctx, const char *str) {
DUK_SNPRINTF(buf, sizeof(buf), "%s", str);
buf[sizeof(buf) - 1] = (char) 0;
DUK_DDDPRINT("parsing: '%s'", buf);
DUK_DDD(DUK_DDDPRINT("parsing: '%s'", buf));
DUK_MEMZERO(&tm, sizeof(tm));
if (strptime((const char *) buf, "%c", &tm) != NULL) {
DUK_DDDPRINT("before mktime: tm={sec:%d,min:%d,hour:%d,mday:%d,mon:%d,year:%d,"
"wday:%d,yday:%d,isdst:%d}",
(int) tm.tm_sec, (int) tm.tm_min, (int) tm.tm_hour,
(int) tm.tm_mday, (int) tm.tm_mon, (int) tm.tm_year,
(int) tm.tm_wday, (int) tm.tm_yday, (int) tm.tm_isdst);
DUK_DDD(DUK_DDDPRINT("before mktime: tm={sec:%d,min:%d,hour:%d,mday:%d,mon:%d,year:%d,"
"wday:%d,yday:%d,isdst:%d}",
(int) tm.tm_sec, (int) tm.tm_min, (int) tm.tm_hour,
(int) tm.tm_mday, (int) tm.tm_mon, (int) tm.tm_year,
(int) tm.tm_wday, (int) tm.tm_yday, (int) tm.tm_isdst));
tm.tm_isdst = -1; /* negative: dst info not available */
t = mktime(&tm);
DUK_DDDPRINT("mktime() -> %d", (int) t);
DUK_DDD(DUK_DDDPRINT("mktime() -> %d", (int) t));
if (t >= 0) {
duk_push_number(ctx, ((double) t) * 1000.0);
return 1;
@ -357,11 +357,11 @@ static int duk__parse_string_getdate(duk_context *ctx, const char *str) {
DUK_MEMZERO(&tm, sizeof(struct tm));
rc = getdate_r(str, &tm);
DUK_DDDPRINT("getdate_r() -> %d", rc);
DUK_DDD(DUK_DDDPRINT("getdate_r() -> %d", rc));
if (rc == 0) {
t = mktime(&tm);
DUK_DDDPRINT("mktime() -> %d", (int) t);
DUK_DDD(DUK_DDDPRINT("mktime() -> %d", (int) t));
if (t >= 0) {
duk_push_number(ctx, (double) t);
return 1;
@ -544,12 +544,12 @@ static int duk__parse_string_iso8601_subset(duk_context *ctx, const char *str) {
for (;;) {
ch = *p++;
DUK_DDDPRINT("parsing, part_idx=%d, char=%d ('%c')", part_idx, (int) ch,
(ch >= 0x20 && ch <= 0x7e) ? ch : '?');
DUK_DDD(DUK_DDDPRINT("parsing, part_idx=%d, char=%d ('%c')", part_idx, (int) ch,
(ch >= 0x20 && ch <= 0x7e) ? ch : '?'));
if (ch >= '0' && ch <= '9') {
if (ndigits >= 9) {
DUK_DDDPRINT("too many digits -> reject");
DUK_DDD(DUK_DDDPRINT("too many digits -> reject"));
goto reject;
}
if (part_idx == DUK__PI_MILLISECOND /*msec*/ && ndigits >= 3) {
@ -573,7 +573,7 @@ static int duk__parse_string_iso8601_subset(duk_context *ctx, const char *str) {
}
}
parts[part_idx] = accum;
DUK_DDDPRINT("wrote part %d -> value %d", part_idx, accum);
DUK_DDD(DUK_DDDPRINT("wrote part %d -> value %d", part_idx, accum));
accum = 0;
ndigits = 0;
@ -584,7 +584,7 @@ static int duk__parse_string_iso8601_subset(duk_context *ctx, const char *str) {
}
}
if (i == (int) sizeof(duk__parse_iso8601_seps)) {
DUK_DDDPRINT("separator character doesn't match -> reject");
DUK_DDD(DUK_DDDPRINT("separator character doesn't match -> reject"));
goto reject;
}
@ -596,8 +596,8 @@ static int duk__parse_string_iso8601_subset(duk_context *ctx, const char *str) {
int nextpart;
int cflags;
DUK_DDDPRINT("part_idx=%d, sep_idx=%d, match_val=0x%08x, considering rule=0x%08x",
part_idx, sep_idx, match_val, rule);
DUK_DDD(DUK_DDDPRINT("part_idx=%d, sep_idx=%d, match_val=0x%08x, considering rule=0x%08x",
part_idx, sep_idx, match_val, rule));
if ((rule & match_val) != match_val) {
continue;
@ -605,8 +605,8 @@ static int duk__parse_string_iso8601_subset(duk_context *ctx, const char *str) {
DUK__UNPACK_RULE(rule, nextpart, cflags);
DUK_DDDPRINT("rule match -> part_idx=%d, sep_idx=%d, match_val=0x%08x, rule=0x%08x -> nextpart=%d, cflags=0x%02x",
part_idx, sep_idx, match_val, rule, nextpart, cflags);
DUK_DDD(DUK_DDDPRINT("rule match -> part_idx=%d, sep_idx=%d, match_val=0x%08x, rule=0x%08x -> nextpart=%d, cflags=0x%02x",
part_idx, sep_idx, match_val, rule, nextpart, cflags));
if (cflags & DUK__CF_NEG) {
neg_tzoffset = 1;
@ -629,7 +629,7 @@ static int duk__parse_string_iso8601_subset(duk_context *ctx, const char *str) {
} /* rule match */
if (i == (int) (sizeof(duk__parse_iso8601_control) / sizeof(int))) {
DUK_DDDPRINT("no rule matches -> reject");
DUK_DDD(DUK_DDDPRINT("no rule matches -> reject"));
goto reject;
}
@ -637,7 +637,7 @@ static int duk__parse_string_iso8601_subset(duk_context *ctx, const char *str) {
/* This shouldn't be necessary, but check just in case
* to avoid any chance of overruns.
*/
DUK_DDDPRINT("NUL after rule matching (should not happen) -> reject");
DUK_DDD(DUK_DDDPRINT("NUL after rule matching (should not happen) -> reject"));
goto reject;
}
} /* if-digit-else-ctrl */
@ -646,14 +646,14 @@ static int duk__parse_string_iso8601_subset(duk_context *ctx, const char *str) {
/* We should never exit the loop above, but if we do, reject
* by falling through.
*/
DUK_DDDPRINT("fell out of char loop without explicit accept/reject -> reject");
DUK_DDD(DUK_DDDPRINT("fell out of char loop without explicit accept/reject -> reject"));
reject:
DUK_DDDPRINT("reject");
DUK_DDD(DUK_DDDPRINT("reject"));
return 0;
accept:
DUK_DDDPRINT("accept");
DUK_DDD(DUK_DDDPRINT("accept"));
/* Apply timezone offset to get the main parts in UTC */
if (neg_year) {
@ -677,7 +677,7 @@ static int duk__parse_string_iso8601_subset(duk_context *ctx, const char *str) {
* potential for Valgrind issues.
*/
for (i = 0; i < DUK__NUM_PARTS; i++) {
DUK_DDDPRINT("part[%d] = %d", i, parts[i]);
DUK_DDD(DUK_DDDPRINT("part[%d] = %d", i, parts[i]));
dparts[i] = parts[i];
}
@ -712,7 +712,7 @@ static int duk__parse_string(duk_context *ctx, const char *str) {
*/
DUK_ASSERT(str != NULL);
DUK_DDDPRINT("parse datetime from string '%s'", str);
DUK_DDD(DUK_DDDPRINT("parse datetime from string '%s'", str));
if (duk__parse_string_iso8601_subset(ctx, str) > 0) {
return 1;
@ -816,11 +816,11 @@ static int duk__year_from_day(int day, int *out_day_within_year) {
for (;;) {
diff_days = duk__day_from_year(year) - day;
DUK_DDDPRINT("year=%d day=%d, diff_days=%d", year, day, diff_days);
DUK_DDD(DUK_DDDPRINT("year=%d day=%d, diff_days=%d", year, day, diff_days));
if (diff_days <= 0) {
*out_day_within_year = -diff_days;
DUK_DDDPRINT("--> year=%d, day-within-year=%d",
year, *out_day_within_year);
DUK_DDD(DUK_DDDPRINT("--> year=%d, day-within-year=%d",
year, *out_day_within_year));
DUK_ASSERT(*out_day_within_year >= 0);
DUK_ASSERT(*out_day_within_year <= (duk__is_leap_year(year) ? 366 : 365));
return year;
@ -937,13 +937,13 @@ static void duk__timeval_to_parts(double d, int *parts, double *dparts, int flag
if (month == 1 && is_leap) {
dim++;
}
DUK_DDDPRINT("month=%d, dim=%d, day=%d", month, dim, day);
DUK_DDD(DUK_DDDPRINT("month=%d, dim=%d, day=%d", month, dim, day));
if (day < dim) {
break;
}
day -= dim;
}
DUK_DDDPRINT("final month=%d", month);
DUK_DDD(DUK_DDDPRINT("final month=%d", month));
DUK_ASSERT(month >= 0 && month <= 11);
DUK_ASSERT(day >= 0 && day <= 31);
@ -1007,7 +1007,7 @@ static double duk__get_timeval_from_dparts(double *dparts, int flags) {
/* MakeDate */
d = tmp_day * ((double) DUK__MS_DAY) + tmp_time;
DUK_DDDPRINT("time=%lf day=%lf --> timeval=%lf", tmp_time, tmp_day, d);
DUK_DDD(DUK_DDDPRINT("time=%lf day=%lf --> timeval=%lf", tmp_time, tmp_day, d));
/* Optional UTC conversion followed by TimeClip().
* Note that this also handles Infinity -> NaN conversion.
@ -1386,9 +1386,9 @@ static void duk__set_parts_from_args(duk_context *ctx, double *dparts, int nargs
dparts[idx] = d;
}
DUK_DDDPRINT("parts from args -> %lf %lf %lf %lf %lf %lf %lf %lf",
dparts[0], dparts[1], dparts[2], dparts[3],
dparts[4], dparts[5], dparts[6], dparts[7]);
DUK_DDD(DUK_DDDPRINT("parts from args -> %lf %lf %lf %lf %lf %lf %lf %lf",
dparts[0], dparts[1], dparts[2], dparts[3],
dparts[4], dparts[5], dparts[6], dparts[7]));
}
/*
@ -1422,7 +1422,7 @@ int duk_bi_date_constructor(duk_context *ctx) {
double dparts[DUK__NUM_PARTS];
double d;
DUK_DDDPRINT("Date constructor, nargs=%d, is_cons=%d", nargs, is_cons);
DUK_DDD(DUK_DDDPRINT("Date constructor, nargs=%d, is_cons=%d", nargs, is_cons));
duk_push_object_helper(ctx,
DUK_HOBJECT_FLAG_EXTENSIBLE |

24
src/duk_bi_function.c

@ -151,24 +151,24 @@ int duk_bi_function_prototype_apply(duk_context *ctx) {
duk_push_this(ctx);
if (!duk_is_callable(ctx, -1)) {
DUK_DDDPRINT("func is not callable");
DUK_DDD(DUK_DDDPRINT("func is not callable"));
goto type_error;
}
duk_insert(ctx, 0);
DUK_ASSERT_TOP(ctx, 3);
DUK_DDDPRINT("func=%!iT, thisArg=%!iT, argArray=%!iT",
duk_get_tval(ctx, 0), duk_get_tval(ctx, 1), duk_get_tval(ctx, 2));
DUK_DDD(DUK_DDDPRINT("func=%!iT, thisArg=%!iT, argArray=%!iT",
duk_get_tval(ctx, 0), duk_get_tval(ctx, 1), duk_get_tval(ctx, 2)));
/* [ func thisArg argArray ] */
if (duk_is_null_or_undefined(ctx, 2)) {
DUK_DDDPRINT("argArray is null/undefined, no args");
DUK_DDD(DUK_DDDPRINT("argArray is null/undefined, no args"));
len = 0;
} else if (!duk_is_object(ctx, 2)) {
goto type_error;
} else {
DUK_DDDPRINT("argArray is an object");
DUK_DDD(DUK_DDDPRINT("argArray is an object"));
/* FIXME: make this an internal helper */
duk_get_prop_stridx(ctx, 2, DUK_STRIDX_LENGTH);
@ -177,7 +177,7 @@ int duk_bi_function_prototype_apply(duk_context *ctx) {
duk_require_stack(ctx, len); /* FIXME: more? */
DUK_DDDPRINT("argArray length is %d", len);
DUK_DDD(DUK_DDDPRINT("argArray length is %d", len));
for (i = 0; i < len; i++) {
duk_get_prop_index(ctx, 2, i);
}
@ -187,8 +187,8 @@ int duk_bi_function_prototype_apply(duk_context *ctx) {
/* [ func thisArg arg1 ... argN ] */
DUK_DDDPRINT("apply, func=%!iT, thisArg=%!iT, len=%d",
duk_get_tval(ctx, 0), duk_get_tval(ctx, 1), len);
DUK_DDD(DUK_DDDPRINT("apply, func=%!iT, thisArg=%!iT, len=%d",
duk_get_tval(ctx, 0), duk_get_tval(ctx, 1), len));
duk_call_method(ctx, len);
return 1;
@ -218,8 +218,8 @@ int duk_bi_function_prototype_call(duk_context *ctx) {
/* [ func thisArg arg1 ... argN ] */
DUK_DDDPRINT("func=%!iT, thisArg=%!iT, argcount=%d, top=%d",
duk_get_tval(ctx, 0), duk_get_tval(ctx, 1), nargs - 1, duk_get_top(ctx));
DUK_DDD(DUK_DDDPRINT("func=%!iT, thisArg=%!iT, argcount=%d, top=%d",
duk_get_tval(ctx, 0), duk_get_tval(ctx, 1), nargs - 1, duk_get_top(ctx)));
duk_call_method(ctx, nargs - 1);
return 1;
}
@ -247,7 +247,7 @@ int duk_bi_function_prototype_bind(duk_context *ctx) {
duk_push_this(ctx);
if (!duk_is_callable(ctx, -1)) {
DUK_DDDPRINT("func is not callable");
DUK_DDD(DUK_DDDPRINT("func is not callable"));
goto type_error;
}
@ -308,7 +308,7 @@ int duk_bi_function_prototype_bind(duk_context *ctx) {
duk_get_prop_stridx(ctx, -2, DUK_STRIDX_FILE_NAME);
duk_def_prop_stridx(ctx, -2, DUK_STRIDX_FILE_NAME, DUK_PROPDESC_FLAGS_WC);
DUK_DDDPRINT("created bound function: %!iT", duk_get_tval(ctx, -1));
DUK_DDD(DUK_DDDPRINT("created bound function: %!iT", duk_get_tval(ctx, -1)));
return 1;

32
src/duk_bi_global.c

@ -206,14 +206,14 @@ static void duk__transform_callback_decode_uri(duk__transform_context *tfm_ctx,
duk_uint8_t *p = tfm_ctx->p;
duk_size_t left = (duk_size_t) (tfm_ctx->p_end - p); /* bytes left */
DUK_DDDPRINT("percent encoding, left=%d", (int) left);
DUK_DDD(DUK_DDDPRINT("percent encoding, left=%d", (int) left));
if (left < 2) {
goto uri_error;
}
t = duk__decode_hex_escape(p, 2);
DUK_DDDPRINT("first byte: %d", t);
DUK_DDD(DUK_DDDPRINT("first byte: %d", t));
if (t < 0) {
goto uri_error;
}
@ -272,7 +272,7 @@ static void duk__transform_callback_decode_uri(duk__transform_context *tfm_ctx,
for (i = 1; i < utf8_blen; i++) {
/* p points to digit part ('%xy', p points to 'x') */
t = duk__decode_hex_escape(p, 2);
DUK_DDDPRINT("i=%d utf8_blen=%d cp=%d t=0x%02x", i, utf8_blen, cp,t);
DUK_DDD(DUK_DDDPRINT("i=%d utf8_blen=%d cp=%d t=0x%02x", i, utf8_blen, cp, t));
if (t < 0) {
goto uri_error;
}
@ -285,7 +285,7 @@ static void duk__transform_callback_decode_uri(duk__transform_context *tfm_ctx,
p--; /* p overshoots */
tfm_ctx->p = p;
DUK_DDDPRINT("final cp=%d, min_cp=%d", cp, min_cp);
DUK_DDD(DUK_DDDPRINT("final cp=%d, min_cp=%d", cp, min_cp));
if (cp < min_cp || cp > 0x10ffffL || (cp >= 0xd800L && cp <= 0xdfffL)) {
goto uri_error;
@ -459,7 +459,7 @@ int duk_bi_global_object_eval(duk_context *ctx) {
act = thr->callstack + thr->callstack_top - 2; /* caller */
if (act->lex_env == NULL) {
DUK_ASSERT(act->var_env == NULL);
DUK_DDDPRINT("delayed environment initialization");
DUK_DDD(DUK_DDDPRINT("delayed environment initialization"));
/* this may have side effects, so re-lookup act */
duk_js_init_activation_environment_records_delayed(thr, act);
@ -474,9 +474,9 @@ int duk_bi_global_object_eval(duk_context *ctx) {
duk_hobject *new_env;
duk_hobject *act_lex_env;
DUK_DDDPRINT("direct eval call to a strict function -> "
"var_env and lex_env to a fresh env, "
"this_binding to caller's this_binding");
DUK_DDD(DUK_DDDPRINT("direct eval call to a strict function -> "
"var_env and lex_env to a fresh env, "
"this_binding to caller's this_binding"));
act = thr->callstack + thr->callstack_top - 2; /* caller */
act_lex_env = act->lex_env;
@ -488,7 +488,7 @@ int duk_bi_global_object_eval(duk_context *ctx) {
act_lex_env);
new_env = duk_require_hobject(ctx, -1);
DUK_ASSERT(new_env != NULL);
DUK_DDDPRINT("new_env allocated: %!iO", new_env);
DUK_DDD(DUK_DDDPRINT("new_env allocated: %!iO", new_env));
outer_lex_env = new_env;
outer_var_env = new_env;
@ -498,9 +498,9 @@ int duk_bi_global_object_eval(duk_context *ctx) {
/* compiler's responsibility */
DUK_ASSERT(DUK_HOBJECT_HAS_NEWENV((duk_hobject *) func));
} else {
DUK_DDDPRINT("direct eval call to a non-strict function -> "
"var_env and lex_env to caller's envs, "
"this_binding to caller's this_binding");
DUK_DDD(DUK_DDDPRINT("direct eval call to a non-strict function -> "
"var_env and lex_env to caller's envs, "
"this_binding to caller's this_binding"));
outer_lex_env = act->lex_env;
outer_var_env = act->var_env;
@ -509,8 +509,8 @@ int duk_bi_global_object_eval(duk_context *ctx) {
DUK_ASSERT(!DUK_HOBJECT_HAS_NEWENV((duk_hobject *) func));
}
} else {
DUK_DDDPRINT("indirect eval call -> var_env and lex_env to "
"global object, this_binding to global object");
DUK_DDD(DUK_DDDPRINT("indirect eval call -> var_env and lex_env to "
"global object, this_binding to global object"));
this_to_global = 1;
outer_lex_env = thr->builtins[DUK_BIDX_GLOBAL_ENV];
@ -532,8 +532,8 @@ int duk_bi_global_object_eval(duk_context *ctx) {
duk_push_tval(ctx, tv);
}
DUK_DDDPRINT("eval -> lex_env=%!iO, var_env=%!iO, this_binding=%!T",
outer_lex_env, outer_var_env, duk_get_tval(ctx, -1));
DUK_DDD(DUK_DDDPRINT("eval -> lex_env=%!iO, var_env=%!iO, this_binding=%!T",
outer_lex_env, outer_var_env, duk_get_tval(ctx, -1)));
duk_call_method(ctx, 0);

92
src/duk_bi_json.c

@ -117,8 +117,8 @@ static duk_uint32_t duk__dec_decode_hex_escape(duk_json_dec_ctx *js_ctx, int n)
x = duk__dec_get(js_ctx);
DUK_DDDPRINT("decode_hex_escape: i=%d, n=%d, res=%d, x=%d",
i, n, (int) res, x);
DUK_DDD(DUK_DDDPRINT("decode_hex_escape: i=%d, n=%d, res=%d, x=%d",
i, n, (int) res, x));
res *= 16;
if (x >= (int) '0' && x <= (int) '9') {
@ -133,7 +133,7 @@ static duk_uint32_t duk__dec_decode_hex_escape(duk_json_dec_ctx *js_ctx, int n)
}
}
DUK_DDDPRINT("final hex decoded value: %d", (int) res);
DUK_DDD(DUK_DDDPRINT("final hex decoded value: %d", (int) res));
return res;
syntax_error:
@ -406,7 +406,7 @@ static void duk__dec_number(duk_json_dec_ctx *js_ctx) {
int x;
int s2n_flags;
DUK_DDDPRINT("parse_number");
DUK_DDD(DUK_DDDPRINT("parse_number"));
/* Caller has already eaten the first character so backtrack one
* byte. This is correct because the first character is either
@ -423,9 +423,9 @@ static void duk__dec_number(duk_json_dec_ctx *js_ctx) {
for (;;) {
x = duk__dec_peek(js_ctx);
DUK_DDDPRINT("parse_number: p_start=%p, p=%p, p_end=%p, x=%d",
(void *) p_start, (void *) js_ctx->p,
(void *) js_ctx->p_end, x);
DUK_DDD(DUK_DDDPRINT("parse_number: p_start=%p, p=%p, p_end=%p, x=%d",
(void *) p_start, (void *) js_ctx->p,
(void *) js_ctx->p_end, x));
if (!((x >= (int) '0' && x <= (int) '9') ||
(x == '.' || x == 'e' || x == 'E' || x == '-'))) {
@ -442,13 +442,13 @@ static void duk__dec_number(duk_json_dec_ctx *js_ctx) {
DUK_S2N_FLAG_ALLOW_MINUS | /* but don't allow leading plus */
DUK_S2N_FLAG_ALLOW_FRAC;
DUK_DDDPRINT("parse_number: string before parsing: %!T", duk_get_tval(ctx, -1));
DUK_DDD(DUK_DDDPRINT("parse_number: string before parsing: %!T", duk_get_tval(ctx, -1)));
duk_numconv_parse(ctx, 10 /*radix*/, s2n_flags);
if (duk_is_nan(ctx, -1)) {
DUK_ERROR(js_ctx->thr, DUK_ERR_SYNTAX_ERROR, "invalid number");
}
DUK_ASSERT(duk_is_number(ctx, -1));
DUK_DDDPRINT("parse_number: final number: %!T", duk_get_tval(ctx, -1));
DUK_DDD(DUK_DDDPRINT("parse_number: final number: %!T", duk_get_tval(ctx, -1)));
/* [ ... num ] */
}
@ -480,7 +480,7 @@ static void duk__dec_object(duk_json_dec_ctx *js_ctx) {
int key_count;
int x;
DUK_DDDPRINT("parse_object");
DUK_DDD(DUK_DDDPRINT("parse_object"));
duk__dec_objarr_entry(js_ctx);
@ -492,8 +492,8 @@ static void duk__dec_object(duk_json_dec_ctx *js_ctx) {
for (;;) {
x = duk__dec_get_nonwhite(js_ctx);
DUK_DDDPRINT("parse_object: obj=%!T, x=%d, key_count=%d",
duk_get_tval(ctx, -1), x, key_count);
DUK_DDD(DUK_DDDPRINT("parse_object: obj=%!T, x=%d, key_count=%d",
duk_get_tval(ctx, -1), x, key_count));
/* handle comma and closing brace */
@ -546,7 +546,7 @@ static void duk__dec_object(duk_json_dec_ctx *js_ctx) {
/* [ ... obj ] */
DUK_DDDPRINT("parse_object: final object is %!T", duk_get_tval(ctx, -1));
DUK_DDD(DUK_DDDPRINT("parse_object: final object is %!T", duk_get_tval(ctx, -1)));
duk__dec_objarr_exit(js_ctx);
return;
@ -561,7 +561,7 @@ static void duk__dec_array(duk_json_dec_ctx *js_ctx) {
int arr_idx;
int x;
DUK_DDDPRINT("parse_array");
DUK_DDD(DUK_DDDPRINT("parse_array"));
duk__dec_objarr_entry(js_ctx);
@ -573,8 +573,8 @@ static void duk__dec_array(duk_json_dec_ctx *js_ctx) {
for (;;) {
x = duk__dec_get_nonwhite(js_ctx);
DUK_DDDPRINT("parse_array: arr=%!T, x=%d, arr_idx=%d",
duk_get_tval(ctx, -1), x, arr_idx);
DUK_DDD(DUK_DDDPRINT("parse_array: arr=%!T, x=%d, arr_idx=%d",
duk_get_tval(ctx, -1), x, arr_idx));
/* handle comma and closing bracket */
@ -606,7 +606,7 @@ static void duk__dec_array(duk_json_dec_ctx *js_ctx) {
/* [ ... arr ] */
DUK_DDDPRINT("parse_array: final array is %!T", duk_get_tval(ctx, -1));
DUK_DDD(DUK_DDDPRINT("parse_array: final array is %!T", duk_get_tval(ctx, -1)));
duk__dec_objarr_exit(js_ctx);
return;
@ -622,7 +622,7 @@ static void duk__dec_value(duk_json_dec_ctx *js_ctx) {
x = duk__dec_get_nonwhite(js_ctx);
DUK_DDDPRINT("parse_value: initial x=%d", x);
DUK_DDD(DUK_DDDPRINT("parse_value: initial x=%d", x));
/* Note: duk__dec_req_stridx() backtracks one char */
@ -693,8 +693,8 @@ static void duk__dec_reviver_walk(duk_json_dec_ctx *js_ctx) {
duk_uint_t i;
duk_uint_t arr_len;
DUK_DDDPRINT("walk: top=%d, holder=%!T, name=%!T",
duk_get_top(ctx), duk_get_tval(ctx, -2), duk_get_tval(ctx, -1));
DUK_DDD(DUK_DDDPRINT("walk: top=%d, holder=%!T, name=%!T",
duk_get_top(ctx), duk_get_tval(ctx, -2), duk_get_tval(ctx, -1)));
duk_dup_top(ctx);
duk_get_prop(ctx, -3); /* -> [ ... holder name val ] */
@ -706,9 +706,9 @@ static void duk__dec_reviver_walk(duk_json_dec_ctx *js_ctx) {
for (i = 0; i < arr_len; i++) {
/* [ ... holder name val ] */
DUK_DDDPRINT("walk: array, top=%d, i=%d, arr_len=%d, holder=%!T, name=%!T, val=%!T",
duk_get_top(ctx), i, arr_len, duk_get_tval(ctx, -3),
duk_get_tval(ctx, -2), duk_get_tval(ctx, -1));
DUK_DDD(DUK_DDDPRINT("walk: array, top=%d, i=%d, arr_len=%d, holder=%!T, name=%!T, val=%!T",
duk_get_top(ctx), i, arr_len, duk_get_tval(ctx, -3),
duk_get_tval(ctx, -2), duk_get_tval(ctx, -1)));
/* FIXME: push_uint_string / push_u32_string */
duk_dup_top(ctx);
@ -727,10 +727,10 @@ static void duk__dec_reviver_walk(duk_json_dec_ctx *js_ctx) {
/* [ ... holder name val ] */
duk_enum(ctx, -1, DUK_ENUM_OWN_PROPERTIES_ONLY /*flags*/);
while (duk_next(ctx, -1 /*enum_index*/, 0 /*get_value*/)) {
DUK_DDDPRINT("walk: object, top=%d, holder=%!T, name=%!T, val=%!T, enum=%!iT, obj_key=%!T",
duk_get_top(ctx), duk_get_tval(ctx, -5),
duk_get_tval(ctx, -4), duk_get_tval(ctx, -3),
duk_get_tval(ctx, -2), duk_get_tval(ctx, -1));
DUK_DDD(DUK_DDDPRINT("walk: object, top=%d, holder=%!T, name=%!T, val=%!T, enum=%!iT, obj_key=%!T",
duk_get_top(ctx), duk_get_tval(ctx, -5),
duk_get_tval(ctx, -4), duk_get_tval(ctx, -3),
duk_get_tval(ctx, -2), duk_get_tval(ctx, -1)));
/* [ ... holder name val enum obj_key ] */
duk_dup(ctx, -3);
@ -757,7 +757,7 @@ static void duk__dec_reviver_walk(duk_json_dec_ctx *js_ctx) {
duk_insert(ctx, -4); /* -> [ ... reviver holder name val ] */
duk_call_method(ctx, 2); /* -> [ ... res ] */
DUK_DDDPRINT("walk: top=%d, result=%!T", duk_get_top(ctx), duk_get_tval(ctx, -1));
DUK_DDD(DUK_DDDPRINT("walk: top=%d, result=%!T", duk_get_top(ctx), duk_get_tval(ctx, -1)));
}
/*
@ -874,8 +874,8 @@ static int duk__enc_key_quotes_needed(duk_hstring *h_key) {
p_end = p_start + DUK_HSTRING_GET_BYTELEN(h_key);
p = p_start;
DUK_DDDPRINT("duk__enc_key_quotes_needed: h_key=%!O, p_start=%p, p_end=%p, p=%p",
(duk_heaphdr *) h_key, (void *) p_start, (void *) p_end, (void *) p);
DUK_DDD(DUK_DDDPRINT("duk__enc_key_quotes_needed: h_key=%!O, p_start=%p, p_end=%p, p=%p",
(duk_heaphdr *) h_key, (void *) p_start, (void *) p_end, (void *) p));
/* Since we only accept ASCII characters, there is no need for
* actual decoding. A non-ASCII character will be >= 0x80 which
@ -921,7 +921,7 @@ static void duk__enc_quote_string(duk_json_enc_ctx *js_ctx, duk_hstring *h_str)
duk_uint8_t *p, *p_start, *p_end, *p_tmp;
duk_ucodepoint_t cp;
DUK_DDDPRINT("duk__enc_quote_string: h_str=%!O", h_str);
DUK_DDD(DUK_DDDPRINT("duk__enc_quote_string: h_str=%!O", h_str));
DUK_ASSERT(h_str != NULL);
p_start = DUK_HSTRING_GET_DATA(h_str);
@ -1047,8 +1047,8 @@ static void duk__enc_objarr_entry(duk_json_enc_ctx *js_ctx, duk_hstring **h_step
DUK_ASSERT(js_ctx->h_indent == NULL);
}
DUK_DDDPRINT("shared entry finished: top=%d, loop=%!T",
duk_get_top(ctx), duk_get_tval(ctx, js_ctx->idx_loop));
DUK_DDD(DUK_DDDPRINT("shared entry finished: top=%d, loop=%!T",
duk_get_top(ctx), duk_get_tval(ctx, js_ctx->idx_loop)));
}
/* Shared exit handling for object/array serialization. */
@ -1091,8 +1091,8 @@ static void duk__enc_objarr_exit(duk_json_enc_ctx *js_ctx, duk_hstring **h_stepb
/* restore stack top after unbalanced code paths */
duk_set_top(ctx, *entry_top);
DUK_DDDPRINT("shared entry finished: top=%d, loop=%!T",
duk_get_top(ctx), duk_get_tval(ctx, js_ctx->idx_loop));
DUK_DDD(DUK_DDDPRINT("shared entry finished: top=%d, loop=%!T",
duk_get_top(ctx), duk_get_tval(ctx, js_ctx->idx_loop)));
}
/* The JO(value) operation: encode object.
@ -1112,7 +1112,7 @@ static void duk__enc_object(duk_json_enc_ctx *js_ctx) {
int arr_len;
int i;
DUK_DDDPRINT("duk__enc_object: obj=%!T", duk_get_tval(ctx, -1));
DUK_DDD(DUK_DDDPRINT("duk__enc_object: obj=%!T", duk_get_tval(ctx, -1)));
duk__enc_objarr_entry(js_ctx, &h_stepback, &h_indent, &entry_top);
@ -1128,7 +1128,7 @@ static void duk__enc_object(duk_json_enc_ctx *js_ctx) {
/* leave stack unbalanced on purpose */
}
DUK_DDDPRINT("idx_keys=%d, h_keys=%!T", idx_keys, duk_get_tval(ctx, idx_keys));
DUK_DDD(DUK_DDDPRINT("idx_keys=%d, h_keys=%!T", idx_keys, duk_get_tval(ctx, idx_keys)));
/* Steps 8-10 have been merged to avoid a "partial" variable. */
@ -1145,8 +1145,8 @@ static void duk__enc_object(duk_json_enc_ctx *js_ctx) {
for (i = 0; i < arr_len; i++) {
duk_get_prop_index(ctx, idx_keys, i); /* -> [ ... key ] */
DUK_DDDPRINT("object property loop: holder=%!T, key=%!T",
duk_get_tval(ctx, idx_obj), duk_get_tval(ctx, -1));
DUK_DDD(DUK_DDDPRINT("object property loop: holder=%!T, key=%!T",
duk_get_tval(ctx, idx_obj), duk_get_tval(ctx, -1)));
undef = duk__enc_value1(js_ctx, idx_obj);
if (undef) {
@ -1216,7 +1216,7 @@ static void duk__enc_array(duk_json_enc_ctx *js_ctx) {
duk_uint_t i;
duk_uint_t arr_len;
DUK_DDDPRINT("duk__enc_array: array=%!T", duk_get_tval(ctx, -1));
DUK_DDD(DUK_DDDPRINT("duk__enc_array: array=%!T", duk_get_tval(ctx, -1)));
duk__enc_objarr_entry(js_ctx, &h_stepback, &h_indent, &entry_top);
@ -1228,8 +1228,8 @@ static void duk__enc_array(duk_json_enc_ctx *js_ctx) {
arr_len = duk_get_length(ctx, idx_arr);
for (i = 0; i < arr_len; i++) {
DUK_DDDPRINT("array entry loop: array=%!T, h_indent=%!O, h_stepback=%!O, index=%d, arr_len=%d",
duk_get_tval(ctx, idx_arr), h_indent, h_stepback, i, arr_len);
DUK_DDD(DUK_DDDPRINT("array entry loop: array=%!T, h_indent=%!O, h_stepback=%!O, index=%d, arr_len=%d",
duk_get_tval(ctx, idx_arr), h_indent, h_stepback, i, arr_len));
if (i > 0) {
DUK__EMIT_1(js_ctx, ',');
@ -1282,20 +1282,20 @@ static int duk__enc_value1(duk_json_enc_ctx *js_ctx, int idx_holder) {
duk_tval *tv;
int c;
DUK_DDDPRINT("duk__enc_value1: idx_holder=%d, holder=%!T, key=%!T",
idx_holder, duk_get_tval(ctx, idx_holder), duk_get_tval(ctx, -1));
DUK_DDD(DUK_DDDPRINT("duk__enc_value1: idx_holder=%d, holder=%!T, key=%!T",
idx_holder, duk_get_tval(ctx, idx_holder), duk_get_tval(ctx, -1)));
duk_dup_top(ctx); /* -> [ ... key key ] */
duk_get_prop(ctx, idx_holder); /* -> [ ... key val ] */
DUK_DDDPRINT("value=%!T", duk_get_tval(ctx, -1));
DUK_DDD(DUK_DDDPRINT("value=%!T", duk_get_tval(ctx, -1)));
h = duk_get_hobject(ctx, -1);
if (h != NULL) {
duk_get_prop_stridx(ctx, -1, DUK_STRIDX_TO_JSON);
h = duk_get_hobject(ctx, -1);
if (h != NULL && DUK_HOBJECT_IS_CALLABLE(h)) {
DUK_DDDPRINT("value is object, has callable toJSON() -> call it");
DUK_DDD(DUK_DDDPRINT("value is object, has callable toJSON() -> call it"));
duk_dup(ctx, -2); /* -> [ ... key val toJSON val ] */
duk_dup(ctx, -4); /* -> [ ... key val toJSON val key ] */
duk_call_method(ctx, 1); /* -> [ ... key val val' ] */

4
src/duk_bi_logger.c

@ -230,7 +230,7 @@ duk_ret_t duk_bi_logger_prototype_log_shared(duk_context *ctx) {
if (tot_len <= DUK_BI_LOGGER_SHORT_MSG_LIMIT) {
duk_hbuffer_dynamic *h_buf;
DUK_DPRINT("reuse existing small log message buffer, tot_len %d", (int) tot_len);
DUK_D(DUK_DPRINT("reuse existing small log message buffer, tot_len %d", (int) tot_len));
/* We can assert for all buffer properties because user code
* never has access to heap->log_buffer.
@ -251,7 +251,7 @@ duk_ret_t duk_bi_logger_prototype_log_shared(duk_context *ctx) {
duk_push_hbuffer(ctx, (duk_hbuffer *) h_buf);
buf = (duk_uint8_t *) DUK_HBUFFER_DYNAMIC_GET_CURR_DATA_PTR(h_buf);
} else {
DUK_DPRINT("use a one-off large log message buffer, tot_len %d", (int) tot_len);
DUK_D(DUK_DPRINT("use a one-off large log message buffer, tot_len %d", (int) tot_len));
buf = (duk_uint8_t *) duk_push_fixed_buffer(ctx, tot_len);
}
DUK_ASSERT(buf != NULL);

4
src/duk_regexp_compiler.c

@ -159,8 +159,8 @@ static duk_uint32_t duk__append_jump_offset(duk_re_compiler_ctx *re_ctx, duk_int
static void duk__generate_ranges(void *userdata, duk_codepoint_t r1, duk_codepoint_t r2, int direct) {
duk_re_compiler_ctx *re_ctx = (duk_re_compiler_ctx *) userdata;
DUK_DDPRINT("duk__generate_ranges(): re_ctx=%p, range=[%d,%d] direct=%d",
(void *) re_ctx, (int) r1, (int) r2, (int) direct);
DUK_DD(DUK_DDPRINT("duk__generate_ranges(): re_ctx=%p, range=[%d,%d] direct=%d",
(void *) re_ctx, (int) r1, (int) r2, (int) direct));
if (!direct && (re_ctx->re_flags & DUK_RE_FLAG_IGNORE_CASE)) {
/*

88
src/duk_regexp_executor.c

@ -156,12 +156,12 @@ static duk_uint8_t *duk__match_regexp(duk_re_matcher_ctx *re_ctx, duk_uint8_t *p
op = (duk_small_int_t) duk__bc_get_u32(re_ctx, &pc);
DUK_DDDPRINT("match: rec=%d, steps=%d, pc (after op)=%d, sp=%d, op=%d",
(int) re_ctx->recursion_depth,
(int) re_ctx->steps_count,
(int) (pc - re_ctx->bytecode),
(int) (sp - re_ctx->input),
(int) op);
DUK_DDD(DUK_DDDPRINT("match: rec=%d, steps=%d, pc (after op)=%d, sp=%d, op=%d",
(int) re_ctx->recursion_depth,
(int) re_ctx->steps_count,
(int) (pc - re_ctx->bytecode),
(int) (sp - re_ctx->input),
(int) op));
switch (op) {
case DUK_REOP_MATCH: {
@ -190,7 +190,7 @@ static duk_uint8_t *duk__match_regexp(duk_re_matcher_ctx *re_ctx, duk_uint8_t *p
goto fail;
}
c2 = duk__inp_get_cp(re_ctx, &sp);
DUK_DDDPRINT("char match, c1=%d, c2=%d", (int) c1, (int) c2);
DUK_DDD(DUK_DDDPRINT("char match, c1=%d, c2=%d", (int) c1, (int) c2));
if (c1 != c2) {
goto fail;
}
@ -226,8 +226,8 @@ static duk_uint8_t *duk__match_regexp(duk_re_matcher_ctx *re_ctx, duk_uint8_t *p
duk_codepoint_t r1, r2;
r1 = (duk_codepoint_t) duk__bc_get_u32(re_ctx, &pc);
r2 = (duk_codepoint_t) duk__bc_get_u32(re_ctx, &pc);
DUK_DDDPRINT("matching ranges/invranges, n=%d, r1=%d, r2=%d, c=%d",
(int) n, (int) r1, (int) r2, (int) c);
DUK_DDD(DUK_DDDPRINT("matching ranges/invranges, n=%d, r1=%d, r2=%d, c=%d",
(int) n, (int) r1, (int) r2, (int) c));
if (c >= r1 && c <= r2) {
/* Note: don't bail out early, we must read all the ranges from
* bytecode. Another option is to skip them efficiently after
@ -365,8 +365,8 @@ static duk_uint8_t *duk__match_regexp(duk_re_matcher_ctx *re_ctx, duk_uint8_t *p
qmin = duk__bc_get_u32(re_ctx, &pc);
qmax = duk__bc_get_u32(re_ctx, &pc);
skip = duk__bc_get_i32(re_ctx, &pc);
DUK_DDDPRINT("minimal quantifier, qmin=%u, qmax=%u, skip=%d",
(unsigned int) qmin, (unsigned int) qmax, (int) skip);
DUK_DDD(DUK_DDDPRINT("minimal quantifier, qmin=%u, qmax=%u, skip=%d",
(unsigned int) qmin, (unsigned int) qmax, (int) skip));
q = 0;
while (q <= qmax) {
@ -395,8 +395,8 @@ static duk_uint8_t *duk__match_regexp(duk_re_matcher_ctx *re_ctx, duk_uint8_t *p
qmax = duk__bc_get_u32(re_ctx, &pc);
atomlen = duk__bc_get_u32(re_ctx, &pc);
skip = duk__bc_get_i32(re_ctx, &pc);
DUK_DDDPRINT("greedy quantifier, qmin=%u, qmax=%u, atomlen=%u, skip=%d",
(unsigned int) qmin, (unsigned int) qmax, (unsigned int) atomlen, (int) skip);
DUK_DDD(DUK_DDDPRINT("greedy quantifier, qmin=%u, qmax=%u, atomlen=%u, skip=%d",
(unsigned int) qmin, (unsigned int) qmax, (unsigned int) atomlen, (int) skip));
q = 0;
while (q < qmax) {
@ -422,8 +422,8 @@ static duk_uint8_t *duk__match_regexp(duk_re_matcher_ctx *re_ctx, duk_uint8_t *p
* do not allow captures in their atom now, so this is not an issue.
*/
DUK_DDDPRINT("greedy quantifier, backtrack %d characters (atomlen)",
atomlen);
DUK_DDD(DUK_DDDPRINT("greedy quantifier, backtrack %d characters (atomlen)",
atomlen));
sp = duk__inp_backtrack(re_ctx, &sp, (duk_uint_fast32_t) atomlen);
q--;
}
@ -437,7 +437,7 @@ static duk_uint8_t *duk__match_regexp(duk_re_matcher_ctx *re_ctx, duk_uint8_t *p
idx = duk__bc_get_u32(re_ctx, &pc);
if (idx >= re_ctx->nsaved) {
/* idx is unsigned, < 0 check is not necessary */
DUK_DPRINT("internal error, regexp save index insane: idx=%d", (int) idx);
DUK_D(DUK_DPRINT("internal error, regexp save index insane: idx=%d", (int) idx));
goto internal_error;
}
old = re_ctx->saved[idx];
@ -468,14 +468,14 @@ static duk_uint8_t *duk__match_regexp(duk_re_matcher_ctx *re_ctx, duk_uint8_t *p
idx_start = duk__bc_get_u32(re_ctx, &pc);
idx_count = duk__bc_get_u32(re_ctx, &pc);
DUK_DDDPRINT("wipe saved range: start=%d, count=%d -> [%d,%d] (captures [%d,%d])",
idx_start, idx_count,
idx_start, idx_start + idx_count - 1,
idx_start / 2, (idx_start + idx_count - 1) / 2);
DUK_DDD(DUK_DDDPRINT("wipe saved range: start=%d, count=%d -> [%d,%d] (captures [%d,%d])",
idx_start, idx_count,
idx_start, idx_start + idx_count - 1,
idx_start / 2, (idx_start + idx_count - 1) / 2));
if (idx_start + idx_count > re_ctx->nsaved || idx_count == 0) {
/* idx is unsigned, < 0 check is not necessary */
DUK_DPRINT("internal error, regexp wipe indices insane: idx_start=%d, idx_count=%d",
(int) idx_start, (int) idx_count);
DUK_D(DUK_DPRINT("internal error, regexp wipe indices insane: idx_start=%d, idx_count=%d",
(int) idx_start, (int) idx_count));
goto internal_error;
}
DUK_ASSERT(idx_count > 0);
@ -497,18 +497,18 @@ static duk_uint8_t *duk__match_regexp(duk_re_matcher_ctx *re_ctx, duk_uint8_t *p
sub_sp = duk__match_regexp(re_ctx, pc, sp);
if (sub_sp) {
/* match: keep wiped/resaved values */
DUK_DDDPRINT("match: keep wiped/resaved values [%d,%d] (captures [%d,%d])",
(int) idx_start, (int) (idx_start + idx_count - 1),
idx_start / 2, (idx_start + idx_count - 1) / 2);
DUK_DDD(DUK_DDDPRINT("match: keep wiped/resaved values [%d,%d] (captures [%d,%d])",
(int) idx_start, (int) (idx_start + idx_count - 1),
idx_start / 2, (idx_start + idx_count - 1) / 2));
duk_pop((duk_context *) re_ctx->thr);
sp = sub_sp;
goto match;
}
/* fail: restore saves */
DUK_DDDPRINT("fail: restore wiped/resaved values [%d,%d] (captures [%d,%d])",
(int) idx_start, (int) (idx_start + idx_count - 1),
idx_start / 2, (idx_start + idx_count - 1) / 2);
DUK_DDD(DUK_DDDPRINT("fail: restore wiped/resaved values [%d,%d] (captures [%d,%d])",
(int) idx_start, (int) (idx_start + idx_count - 1),
idx_start / 2, (idx_start + idx_count - 1) / 2));
DUK_MEMCPY(re_ctx->saved + idx_start, range_save, sizeof(duk_uint8_t *) * idx_count);
duk_pop((duk_context *) re_ctx->thr);
goto fail;
@ -590,16 +590,16 @@ static duk_uint8_t *duk__match_regexp(duk_re_matcher_ctx *re_ctx, duk_uint8_t *p
idx = idx << 1; /* backref n -> saved indices [n*2, n*2+1] */
if (idx < 2 || idx + 1 >= re_ctx->nsaved) {
/* regexp compiler should catch these */
DUK_DPRINT("internal error, backreference index insane");
DUK_D(DUK_DPRINT("internal error, backreference index insane"));
goto internal_error;
}
if (!re_ctx->saved[idx] || !re_ctx->saved[idx+1]) {
/* capture is 'undefined', always matches! */
DUK_DDDPRINT("backreference: saved[%d,%d] not complete, always match",
idx, idx+1);
DUK_DDD(DUK_DDDPRINT("backreference: saved[%d,%d] not complete, always match",
idx, idx+1));
break;
}
DUK_DDDPRINT("backreference: match saved[%d,%d]", idx, idx+1);
DUK_DDD(DUK_DDDPRINT("backreference: match saved[%d,%d]", idx, idx+1));
p = re_ctx->saved[idx];
while (p < re_ctx->saved[idx+1]) {
@ -622,7 +622,7 @@ static duk_uint8_t *duk__match_regexp(duk_re_matcher_ctx *re_ctx, duk_uint8_t *p
break;
}
default: {
DUK_DPRINT("internal error, regexp opcode error: %d", op);
DUK_D(DUK_DPRINT("internal error, regexp opcode error: %d", op));
goto internal_error;
}
}
@ -670,7 +670,7 @@ static void duk__regexp_match_helper(duk_hthread *thr, duk_small_int_t force_glo
DUK_ASSERT(thr != NULL);
DUK_ASSERT(ctx != NULL);
DUK_DDPRINT("regexp match: regexp=%!T, input=%!T", duk_get_tval(ctx, -2), duk_get_tval(ctx, -1));
DUK_DD(DUK_DDPRINT("regexp match: regexp=%!T, input=%!T", duk_get_tval(ctx, -2), duk_get_tval(ctx, -1)));
/*
* Regexp instance check, bytecode check, input coercion.
@ -740,9 +740,9 @@ static void duk__regexp_match_helper(duk_hthread *thr, duk_small_int_t force_glo
}
#endif
DUK_DDDPRINT("regexp ctx initialized, flags=0x%08x, nsaved=%d, recursion_limit=%d, steps_limit=%d",
(unsigned int) re_ctx.re_flags, (int) re_ctx.nsaved, (int) re_ctx.recursion_limit,
(int) re_ctx.steps_limit);
DUK_DDD(DUK_DDDPRINT("regexp ctx initialized, flags=0x%08x, nsaved=%d, recursion_limit=%d, steps_limit=%d",
(unsigned int) re_ctx.re_flags, (int) re_ctx.nsaved, (int) re_ctx.recursion_limit,
(int) re_ctx.steps_limit));
/*
* Get starting character offset for match, and initialize 'sp' based on it.
@ -805,9 +805,9 @@ static void duk__regexp_match_helper(duk_hthread *thr, duk_small_int_t force_glo
/* Note: ctx.steps is intentionally not reset, it applies to the entire unanchored match */
DUK_ASSERT(re_ctx.recursion_depth == 0);
DUK_DDDPRINT("attempt match at char offset %d; %p [%p,%p]",
(int) char_offset, (void *) sp, (void *) re_ctx.input,
(void *) re_ctx.input_end);
DUK_DDD(DUK_DDDPRINT("attempt match at char offset %d; %p [%p,%p]",
(int) char_offset, (void *) sp, (void *) re_ctx.input,
(void *) re_ctx.input_end));
/*
* Note:
@ -829,7 +829,7 @@ static void duk__regexp_match_helper(duk_hthread *thr, duk_small_int_t force_glo
*/
if (duk__match_regexp(&re_ctx, re_ctx.bytecode, sp) != NULL) {
DUK_DDDPRINT("match at offset %d", (int) char_offset);
DUK_DDD(DUK_DDDPRINT("match at offset %d", (int) char_offset));
match = 1;
break;
}
@ -846,7 +846,7 @@ static void duk__regexp_match_helper(duk_hthread *thr, duk_small_int_t force_glo
* -> no need or use for a negative check
*/
DUK_DDDPRINT("no match after trying all sp offsets");
DUK_DDD(DUK_DDDPRINT("no match after trying all sp offsets"));
break;
}
@ -878,7 +878,7 @@ static void duk__regexp_match_helper(duk_hthread *thr, duk_small_int_t force_glo
#endif
duk_uint32_t char_end_offset = 0;
DUK_DDDPRINT("regexp matches at char_offset %d", (int) char_offset);
DUK_DDD(DUK_DDDPRINT("regexp matches at char_offset %d", (int) char_offset));
DUK_ASSERT(re_ctx.nsaved >= 2); /* must have start and end */
DUK_ASSERT((re_ctx.nsaved % 2) == 0); /* and even number */
@ -954,7 +954,7 @@ static void duk__regexp_match_helper(duk_hthread *thr, duk_small_int_t force_glo
* initially, it is reset to zero.
*/
DUK_DDDPRINT("regexp does not match");
DUK_DDD(DUK_DDDPRINT("regexp does not match"));
duk_push_null(ctx);

28
src/duk_unicode_support.c

@ -304,7 +304,7 @@ static duk_small_int_t duk__uni_range_match(const duk_uint8_t *unitab, duk_size_
/* [r1,r2] is the range */
DUK_DDDPRINT("duk__uni_range_match: cp=%06x range=[0x%06x,0x%06x]", (int) cp, (int) r1, (int) r2);
DUK_DDD(DUK_DDDPRINT("duk__uni_range_match: cp=%06x range=[0x%06x,0x%06x]", (int) cp, (int) r1, (int) r2));
if (cp >= r1 && cp <= r2) {
return 1;
}
@ -671,10 +671,10 @@ static duk_codepoint_t duk__slow_case_conversion(duk_hthread *thr,
duk_codepoint_t start_i;
duk_codepoint_t start_o;
DUK_DDDPRINT("slow case conversion for codepoint: %d", (int) cp);
DUK_DDD(DUK_DDDPRINT("slow case conversion for codepoint: %d", (int) cp));
/* range conversion with a "skip" */
DUK_DDDPRINT("checking ranges");
DUK_DDD(DUK_DDDPRINT("checking ranges"));
for (;;) {
skip++;
n = (duk_small_int_t) duk_bd_decode(bd_ctx, 6);
@ -682,20 +682,20 @@ static duk_codepoint_t duk__slow_case_conversion(duk_hthread *thr,
/* end marker */
break;
}
DUK_DDDPRINT("skip=%d, n=%d", (int) skip, (int) n);
DUK_DDD(DUK_DDDPRINT("skip=%d, n=%d", (int) skip, (int) n));
while (n--) {
start_i = (duk_codepoint_t) duk_bd_decode(bd_ctx, 16);
start_o = (duk_codepoint_t) duk_bd_decode(bd_ctx, 16);
count = (duk_small_int_t) duk_bd_decode(bd_ctx, 7);
DUK_DDDPRINT("range: start_i=%d, start_o=%d, count=%d, skip=%d",
(int) start_i, (int) start_o, (int) count, (int) skip);
DUK_DDD(DUK_DDDPRINT("range: start_i=%d, start_o=%d, count=%d, skip=%d",
(int) start_i, (int) start_o, (int) count, (int) skip));
if (cp >= start_i) {
tmp_cp = cp - start_i; /* always >= 0 */
if (tmp_cp < (duk_codepoint_t) count * (duk_codepoint_t) skip &&
(tmp_cp % (duk_codepoint_t) skip) == 0) {
DUK_DDDPRINT("range matches input codepoint");
DUK_DDD(DUK_DDDPRINT("range matches input codepoint"));
cp = start_o + tmp_cp;
goto single;
}
@ -705,13 +705,13 @@ static duk_codepoint_t duk__slow_case_conversion(duk_hthread *thr,
/* 1:1 conversion */
n = (duk_small_int_t) duk_bd_decode(bd_ctx, 6);
DUK_DDDPRINT("checking 1:1 conversions (count %d)", (int) n);
DUK_DDD(DUK_DDDPRINT("checking 1:1 conversions (count %d)", (int) n));
while (n--) {
start_i = (duk_codepoint_t) duk_bd_decode(bd_ctx, 16);
start_o = (duk_codepoint_t) duk_bd_decode(bd_ctx, 16);
DUK_DDDPRINT("1:1 conversion %d -> %d", (int) start_i, (int) start_o);
DUK_DDD(DUK_DDDPRINT("1:1 conversion %d -> %d", (int) start_i, (int) start_o));
if (cp == start_i) {
DUK_DDDPRINT("1:1 matches input codepoint");
DUK_DDD(DUK_DDDPRINT("1:1 matches input codepoint"));
cp = start_o;
goto single;
}
@ -719,13 +719,13 @@ static duk_codepoint_t duk__slow_case_conversion(duk_hthread *thr,
/* complex, multicharacter conversion */
n = (duk_small_int_t) duk_bd_decode(bd_ctx, 7);
DUK_DDDPRINT("checking 1:n conversions (count %d)", n);
DUK_DDD(DUK_DDDPRINT("checking 1:n conversions (count %d)", n));
while (n--) {
start_i = (duk_codepoint_t) duk_bd_decode(bd_ctx, 16);
t = (duk_small_int_t) duk_bd_decode(bd_ctx, 2);
DUK_DDDPRINT("1:n conversion %d -> %d chars", (int) start_i, (int) t);
DUK_DDD(DUK_DDDPRINT("1:n conversion %d -> %d chars", (int) start_i, (int) t));
if (cp == start_i) {
DUK_DDDPRINT("1:n matches input codepoint");
DUK_DDD(DUK_DDDPRINT("1:n matches input codepoint"));
if (buf) {
while (t--) {
tmp_cp = (duk_codepoint_t) duk_bd_decode(bd_ctx, 16);
@ -742,7 +742,7 @@ static duk_codepoint_t duk__slow_case_conversion(duk_hthread *thr,
}
/* default: no change */
DUK_DDDPRINT("no rule matches, output is same as input");
DUK_DDD(DUK_DDDPRINT("no rule matches, output is same as input"));
/* fall through */
single:

8
src/duk_util_bitdecoder.c

@ -20,7 +20,7 @@ duk_int32_t duk_bd_decode(duk_bitdecoder_ctx *ctx, duk_small_int_t bits) {
while (ctx->currbits < bits) {
#if 0
DUK_DDDPRINT("decode_bits: shift more data (bits=%d, currbits=%d)", bits, ctx->currbits);
DUK_DDD(DUK_DDDPRINT("decode_bits: shift more data (bits=%d, currbits=%d)", bits, ctx->currbits));
#endif
ctx->currval <<= 8;
if (ctx->offset < ctx->length) {
@ -32,7 +32,7 @@ duk_int32_t duk_bd_decode(duk_bitdecoder_ctx *ctx, duk_small_int_t bits) {
ctx->currbits += 8;
}
#if 0
DUK_DDDPRINT("decode_bits: bits=%d, currbits=%d, currval=0x%08x", bits, ctx->currbits, ctx->currval);
DUK_DDD(DUK_DDDPRINT("decode_bits: bits=%d, currbits=%d, currval=0x%08x", bits, ctx->currbits, ctx->currval));
#endif
/* Extract 'top' bits of currval; note that the extracted bits do not need
@ -44,8 +44,8 @@ duk_int32_t duk_bd_decode(duk_bitdecoder_ctx *ctx, duk_small_int_t bits) {
ctx->currbits = shift; /* remaining */
#if 0
DUK_DDDPRINT("decode_bits: %d bits -> 0x%08x (%d), currbits=%d, currval=0x%08x",
bits, tmp, tmp, ctx->currbits, ctx->currval);
DUK_DDD(DUK_DDDPRINT("decode_bits: %d bits -> 0x%08x (%d), currbits=%d, currval=0x%08x",
bits, tmp, tmp, ctx->currbits, ctx->currval));
#endif
return tmp;

2
src/duk_util_hashprime.c

@ -60,7 +60,7 @@ duk_uint32_t duk_util_get_hash_prime(duk_uint32_t size) {
/* correction */
curr += t;
DUK_DDDPRINT("size=%d, curr=%d", size, curr);
DUK_DDD(DUK_DDDPRINT("size=%d, curr=%d", size, curr));
if (curr >= size) {
return curr;

Loading…
Cancel
Save