diff --git a/lib/exec.c b/lib/exec.c index 4899663..d550181 100644 --- a/lib/exec.c +++ b/lib/exec.c @@ -1200,12 +1200,9 @@ static int execute (hcl_t* hcl) hcl->proc_switched = 0; #endif - if (HCL_UNLIKELY(hcl->ip >= hcl->code.bc.len) || HCL_UNLIKELY(hcl->abort_req)) + if (HCL_UNLIKELY(hcl->ip >= hcl->code.bc.len)) { - if (hcl->abort_req) - HCL_DEBUG0 (hcl, "Stopping execution for abortion request\n"); - else - HCL_DEBUG1 (hcl, "Stopping executeion as IP reached the end of bytecode(%zu)\n", hcl->code.bc.len); + HCL_DEBUG1 (hcl, "Stopping executeion as IP reached the end of bytecode(%zu)\n", hcl->code.bc.len); return_value = hcl->_nil; goto handle_return; } @@ -1217,6 +1214,15 @@ static int execute (hcl_t* hcl) /*while (bcode == HCL_CODE_NOOP) FETCH_BYTE_CODE_TO (hcl, bcode);*/ if (hcl->vm_checkpoint_cb_count) vm_checkpoint (hcl); + + if (HCL_UNLIKELY(hcl->abort_req)) + { + /* place the abortion check after vm_checkpoint + * to honor hcl_abort() if called in the callback, */ + HCL_DEBUG0 (hcl, "Stopping execution for abortion request\n"); + return_value = hcl->_nil; + goto handle_return; + } #if defined(HCL_PROFILE_VM) inst_counter++; diff --git a/lib/hcl.c b/lib/hcl.c index 787def0..7ff45b0 100644 --- a/lib/hcl.c +++ b/lib/hcl.c @@ -416,6 +416,10 @@ hcl_cb_t* hcl_regcb (hcl_t* hcl, hcl_cb_t* tmpl) actual->prev = HCL_NULL; hcl->cblist = actual; + /* vm_checkpoint is invoked very frequently. + * and there might be multiple vm_checkpoint callbacks registered. + * keeping the count of vm_checkpoint callbacks registered + * speeds up the check */ if (actual->vm_checkpoint) hcl->vm_checkpoint_cb_count++; return actual;