From 4238379552a87efafe0cfc9c059222095ff16a6d Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Wed, 18 Dec 2019 12:11:18 -0500 Subject: [PATCH] Use _setjmp/_longjmp on BSDs. This doesn't save the signal mask so should be a bit faster. --- src/core/asm.c | 18 +++++++++++++++--- src/core/capi.c | 4 ++++ src/core/vm.c | 4 ++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/core/asm.c b/src/core/asm.c index 3b8c59d7..9247ff8b 100644 --- a/src/core/asm.c +++ b/src/core/asm.c @@ -173,17 +173,25 @@ static void janet_asm_deinit(JanetAssembler *a) { janet_table_deinit(&a->defs); } +static void janet_asm_longjmp(JanetAssembler *a) { +#if defined(JANET_BSD) || defined(JANET_APPLE) + _longjmp(a->on_error, 1); +#else + longjmp(a->on_error, 1); +#endif +} + /* Throw some kind of assembly error */ static void janet_asm_error(JanetAssembler *a, const char *message) { a->errmessage = janet_formatc("%s, instruction %d", message, a->errindex); - longjmp(a->on_error, 1); + janet_asm_longjmp(a); } #define janet_asm_assert(a, c, m) do { if (!(c)) janet_asm_error((a), (m)); } while (0) /* Throw some kind of assembly error */ static void janet_asm_errorv(JanetAssembler *a, const uint8_t *m) { a->errmessage = m; - longjmp(a->on_error, 1); + janet_asm_longjmp(a); } /* Add a closure environment to the assembler. Sub funcdefs may need @@ -501,10 +509,14 @@ static JanetAssembleResult janet_asm1(JanetAssembler *parent, Janet source, int janet_table_init(&a.defs, 0); /* Set error jump */ +#if defined(JANET_BSD) || defined(JANET_APPLE) + if (_setjmp(a.on_error)) { +#else if (setjmp(a.on_error)) { +#endif if (NULL != a.parent) { janet_asm_deinit(&a); - longjmp(a.parent->on_error, 1); + janet_asm_longjmp(a.parent); } result.funcdef = NULL; result.error = a.errmessage; diff --git a/src/core/capi.c b/src/core/capi.c index b5a8d8e8..066d29fb 100644 --- a/src/core/capi.c +++ b/src/core/capi.c @@ -29,7 +29,11 @@ void janet_panicv(Janet message) { if (janet_vm_return_reg != NULL) { *janet_vm_return_reg = message; +#if defined(JANET_BSD) || defined(JANET_APPLE) + _longjmp(*janet_vm_jmp_buf, 1); +#else longjmp(*janet_vm_jmp_buf, 1); +#endif } else { fputs((const char *)janet_formatc("janet top level panic - %v\n", message), stdout); exit(1); diff --git a/src/core/vm.c b/src/core/vm.c index 4fd94a55..4f5bd24d 100644 --- a/src/core/vm.c +++ b/src/core/vm.c @@ -1153,7 +1153,11 @@ JanetSignal janet_continue(JanetFiber *fiber, Janet in, Janet *out) { /* Run loop */ JanetSignal signal; +#if defined(JANET_BSD) || defined(JANET_APPLE) + if (_setjmp(buf)) { +#else if (setjmp(buf)) { +#endif signal = JANET_SIGNAL_ERROR; } else { signal = run_vm(fiber, in, old_status);