Skip to content

Commit a3aeefd

Browse files
authored
Merge pull request #5430 from microDev1/patch
Convert all modules to use `MP_REGISTER_MODULE`
2 parents 98ee9ee + a279f7b commit a3aeefd

File tree

11 files changed

+41
-93
lines changed

11 files changed

+41
-93
lines changed

extmod/modubinascii.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,5 @@ const mp_obj_module_t mp_module_ubinascii = {
235235
.base = { &mp_type_module },
236236
.globals = (mp_obj_dict_t *)&mp_module_binascii_globals,
237237
};
238+
239+
MP_REGISTER_MODULE(MP_QSTR_binascii, mp_module_ubinascii, MICROPY_PY_UBINASCII);

extmod/modujson.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,4 +375,6 @@ const mp_obj_module_t mp_module_ujson = {
375375
.globals = (mp_obj_dict_t *)&mp_module_ujson_globals,
376376
};
377377

378+
MP_REGISTER_MODULE(MP_QSTR_json, mp_module_ujson, MICROPY_PY_UJSON);
379+
378380
#endif // MICROPY_PY_UJSON

extmod/modure.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,8 @@ const mp_obj_module_t mp_module_ure = {
469469
.base = { &mp_type_module },
470470
.globals = (mp_obj_dict_t *)&mp_module_re_globals,
471471
};
472+
473+
MP_REGISTER_MODULE(MP_QSTR_re, mp_module_ure, MICROPY_PY_URE);
472474
#endif
473475

474476
// Source files #include'd here to make sure they're compiled in

ports/atmel-samd/bindings/samd/__init__.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,5 @@ const mp_obj_module_t samd_module = {
5757
.base = { &mp_type_module },
5858
.globals = (mp_obj_dict_t *)&samd_module_globals,
5959
};
60+
61+
MP_REGISTER_MODULE(MP_QSTR_samd, samd_module, CIRCUITPY_SAMD);

ports/espressif/bindings/espidf/__init__.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,5 @@ void raise_esp_error(esp_err_t err) {
208208
}
209209
mp_raise_msg_varg(exception_type, translate("%s error 0x%x"), group, err);
210210
}
211+
212+
MP_REGISTER_MODULE(MP_QSTR_espidf, espidf_module, CIRCUITPY_ESPIDF);

ports/raspberrypi/bindings/rp2pio/__init__.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,5 @@ const mp_obj_module_t rp2pio_module = {
5858
.base = { &mp_type_module },
5959
.globals = (mp_obj_dict_t *)&rp2pio_module_globals,
6060
};
61+
62+
MP_REGISTER_MODULE(MP_QSTR_rp2pio, rp2pio_module, CIRCUITPY_RP2PIO);

py/circuitpy_mpconfig.h

Lines changed: 19 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -244,26 +244,16 @@ typedef long mp_off_t;
244244
// These CIRCUITPY_xxx values should all be defined in the *.mk files as being on or off.
245245
// So if any are not defined in *.mk, they'll throw an error here.
246246

247-
#if CIRCUITPY_BINASCII
248-
#define MICROPY_PY_UBINASCII CIRCUITPY_BINASCII
249-
#define BINASCII_MODULE { MP_ROM_QSTR(MP_QSTR_binascii), MP_ROM_PTR(&mp_module_ubinascii) },
250-
#else
251-
#define BINASCII_MODULE
252-
#endif
253-
254247
#if CIRCUITPY_BOARD
255248
#define BOARD_I2C (defined(DEFAULT_I2C_BUS_SDA) && defined(DEFAULT_I2C_BUS_SCL))
256249
#define BOARD_SPI (defined(DEFAULT_SPI_BUS_SCK) && defined(DEFAULT_SPI_BUS_MISO) && defined(DEFAULT_SPI_BUS_MOSI))
257250
#define BOARD_UART (defined(DEFAULT_UART_BUS_RX) && defined(DEFAULT_UART_BUS_TX))
258-
259251
// I2C and SPI are always allocated off the heap.
260-
261252
#if BOARD_UART
262253
#define BOARD_UART_ROOT_POINTER mp_obj_t shared_uart_bus;
263254
#else
264255
#define BOARD_UART_ROOT_POINTER
265256
#endif
266-
267257
#else
268258
#define BOARD_UART_ROOT_POINTER
269259
#endif
@@ -276,23 +266,6 @@ typedef long mp_off_t;
276266
#define CIRCUITPY_DISPLAY_LIMIT (0)
277267
#endif
278268

279-
#if CIRCUITPY_ERRNO
280-
#define MICROPY_PY_UERRNO (1)
281-
// Uses about 80 bytes.
282-
#define MICROPY_PY_UERRNO_ERRORCODE (1)
283-
#define ERRNO_MODULE { MP_ROM_QSTR(MP_QSTR_errno), MP_ROM_PTR(&mp_module_uerrno) },
284-
#else
285-
#define ERRNO_MODULE
286-
#
287-
#endif
288-
289-
#if CIRCUITPY_ESPIDF
290-
extern const struct _mp_obj_module_t espidf_module;
291-
#define ESPIDF_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_espidf),(mp_obj_t)&espidf_module },
292-
#else
293-
#define ESPIDF_MODULE
294-
#endif
295-
296269
#if CIRCUITPY_GAMEPADSHIFT
297270
// Scan gamepad every 32ms
298271
#define CIRCUITPY_GAMEPAD_TICKS 0x1f
@@ -301,18 +274,6 @@ extern const struct _mp_obj_module_t espidf_module;
301274
#define GAMEPAD_ROOT_POINTERS
302275
#endif
303276

304-
#if CIRCUITPY_JSON
305-
#define MICROPY_PY_UJSON (1)
306-
#define MICROPY_PY_IO (1)
307-
#define JSON_MODULE { MP_ROM_QSTR(MP_QSTR_json), MP_ROM_PTR(&mp_module_ujson) },
308-
#else
309-
#ifndef MICROPY_PY_IO
310-
// We don't need MICROPY_PY_IO unless someone else wants it.
311-
#define MICROPY_PY_IO (0)
312-
#endif
313-
#define JSON_MODULE
314-
#endif
315-
316277
#if CIRCUITPY_KEYPAD
317278
#define KEYPAD_ROOT_POINTERS mp_obj_t keypad_scanners_linked_list;
318279
#else
@@ -331,83 +292,51 @@ extern const struct _mp_obj_module_t espidf_module;
331292
extern const struct _mp_obj_module_t nvm_module;
332293
#endif
333294

334-
#if CIRCUITPY_OS
335-
extern const struct _mp_obj_module_t os_module;
336-
#define OS_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_os), (mp_obj_t)&os_module },
337-
#define OS_MODULE_ALT_NAME { MP_OBJ_NEW_QSTR(MP_QSTR__os), (mp_obj_t)&os_module },
338-
#else
339-
#define OS_MODULE
340-
#define OS_MODULE_ALT_NAME
341-
#endif
295+
// Following modules are implemented in either extmod or py directory.
342296

343-
#if CIRCUITPY_RE
344-
#define MICROPY_PY_URE (1)
345-
#define RE_MODULE { MP_ROM_QSTR(MP_QSTR_re), MP_ROM_PTR(&mp_module_ure) },
346-
#else
347-
#define RE_MODULE
348-
#endif
297+
#define MICROPY_PY_UBINASCII CIRCUITPY_BINASCII
349298

350-
#if CIRCUITPY_RP2PIO
351-
extern const struct _mp_obj_module_t rp2pio_module;
352-
#define RP2PIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_rp2pio),(mp_obj_t)&rp2pio_module },
353-
#else
354-
#define RP2PIO_MODULE
355-
#endif
299+
#define MICROPY_PY_UERRNO CIRCUITPY_ERRNO
300+
// Uses about 80 bytes.
301+
#define MICROPY_PY_UERRNO_ERRORCODE CIRCUITPY_ERRNO
356302

357-
#if CIRCUITPY_SAMD
358-
extern const struct _mp_obj_module_t samd_module;
359-
#define SAMD_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_samd),(mp_obj_t)&samd_module },
360-
#else
361-
#define SAMD_MODULE
362-
#endif
303+
#define MICROPY_PY_URE CIRCUITPY_RE
363304

364-
#if CIRCUITPY_TIME
365-
extern const struct _mp_obj_module_t time_module;
366-
#define TIME_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_module },
367-
#define TIME_MODULE_ALT_NAME { MP_OBJ_NEW_QSTR(MP_QSTR__time), (mp_obj_t)&time_module },
305+
#if CIRCUITPY_JSON
306+
#define MICROPY_PY_UJSON (1)
307+
#define MICROPY_PY_IO (1)
368308
#else
369-
#define TIME_MODULE
370-
#define TIME_MODULE_ALT_NAME
309+
#ifndef MICROPY_PY_IO
310+
// We don't need MICROPY_PY_IO unless someone else wants it.
311+
#define MICROPY_PY_IO (0)
312+
#endif
371313
#endif
372314

373-
#if defined(CIRCUITPY_ULAB) && CIRCUITPY_ULAB
315+
#if CIRCUITPY_ULAB
374316
// ulab requires reverse special methods
375317
#if defined(MICROPY_PY_REVERSE_SPECIAL_METHODS) && !MICROPY_PY_REVERSE_SPECIAL_METHODS
376318
#error "ulab requires MICROPY_PY_REVERSE_SPECIAL_METHODS"
377319
#endif
378-
#define ULAB_MODULE \
379-
{ MP_ROM_QSTR(MP_QSTR_ulab), MP_ROM_PTR(&ulab_user_cmodule) },
380-
#else
381-
#define ULAB_MODULE
382320
#endif
383321

384322
// Define certain native modules with weak links so they can be replaced with Python
385323
// implementations. This list may grow over time.
386-
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
387-
OS_MODULE \
388-
TIME_MODULE \
324+
325+
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS
389326

390327
// Native modules that are weak links can be accessed directly
391328
// by prepending their name with an underscore. This list should correspond to
392329
// MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS, assuming you want the native modules
393330
// to be accessible when overriden.
394-
#define MICROPY_PORT_BUILTIN_MODULE_ALT_NAMES \
395-
OS_MODULE_ALT_NAME \
396-
TIME_MODULE_ALT_NAME \
331+
332+
#define MICROPY_PORT_BUILTIN_MODULE_ALT_NAMES
397333

398334
// This is an inclusive list that should correspond to the CIRCUITPY_XXX list above,
399335
// including dependencies.
400336
// Some of these definitions will be blank depending on what is turned on and off.
401337
// Some are omitted because they're in MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS above.
402338

403-
#define MICROPY_PORT_BUILTIN_MODULES_STRONG_LINKS \
404-
BINASCII_MODULE \
405-
ERRNO_MODULE \
406-
ESPIDF_MODULE \
407-
JSON_MODULE \
408-
RE_MODULE \
409-
RP2PIO_MODULE \
410-
SAMD_MODULE \
339+
#define MICROPY_PORT_BUILTIN_MODULES_STRONG_LINKS
411340

412341
// The following modules are defined in their respective __init__.c file in the
413342
// shared-bindings directory using MP_REGISTER_MODULE.

py/moduerrno.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ const mp_obj_module_t mp_module_uerrno = {
105105
.globals = (mp_obj_dict_t *)&mp_module_uerrno_globals,
106106
};
107107

108+
MP_REGISTER_MODULE(MP_QSTR_errno, mp_module_uerrno, MICROPY_PY_UERRNO);
109+
108110
qstr mp_errno_to_str(mp_obj_t errno_val) {
109111
// Otherwise, return the Exxxx string for that error code
110112
#if MICROPY_PY_UERRNO_ERRORCODE

shared-bindings/os/__init__.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,5 @@ const mp_obj_module_t os_module = {
247247
.base = { &mp_type_module },
248248
.globals = (mp_obj_dict_t *)&os_module_globals,
249249
};
250+
251+
MP_REGISTER_MODULE(MP_QSTR_os, os_module, CIRCUITPY_OS);

shared-bindings/time/__init__.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,5 @@ const mp_obj_module_t time_module = {
330330
.base = { &mp_type_module },
331331
.globals = (mp_obj_dict_t *)&time_module_globals,
332332
};
333+
334+
MP_REGISTER_MODULE(MP_QSTR_time, time_module, CIRCUITPY_TIME);

tests/unix/extra_coverage.py.exp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ ame__
3030
mport
3131

3232
builtins micropython _thread array
33-
btree cexample cmath collections
34-
cppexample ffi framebuf gc
35-
hashlib math qrio sys
33+
binascii btree cexample cmath
34+
collections cppexample errno ffi
35+
framebuf gc hashlib json
36+
math qrio re sys
3637
termios ubinascii uctypes uerrno
3738
uheapq uio ujson ulab
3839
uos urandom ure uselect

0 commit comments

Comments
 (0)