Skip to content

Commit ad053d8

Browse files
authored
GH-131498: Cases generator: Parse down to C statement level. (GH-131948)
* Parse down to statement level in the cases generator * Add handling for #if macros, treating them much like normal ifs.
1 parent 6e91d1f commit ad053d8

16 files changed

+804
-968
lines changed

Lib/test/test_generated_cases.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,6 @@ def test_error_if_plain_with_comment(self):
457457
if (cond) {
458458
JUMP_TO_LABEL(label);
459459
}
460-
// Comment is ok
461460
DISPATCH();
462461
}
463462
"""
@@ -586,7 +585,6 @@ def test_suppress_dispatch(self):
586585
587586
LABEL(somewhere)
588587
{
589-
590588
}
591589
"""
592590
self.run_cases_test(input, output)
@@ -1351,7 +1349,6 @@ def test_pop_on_error_peeks(self):
13511349
}
13521350
// THIRD
13531351
{
1354-
// Mark j and k as used
13551352
if (cond) {
13561353
JUMP_TO_LABEL(pop_2_error);
13571354
}
@@ -1757,17 +1754,14 @@ def test_complex_label(self):
17571754
output = """
17581755
LABEL(other_label)
17591756
{
1760-
17611757
}
17621758
17631759
LABEL(other_label2)
17641760
{
1765-
17661761
}
17671762
17681763
LABEL(my_label)
17691764
{
1770-
// Comment
17711765
_PyFrame_SetStackPointer(frame, stack_pointer);
17721766
do_thing();
17731767
stack_pointer = _PyFrame_GetStackPointer(frame);
@@ -1795,7 +1789,6 @@ def test_spilled_label(self):
17951789
output = """
17961790
LABEL(one)
17971791
{
1798-
/* STACK SPILLED */
17991792
stack_pointer = _PyFrame_GetStackPointer(frame);
18001793
JUMP_TO_LABEL(two);
18011794
}
@@ -1851,7 +1844,6 @@ def test_multiple_labels(self):
18511844
output = """
18521845
LABEL(my_label_1)
18531846
{
1854-
// Comment
18551847
_PyFrame_SetStackPointer(frame, stack_pointer);
18561848
do_thing1();
18571849
stack_pointer = _PyFrame_GetStackPointer(frame);
@@ -1860,7 +1852,6 @@ def test_multiple_labels(self):
18601852
18611853
LABEL(my_label_2)
18621854
{
1863-
// Comment
18641855
_PyFrame_SetStackPointer(frame, stack_pointer);
18651856
do_thing2();
18661857
stack_pointer = _PyFrame_GetStackPointer(frame);

Python/bytecodes.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ dummy_func(
163163
op(_CHECK_PERIODIC_IF_NOT_YIELD_FROM, (--)) {
164164
if ((oparg & RESUME_OPARG_LOCATION_MASK) < RESUME_AFTER_YIELD_FROM) {
165165
_Py_CHECK_EMSCRIPTEN_SIGNALS_PERIODICALLY();
166-
QSBR_QUIESCENT_STATE(tstate); \
166+
QSBR_QUIESCENT_STATE(tstate);
167167
if (_Py_atomic_load_uintptr_relaxed(&tstate->eval_breaker) & _PY_EVAL_EVENTS_MASK) {
168168
int err = _Py_HandlePending(tstate);
169169
ERROR_IF(err != 0, error);
@@ -2245,7 +2245,8 @@ dummy_func(
22452245
PyObject *attr_o = FT_ATOMIC_LOAD_PTR_ACQUIRE(*value_ptr);
22462246
DEOPT_IF(attr_o == NULL);
22472247
#ifdef Py_GIL_DISABLED
2248-
if (!_Py_TryIncrefCompareStackRef(value_ptr, attr_o, &attr)) {
2248+
int increfed = _Py_TryIncrefCompareStackRef(value_ptr, attr_o, &attr);
2249+
if (!increfed) {
22492250
DEOPT_IF(true);
22502251
}
22512252
#else
@@ -2322,7 +2323,8 @@ dummy_func(
23222323
}
23232324
STAT_INC(LOAD_ATTR, hit);
23242325
#ifdef Py_GIL_DISABLED
2325-
if (!_Py_TryIncrefCompareStackRef(&ep->me_value, attr_o, &attr)) {
2326+
int increfed = _Py_TryIncrefCompareStackRef(&ep->me_value, attr_o, &attr);
2327+
if (!increfed) {
23262328
DEOPT_IF(true);
23272329
}
23282330
#else

0 commit comments

Comments
 (0)