Skip to content

Commit bb3bdda

Browse files
tomlogicdpgeorge
authored andcommitted
py/builtinevex: Add typechecking of globals/locals args to eval/exec.
1 parent 6c1b7e0 commit bb3bdda

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

py/builtinevex.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,15 @@ STATIC mp_obj_t eval_exec_helper(size_t n_args, const mp_obj_t *args, mp_parse_i
113113
// work out the context
114114
mp_obj_dict_t *globals = mp_globals_get();
115115
mp_obj_dict_t *locals = mp_locals_get();
116-
if (n_args > 1) {
117-
globals = MP_OBJ_TO_PTR(args[1]);
118-
if (n_args > 2) {
119-
locals = MP_OBJ_TO_PTR(args[2]);
120-
} else {
121-
locals = globals;
116+
for (size_t i = 1; i < 3 && i < n_args; ++i) {
117+
if (args[i] != mp_const_none) {
118+
if (!MP_OBJ_IS_TYPE(args[i], &mp_type_dict)) {
119+
mp_raise_TypeError(NULL);
120+
}
121+
locals = MP_OBJ_TO_PTR(args[i]);
122+
if (i == 1) {
123+
globals = locals;
124+
}
122125
}
123126
}
124127

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy