summaryrefslogtreecommitdiff
path: root/py/dynruntime.h
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2023-08-25 15:43:50 +1000
committerJim Mussared <jim.mussared@gmail.com>2023-09-01 16:14:22 +1000
commita64f2fdca09eb00fa4a6c0e96cd783f3ee772e57 (patch)
tree57bfaca2f620835d3c1d849dd52482ab6b19ff65 /py/dynruntime.h
parent4837ec336a8047a1707534315f6b4b8aeac3f891 (diff)
py/dynruntime.h: Implement MP_OBJ_NEW_QSTR.
Because mpy_ld.py doesn't know the target object representation, it emits instances of `MP_OBJ_NEW_QSTR(MP_QSTR_Foo)` as const string objects, rather than qstrs. However this doesn't work for map keys (e.g. for a locals dict) because the map has all_keys_are_qstrs flag is set (and also auto-complete requires the map keys to be qstrs). Instead, emit them as regular qstrs, and make a functioning MP_OBJ_NEW_QSTR function available (via `native_to_obj`, also used for e.g. making integers). Remove the code from mpy_ld.py to emit qstrs as constant strings, but leave behind the scaffold to emit constant objects in case we want to do use this in the future. Strictly this should be a .mpy sub-version bump, even though the function table isn't changing, it does lead to a change in behavior for a new .mpy running against old MicroPython. `mp_native_to_obj` will incorrectly return the qstr value directly as an `mp_obj_t`, leading to unexpected results. But given that it's broken at the moment, it seems unlikely that anyone is relying on this, so it's not work the other downsides of a sub-version bump (i.e. breaking pure-Python modules that use @native). The opposite case of running an old .mpy on new MicroPython is unchanged, and remains broken in exactly the same way. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'py/dynruntime.h')
-rw-r--r--py/dynruntime.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/py/dynruntime.h b/py/dynruntime.h
index 8564715c0..90c401ab4 100644
--- a/py/dynruntime.h
+++ b/py/dynruntime.h
@@ -79,7 +79,7 @@ static inline void *m_realloc_dyn(void *ptr, size_t new_num_bytes) {
/******************************************************************************/
// Types and objects
-#define MP_OBJ_NEW_QSTR(x) MP_OBJ_NEW_QSTR_##x
+#define MP_OBJ_NEW_QSTR(x) (mp_fun_table.native_to_obj(x, MP_NATIVE_TYPE_QSTR))
#define mp_type_type (*mp_fun_table.type_type)
#define mp_type_NoneType (*mp_obj_get_type(mp_const_none))