aboutsummaryrefslogtreecommitdiff
path: root/py/objmodule.h
AgeCommit message (Collapse)Author
2022-03-10py/objmodule: Support delegating failed attr lookups.Damien George
This commit adds generic support for mutable module attributes on built in modules, by adding support for an optional hook function for module attribute lookup. If a module wants to support additional attribute load/ store/delete (beyond what is in the constant, globals dict) then it should add at the very end of its globals dict MP_MODULE_ATTR_DELEGATION_ENTRY(). This should point to a custom function which will handle any additional attributes. The mp_module_generic_attr() function is provided as a helper function for additional attributes: it requires an array of qstrs (terminated in MP_QSTRnull) and a corresponding array of objects (with a 1-1 mapping between qstrs and objects). If the qstr is found in the array then the corresponding object is loaded/stored/deleted. Signed-off-by: Damien George <damien@micropython.org>
2021-12-01py/builtinimport: Refactor module importing.Jim Mussared
Simplify and document/comment the handling of builtin import for: - already-loaded modules - built-in modules - built-in umodules (formerly weak links) - filesystem modules Retains existing functionality with smaller code size but should also facilitate potential new features (built-in packages, controlling the frozen path). Also makes the (unix-only) -m behavior a bit more obvious and configurable. Code size change with this commit: bare-arm: +0 +0.000% minimal x86: -64 -0.039% unix x64: -32 -0.006% unix nanbox: -4 -0.001% stm32: -184 -0.047% PYBV10 cc3200: -120 -0.065% esp8266: -228 -0.033% GENERIC esp32: -268 -0.018% GENERIC[incl +16(data)] nrf: -152 -0.087% pca10040 rp2: -256 -0.052% PICO samd: -80 -0.057% ADAFRUIT_ITSYBITSY_M4_EXPRESS
2020-02-11py/objmodule.h: Remove obsolete mp_builtin_module_weak_links_map decl.Damien George
It was made obsolete in d2384efa809953152c57cbda4c339dfbaa64cf29
2019-10-22py: Automatically provide weak links from "foo" to "ufoo" module name.Damien George
This commit implements automatic module weak links for all built-in modules, by searching for "ufoo" in the built-in module list if "foo" cannot be found. This means that all modules named "ufoo" are always available as "foo". Also, a port can no longer add any other weak links, which makes strict the definition of a weak link. It saves some code size (about 100-200 bytes) on ports that previously had lots of weak links. Some changes from the previous behaviour: - It doesn't intern the non-u module names (eg "foo" is not interned), which saves code size, but will mean that "import foo" creates a new qstr (namely "foo") in RAM (unless the importing module is frozen). - help('modules') no longer lists non-u module names, only the u-variants; this reduces duplication in the help listing. Weak links are effectively the same as having a set of symbolic links on the filesystem that is searched last. So an "import foo" will search built-in modules first, then all paths in sys.path, then weak links last, importing "ufoo" if it exists. Thus a file called "foo.py" somewhere in sys.path will still have precedence over the weak link of "foo" to "ufoo". See issues: #1740, #4449, #5229, #5241.
2018-02-20py/objmodule: Factor common code for calling __init__ on builtin module.Damien George
2017-07-31all: Use the name MicroPython consistently in commentsAlexander Steffen
There were several different spellings of MicroPython present in comments, when there should be only one.
2017-07-18all: Unify header guard usage.Alexander Steffen
The code conventions suggest using header guards, but do not define how those should look like and instead point to existing files. However, not all existing files follow the same scheme, sometimes omitting header guards altogether, sometimes using non-standard names, making it easy to accidentally pick a "wrong" example. This commit ensures that all header files of the MicroPython project (that were not simply copied from somewhere else) follow the same pattern, that was already present in the majority of files, especially in the py folder. The rules are as follows. Naming convention: * start with the words MICROPY_INCLUDED * contain the full path to the file * replace special characters with _ In addition, there are no empty lines before #ifndef, between #ifndef and one empty line before #endif. #endif is followed by a comment containing the name of the guard macro. py/grammar.h cannot use header guards by design, since it has to be included multiple times in a single C file. Several other files also do not need header guards as they are only used internally and guaranteed to be included only once: * MICROPY_MPHALPORT_H * mpconfigboard.h * mpconfigport.h * mpthreadport.h * pin_defs_*.h * qstrdefs*.h
2017-01-26py/objmodule: Move module init/deinit code into runtime functions.Damien George
They are one-line functions and having them inline in mp_init/mp_deinit eliminates the overhead of a function call, and matches how other state is initialised in mp_init.
2017-01-22py: Move weak-link map to objmodule.c, and expose module maps as public.Damien George
2015-01-01py: Move to guarded includes, everywhere in py/ core.Damien George
Addresses issue #1022.
2014-05-03Add license header to (almost) all files.Damien George
Blanket wide to all .c and .h files. Some files originating from ST are difficult to deal with (license wise) so it was left out of those. Also merged modpyb.h, modos.h, modstm.h and modtime.h in stmhal/.
2014-03-25Proper support for registering builtin modules in ROM.Damien George
Comes with some refactoring of code and renaming of files. All modules are now named mod*.[ch].