Skip to content

Commit eece9b0

Browse files
committed
Make sure that asserts work correctly when neither NDEBUG nor PyDEBUG are defined
1 parent 80d8d73 commit eece9b0

8 files changed

Lines changed: 88 additions & 13 deletions

File tree

Include/internal/pycore_interpframe.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,18 @@ _PyFrame_StackPointerInvalidate(_PyInterpreterFrame *frame)
265265
#endif
266266
}
267267

268+
static inline void
269+
_PyFrame_StackAssertInvalid(_PyInterpreterFrame *frame)
270+
{
271+
#ifdef Py_DEBUG
272+
/* Avoid bloating the JIT code */
273+
#ifndef _Py_JIT
274+
assert(frame->stackpointer_valid == 0);
275+
#endif
276+
#endif
277+
}
278+
279+
268280
/* Determine whether a frame is incomplete.
269281
* A frame is incomplete if it is part way through
270282
* creating cell objects or a generator or coroutine.

Lib/test/test_generated_cases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,7 @@ def test_stack_reload_only(self):
15361536
INSTRUCTION_STATS(BALANCED);
15371537
// Explicit stack reload
15381538
stack_pointer = _PyFrame_GetStackPointer(frame);
1539-
assert(frame->stackpointer_valid == 0);
1539+
_PyFrame_StackAssertInvalid(frame);
15401540
DISPATCH();
15411541
}
15421542
"""

Modules/_testinternalcapi/test_cases.c.h

Lines changed: 33 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bytecodes.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4666,7 +4666,9 @@ dummy_func(
46664666
tstate->py_recursion_remaining--;
46674667
RELOAD_STACK();
46684668
LOAD_IP(0);
4669+
#ifdef Py_DEBUG
46694670
assert(frame->previous->stackpointer_valid == 1);
4671+
#endif
46704672
DTRACE_FUNCTION_ENTRY();
46714673
LLTRACE_RESUME_FRAME();
46724674
}
@@ -6480,7 +6482,7 @@ dummy_func(
64806482
}
64816483

64826484
label(error) {
6483-
assert(frame->stackpointer_valid == 0);
6485+
_PyFrame_StackAssertInvalid(frame);
64846486
/* Double-check exception status. */
64856487
#ifdef NDEBUG
64866488
if (!_PyErr_Occurred(tstate)) {
@@ -6599,7 +6601,9 @@ dummy_func(
65996601
}
66006602

66016603
spilled label(start_frame) {
6604+
#ifdef Py_DEBUG
66026605
assert(frame->stackpointer_valid == 1);
6606+
#endif
66036607
int too_deep = _Py_EnterRecursivePy(tstate);
66046608
if (too_deep) {
66056609
goto exit_unwind_notrace;

Python/executor_cases.c.h

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)