Merge pull request #5430 from microDev1/patch

Convert all modules to use `MP_REGISTER_MODULE`
This commit is contained in:
microDev 2021-10-07 09:44:11 +05:30 committed by GitHub
commit a3aeefd92c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 45 additions and 97 deletions

View File

@ -235,3 +235,5 @@ const mp_obj_module_t mp_module_ubinascii = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&mp_module_binascii_globals,
};
MP_REGISTER_MODULE(MP_QSTR_binascii, mp_module_ubinascii, MICROPY_PY_UBINASCII);

View File

@ -375,4 +375,6 @@ const mp_obj_module_t mp_module_ujson = {
.globals = (mp_obj_dict_t *)&mp_module_ujson_globals,
};
MP_REGISTER_MODULE(MP_QSTR_json, mp_module_ujson, MICROPY_PY_UJSON);
#endif // MICROPY_PY_UJSON

View File

@ -469,6 +469,8 @@ const mp_obj_module_t mp_module_ure = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&mp_module_re_globals,
};
MP_REGISTER_MODULE(MP_QSTR_re, mp_module_ure, MICROPY_PY_URE);
#endif
// Source files #include'd here to make sure they're compiled in

View File

@ -57,3 +57,5 @@ const mp_obj_module_t samd_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&samd_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_samd, samd_module, CIRCUITPY_SAMD);

View File

@ -208,3 +208,5 @@ void raise_esp_error(esp_err_t err) {
}
mp_raise_msg_varg(exception_type, translate("%s error 0x%x"), group, err);
}
MP_REGISTER_MODULE(MP_QSTR_espidf, espidf_module, CIRCUITPY_ESPIDF);

View File

@ -58,3 +58,5 @@ const mp_obj_module_t rp2pio_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&rp2pio_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_rp2pio, rp2pio_module, CIRCUITPY_RP2PIO);

View File

@ -244,26 +244,16 @@ typedef long mp_off_t;
// These CIRCUITPY_xxx values should all be defined in the *.mk files as being on or off.
// So if any are not defined in *.mk, they'll throw an error here.
#if CIRCUITPY_BINASCII
#define MICROPY_PY_UBINASCII CIRCUITPY_BINASCII
#define BINASCII_MODULE { MP_ROM_QSTR(MP_QSTR_binascii), MP_ROM_PTR(&mp_module_ubinascii) },
#else
#define BINASCII_MODULE
#endif
#if CIRCUITPY_BOARD
#define BOARD_I2C (defined(DEFAULT_I2C_BUS_SDA) && defined(DEFAULT_I2C_BUS_SCL))
#define BOARD_SPI (defined(DEFAULT_SPI_BUS_SCK) && defined(DEFAULT_SPI_BUS_MISO) && defined(DEFAULT_SPI_BUS_MOSI))
#define BOARD_UART (defined(DEFAULT_UART_BUS_RX) && defined(DEFAULT_UART_BUS_TX))
// I2C and SPI are always allocated off the heap.
#if BOARD_UART
#define BOARD_UART_ROOT_POINTER mp_obj_t shared_uart_bus;
#else
#define BOARD_UART_ROOT_POINTER
#endif
#else
#define BOARD_UART_ROOT_POINTER
#endif
@ -276,23 +266,6 @@ typedef long mp_off_t;
#define CIRCUITPY_DISPLAY_LIMIT (0)
#endif
#if CIRCUITPY_ERRNO
#define MICROPY_PY_UERRNO (1)
// Uses about 80 bytes.
#define MICROPY_PY_UERRNO_ERRORCODE (1)
#define ERRNO_MODULE { MP_ROM_QSTR(MP_QSTR_errno), MP_ROM_PTR(&mp_module_uerrno) },
#else
#define ERRNO_MODULE
#
#endif
#if CIRCUITPY_ESPIDF
extern const struct _mp_obj_module_t espidf_module;
#define ESPIDF_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_espidf),(mp_obj_t)&espidf_module },
#else
#define ESPIDF_MODULE
#endif
#if CIRCUITPY_GAMEPADSHIFT
// Scan gamepad every 32ms
#define CIRCUITPY_GAMEPAD_TICKS 0x1f
@ -301,18 +274,6 @@ extern const struct _mp_obj_module_t espidf_module;
#define GAMEPAD_ROOT_POINTERS
#endif
#if CIRCUITPY_JSON
#define MICROPY_PY_UJSON (1)
#define MICROPY_PY_IO (1)
#define JSON_MODULE { MP_ROM_QSTR(MP_QSTR_json), MP_ROM_PTR(&mp_module_ujson) },
#else
#ifndef MICROPY_PY_IO
// We don't need MICROPY_PY_IO unless someone else wants it.
#define MICROPY_PY_IO (0)
#endif
#define JSON_MODULE
#endif
#if CIRCUITPY_KEYPAD
#define KEYPAD_ROOT_POINTERS mp_obj_t keypad_scanners_linked_list;
#else
@ -331,83 +292,51 @@ extern const struct _mp_obj_module_t espidf_module;
extern const struct _mp_obj_module_t nvm_module;
#endif
#if CIRCUITPY_OS
extern const struct _mp_obj_module_t os_module;
#define OS_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_os), (mp_obj_t)&os_module },
#define OS_MODULE_ALT_NAME { MP_OBJ_NEW_QSTR(MP_QSTR__os), (mp_obj_t)&os_module },
// Following modules are implemented in either extmod or py directory.
#define MICROPY_PY_UBINASCII CIRCUITPY_BINASCII
#define MICROPY_PY_UERRNO CIRCUITPY_ERRNO
// Uses about 80 bytes.
#define MICROPY_PY_UERRNO_ERRORCODE CIRCUITPY_ERRNO
#define MICROPY_PY_URE CIRCUITPY_RE
#if CIRCUITPY_JSON
#define MICROPY_PY_UJSON (1)
#define MICROPY_PY_IO (1)
#else
#define OS_MODULE
#define OS_MODULE_ALT_NAME
#ifndef MICROPY_PY_IO
// We don't need MICROPY_PY_IO unless someone else wants it.
#define MICROPY_PY_IO (0)
#endif
#endif
#if CIRCUITPY_RE
#define MICROPY_PY_URE (1)
#define RE_MODULE { MP_ROM_QSTR(MP_QSTR_re), MP_ROM_PTR(&mp_module_ure) },
#else
#define RE_MODULE
#endif
#if CIRCUITPY_RP2PIO
extern const struct _mp_obj_module_t rp2pio_module;
#define RP2PIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_rp2pio),(mp_obj_t)&rp2pio_module },
#else
#define RP2PIO_MODULE
#endif
#if CIRCUITPY_SAMD
extern const struct _mp_obj_module_t samd_module;
#define SAMD_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_samd),(mp_obj_t)&samd_module },
#else
#define SAMD_MODULE
#endif
#if CIRCUITPY_TIME
extern const struct _mp_obj_module_t time_module;
#define TIME_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_module },
#define TIME_MODULE_ALT_NAME { MP_OBJ_NEW_QSTR(MP_QSTR__time), (mp_obj_t)&time_module },
#else
#define TIME_MODULE
#define TIME_MODULE_ALT_NAME
#endif
#if defined(CIRCUITPY_ULAB) && CIRCUITPY_ULAB
#if CIRCUITPY_ULAB
// ulab requires reverse special methods
#if defined(MICROPY_PY_REVERSE_SPECIAL_METHODS) && !MICROPY_PY_REVERSE_SPECIAL_METHODS
#error "ulab requires MICROPY_PY_REVERSE_SPECIAL_METHODS"
#endif
#define ULAB_MODULE \
{ MP_ROM_QSTR(MP_QSTR_ulab), MP_ROM_PTR(&ulab_user_cmodule) },
#else
#define ULAB_MODULE
#endif
// Define certain native modules with weak links so they can be replaced with Python
// implementations. This list may grow over time.
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
OS_MODULE \
TIME_MODULE \
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS
// Native modules that are weak links can be accessed directly
// by prepending their name with an underscore. This list should correspond to
// MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS, assuming you want the native modules
// to be accessible when overriden.
#define MICROPY_PORT_BUILTIN_MODULE_ALT_NAMES \
OS_MODULE_ALT_NAME \
TIME_MODULE_ALT_NAME \
#define MICROPY_PORT_BUILTIN_MODULE_ALT_NAMES
// This is an inclusive list that should correspond to the CIRCUITPY_XXX list above,
// including dependencies.
// Some of these definitions will be blank depending on what is turned on and off.
// Some are omitted because they're in MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS above.
#define MICROPY_PORT_BUILTIN_MODULES_STRONG_LINKS \
BINASCII_MODULE \
ERRNO_MODULE \
ESPIDF_MODULE \
JSON_MODULE \
RE_MODULE \
RP2PIO_MODULE \
SAMD_MODULE \
#define MICROPY_PORT_BUILTIN_MODULES_STRONG_LINKS
// The following modules are defined in their respective __init__.c file in the
// shared-bindings directory using MP_REGISTER_MODULE.

View File

@ -105,6 +105,8 @@ const mp_obj_module_t mp_module_uerrno = {
.globals = (mp_obj_dict_t *)&mp_module_uerrno_globals,
};
MP_REGISTER_MODULE(MP_QSTR_errno, mp_module_uerrno, MICROPY_PY_UERRNO);
qstr mp_errno_to_str(mp_obj_t errno_val) {
// Otherwise, return the Exxxx string for that error code
#if MICROPY_PY_UERRNO_ERRORCODE

View File

@ -247,3 +247,5 @@ const mp_obj_module_t os_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&os_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_os, os_module, CIRCUITPY_OS);

View File

@ -330,3 +330,5 @@ const mp_obj_module_t time_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&time_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_time, time_module, CIRCUITPY_TIME);

View File

@ -30,9 +30,10 @@ ame__
mport
builtins micropython _thread array
btree cexample cmath collections
cppexample ffi framebuf gc
hashlib math qrio sys
binascii btree cexample cmath
collections cppexample errno ffi
framebuf gc hashlib json
math qrio re sys
termios ubinascii uctypes uerrno
uheapq uio ujson ulab
uos urandom ure uselect