Convert all modules to use MP_REGISTER_MODULE

Convert binascii, errno, json, and re to use MP_REGISTER_MODULE.

Resolves #5183.
This commit is contained in:
microDev 2021-10-05 18:45:44 +05:30
parent a46aa48e23
commit 0eafb672b8
No known key found for this signature in database
GPG Key ID: 2C0867BE60967730
5 changed files with 27 additions and 42 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

@ -244,13 +244,6 @@ 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))
@ -273,15 +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_GAMEPADSHIFT
// Scan gamepad every 32ms
#define CIRCUITPY_GAMEPAD_TICKS 0x1f
@ -290,18 +274,6 @@ typedef long mp_off_t;
#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
@ -320,22 +292,31 @@ typedef long mp_off_t;
extern const struct _mp_obj_module_t nvm_module;
#endif
#if CIRCUITPY_RE
#define MICROPY_PY_URE (1)
#define RE_MODULE { MP_ROM_QSTR(MP_QSTR_re), MP_ROM_PTR(&mp_module_ure) },
// 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 RE_MODULE
#ifndef MICROPY_PY_IO
// We don't need MICROPY_PY_IO unless someone else wants it.
#define MICROPY_PY_IO (0)
#endif
#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
@ -355,11 +336,7 @@ extern const struct _mp_obj_module_t nvm_module;
// 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 \
JSON_MODULE \
RE_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