diff options
author | Tom Collins <tom.collins@digi.com> | 2017-07-11 15:27:42 -0700 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-07-21 15:16:51 +1000 |
commit | bb3bddabb53e00965f9becba6df6af99c6c9bc77 (patch) | |
tree | fa99803a2f5e9ed7fb39aacc50024a509631a36a /py/builtinevex.c | |
parent | 6c1b7e008d48799c2324e8fa44acd9af365e62e2 (diff) |
py/builtinevex: Add typechecking of globals/locals args to eval/exec.
Diffstat (limited to 'py/builtinevex.c')
-rw-r--r-- | py/builtinevex.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/py/builtinevex.c b/py/builtinevex.c index d9a3833cc..4390d0cc7 100644 --- a/py/builtinevex.c +++ b/py/builtinevex.c @@ -113,12 +113,15 @@ STATIC mp_obj_t eval_exec_helper(size_t n_args, const mp_obj_t *args, mp_parse_i // work out the context mp_obj_dict_t *globals = mp_globals_get(); mp_obj_dict_t *locals = mp_locals_get(); - if (n_args > 1) { - globals = MP_OBJ_TO_PTR(args[1]); - if (n_args > 2) { - locals = MP_OBJ_TO_PTR(args[2]); - } else { - locals = globals; + for (size_t i = 1; i < 3 && i < n_args; ++i) { + if (args[i] != mp_const_none) { + if (!MP_OBJ_IS_TYPE(args[i], &mp_type_dict)) { + mp_raise_TypeError(NULL); + } + locals = MP_OBJ_TO_PTR(args[i]); + if (i == 1) { + globals = locals; + } } } |