From 6dce8f749db3dad3aaba650fe32d6872e98cf470 Mon Sep 17 00:00:00 2001 From: Wang Renxin Date: Sun, 7 May 2017 14:13:09 +0800 Subject: [PATCH] *fixed a wrong context processing bug when evaluating a routine manually, thanks to Diederik for pointing it out. --- HISTORY | 3 +++ core/my_basic.c | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/HISTORY b/HISTORY index d9bd96c..0253cf7 100755 --- a/HISTORY +++ b/HISTORY @@ -1,3 +1,6 @@ +May. 7 2017 +Fixed a wrong context processing bug when evaluating a routine manually, thanks to Diederik for pointing it out + May. 6 2017 Added a tobe returned parameter to the mb_eval_routine function diff --git a/core/my_basic.c b/core/my_basic.c index 4ac66d5..567b7cc 100755 --- a/core/my_basic.c +++ b/core/my_basic.c @@ -12936,7 +12936,9 @@ _exit: /* Evaluate a sub routine */ int mb_eval_routine(struct mb_interpreter_t* s, void** l, mb_value_t val, mb_value_t* args, unsigned argc, mb_value_t* ret) { int result = MB_FUNC_OK; + _running_context_t* running = 0; _object_t obj; + _ls_node_t* ast = 0; if(!s || !l) { result = MB_FUNC_ERR; @@ -12944,16 +12946,18 @@ int mb_eval_routine(struct mb_interpreter_t* s, void** l, mb_value_t val, mb_val goto _exit; } + running = s->running_context; + if(val.type != MB_DT_ROUTINE) { _handle_error_on_obj(s, SE_RN_ROUTINE_EXPECTED, s->source_file, DON2(l), MB_FUNC_ERR, _exit, result); } _MAKE_NIL(&obj); _public_value_to_internal_object(&val, &obj); - result = _eval_routine(s, (_ls_node_t**)l, args, argc, obj.data.routine, _has_routine_fun_arg, _pop_routine_fun_arg); + ast = (_ls_node_t*)(*l); + result = _eval_routine(s, &ast, args, argc, obj.data.routine, _has_routine_fun_arg, _pop_routine_fun_arg); if(ret) { - _running_context_t* running = s->running_context; _assign_public_value(ret, &running->intermediate_value); _MAKE_NIL(&obj); _public_value_to_internal_object(ret, &obj);