Skip to content

Commit 0eafb67

Browse files
committed
Convert all modules to use MP_REGISTER_MODULE
Convert binascii, errno, json, and re to use MP_REGISTER_MODULE. Resolves #5183.
1 parent a46aa48 commit 0eafb67

File tree

5 files changed

+27
-42
lines changed

5 files changed

+27
-42
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

py/circuitpy_mpconfig.h

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,6 @@ 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))
@@ -273,15 +266,6 @@ typedef long mp_off_t;
273266
#define CIRCUITPY_DISPLAY_LIMIT (0)
274267
#endif
275268

276-
#if CIRCUITPY_ERRNO
277-
#define MICROPY_PY_UERRNO (1)
278-
// Uses about 80 bytes.
279-
#define MICROPY_PY_UERRNO_ERRORCODE (1)
280-
#define ERRNO_MODULE { MP_ROM_QSTR(MP_QSTR_errno), MP_ROM_PTR(&mp_module_uerrno) },
281-
#else
282-
#define ERRNO_MODULE
283-
#endif
284-
285269
#if CIRCUITPY_GAMEPADSHIFT
286270
// Scan gamepad every 32ms
287271
#define CIRCUITPY_GAMEPAD_TICKS 0x1f
@@ -290,18 +274,6 @@ typedef long mp_off_t;
290274
#define GAMEPAD_ROOT_POINTERS
291275
#endif
292276

293-
#if CIRCUITPY_JSON
294-
#define MICROPY_PY_UJSON (1)
295-
#define MICROPY_PY_IO (1)
296-
#define JSON_MODULE { MP_ROM_QSTR(MP_QSTR_json), MP_ROM_PTR(&mp_module_ujson) },
297-
#else
298-
#ifndef MICROPY_PY_IO
299-
// We don't need MICROPY_PY_IO unless someone else wants it.
300-
#define MICROPY_PY_IO (0)
301-
#endif
302-
#define JSON_MODULE
303-
#endif
304-
305277
#if CIRCUITPY_KEYPAD
306278
#define KEYPAD_ROOT_POINTERS mp_obj_t keypad_scanners_linked_list;
307279
#else
@@ -320,22 +292,31 @@ typedef long mp_off_t;
320292
extern const struct _mp_obj_module_t nvm_module;
321293
#endif
322294

323-
#if CIRCUITPY_RE
324-
#define MICROPY_PY_URE (1)
325-
#define RE_MODULE { MP_ROM_QSTR(MP_QSTR_re), MP_ROM_PTR(&mp_module_ure) },
295+
// Following modules are implemented in either extmod or py directory.
296+
297+
#define MICROPY_PY_UBINASCII CIRCUITPY_BINASCII
298+
299+
#define MICROPY_PY_UERRNO CIRCUITPY_ERRNO
300+
// Uses about 80 bytes.
301+
#define MICROPY_PY_UERRNO_ERRORCODE CIRCUITPY_ERRNO
302+
303+
#define MICROPY_PY_URE CIRCUITPY_RE
304+
305+
#if CIRCUITPY_JSON
306+
#define MICROPY_PY_UJSON (1)
307+
#define MICROPY_PY_IO (1)
326308
#else
327-
#define RE_MODULE
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
328313
#endif
329314

330-
#if defined(CIRCUITPY_ULAB) && CIRCUITPY_ULAB
315+
#if CIRCUITPY_ULAB
331316
// ulab requires reverse special methods
332317
#if defined(MICROPY_PY_REVERSE_SPECIAL_METHODS) && !MICROPY_PY_REVERSE_SPECIAL_METHODS
333318
#error "ulab requires MICROPY_PY_REVERSE_SPECIAL_METHODS"
334319
#endif
335-
#define ULAB_MODULE \
336-
{ MP_ROM_QSTR(MP_QSTR_ulab), MP_ROM_PTR(&ulab_user_cmodule) },
337-
#else
338-
#define ULAB_MODULE
339320
#endif
340321

341322
// 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;
355336
// Some of these definitions will be blank depending on what is turned on and off.
356337
// Some are omitted because they're in MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS above.
357338

358-
#define MICROPY_PORT_BUILTIN_MODULES_STRONG_LINKS \
359-
BINASCII_MODULE \
360-
ERRNO_MODULE \
361-
JSON_MODULE \
362-
RE_MODULE \
339+
#define MICROPY_PORT_BUILTIN_MODULES_STRONG_LINKS
363340

364341
// The following modules are defined in their respective __init__.c file in the
365342
// 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

0 commit comments

Comments
 (0)