Skip to content

Commit 7e4a2b0

Browse files
committed
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).
1 parent aabd83e commit 7e4a2b0

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

py/emitglue.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ mp_obj_t mp_make_function_from_raw_code(mp_raw_code_t *rc, mp_obj_t def_args, mp
120120
assert(def_args == MP_OBJ_NULL || MP_OBJ_IS_TYPE(def_args, &mp_type_tuple));
121121

122122
// TODO implement default kw args
123-
assert(def_kw_args == MP_OBJ_NULL);
123+
if (def_kw_args != MP_OBJ_NULL) {
124+
mp_not_implemented("Default values for kw-only args");
125+
}
124126

125127
// make the function, depending on the raw code kind
126128
mp_obj_t fun;

py/runtime.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,10 @@ void *m_malloc_fail(int num_bytes) {
11501150
nlr_raise((mp_obj_t)&mp_const_MemoryError_obj);
11511151
}
11521152

1153+
NORETURN void mp_not_implemented(const char *msg) {
1154+
nlr_raise(mp_obj_new_exception_msg(&mp_type_NotImplementedError, msg));
1155+
}
1156+
11531157
// these must correspond to the respective enum
11541158
void *const mp_fun_table[MP_F_NUMBER_OF] = {
11551159
mp_load_const_int,

py/runtime.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ mp_obj_t mp_import_name(qstr name, mp_obj_t fromlist, mp_obj_t level);
112112
mp_obj_t mp_import_from(mp_obj_t module, qstr name);
113113
void mp_import_all(mp_obj_t module);
114114

115+
// Raise NotImplementedError with given message
116+
NORETURN void mp_not_implemented(const char *msg);
117+
115118
extern struct _mp_obj_list_t mp_sys_path_obj;
116119
extern struct _mp_obj_list_t mp_sys_argv_obj;
117120
#define mp_sys_path ((mp_obj_t)&mp_sys_path_obj)

0 commit comments

Comments
 (0)