Browse Source

wrap setjmp, longjmp, abort, exit, fputc

pull/2/head
Sami Vaarala 11 years ago
parent
commit
88f2f74324
  1. 2
      src/duk_api.c
  2. 6
      src/duk_bi_logger.c
  3. 2
      src/duk_error_longjmp.c
  4. 6
      src/duk_error_macros.c
  5. 13
      src/duk_features.h
  6. 4
      src/duk_js_call.c
  7. 2
      src/duk_js_executor.c

2
src/duk_api.c

@ -2666,7 +2666,7 @@ const char *duk_push_vsprintf(duk_context *ctx, const char *fmt, va_list ap) {
buf = duk_push_dynamic_buffer(ctx, sz);
for(;;) {
for (;;) {
len = duk__try_push_vsprintf(ctx, buf, sz, fmt, ap);
if (len >= 0) {
break;

6
src/duk_bi_logger.c

@ -103,9 +103,9 @@ duk_ret_t duk_bi_logger_prototype_raw(duk_context *ctx) {
#ifdef DUK_USE_FILE_IO
data = (const char *) duk_require_buffer(ctx, 0, &data_len);
fwrite((const void *) data, 1, data_len, stderr);
fputc((int) '\n', stderr);
fflush(stderr);
DUK_FWRITE((const void *) data, 1, data_len, stderr);
DUK_FPUTC((int) '\n', stderr);
DUK_FFLUSH(stderr);
#else
/* nop */
#endif

2
src/duk_error_longjmp.c

@ -19,7 +19,7 @@ void duk_err_longjmp(duk_hthread *thr) {
DUK_UNREACHABLE();
}
longjmp(thr->heap->lj.jmpbuf_ptr->jb, DUK_LONGJMP_DUMMY_VALUE);
DUK_LONGJMP(thr->heap->lj.jmpbuf_ptr->jb, DUK_LONGJMP_DUMMY_VALUE);
DUK_UNREACHABLE();
}

6
src/duk_error_macros.c

@ -106,13 +106,13 @@ void duk_default_panic_handler(int code, const char *msg) {
#endif
#if defined(DUK_USE_PANIC_ABORT)
abort();
DUK_ABORT();
#elif defined(DUK_USE_PANIC_EXIT)
exit(-1);
DUK_EXIT(-1);
#elif defined(DUK_USE_PANIC_SEGFAULT)
/* exit() afterwards to satisfy "noreturn" */
DUK_CAUSE_SEGFAULT();
exit(-1);
DUK_EXIT(-1);
#else
#error no DUK_USE_PANIC_xxx macro defined
#endif

13
src/duk_features.h

@ -1308,8 +1308,19 @@ typedef FILE duk_file;
#define DUK_FSEEK fseek
#define DUK_FTELL ftell
#define DUK_FFLUSH fflush
#define DUK_FPUTC fputc
#define DUK_MEMZERO(p,n) DUK_MEMSET((p), 0, (n))
#define DUK_MEMZERO(p,n) \
DUK_MEMSET((p), 0, (n))
/*
* Miscellaneous ANSI C or other platform wrappers.
*/
#define DUK_ABORT abort
#define DUK_EXIT exit
#define DUK_SETJMP setjmp
#define DUK_LONGJMP longjmp
/*
* Macro hackery to convert e.g. __LINE__ to a string without formatting,

4
src/duk_js_call.c

@ -730,7 +730,7 @@ int duk_handle_call(duk_hthread *thr,
old_jmpbuf_ptr = thr->heap->lj.jmpbuf_ptr;
thr->heap->lj.jmpbuf_ptr = &our_jmpbuf;
if (setjmp(thr->heap->lj.jmpbuf_ptr->jb) == 0) {
if (DUK_SETJMP(thr->heap->lj.jmpbuf_ptr->jb) == 0) {
DUK_DDDPRINT("setjmp catchpoint setup complete");
goto handle_call;
}
@ -1507,7 +1507,7 @@ int duk_handle_safe_call(duk_hthread *thr,
old_jmpbuf_ptr = thr->heap->lj.jmpbuf_ptr;
thr->heap->lj.jmpbuf_ptr = &our_jmpbuf;
if (setjmp(thr->heap->lj.jmpbuf_ptr->jb) == 0) {
if (DUK_SETJMP(thr->heap->lj.jmpbuf_ptr->jb) == 0) {
goto handle_call;
}

2
src/duk_js_executor.c

@ -1450,7 +1450,7 @@ void duk_js_execute_bytecode(duk_hthread *entry_thread) {
thr->heap->lj.jmpbuf_ptr = &jmpbuf;
DUK_ASSERT(thr->heap->lj.jmpbuf_ptr != NULL);
if (setjmp(thr->heap->lj.jmpbuf_ptr->jb)) {
if (DUK_SETJMP(thr->heap->lj.jmpbuf_ptr->jb)) {
/*
* Note: any local variables accessed here must have their value
* assigned *before* the setjmp() call, OR they must be declared

Loading…
Cancel
Save