Skip to content

Commit 7d2ee8a

Browse files
committed
py/mpconfig: Enable module delegation if sys needs it.
Otherwise you can get into the confusing state where e.g. sys.ps1 is enabled in config (via `MICROPY_PY_SYS_PS1_PS2`) but still doesn't actually get enabled. Also verify that the required delegation options are enabled in modsys.c. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
1 parent e6926d6 commit 7d2ee8a

4 files changed

Lines changed: 18 additions & 2 deletions

File tree

ports/esp8266/mpconfigport.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#define MICROPY_OPT_MATH_FACTORIAL (0)
2020
#define MICROPY_REPL_EMACS_KEYS (0)
2121
#define MICROPY_PY_BUILTINS_COMPLEX (0)
22-
#define MICROPY_MODULE_ATTR_DELEGATION (0)
2322
#define MICROPY_PY_FUNCTION_ATTRS (0)
2423
#define MICROPY_PY_DELATTR_SETATTR (0)
2524
#define MICROPY_PY_BUILTINS_STR_CENTER (0)

py/modsys.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,21 @@ STATIC mp_obj_t mp_sys_settrace(mp_obj_t obj) {
195195
MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_settrace_obj, mp_sys_settrace);
196196
#endif // MICROPY_PY_SYS_SETTRACE
197197

198+
199+
#if MICROPY_PY_SYS_PS1_PS2 && !MICROPY_PY_SYS_ATTR_DELEGATION
200+
#error "MICROPY_PY_SYS_PS1_PS2 requires MICROPY_PY_SYS_ATTR_DELEGATION"
201+
#endif
202+
203+
#if MICROPY_PY_SYS_TRACEBACKLIMIT && !MICROPY_PY_SYS_ATTR_DELEGATION
204+
#error "MICROPY_PY_SYS_TRACEBACKLIMIT requires MICROPY_PY_SYS_ATTR_DELEGATION"
205+
#endif
206+
207+
#if MICROPY_PY_SYS_ATTR_DELEGATION && !MICROPY_MODULE_ATTR_DELEGATION
208+
#error "MICROPY_PY_SYS_ATTR_DELEGATION requires MICROPY_MODULE_ATTR_DELEGATION"
209+
#endif
210+
198211
#if MICROPY_PY_SYS_ATTR_DELEGATION
212+
// Must be kept in sync with the enum at the top of mpstate.h.
199213
STATIC const uint16_t sys_mutable_keys[] = {
200214
#if MICROPY_PY_SYS_PS1_PS2
201215
MP_QSTR_ps1,

py/mpconfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ typedef double mp_float_t;
842842
// Whether modules can use MP_REGISTER_MODULE_DELEGATION() to delegate failed
843843
// attribute lookups to a custom handler function.
844844
#ifndef MICROPY_MODULE_ATTR_DELEGATION
845-
#define MICROPY_MODULE_ATTR_DELEGATION (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
845+
#define MICROPY_MODULE_ATTR_DELEGATION (MICROPY_PY_SYS_ATTR_DELEGATION || MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
846846
#endif
847847

848848
// Whether to call __init__ when importing builtin modules for the first time.

py/mpstate.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
// memory system, runtime and virtual machine. The state is a global
4141
// variable, but in the future it is hoped that the state can become local.
4242

43+
#if MICROPY_PY_SYS_ATTR_DELEGATION
44+
// Must be kept in sync with sys_mutable_keys in modsys.c.
4345
enum {
4446
#if MICROPY_PY_SYS_PS1_PS2
4547
MP_SYS_MUTABLE_PS1,
@@ -50,6 +52,7 @@ enum {
5052
#endif
5153
MP_SYS_MUTABLE_NUM,
5254
};
55+
#endif // MICROPY_PY_SYS_ATTR_DELEGATION
5356

5457
// This structure contains dynamic configuration for the compiler.
5558
#if MICROPY_DYNAMIC_COMPILER

0 commit comments

Comments
 (0)