summaryrefslogtreecommitdiff
path: root/py/builtin.h
diff options
context:
space:
mode:
authorLaurens Valk <laurens@pybricks.com>2022-08-19 16:40:28 +0200
committerDamien George <damien@micropython.org>2022-08-23 13:34:06 +1000
commitd8ad87843ab38dcc74e7e86354849fff585e1ba8 (patch)
tree81906ccc6b70ea3c32aa07fc51ce6a3ce979ebe8 /py/builtin.h
parent3d65101a8a55550bdbaa4df4e216edba238fa299 (diff)
py/builtinimport: Allow overriding of mp_builtin___import__.
This allows ports to override mp_builtin___import__. This can be useful in MicroPython applications where MICROPY_ENABLE_EXTERNAL_IMPORT has to be disabled due to its impact on build size (2% to 2.5% of the minimal port). By overriding the otherwise very minimal mp_builtin___import__, ports can still allow limited forms of application-specific imports. Signed-off-by: Laurens Valk <laurens@pybricks.com>
Diffstat (limited to 'py/builtin.h')
-rw-r--r--py/builtin.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/py/builtin.h b/py/builtin.h
index fb1162784..7232142b7 100644
--- a/py/builtin.h
+++ b/py/builtin.h
@@ -64,7 +64,13 @@ MP_DECLARE_CONST_FUN_OBJ_KW(mp_builtin_open_obj);
#endif
+// A port can provide its own import handler by defining mp_builtin___import__.
+#ifndef mp_builtin___import__
+#define mp_builtin___import__ mp_builtin___import___default
+#endif
mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args);
+mp_obj_t mp_builtin___import___default(size_t n_args, const mp_obj_t *args);
+
mp_obj_t mp_micropython_mem_info(size_t n_args, const mp_obj_t *args);
MP_DECLARE_CONST_FUN_OBJ_VAR(mp_builtin___build_class___obj);