diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-06-07 23:22:41 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-06-07 23:26:27 +0300 |
commit | 7e4a2b0edca2953ae3dd19f9ad554739a9174c81 (patch) | |
tree | c5a0a0faa0000789edc76dc411ca2914b80d8877 /py | |
parent | aabd83ea204325cdf45355a5bdc6838745484060 (diff) | |
download | micropython-7e4a2b0edca2953ae3dd19f9ad554739a9174c81.tar.gz micropython-7e4a2b0edca2953ae3dd19f9ad554739a9174c81.zip |
py: Add generic mp_not_implemented() func to use instead of assert().
Benefits: won't crash baremetal targets, will provide Python source location
when not implemented feature used (it will no longer provide C source
location, but just grep for error message).
Diffstat (limited to 'py')
-rw-r--r-- | py/emitglue.c | 4 | ||||
-rw-r--r-- | py/runtime.c | 4 | ||||
-rw-r--r-- | py/runtime.h | 3 |
3 files changed, 10 insertions, 1 deletions
diff --git a/py/emitglue.c b/py/emitglue.c index a89ef6766a..732e4b5500 100644 --- a/py/emitglue.c +++ b/py/emitglue.c @@ -120,7 +120,9 @@ mp_obj_t mp_make_function_from_raw_code(mp_raw_code_t *rc, mp_obj_t def_args, mp assert(def_args == MP_OBJ_NULL || MP_OBJ_IS_TYPE(def_args, &mp_type_tuple)); // TODO implement default kw args - assert(def_kw_args == MP_OBJ_NULL); + if (def_kw_args != MP_OBJ_NULL) { + mp_not_implemented("Default values for kw-only args"); + } // make the function, depending on the raw code kind mp_obj_t fun; diff --git a/py/runtime.c b/py/runtime.c index cdbf99d4a5..179b48d327 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -1150,6 +1150,10 @@ void *m_malloc_fail(int num_bytes) { nlr_raise((mp_obj_t)&mp_const_MemoryError_obj); } +NORETURN void mp_not_implemented(const char *msg) { + nlr_raise(mp_obj_new_exception_msg(&mp_type_NotImplementedError, msg)); +} + // these must correspond to the respective enum void *const mp_fun_table[MP_F_NUMBER_OF] = { mp_load_const_int, diff --git a/py/runtime.h b/py/runtime.h index dbd413180b..fb61c01dd1 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -112,6 +112,9 @@ mp_obj_t mp_import_name(qstr name, mp_obj_t fromlist, mp_obj_t level); mp_obj_t mp_import_from(mp_obj_t module, qstr name); void mp_import_all(mp_obj_t module); +// Raise NotImplementedError with given message +NORETURN void mp_not_implemented(const char *msg); + extern struct _mp_obj_list_t mp_sys_path_obj; extern struct _mp_obj_list_t mp_sys_argv_obj; #define mp_sys_path ((mp_obj_t)&mp_sys_path_obj) |