Commit Graph

14 Commits

Author SHA1 Message Date
Damien George 5ce1a03a78 py/makemoduledefs.py: Automatically declare delegation attr functions.
So that the delegation functions don't need to be put somewhere global,
like in mpconfigport.h.  That would otherwise make it hard for extension
modules to use delegation.

Signed-off-by: Damien George <damien@micropython.org>
2023-06-14 19:03:46 +10:00
Damien George 44295c9daa py/makemoduledefs.py: Fix declaring multiple module delegations.
Signed-off-by: Damien George <damien@micropython.org>
2023-06-14 19:03:29 +10:00
Jim Mussared e6926d6021 py/objmodule: Workaround for MSVC with no module delegation.
When compiling mpy-cross, there is no `sys` module, and so there will
be no entries in the `mp_builtin_module_delegation_table`.

MSVC doesn't like this, so instead pretend as if the feature isn't
enabled at all.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:24 +10:00
Jim Mussared 13c817e61c py/objmodule: Add a table of built-in modules with delegation.
This replaces the previous QSTR_null entry in the globals dict which could
leak out to Python (e.g. via iteration of mod.__dict__) and could lead to
crashes.

It results in smaller code size at the expense of turning a lookup into a
loop, but the list it is looping over likely only contains one or two
elements.

To allow a module to register its custom attr function it can use the new
`MP_REGISTER_MODULE_DELEGATION` macro.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:24 +10:00
Jim Mussared 24c02c4eb5 py/makemoduledefs.py: Add a way to register extensible built-in modules.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:21 +10:00
Phil Howard 37d5114cec py/makemoduledefs.py: Emit useful error for legacy MP_REGISTER_MODULE.
Catch calls to legacy:

MP_REGISTER_MODULE(name, module, enable)

Emit a friendly error suggesting they be rewritten to:

MP_REGISTER_MODULE(name, module).

Signed-off-by: Phil Howard <phil@pimoroni.com>
2022-06-14 15:05:37 +01:00
Damien George c7271a86ca py/makemoduledefs.py: Remove shebang line and adjust style of comment.
This file is not executable so shouldn't have the shebang line.  This line
can cause issues when building on Windows msvc when the PyPython variable
is set to something other than "python", because it reverts back to using
the shebang line.

The top comment is also changed to """ style which matches all other
preprocessing scripts in the py/ directory.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-08 15:00:59 +10:00
Damien George efe23aca71 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>
2022-06-02 16:31:37 +10:00
Damien George 47f634300c py: Change makemoduledefs process so it uses output of qstr extraction.
This cleans up the parsing of MP_REGISTER_MODULE() and generation of
genhdr/moduledefs.h so that it uses the same process as compressed error
string messages, using the output of qstr extraction.

This makes sure all MP_REGISTER_MODULE()'s that are part of the build are
correctly picked up.  Previously the extraction would miss some (eg if you
had a mod.c file in the board directory for an stm32 board).

Build speed is more or less unchanged.

Thanks to @stinos for the ports/windows/msvc/genhdr.targets changes.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-02 16:29:53 +10:00
Jim Mussared 469450171f py/makemoduledefs.py: Allow multiple ways to register a module.
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 <jim.mussared@gmail.com>
2022-05-18 20:49:12 +10:00
Damien George 06659077a8 all: Update Python code to conform to latest black formatting.
Updating to Black v20.8b1 there are two changes that affect the code in
this repository:

- If there is a trailing comma in a list (eg [], () or function call) then
  that list is now written out with one line per element.  So remove such
  trailing commas where the list should stay on one line.

- Spaces at the start of """ doc strings are removed.

Signed-off-by: Damien George <damien@micropython.org>
2020-08-29 15:18:01 +10:00
Damien George 69661f3343 all: Reformat C and Python source code with tools/codeformat.py.
This is run with uncrustify 0.70.1, and black 19.10b0.
2020-02-28 10:33:03 +11:00
Damien George 673e154dfe py/makedefs: Use io.open with utf-8 encoding when processing source.
In case (user) source code contains utf-8 encoded data and the default
locale is not utf-8.

See #4592.
2019-04-12 11:34:52 +10:00
Andrew Leech cf22f4793c py: Allow registration of modules at their definition.
During make, makemoduledefs.py parses the current builds c files for
MP_REGISTER_MODULE(module_name, obj_module, enabled_define)

These are used to generate a header with the required entries for
"mp_rom_map_elem_t mp_builtin_module_table[]" in py/objmodule.c
2019-03-08 22:46:43 +11:00