diff options
-rw-r--r-- | examples/exception-handler.c | 2 | ||||
-rw-r--r-- | lib/ubus.c | 2 | ||||
-rw-r--r-- | vm.c | 21 |
3 files changed, 19 insertions, 6 deletions
diff --git a/examples/exception-handler.c b/examples/exception-handler.c index 1e722ec..a9a0299 100644 --- a/examples/exception-handler.c +++ b/examples/exception-handler.c @@ -30,7 +30,7 @@ static const char *program = MULTILINE_STRING( doesnotexist(); } - fail(); + map([1], x => fail(x)); %} ); @@ -102,7 +102,7 @@ uc_blob_to_json(uc_vm_t *vm, struct blob_attr *attr, bool table, const char **na return ucv_int64_new((int32_t)be32_to_cpu(*(uint32_t *)data)); case BLOBMSG_TYPE_INT64: - return ucv_uint64_new(be64_to_cpu(*(uint64_t *)data)); + return ucv_int64_new((int64_t)be64_to_cpu(*(uint64_t *)data)); case BLOBMSG_TYPE_DOUBLE: ; @@ -733,6 +733,18 @@ uc_vm_exception_new(uc_vm_t *vm, uc_exception_type_t type, const char *message, return exo; } +static void +uc_vm_clear_exception(uc_vm_t *vm) +{ + vm->exception.type = EXCEPTION_NONE; + + ucv_put(vm->exception.stacktrace); + vm->exception.stacktrace = NULL; + + free(vm->exception.message); + vm->exception.message = NULL; +} + static bool uc_vm_handle_exception(uc_vm_t *vm) { @@ -767,10 +779,7 @@ uc_vm_handle_exception(uc_vm_t *vm) uc_vm_stack_push(vm, exo); /* reset exception information */ - free(vm->exception.message); - - vm->exception.type = EXCEPTION_NONE; - vm->exception.message = NULL; + uc_vm_clear_exception(vm); /* jump to exception handler */ if (chunk->ehranges.entries[i].target >= chunk->count) { @@ -2301,6 +2310,8 @@ uc_vm_execute_chunk(uc_vm_t *vm) while (!uc_vm_handle_exception(vm)) { /* no further callframe to pop, report unhandled exception and terminate */ if (vm->callframes.count <= 1) { + uc_vm_reset_callframes(vm); + if (vm->exhandler) vm->exhandler(vm, &vm->exception); @@ -2390,6 +2401,8 @@ uc_vm_call(uc_vm_t *vm, bool mcall, size_t nargs) uc_value_t *ctx = mcall ? ucv_get(uc_vm_stack_peek(vm, nargs + 1)) : NULL; uc_value_t *fno = ucv_get(uc_vm_stack_peek(vm, nargs)); + uc_vm_clear_exception(vm); + if (uc_vm_call_function(vm, ctx, fno, mcall, nargs & 0xffff)) { if (ucv_type(fno) != UC_CFUNCTION) uc_vm_execute_chunk(vm); |