Browse Source

Miscellaneous code cleanups

* Comment cleanups

* String hash declaration fix when dense hash not used

* -Wcast-qual fix for debug fixedbuffer

- Debugger is_err macro argument renaming and re-typing
pull/437/head
Sami Vaarala 9 years ago
parent
commit
03edf0dba7
  1. 8
      src/duk_bi_global.c
  2. 2
      src/duk_debug.h
  3. 6
      src/duk_debug_fixedbuffer.c
  4. 21
      src/duk_debugger.c
  5. 2
      src/duk_util.h

8
src/duk_bi_global.c

@ -450,14 +450,14 @@ DUK_INTERNAL duk_ret_t duk_bi_global_object_eval(duk_context *ctx) {
}
#if defined(DUK_USE_DEBUGGER_SUPPORT)
/* NOTE: level is used only by the debugger and should never be present
* for an Ecmascript eval().
/* NOTE: level is used only by the debugger and should never be present
* for an Ecmascript eval().
*/
level = -2; /* by default, use caller's environment */
DUK_ASSERT(level == -2); /* by default, use caller's environment */
if (duk_get_top(ctx) >= 2 && duk_is_number(ctx, 1)) {
level = duk_get_int(ctx, 1);
}
DUK_ASSERT(level <= -2);
DUK_ASSERT(level <= -2); /* This is guaranteed by debugger code. */
#endif
/* [ source ] */

2
src/duk_debug.h

@ -173,7 +173,7 @@ DUK_INTERNAL_DECL duk_small_int_t duk_debug_level_stash;
DUK_INTERNAL_DECL void duk_debug_log(const char *fmt, ...);
#endif /* DUK_USE_VARIADIC_MACROS */
DUK_INTERNAL_DECL void duk_fb_put_bytes(duk_fixedbuffer *fb, duk_uint8_t *buffer, duk_size_t length);
DUK_INTERNAL_DECL void duk_fb_put_bytes(duk_fixedbuffer *fb, const duk_uint8_t *buffer, duk_size_t length);
DUK_INTERNAL_DECL void duk_fb_put_byte(duk_fixedbuffer *fb, duk_uint8_t x);
DUK_INTERNAL_DECL void duk_fb_put_cstring(duk_fixedbuffer *fb, const char *x);
DUK_INTERNAL_DECL void duk_fb_sprintf(duk_fixedbuffer *fb, const char *fmt, ...);

6
src/duk_debug_fixedbuffer.c

@ -7,7 +7,7 @@
#ifdef DUK_USE_DEBUG
DUK_INTERNAL void duk_fb_put_bytes(duk_fixedbuffer *fb, duk_uint8_t *buffer, duk_size_t length) {
DUK_INTERNAL void duk_fb_put_bytes(duk_fixedbuffer *fb, const duk_uint8_t *buffer, duk_size_t length) {
duk_size_t avail;
duk_size_t copylen;
@ -23,11 +23,11 @@ DUK_INTERNAL void duk_fb_put_bytes(duk_fixedbuffer *fb, duk_uint8_t *buffer, duk
}
DUK_INTERNAL void duk_fb_put_byte(duk_fixedbuffer *fb, duk_uint8_t x) {
duk_fb_put_bytes(fb, &x, 1);
duk_fb_put_bytes(fb, (const duk_uint8_t *) &x, 1);
}
DUK_INTERNAL void duk_fb_put_cstring(duk_fixedbuffer *fb, const char *x) {
duk_fb_put_bytes(fb, (duk_uint8_t *) x, (duk_size_t) DUK_STRLEN(x));
duk_fb_put_bytes(fb, (const duk_uint8_t *) x, (duk_size_t) DUK_STRLEN(x));
}
DUK_INTERNAL void duk_fb_sprintf(duk_fixedbuffer *fb, const char *fmt, ...) {

21
src/duk_debugger.c

@ -23,12 +23,12 @@ typedef union {
* Detach handling
*/
#define DUK__SET_CONN_BROKEN(thr, is_err) do { \
#define DUK__SET_CONN_BROKEN(thr,reason) do { \
/* For now shared handler is fine. */ \
duk__debug_do_detach1((thr)->heap, (is_err)); \
duk__debug_do_detach1((thr)->heap, (reason)); \
} while (0)
DUK_LOCAL void duk__debug_do_detach1(duk_heap *heap, duk_bool_t is_err) {
DUK_LOCAL void duk__debug_do_detach1(duk_heap *heap, duk_int_t reason) {
/* Can be called multiple times with no harm. Mark the transport
* bad (dbg_read_cb == NULL) and clear state except for the detached
* callback and the udata field. The detached callback is delayed
@ -43,9 +43,8 @@ DUK_LOCAL void duk__debug_do_detach1(duk_heap *heap, duk_bool_t is_err) {
DUK_D(DUK_DPRINT("debugger transport detaching, marking transport broken"));
heap->dbg_detaching = 1;
heap->dbg_detaching = 1; /* prevent multiple in-progress detaches */
/* avoid sending multiple Detaching notifys */
if (heap->dbg_write_cb != NULL) {
duk_hthread *thr;
@ -53,7 +52,7 @@ DUK_LOCAL void duk__debug_do_detach1(duk_heap *heap, duk_bool_t is_err) {
DUK_ASSERT(thr != NULL);
duk_debug_write_notify(thr, DUK_DBG_CMD_DETACHING);
duk_debug_write_int(thr, is_err);
duk_debug_write_int(thr, reason);
duk_debug_write_eom(thr);
}
@ -1370,11 +1369,11 @@ DUK_LOCAL void duk__debug_handle_eval(duk_hthread *thr, duk_heap *heap) {
DUK_D(DUK_DPRINT("debug command Eval"));
/* The eval code is executed within the lexical environment of a specified
* activation. For now, use global object eval() function, with the eval
* activation. For now, use global object eval() function, with the eval
* considered a 'direct call to eval'.
*
* Callstack level for debug commands only affects scope--the callstack as
* seen by, e.g. Duktape.act() will be the same regardless.
* Callstack level for debug commands only affects scope -- the callstack
* as seen by, e.g. Duktape.act() will be the same regardless.
*/
/* nargs == 2 so we can pass a callstack level to eval(). */
@ -1384,7 +1383,7 @@ DUK_LOCAL void duk__debug_handle_eval(duk_hthread *thr, duk_heap *heap) {
(void) duk_debug_read_hstring(thr);
if (duk_debug_peek_byte(thr) != DUK_DBG_MARKER_EOM) {
level = duk_debug_read_int(thr); /* optional callstack level */
if (level >= 0 || -level > (duk_int32_t)thr->callstack_top) {
if (level >= 0 || -level > (duk_int32_t) thr->callstack_top) {
DUK_D(DUK_DPRINT("invalid callstack level for Eval"));
duk_debug_write_error_eom(thr, DUK_DBG_ERR_NOTFOUND, "invalid callstack level");
return;
@ -1409,7 +1408,7 @@ DUK_LOCAL void duk__debug_handle_eval(duk_hthread *thr, duk_heap *heap) {
/* Direct eval requires that there's a current
* activation and it is an Ecmascript function.
* When Eval is executed from e.g. cooperate API
* call we'll need to an indirect eval instead.
* call we'll need to do an indirect eval instead.
*/
call_flags |= DUK_CALL_FLAG_DIRECT_EVAL;
}

2
src/duk_util.h

@ -475,7 +475,9 @@ DUK_INTERNAL_DECL duk_uint8_t duk_util_probe_steps[32];
#endif /* !DUK_SINGLE_FILE */
#endif
#if defined(DUK_USE_STRHASH_DENSE)
DUK_INTERNAL_DECL duk_uint32_t duk_util_hashbytes(const duk_uint8_t *data, duk_size_t len, duk_uint32_t seed);
#endif
#if defined(DUK_USE_HOBJECT_HASH_PART) || defined(DUK_USE_STRTAB_PROBE)
DUK_INTERNAL_DECL duk_uint32_t duk_util_get_hash_prime(duk_uint32_t size);

Loading…
Cancel
Save