◐ Shell
clean mode source ↗

bpo-29683 - Fixes to _PyCode_SetExtra when co_extra->ce->extras is allocated by brianfcoleman · Pull Request #376 · python/cpython

serhiy-storchaka

serhiy-storchaka

allocated.

On PyMem_Realloc failure, _PyCode_SetExtra should free co_extra if
co_extra->ce_extras could not be allocated.
On PyMem_Realloc success, _PyCode_SetExtra should set all unused slots in
co_extra->ce_extras to NULL.

jaraco pushed a commit that referenced this pull request

Dec 2, 2022

SonicField added a commit to SonicField/cpython that referenced this pull request

May 13, 2026
…OCK.

Closes gatekeeper 15:39:42Z PASS-(b) BLOCK three-amendment list:
- (3-gate) JIT_TEST_VARIADIC_BRIDGE bad-path gate invocation
- (5-positive) JIT_TEST_EXERCISE counter for site 600 traversal
- (carry-forward-counter) JIT_TEST_COUNTER standalone test gate

Implementation:

(5-positive) lir_block_builder_c.cpp adds g_lir_bbb_append_invoke_call_count
incremented on every wrapper invocation, gated on `Py_DEBUG ||
JIT_TEST_EXERCISE`. Counter is structurally present in pydebug builds
(automatic ARM64 gate coverage) and opt-in for release (x86 with
-DJIT_TEST_EXERCISE).

scripts/gate_phoenix.sh Step 1a-4 adds three substeps:
- (5-positive): nm-grep counter symbol; if pydebug, JIT smoke step
  reads counter via ctypes pre/post force_compile fib + WARNs if
  delta == 0 (theologian site-600 fib-traversal claim NOT confirmed)
- (3-gate): bad-path build conditional on JIT_VARIADIC_BAD_PATH_VERIFY=1
  env var (full pydebug rebuild ~5min; opt-in to avoid gate latency).
  When invoked, force_compile fib expected to fire JIT_CHECK with
  'shadow-emit: input count mismatch' message
- (carry-forward-counter): standalone compile of test_unlinked_instr.cpp
  with -DJIT_TEST_COUNTER + run; INFO-out on compile failure (deps
  unresolved per CMakeLists test_*.cpp exclude regex)

JIT smoke (Step 2) extended to read g_lir_bbb_append_invoke_call_count
via ctypes.c_int.in_dll(libpy, ...). Counter delta after force_compile fib
proves site 600 traversed; missing/zero counter triggers WARN (not FAIL)
to surface theologian inferential-traversal claim for supervisor disposition
without blocking on unrelated infrastructure gaps.

Per pythia python#376 second-order risk: site-600 fib-traversal claim becomes
empirical not inferential when counter delta > 0 in pydebug build.

Net: +18 LOC lir_block_builder_c.cpp (counter + gating), +118 LOC
gate_phoenix.sh (Step 1a-4 triple + smoke counter probe).

Cumulative c22b-mech: f47e4bf + 6944618 + this commit = 5 files
+389 LOC.

Self-attribution: chat-recheck-before-commit lapse on f47e4bf missed
gatekeeper 15:39:42Z 3-amendment list; 6944618 addressed only one;
this commit addresses remaining two. Triple-failure-mode of the
[chat_recheck_before_claim] guidance in this session (theologian
5a8ea9c + my f47e4bf + 6944618 race-window) is institutional
signal that race-window detection needs hardening beyond the existing
'recheck before commit' rule.

SonicField added a commit to SonicField/cpython that referenced this pull request

May 13, 2026
Two root causes diagnosed by testkeeper:
- (A) script bug: EXTRA_CXXFLAGS env var not consumed by build_phoenix.sh
  (it expects EXTRA_CMAKE_FLAGS); -DJIT_TEST_VARIADIC_BRIDGE never reached
  the cmake compile flags -> shadow-emit divergence path was compiled out
- (B) test-fixture inadequacy: fib(10) uses small interned ints whose
  refcount never decreases to zero, so MakeDecref dealloc-fallthrough
  generates site 600 in compiled code but never executes it at runtime.
  (Pythia python#376 second-order risk lands empirically.)

Fix:
- (A) EXTRA_CXXFLAGS -> EXTRA_CMAKE_FLAGS=" -DJIT_TEST_VARIADIC_BRIDGE=1
  -DJIT_TEST_EXERCISE=1" (also forces counter into release build for
  diagnostic disambiguation)
- (B) Replace fib(10) with stress fixture: 1000 iters of [None]*100 list
  alloc + dealloc; lists are not interned, deallocs reach _Py_Dealloc

Diagnostic added: counter delta surfaced inline. If counter == 0 even with
EXERCISE flag, FAIL-DIAGNOSTIC explicit (site re-selection for c23+).
Disambiguates (3-gate) FAIL between mechanism bug and traversal inference
failure.

Self-attribution: third amendment cycle on c22b-mech demonstrates the
recursive split from c22 -> c22a + c22b-api + c22b-mech accretes
verification debt. Pythia python#380 escape-hatch concern compounds — this fix
restores (3-gate) falsifiability but the FAIL surfaced only because
testkeeper invoked the opt-in env-var. Without explicit invocation the
mechanism degraded silently (script bug on first execution).

SonicField added a commit to SonicField/cpython that referenced this pull request

May 13, 2026
…confirmed traversal path.

testkeeper 16:31:45Z: amend-3 [None]*100 stress fixture FAILED to reach
site 600 (counter delta == 0). Same run's JIT smoke (add+mul+fib
force_compile sequence) DID reach site 600 (counter delta == 5),
empirically confirming theologian's fib-traversal inference.

Site 600 traversal happens during JIT compilation infrastructure path
(force_compile internals create non-interned objects flowing through
_Py_Dealloc), NOT through fib's runtime int-decref code (interned small
ints never decref to zero — pythia python#376 second-order risk on fib's
_runtime_ traversal does land, but the _compile-time_ traversal works).

Amend-4 changes (3-gate) substep stress fixture to use the same
add+mul+fib force_compile + invoke pattern that JIT smoke uses (counter
delta empirically 5). This aligns the negative-test fixture with the
empirically-confirmed traversal path, so the bad-path build's
shadow-emit divergence will fire JIT_CHECK on actual wrapper invocation.

theologian's site-600 inference UPHELD per testkeeper empirical
evidence; (3-gate) fixture-choice was the only remaining gap.

Net: ~10 LOC churn in scripts/gate_phoenix.sh Step 1a-4 (3-gate) substep.