8000 py: Add independent config for debugging sentinel object values. · micropython/micropython@02cc288 · GitHub
[go: up one dir, main page]

Skip to content

Commit 02cc288

Browse files
committed
py: Add independent config for debugging sentinel object values.
The new compile-time option is MICROPY_DEBUG_MP_OBJ_SENTINELS, disabled by default. This is to allow finer control of whether this debugging feature is enabled or not (because, for example, this setting must be the same for mpy-cross and the MicroPython main code when using native code generation).
1 parent f2ebee9 commit 02cc288

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

py/emitnative.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,12 +2094,12 @@ STATIC void emit_native_for_iter(emit_t *emit, mp_uint_t label) {
20942094
emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_1, MP_OBJ_ITER_BUF_NSLOTS);
20952095
adjust_stack(emit, MP_OBJ_ITER_BUF_NSLOTS);
20962096
emit_call(emit, MP_F_NATIVE_ITERNEXT);
2097-
#ifdef NDEBUG
2098-
MP_STATIC_ASSERT(MP_OBJ_STOP_ITERATION == 0);
2099-
ASM_JUMP_IF_REG_ZERO(emit->as, REG_RET, label, false);
2100-
#else
2097+
#if MICROPY_DEBUG_MP_OBJ_SENTINELS
21012098
ASM_MOV_REG_IMM(emit->as, REG_TEMP1, (mp_uint_t)MP_OBJ_STOP_ITERATION);
21022099
ASM_JUMP_IF_REG_EQ(emit->as, REG_RET, REG_TEMP1, label);
2100+
#else
2101+
MP_STATIC_ASSERT(MP_OBJ_STOP_ITERATION == 0);
2102+
ASM_JUMP_IF_REG_ZERO(emit->as, REG_RET, label, false);
21032103
#endif
21042104
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
21052105
}

py/mpconfig.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,11 @@
414414
#define MICROPY_DEBUG_VERBOSE (0)
415415
#endif
416416

417+
// Whether to enable debugging versions of MP_OBJ_NULL/STOP_ITERATION/SENTINEL
418+
#ifndef MICROPY_DEBUG_MP_OBJ_SENTINELS
419+
#define MICROPY_DEBUG_MP_OBJ_SENTINELS (0)
420+
#endif
421+
417422
// Whether to enable a simple VM stack overflow check
418423
#ifndef MICROPY_DEBUG_VM_STACK_OVERFLOW
419424
#define MICROPY_DEBUG_VM_STACK_OVERFLOW (0)

py/obj.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
6565
// For debugging purposes they are all different. For non-debug mode, we alias
6666
// as many as we can to MP_OBJ_NULL because it's cheaper to load/compare 0.
6767

68-
#ifdef NDEBUG
69-
#define MP_OBJ_NULL (MP_OBJ_FROM_PTR((void*)0))
70-
#define MP_OBJ_STOP_ITERATION (MP_OBJ_FROM_PTR((void*)0))
71-
#define MP_OBJ_SENTINEL (MP_OBJ_FROM_PTR((void*)4))
72-
#else
68+
#if MICROPY_DEBUG_MP_OBJ_SENTINELS
7369
#define MP_OBJ_NULL (MP_OBJ_FROM_PTR((void*)0))
7470
#define MP_OBJ_STOP_ITERATION (MP_OBJ_FROM_PTR((void*)4))
7571
#define MP_OBJ_SENTINEL (MP_OBJ_FROM_PTR((void*)8))
72+
#else
73+
#define MP_OBJ_NULL (MP_OBJ_FROM_PTR((void*)0))
74+
#define MP_OBJ_STOP_ITERATION (MP_OBJ_FROM_PTR((void*)0))
75+
#define MP_OBJ_SENTINEL (MP_OBJ_FROM_PTR((void*)4))
7676
#endif
7777

7878
// These mac 38EF ros/inline functions operate on objects and depend on the

0 commit comments

Comments
 (0)
0