Thanks to visit codestin.com
Credit goes to github.com

Skip to content

top: Replace MICROPY_PORT_BUILTIN_MODULES with MP_REGISTER_MODULE. #8566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
May 19, 2022

Conversation

jimmo
Copy link
Member

@jimmo jimmo commented Apr 20, 2022

No need to have two different ways of registering modules. Simplifies mpconfigport.h and makes it consistent across all ways of defining modules (built-in, extmod, port, board, user-c-module).

It might be good to extend makemodulesdefs.py to also handle module constants (and maybe root pointers?) in the future.

print(
(
"#if ({enabled_define})\n"
" extern const struct _mp_obj_module_t {obj_module};\n"
" #undef {mod_def}\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that if two or more modules with the same name are enabled, then the last one (according to sorted()) "wins"?

@dlech
Copy link
Contributor

dlech commented Apr 22, 2022

Not a big deal, but is seems like in the vast majority of the cases, the 3rd parameter is 1 or could be 1, so perhaps we should just drop this parameter?

@dpgeorge
Copy link
Member

Not a big deal, but is seems like in the vast majority of the cases, the 3rd parameter is 1 or could be 1, so perhaps we should just drop this parameter?

You mean the #if config option to enable the module? That is definitely needed so that ports can selectively enable the modules (if the 3rd param was 1 then all modules would always be enabled on all builds).

@dlech
Copy link
Contributor

dlech commented Apr 22, 2022

OK, maybe I misunderstood how the code generator works.

@jimmo
Copy link
Member Author

jimmo commented Apr 22, 2022

You mean the #if config option to enable the module? That is definitely needed so that ports can selectively enable the modules (if the 3rd param was 1 then all modules would always be enabled on all builds).

In most cases the MP_REGISTER_MODULE(..., ..., X) is already inside an #if X, so it could well be just 1. I followed the existing pattern from modarray.c.

I could try and come up with a varargs macro that makes that last parameter optional (default to 1).

@dlech
Copy link
Contributor

dlech commented Apr 22, 2022

I could try and come up with a varargs macro that makes that last parameter optional (default to 1).

There are probably better ways to spend your time. 😉

In most cases the MP_REGISTER_MODULE(..., ..., X) is already inside an #if X, so it could well be just 1. I followed the existing pattern from modarray.c.

This is why I thought we could just eliminate the parameter altogether. But if there are a few special cases where this doesn't work and can't be worked around by adding a #if then we need the 3rd parameter.

@dpgeorge dpgeorge added the py-core Relates to py/ directory in source label Apr 29, 2022
@dpgeorge
Copy link
Member

Note that MP_REGISTER_MODULE() is not scanned if the file it is in is #include'd. Eg defining a custom board that has a file board.c that has:

#include "common_board_files/modfoo.c`
...

And then modfoo.c uses MP_REGISTER_MODULE(foo), this will not be picked up. At the moment the way around this issue is to add another MP_REGISTER_MODULE(foo) in board.c (in this example).

@jimmo jimmo force-pushed the module-register branch from 894af03 to 3afd625 Compare May 13, 2022 06:30
@jimmo
Copy link
Member Author

jimmo commented May 13, 2022

I've rebased this and updated the renesas-ra port to use it.

Note that MP_REGISTER_MODULE() is not scanned if the file it is in is #include'd.

*blinks*

...I guess that's a good argument for making makemoduledefs.py run on the qstr pre-processed code (like error compression does). I think that's a good idea anyway, and it lets us solve the third-argument problem that was discussed above. I will do that in a follow-up PR.

jimmo added 16 commits May 18, 2022 20:49
For example, ussl can come from axtls or mbedtls. If neither are enabled
then don't try and set an empty definition twice, and only include it
once in MICROPY_REGISTERED_MODULES.

Signed-off-by: Jim Mussared <[email protected]>
_onewire, socket, and network were previously added by the port rather
than objmodule.c.

Signed-off-by: Jim Mussared <[email protected]>
jimmo added 3 commits May 18, 2022 20:57
This functionality is now replaced with MP_REGISTER_MODULE.

Signed-off-by: Jim Mussared <[email protected]>
@jimmo jimmo force-pushed the module-register branch from 3afd625 to 8b201dc Compare May 18, 2022 10:58
@dpgeorge dpgeorge merged commit 8b201dc into micropython:master May 19, 2022
@dpgeorge
Copy link
Member

Thanks for updating, now merged.

@robert-hh
Copy link
Contributor

robert-hh commented May 20, 2022

@jimmo As consequence of this and the previous related change, ports which use lwip do not have a usocket module any more registered, causing some tests and uasyncio/stream.py to fail.
See also #8681

@jimmo
Copy link
Member Author

jimmo commented May 20, 2022

@jimmo As consequence of this and the previous related change, ports which use lwip do not have a usocket module any more registered, causing some tests and uasyncio/stream.py to fail.

@robert-hh Thanks. I will take a look ASAP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
py-core Relates to py/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants