From 87ba67f42d36ca001298644c2e4f2f3a26d5c40b Mon Sep 17 00:00:00 2001 From: Masamitsu MURASE Date: Mon, 13 Aug 2012 01:49:50 +0900 Subject: Modify exception handling. If an exception is raised before cipush is called in mrb_run, it should be handled in the outer mrb_run. --- src/vm.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/vm.c b/src/vm.c index ac6dc9f1a..fa5a52d1f 100644 --- a/src/vm.c +++ b/src/vm.c @@ -20,6 +20,7 @@ #include #include #include +#include #define STACK_INIT_SIZE 128 #define CALLINFO_INIT_SIZE 32 @@ -402,6 +403,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) int ai = mrb->arena_idx; jmp_buf *prev_jmp = (jmp_buf *)mrb->jmp; jmp_buf c_jmp; + ptrdiff_t ciidx = mrb->ci - mrb->cibase; #ifdef DIRECT_THREADED static void *optable[] = { @@ -1028,6 +1030,10 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) ci = mrb->ci; eidx = mrb->ci->eidx; if (ci == mrb->cibase) goto L_STOP; + if (ciidx == ci - mrb->cibase){ + mrb->jmp = prev_jmp; + longjmp(*(jmp_buf*)mrb->jmp, 1); + } while (ci[0].ridx == ci[-1].ridx) { cipop(mrb); ci = mrb->ci; -- cgit v1.2.3 From 686b6eb629d1694b620d9e36b7329efd7754b8c3 Mon Sep 17 00:00:00 2001 From: Masamitsu MURASE Date: Mon, 13 Aug 2012 01:57:00 +0900 Subject: Add more test for exception. --- test/t/exception.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/t/exception.rb b/test/t/exception.rb index 0aed0e2e6..2ea319caa 100644 --- a/test/t/exception.rb +++ b/test/t/exception.rb @@ -253,3 +253,19 @@ assert('Exception 13') do end a == :ok end + +def exception_test14 + UnknownConstant +end + +assert('Exception 14') do + a = :ng + begin + send(:exception_test14) + rescue + a = :ok + end + + a == :ok +end + -- cgit v1.2.3