diff options
| author | Damien George <damien@micropython.org> | 2022-05-31 22:56:11 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2022-06-02 16:31:37 +1000 |
| commit | efe23aca7154d21a9e8f283313c7a1ac29e05d86 (patch) | |
| tree | 385afed48501b70d94ac3869901ad6fd809201f8 /docs/develop | |
| parent | 47f634300c5572571816817f16836113c98814ae (diff) | |
all: Remove third argument to MP_REGISTER_MODULE.
It's no longer needed because this macro is now processed after
preprocessing the source code via cpp (in the qstr extraction stage), which
means unused MP_REGISTER_MODULE's are filtered out by the preprocessor.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'docs/develop')
| -rw-r--r-- | docs/develop/cmodules.rst | 12 | ||||
| -rw-r--r-- | docs/develop/library.rst | 2 | ||||
| -rw-r--r-- | docs/develop/porting.rst | 7 |
3 files changed, 9 insertions, 12 deletions
diff --git a/docs/develop/cmodules.rst b/docs/develop/cmodules.rst index 38225e868..143057f7f 100644 --- a/docs/develop/cmodules.rst +++ b/docs/develop/cmodules.rst @@ -221,23 +221,25 @@ as described above. If a module is not enabled by default then the corresponding C preprocessor macro must be enabled. This macro name can be found by searching for the ``MP_REGISTER_MODULE`` line in the module's source code (it usually appears at the end of the main source file). -The third argument to ``MP_REGISTER_MODULE`` is the macro name, and this must be set -to 1 using ``CFLAGS_EXTRA`` to make the module available. If the third argument is just -the number 1 then the module is enabled by default. +This macro should be surrounded by a ``#if X`` / ``#endif`` pair, and the configuration +option ``X`` must be set to 1 using ``CFLAGS_EXTRA`` to make the module available. If +there is no ``#if X`` / ``#endif`` pair then the module is enabled by default. For example, the ``examples/usercmodule/cexample`` module is enabled by default so has the following line in its source code: .. code-block:: c - MP_REGISTER_MODULE(MP_QSTR_cexample, example_user_cmodule, 1); + MP_REGISTER_MODULE(MP_QSTR_cexample, example_user_cmodule); Alternatively, to make this module disabled by default but selectable through a preprocessor configuration option, it would be: .. code-block:: c - MP_REGISTER_MODULE(MP_QSTR_cexample, example_user_cmodule, MODULE_CEXAMPLE_ENABLED); + #if MODULE_CEXAMPLE_ENABLED + MP_REGISTER_MODULE(MP_QSTR_cexample, example_user_cmodule); + #endif In this case the module is enabled by adding ``CFLAGS_EXTRA=-DMODULE_CEXAMPLE_ENABLED=1`` to the ``make`` command, or editing ``mpconfigport.h`` or ``mpconfigboard.h`` to add diff --git a/docs/develop/library.rst b/docs/develop/library.rst index 47ea2dc8d..c2a86ea16 100644 --- a/docs/develop/library.rst +++ b/docs/develop/library.rst @@ -64,7 +64,7 @@ hypothetical new module ``subsystem`` in the file ``modsubsystem.c``: .globals = (mp_obj_dict_t *)&mp_module_subsystem_globals, }; - MP_REGISTER_MODULE(MP_QSTR_subsystem, mp_module_subsystem, MICROPY_PY_SUBSYSTEM); + MP_REGISTER_MODULE(MP_QSTR_subsystem, mp_module_subsystem); #endif diff --git a/docs/develop/porting.rst b/docs/develop/porting.rst index d08fd74e4..bc25f47ed 100644 --- a/docs/develop/porting.rst +++ b/docs/develop/porting.rst @@ -280,12 +280,7 @@ To add a custom module like ``myport``, first add the module definition in a fil .globals = (mp_obj_dict_t *)&myport_module_globals, }; - MP_REGISTER_MODULE(MP_QSTR_myport, myport_module, 1); - -Note: the "1" as the third argument in ``MP_REGISTER_MODULE`` enables this new module -unconditionally. To allow it to be conditionally enabled, replace the "1" by -``MICROPY_PY_MYPORT`` and then add ``#define MICROPY_PY_MYPORT (1)`` in ``mpconfigport.h`` -accordingly. + MP_REGISTER_MODULE(MP_QSTR_myport, myport_module); You will also need to edit the Makefile to add ``modmyport.c`` to the ``SRC_C`` list, and a new line adding the same file to ``SRC_QSTR`` (so qstrs are searched for in this new file), |
