Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stable ABI: Objects/bytesobject.c:122: PyBytes_FromStringAndSize: Assertion '_Py_IsImmortal(op)' failed. #123091

Closed
mgorny opened this issue Aug 17, 2024 · 22 comments
Labels
3.13 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@mgorny
Copy link
Contributor

mgorny commented Aug 17, 2024

Crash report

What happened?

While testing qiskit, I've found another crash in the stable ABI with 3.13. I've confirmed it with CPython 3.13 as of 3ab8eaf.

To reproduce:

pip install qiskit pytest ddt
git clone https://github.com/Qiskit/qiskit/
cd qiskit
mv qiskit{,~}  # hide the non-compiled package
pytest -s test/python/circuit/library/test_blueprintcircuit.py::TestBlueprintCircuit::test_global_phase_copied

Python traceback:

========================================================= test session starts =========================================================
platform linux -- Python 3.13.0rc1, pytest-8.3.2, pluggy-1.5.0
rootdir: /tmp/qiskit
configfile: pyproject.toml
collected 1 item                                                                                                                      

test/python/circuit/library/test_blueprintcircuit.py python: Objects/bytesobject.c:122: PyBytes_FromStringAndSize: Assertion `_Py_IsImmortal(op)' failed.
Fatal Python error: Aborted

Current thread 0x00007f1add1ff740 (most recent call first):
  File "/tmp/venv/lib/python3.13/site-packages/qiskit/circuit/quantumcircuit.py", line 3714 in copy_empty_like
  File "/tmp/venv/lib/python3.13/site-packages/qiskit/circuit/library/blueprintcircuit.py", line 204 in copy_empty_like
  File "/tmp/qiskit/test/python/circuit/library/test_blueprintcircuit.py", line 204 in test_global_phase_copied
  File "/home/mgorny/git/cpython/Lib/unittest/case.py", line 606 in _callTestMethod
  File "/home/mgorny/git/cpython/Lib/unittest/case.py", line 651 in run
  File "/home/mgorny/git/cpython/Lib/unittest/case.py", line 707 in __call__
  File "/tmp/venv/lib/python3.13/site-packages/_pytest/unittest.py", line 351 in runtest
  File "/tmp/venv/lib/python3.13/site-packages/_pytest/runner.py", line 174 in pytest_runtest_call
  File "/tmp/venv/lib/python3.13/site-packages/pluggy/_callers.py", line 103 in _multicall
  File "/tmp/venv/lib/python3.13/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/tmp/venv/lib/python3.13/site-packages/pluggy/_hooks.py", line 513 in __call__
  File "/tmp/venv/lib/python3.13/site-packages/_pytest/runner.py", line 242 in <lambda>
  File "/tmp/venv/lib/python3.13/site-packages/_pytest/runner.py", line 341 in from_call
  File "/tmp/venv/lib/python3.13/site-packages/_pytest/runner.py", line 241 in call_and_report
  File "/tmp/venv/lib/python3.13/site-packages/_pytest/runner.py", line 132 in runtestprotocol
  File "/tmp/venv/lib/python3.13/site-packages/_pytest/runner.py", line 113 in pytest_runtest_protocol
  File "/tmp/venv/lib/python3.13/site-packages/pluggy/_callers.py", line 103 in _multicall
  File "/tmp/venv/lib/python3.13/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/tmp/venv/lib/python3.13/site-packages/pluggy/_hooks.py", line 513 in __call__
  File "/tmp/venv/lib/python3.13/site-packages/_pytest/main.py", line 362 in pytest_runtestloop
  File "/tmp/venv/lib/python3.13/site-packages/pluggy/_callers.py", line 103 in _multicall
  File "/tmp/venv/lib/python3.13/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/tmp/venv/lib/python3.13/site-packages/pluggy/_hooks.py", line 513 in __call__
  File "/tmp/venv/lib/python3.13/site-packages/_pytest/main.py", line 337 in _main
  File "/tmp/venv/lib/python3.13/site-packages/_pytest/main.py", line 283 in wrap_session
  File "/tmp/venv/lib/python3.13/site-packages/_pytest/main.py", line 330 in pytest_cmdline_main
  File "/tmp/venv/lib/python3.13/site-packages/pluggy/_callers.py", line 103 in _multicall
  File "/tmp/venv/lib/python3.13/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/tmp/venv/lib/python3.13/site-packages/pluggy/_hooks.py", line 513 in __call__
  File "/tmp/venv/lib/python3.13/site-packages/_pytest/config/__init__.py", line 175 in main
  File "/tmp/venv/lib/python3.13/site-packages/_pytest/config/__init__.py", line 201 in console_main
  File "/tmp/venv/bin/pytest", line 8 in <module>

Extension modules: numpy._core._multiarray_umath, numpy._core._multiarray_tests, numpy.linalg._umath_linalg, symengine.lib.symengine_wrapper, numpy.random._common, numpy.random.bit_generator, numpy.random._bounded_integers, numpy.random._mt19937, numpy.random.mtrand, numpy.random._philox, numpy.random._pcg64, numpy.random._sfc64, numpy.random._generator, scipy._lib._ccallback_c (total: 14)
Aborted (core dumped)

C backtrace:

(gdb) bt
#0  0x00007f88c9c9639c in ?? () from /usr/lib64/libc.so.6
#1  0x00007f88c9c3ec96 in raise () from /usr/lib64/libc.so.6
#2  0x00007f88ca0b6806 in faulthandler_fatal_error (signum=6) at ./Modules/faulthandler.c:338
#3  <signal handler called>
#4  0x00007f88c9c9639c in ?? () from /usr/lib64/libc.so.6
#5  0x00007f88c9c3ec96 in raise () from /usr/lib64/libc.so.6
#6  0x00007f88c9c268fa in abort () from /usr/lib64/libc.so.6
#7  0x00007f88c9c2681e in ?? () from /usr/lib64/libc.so.6
#8  0x00007f88c9c36fd6 in __assert_fail () from /usr/lib64/libc.so.6
#9  0x00007f88c9ee1a06 in PyBytes_FromStringAndSize (str=0x7f88ca37cd60 <_PyRuntime+78432> "a", size=1) at Objects/bytesobject.c:122
#10 0x00007f88c9f8b15e in unicode_encode_utf8 (unicode=0x7f88ca37cd38 <_PyRuntime+78392>, 
    error_handler=error_handler@entry=_Py_ERROR_UNKNOWN, errors=errors@entry=0x0) at Objects/unicodeobject.c:5340
#11 0x00007f88c9f98a30 in _PyUnicode_AsUTF8String (unicode=<optimized out>, errors=errors@entry=0x0) at Objects/unicodeobject.c:5428
#12 0x00007f88c9f98a47 in PyUnicode_AsUTF8String (unicode=<optimized out>) at Objects/unicodeobject.c:5435
#13 0x00007f88c7ee711e in <pyo3::pybacked::PyBackedStr as pyo3::conversion::FromPyObject>::extract_bound ()
   from /tmp/venv/lib/python3.13/site-packages/qiskit/_accelerate.abi3.so
#14 0x00007f88c80a2c47 in qiskit_circuit::parameter_table::ParameterTable::track ()
   from /tmp/venv/lib/python3.13/site-packages/qiskit/_accelerate.abi3.so
#15 0x00007f88c7f878ce in qiskit_circuit::circuit_data::CircuitData::set_global_phase ()
   from /tmp/venv/lib/python3.13/site-packages/qiskit/_accelerate.abi3.so
#16 0x00007f88c7f86f0d in qiskit_circuit::circuit_data::CircuitData::new ()
   from /tmp/venv/lib/python3.13/site-packages/qiskit/_accelerate.abi3.so
#17 0x00007f88c80b5a70 in qiskit_circuit::circuit_data::CircuitData::__pymethod___new____ ()
   from /tmp/venv/lib/python3.13/site-packages/qiskit/_accelerate.abi3.so
#18 0x00007f88c7f510d4 in pyo3::impl_::trampoline::trampoline ()
   from /tmp/venv/lib/python3.13/site-packages/qiskit/_accelerate.abi3.so
#19 0x00007f88c80933c1 in qiskit_circuit::circuit_data::<impl pyo3::impl_::pyclass::PyMethods<qiskit_circuit::circuit_data::CircuitData> for pyo3::impl_::pyclass::PyClassImplCollector<qiskit_circuit::circuit_data::CircuitData>>::py_methods::ITEMS::trampoline ()
   from /tmp/venv/lib/python3.13/site-packages/qiskit/_accelerate.abi3.so
#20 0x00007f88c9f6e758 in type_call (self=0x565319729bb0, args=0x7f88c2a3c840, kwds=0x7f88c2a3d680) at Objects/typeobject.c:1978
#21 0x00007f88c9eea976 in _PyObject_MakeTpCall (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, 
    callable=callable@entry=0x565319729bb0, args=args@entry=0x7f88ca51d608, nargs=<optimized out>, 
    keywords=keywords@entry=0x7f88c5f8d540) at Objects/call.c:242
#22 0x00007f88c9eeabc6 in _PyObject_VectorcallTstate (tstate=0x7f88ca3aebc0 <_PyRuntime+282816>, 
    callable=callable@entry=0x565319729bb0, args=args@entry=0x7f88ca51d608, nargsf=<optimized out>, nargsf@entry=9223372036854775810, 
    kwnames=kwnames@entry=0x7f88c5f8d540) at ./Include/internal/pycore_call.h:166
#23 0x00007f88c9eeac3b in PyObject_Vectorcall (callable=callable@entry=0x565319729bb0, args=args@entry=0x7f88ca51d608, 
    nargsf=9223372036854775810, kwnames=kwnames@entry=0x7f88c5f8d540) at Objects/call.c:327
#24 0x00007f88ca01692e in _PyEval_EvalFrameDefault (tstate=0x7f88ca3aebc0 <_PyRuntime+282816>, frame=0x7f88ca51d588, throwflag=0)
    at Python/generated_cases.c.h:1500
#25 0x00007f88ca022a66 in _PyEval_EvalFrame (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, frame=<optimized out>, 
    throwflag=throwflag@entry=0) at ./Include/internal/pycore_ceval.h:119
#26 0x00007f88ca022ba9 in _PyEval_Vector (tstate=0x7f88ca3aebc0 <_PyRuntime+282816>, func=func@entry=0x7f88c87b23e0, 
    locals=locals@entry=0x0, args=args@entry=0x7f88c3181be0, argcount=argcount@entry=1, kwnames=kwnames@entry=0x7f88c8f335e0)
    at Python/ceval.c:1806
#27 0x00007f88c9eea7bf in _PyFunction_Vectorcall (func=0x7f88c87b23e0, stack=0x7f88c3181be0, nargsf=<optimized out>, 
    kwnames=0x7f88c8f335e0) at Objects/call.c:413
#28 0x00007f88c9eeda11 in _PyObject_VectorcallTstate (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, 
    callable=callable@entry=0x7f88c87b23e0, args=args@entry=0x7f88c3181be0, nargsf=nargsf@entry=1, 
    kwnames=kwnames@entry=0x7f88c8f335e0) at ./Include/internal/pycore_call.h:168
#29 0x00007f88c9eedc09 in method_vectorcall (method=<optimized out>, args=0x7f88c3181be8, nargsf=<optimized out>, 
    kwnames=0x7f88c8f335e0) at Objects/classobject.c:62
#30 0x00007f88c9eec5d2 in _PyVectorcall_Call (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, 
    func=0x7f88c9eeda93 <method_vectorcall>, callable=callable@entry=0x7f88c2a3cdc0, 
    tuple=tuple@entry=0x7f88ca37f318 <_PyRuntime+88088>, kwargs=kwargs@entry=0x7f88c31954c0) at Objects/call.c:285
#31 0x00007f88c9eec839 in _PyObject_Call (tstate=0x7f88ca3aebc0 <_PyRuntime+282816>, callable=callable@entry=0x7f88c2a3cdc0, 
    args=args@entry=0x7f88ca37f318 <_PyRuntime+88088>, kwargs=kwargs@entry=0x7f88c31954c0) at Objects/call.c:348
#32 0x00007f88c9eec883 in PyObject_Call (callable=callable@entry=0x7f88c2a3cdc0, args=args@entry=0x7f88ca37f318 <_PyRuntime+88088>, 
    kwargs=kwargs@entry=0x7f88c31954c0) at Objects/call.c:373
#33 0x00007f88ca0161ec in _PyEval_EvalFrameDefault (tstate=0x7f88ca3aebc0 <_PyRuntime+282816>, frame=0x7f88ca51d278, throwflag=0)
    at Python/generated_cases.c.h:1353
#34 0x00007f88ca022a66 in _PyEval_EvalFrame (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, frame=<optimized out>, 
    throwflag=throwflag@entry=0) at ./Include/internal/pycore_ceval.h:119
#35 0x00007f88ca022ba9 in _PyEval_Vector (tstate=0x7f88ca3aebc0 <_PyRuntime+282816>, func=func@entry=0x7f88c87b25c0, 
    locals=locals@entry=0x0, args=args@entry=0x7f88c842c038, argcount=argcount@entry=1, kwnames=kwnames@entry=0x7f88c8baf010)
    at Python/ceval.c:1806
#36 0x00007f88c9eea7bf in _PyFunction_Vectorcall (func=0x7f88c87b25c0, stack=0x7f88c842c038, nargsf=<optimized out>, 
    kwnames=0x7f88c8baf010) at Objects/call.c:413
#37 0x00007f88c9eec310 in _PyObject_VectorcallDictTstate (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, 
    callable=callable@entry=0x7f88c87b25c0, args=args@entry=0x7ffdb7758be0, nargsf=<optimized out>, nargsf@entry=1, 
    kwargs=kwargs@entry=0x7f88c8397940) at Objects/call.c:146
--Type <RET> for more, q to quit, c to continue without paging--c
#38 0x00007f88c9eec41b in _PyObject_Call_Prepend (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, 
    callable=callable@entry=0x7f88c87b25c0, obj=obj@entry=0x7f88c2b57750, args=args@entry=0x7f88ca37f318 <_PyRuntime+88088>, 
    kwargs=kwargs@entry=0x7f88c8397940) at Objects/call.c:504
#39 0x00007f88c9f74087 in slot_tp_call (self=0x7f88c2b57750, args=0x7f88ca37f318 <_PyRuntime+88088>, kwds=0x7f88c8397940)
    at Objects/typeobject.c:9534
#40 0x00007f88c9eea976 in _PyObject_MakeTpCall (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, 
    callable=callable@entry=0x7f88c2b57750, args=args@entry=0x7f88ca51d258, nargs=<optimized out>, 
    keywords=keywords@entry=0x7f88c84a23e0) at Objects/call.c:242
#41 0x00007f88c9eeabc6 in _PyObject_VectorcallTstate (tstate=0x7f88ca3aebc0 <_PyRuntime+282816>, 
    callable=callable@entry=0x7f88c2b57750, args=args@entry=0x7f88ca51d258, nargsf=<optimized out>, nargsf@entry=9223372036854775808, 
    kwnames=kwnames@entry=0x7f88c84a23e0) at ./Include/internal/pycore_call.h:166
#42 0x00007f88c9eeac3b in PyObject_Vectorcall (callable=callable@entry=0x7f88c2b57750, args=args@entry=0x7f88ca51d258, 
    nargsf=9223372036854775808, kwnames=kwnames@entry=0x7f88c84a23e0) at Objects/call.c:327
#43 0x00007f88ca01692e in _PyEval_EvalFrameDefault (tstate=0x7f88ca3aebc0 <_PyRuntime+282816>, frame=0x7f88ca51d1e0, throwflag=0)
    at Python/generated_cases.c.h:1500
#44 0x00007f88ca022a66 in _PyEval_EvalFrame (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, frame=<optimized out>, 
    throwflag=throwflag@entry=0) at ./Include/internal/pycore_ceval.h:119
#45 0x00007f88ca022ba9 in _PyEval_Vector (tstate=0x7f88ca3aebc0 <_PyRuntime+282816>, func=func@entry=0x7f88c8baa0c0, 
    locals=locals@entry=0x0, args=args@entry=0x7f88c842c098, argcount=argcount@entry=1, kwnames=kwnames@entry=0x7f88c83da3e0)
    at Python/ceval.c:1806
#46 0x00007f88c9eea7bf in _PyFunction_Vectorcall (func=0x7f88c8baa0c0, stack=0x7f88c842c098, nargsf=<optimized out>, 
    kwnames=0x7f88c83da3e0) at Objects/call.c:413
#47 0x00007f88c9eec310 in _PyObject_VectorcallDictTstate (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, 
    callable=callable@entry=0x7f88c8baa0c0, args=args@entry=0x7ffdb7758fb0, nargsf=<optimized out>, nargsf@entry=1, 
    kwargs=kwargs@entry=0x7f88c2a1c240) at Objects/call.c:146
#48 0x00007f88c9eec41b in _PyObject_Call_Prepend (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, 
    callable=callable@entry=0x7f88c8baa0c0, obj=obj@entry=0x7f88c84b7510, args=args@entry=0x7f88ca37f318 <_PyRuntime+88088>, 
    kwargs=kwargs@entry=0x7f88c2a1c240) at Objects/call.c:504
#49 0x00007f88c9f74087 in slot_tp_call (self=self@entry=0x7f88c84b7510, args=args@entry=0x7f88ca37f318 <_PyRuntime+88088>, 
    kwds=kwds@entry=0x7f88c2a1c240) at Objects/typeobject.c:9534
#50 0x00007f88c9eec797 in _PyObject_Call (tstate=0x7f88ca3aebc0 <_PyRuntime+282816>, callable=callable@entry=0x7f88c84b7510, 
    args=args@entry=0x7f88ca37f318 <_PyRuntime+88088>, kwargs=kwargs@entry=0x7f88c2a1c240) at Objects/call.c:361
#51 0x00007f88c9eec883 in PyObject_Call (callable=callable@entry=0x7f88c84b7510, args=args@entry=0x7f88ca37f318 <_PyRuntime+88088>, 
    kwargs=kwargs@entry=0x7f88c2a1c240) at Objects/call.c:373
#52 0x00007f88ca0161ec in _PyEval_EvalFrameDefault (tstate=0x7f88ca3aebc0 <_PyRuntime+282816>, frame=0x7f88ca51ce78, throwflag=0)
    at Python/generated_cases.c.h:1353
#53 0x00007f88ca022a66 in _PyEval_EvalFrame (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, frame=<optimized out>, 
    throwflag=throwflag@entry=0) at ./Include/internal/pycore_ceval.h:119
#54 0x00007f88ca022ba9 in _PyEval_Vector (tstate=0x7f88ca3aebc0 <_PyRuntime+282816>, func=func@entry=0x7f88c8baa0c0, 
    locals=locals@entry=0x0, args=args@entry=0x7f88c8467e78, argcount=argcount@entry=1, kwnames=kwnames@entry=0x7f88c86437c0)
    at Python/ceval.c:1806
#55 0x00007f88c9eea7bf in _PyFunction_Vectorcall (func=0x7f88c8baa0c0, stack=0x7f88c8467e78, nargsf=<optimized out>, 
    kwnames=0x7f88c86437c0) at Objects/call.c:413
#56 0x00007f88c9eec310 in _PyObject_VectorcallDictTstate (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, 
    callable=callable@entry=0x7f88c8baa0c0, args=args@entry=0x7ffdb7759330, nargsf=<optimized out>, nargsf@entry=1, 
    kwargs=kwargs@entry=0x7f88c83977c0) at Objects/call.c:146
#57 0x00007f88c9eec41b in _PyObject_Call_Prepend (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, 
    callable=callable@entry=0x7f88c8baa0c0, obj=obj@entry=0x7f88c84b76a0, args=args@entry=0x7f88ca37f318 <_PyRuntime+88088>, 
    kwargs=kwargs@entry=0x7f88c83977c0) at Objects/call.c:504
#58 0x00007f88c9f74087 in slot_tp_call (self=0x7f88c84b76a0, args=0x7f88ca37f318 <_PyRuntime+88088>, kwds=0x7f88c83977c0)
    at Objects/typeobject.c:9534
#59 0x00007f88c9eea976 in _PyObject_MakeTpCall (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, 
    callable=callable@entry=0x7f88c84b76a0, args=args@entry=0x7f88ca51c900, nargs=<optimized out>, 
    keywords=keywords@entry=0x7f88c88868c0) at Objects/call.c:242
#60 0x00007f88c9eeabc6 in _PyObject_VectorcallTstate (tstate=0x7f88ca3aebc0 <_PyRuntime+282816>, 
    callable=callable@entry=0x7f88c84b76a0, args=args@entry=0x7f88ca51c900, nargsf=<optimized out>, nargsf@entry=9223372036854775808, 
    kwnames=kwnames@entry=0x7f88c88868c0) at ./Include/internal/pycore_call.h:166
#61 0x00007f88c9eeac3b in PyObject_Vectorcall (callable=callable@entry=0x7f88c84b76a0, args=args@entry=0x7f88ca51c900, 
    nargsf=9223372036854775808, kwnames=kwnames@entry=0x7f88c88868c0) at Objects/call.c:327
#62 0x00007f88ca01692e in _PyEval_EvalFrameDefault (tstate=0x7f88ca3aebc0 <_PyRuntime+282816>, frame=0x7f88ca51c880, throwflag=0)
    at Python/generated_cases.c.h:1500
#63 0x00007f88ca022a66 in _PyEval_EvalFrame (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, frame=<optimized out>, 
    throwflag=throwflag@entry=0) at ./Include/internal/pycore_ceval.h:119
#64 0x00007f88ca022ba9 in _PyEval_Vector (tstate=0x7f88ca3aebc0 <_PyRuntime+282816>, func=func@entry=0x7f88c8baa0c0, 
    locals=locals@entry=0x0, args=args@entry=0x7f88c5ed9818, argcount=argcount@entry=1, kwnames=kwnames@entry=0x7f88c83da380)
    at Python/ceval.c:1806
#65 0x00007f88c9eea7bf in _PyFunction_Vectorcall (func=0x7f88c8baa0c0, stack=0x7f88c5ed9818, nargsf=<optimized out>, 
    kwnames=0x7f88c83da380) at Objects/call.c:413
#66 0x00007f88c9eec310 in _PyObject_VectorcallDictTstate (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, 
    callable=callable@entry=0x7f88c8baa0c0, args=args@entry=0x7ffdb7759700, nargsf=<optimized out>, nargsf@entry=1, 
    kwargs=kwargs@entry=0x7f88c83a57c0) at Objects/call.c:146
#67 0x00007f88c9eec41b in _PyObject_Call_Prepend (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, 
    callable=callable@entry=0x7f88c8baa0c0, obj=obj@entry=0x7f88c84b7790, args=args@entry=0x7f88ca37f318 <_PyRuntime+88088>, 
    kwargs=kwargs@entry=0x7f88c83a57c0) at Objects/call.c:504
#68 0x00007f88c9f74087 in slot_tp_call (self=0x7f88c84b7790, args=0x7f88ca37f318 <_PyRuntime+88088>, kwds=0x7f88c83a57c0)
    at Objects/typeobject.c:9534
#69 0x00007f88c9eea976 in _PyObject_MakeTpCall (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, 
    callable=callable@entry=0x7f88c84b7790, args=args@entry=0x7f88ca51c608, nargs=<optimized out>, 
    keywords=keywords@entry=0x7f88c89df760) at Objects/call.c:242
#70 0x00007f88c9eeabc6 in _PyObject_VectorcallTstate (tstate=0x7f88ca3aebc0 <_PyRuntime+282816>, 
    callable=callable@entry=0x7f88c84b7790, args=args@entry=0x7f88ca51c608, nargsf=<optimized out>, nargsf@entry=9223372036854775808, 
    kwnames=kwnames@entry=0x7f88c89df760) at ./Include/internal/pycore_call.h:166
#71 0x00007f88c9eeac3b in PyObject_Vectorcall (callable=callable@entry=0x7f88c84b7790, args=args@entry=0x7f88ca51c608, 
    nargsf=9223372036854775808, kwnames=kwnames@entry=0x7f88c89df760) at Objects/call.c:327
#72 0x00007f88ca01692e in _PyEval_EvalFrameDefault (tstate=0x7f88ca3aebc0 <_PyRuntime+282816>, frame=0x7f88ca51c5a0, throwflag=0)
    at Python/generated_cases.c.h:1500
#73 0x00007f88ca022a66 in _PyEval_EvalFrame (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, frame=<optimized out>, 
    throwflag=throwflag@entry=0) at ./Include/internal/pycore_ceval.h:119
#74 0x00007f88ca022ba9 in _PyEval_Vector (tstate=0x7f88ca3aebc0 <_PyRuntime+282816>, func=func@entry=0x7f88c8baa0c0, 
    locals=locals@entry=0x0, args=args@entry=0x7f88c8467598, argcount=argcount@entry=1, kwnames=kwnames@entry=0x7f88c8ef05b0)
    at Python/ceval.c:1806
#75 0x00007f88c9eea7bf in _PyFunction_Vectorcall (func=0x7f88c8baa0c0, stack=0x7f88c8467598, nargsf=<optimized out>, 
    kwnames=0x7f88c8ef05b0) at Objects/call.c:413
#76 0x00007f88c9eec310 in _PyObject_VectorcallDictTstate (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, 
    callable=callable@entry=0x7f88c8baa0c0, args=args@entry=0x7ffdb7759ad0, nargsf=<optimized out>, nargsf@entry=1, 
    kwargs=kwargs@entry=0x7f88c83bb780) at Objects/call.c:146
#77 0x00007f88c9eec41b in _PyObject_Call_Prepend (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, 
    callable=callable@entry=0x7f88c8baa0c0, obj=obj@entry=0x7f88c84b6a20, args=args@entry=0x7f88ca37f318 <_PyRuntime+88088>, 
    kwargs=kwargs@entry=0x7f88c83bb780) at Objects/call.c:504
#78 0x00007f88c9f74087 in slot_tp_call (self=0x7f88c84b6a20, args=0x7f88ca37f318 <_PyRuntime+88088>, kwds=0x7f88c83bb780)
    at Objects/typeobject.c:9534
#79 0x00007f88c9eea976 in _PyObject_MakeTpCall (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, 
    callable=callable@entry=0x7f88c84b6a20, args=args@entry=0x7f88ca51c1d8, nargs=<optimized out>, 
    keywords=keywords@entry=0x7f88c89dfe20) at Objects/call.c:242
#80 0x00007f88c9eeabc6 in _PyObject_VectorcallTstate (tstate=0x7f88ca3aebc0 <_PyRuntime+282816>, 
    callable=callable@entry=0x7f88c84b6a20, args=args@entry=0x7f88ca51c1d8, nargsf=<optimized out>, nargsf@entry=9223372036854775808, 
    kwnames=kwnames@entry=0x7f88c89dfe20) at ./Include/internal/pycore_call.h:166
#81 0x00007f88c9eeac3b in PyObject_Vectorcall (callable=callable@entry=0x7f88c84b6a20, args=args@entry=0x7f88ca51c1d8, 
    nargsf=9223372036854775808, kwnames=kwnames@entry=0x7f88c89dfe20) at Objects/call.c:327
#82 0x00007f88ca01692e in _PyEval_EvalFrameDefault (tstate=0x7f88ca3aebc0 <_PyRuntime+282816>, frame=0x7f88ca51c120, throwflag=0)
    at Python/generated_cases.c.h:1500
#83 0x00007f88ca022a66 in _PyEval_EvalFrame (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, frame=<optimized out>, 
    throwflag=throwflag@entry=0) at ./Include/internal/pycore_ceval.h:119
#84 0x00007f88ca022ba9 in _PyEval_Vector (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, func=func@entry=0x7f88c9bd54e0, 
    locals=locals@entry=0x7f88c8ef4780, args=args@entry=0x0, argcount=argcount@entry=0, kwnames=kwnames@entry=0x0)
    at Python/ceval.c:1806
#85 0x00007f88ca022c7a in PyEval_EvalCode (co=co@entry=0x7f88c9b89830, globals=globals@entry=0x7f88c8ef4780, 
    locals=locals@entry=0x7f88c8ef4780) at Python/ceval.c:596
#86 0x00007f88ca08a764 in run_eval_code_obj (tstate=tstate@entry=0x7f88ca3aebc0 <_PyRuntime+282816>, co=co@entry=0x7f88c9b89830, 
    globals=globals@entry=0x7f88c8ef4780, locals=locals@entry=0x7f88c8ef4780) at Python/pythonrun.c:1292
#87 0x00007f88ca08a941 in run_mod (mod=mod@entry=0x5653193896f8, filename=filename@entry=0x7f88c8ef48f0, 
    globals=globals@entry=0x7f88c8ef4780, locals=locals@entry=0x7f88c8ef4780, flags=flags@entry=0x7ffdb7759ff8, 
    arena=arena@entry=0x7f88c9b1fd10, interactive_src=0x0, generate_new_source=0) at Python/pythonrun.c:1377
#88 0x00007f88ca08b1df in pyrun_file (fp=fp@entry=0x5653192eaa60, filename=filename@entry=0x7f88c8ef48f0, start=start@entry=257, 
    globals=globals@entry=0x7f88c8ef4780, locals=locals@entry=0x7f88c8ef4780, closeit=closeit@entry=1, flags=0x7ffdb7759ff8)
    at Python/pythonrun.c:1210
#89 0x00007f88ca08cb1a in _PyRun_SimpleFileObject (fp=fp@entry=0x5653192eaa60, filename=filename@entry=0x7f88c8ef48f0, 
    closeit=closeit@entry=1, flags=flags@entry=0x7ffdb7759ff8) at Python/pythonrun.c:459
#90 0x00007f88ca08cd2a in _PyRun_AnyFileObject (fp=fp@entry=0x5653192eaa60, filename=filename@entry=0x7f88c8ef48f0, 
    closeit=closeit@entry=1, flags=flags@entry=0x7ffdb7759ff8) at Python/pythonrun.c:77
#91 0x00007f88ca0b281c in pymain_run_file_obj (program_name=program_name@entry=0x7f88c8f4d930, 
    filename=filename@entry=0x7f88c8ef48f0, skip_source_first_line=0) at Modules/main.c:409
#92 0x00007f88ca0b293d in pymain_run_file (config=config@entry=0x7f88ca3812b8 <_PyRuntime+96184>) at Modules/main.c:428
#93 0x00007f88ca0b34a7 in pymain_run_python (exitcode=exitcode@entry=0x7ffdb775a164) at Modules/main.c:696
#94 0x00007f88ca0b36fd in Py_RunMain () at Modules/main.c:775
#95 0x00007f88ca0b377e in pymain_main (args=args@entry=0x7ffdb775a1c0) at Modules/main.c:805
#96 0x00007f88ca0b3855 in Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at Modules/main.c:829
#97 0x00005652f235b186 in main (argc=<optimized out>, argv=<optimized out>) at ./Programs/python.c:15

CC @davidhewitt (this seems to be another problem fixed by PyO3/pyo3#4324)

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

Python 3.13.0rc1 (main, Aug 16 2024, 17:36:06) [GCC 14.2.0]

Linked PRs

@mgorny mgorny added the type-crash A hard crash of the interpreter, possibly with a core dump label Aug 17, 2024
@ZeroIntensity
Copy link
Member

I think this should get investigated by PyO3 first, but at a very quick glance, this looks like it could be a problem with the latin 1-byte strings string interning. Possibly related to #122303.

@ZeroIntensity
Copy link
Member

Actually, scratch that: I think it's caused by #120520, which allows interned strings to be mortal, so this might just be a precondition that wasn't updated. Do any other bugs occur if you remove that assertion?

@mgorny
Copy link
Contributor Author

mgorny commented Aug 17, 2024

If you mean that specific test, it passes then. However, the test suite in general triggers another failed assertion:

python: Objects/typeobject.c:5660: fini_static_type: Assertion `_Py_IsImmortal((PyObject *)type)' failed.
#0  0x00007f8269db339c in ?? () from /usr/lib64/libc.so.6
#1  0x00007f8269d5bc96 in raise () from /usr/lib64/libc.so.6
#2  0x00007f8269d438fa in abort () from /usr/lib64/libc.so.6
#3  0x00007f8269d4381e in ?? () from /usr/lib64/libc.so.6
#4  0x00007f8269d53fd6 in __assert_fail () from /usr/lib64/libc.so.6
#5  0x00007f826a16e020 in fini_static_type (interp=interp@entry=0x7f826a57f380 <_PyRuntime+88192>, 
    type=type@entry=0x7f826a536d80 <_PyExc_IndexError>, isbuiltin=isbuiltin@entry=1, final=1) at Objects/typeobject.c:5660
#6  0x00007f826a1702ee in _PyStaticType_FiniBuiltin (interp=interp@entry=0x7f826a57f380 <_PyRuntime+88192>, 
    type=type@entry=0x7f826a536d80 <_PyExc_IndexError>) at Objects/typeobject.c:5696
#7  0x00007f826a0fe59c in _PyExc_FiniTypes (interp=interp@entry=0x7f826a57f380 <_PyRuntime+88192>) at Objects/exceptions.c:3692
#8  0x00007f826a101067 in _PyExc_Fini (interp=interp@entry=0x7f826a57f380 <_PyRuntime+88192>) at Objects/exceptions.c:3823
#9  0x00007f826a282e00 in finalize_interp_types (interp=0x7f826a57f380 <_PyRuntime+88192>) at Python/pylifecycle.c:1825
#10 0x00007f826a282ec9 in finalize_interp_clear (tstate=tstate@entry=0x7f826a5aebc0 <_PyRuntime+282816>) at Python/pylifecycle.c:1885
#11 0x00007f826a285115 in _Py_Finalize (runtime=runtime@entry=0x7f826a569b00 <_PyRuntime>) at Python/pylifecycle.c:2166
#12 0x00007f826a28563c in Py_Exit (sts=2) at Python/pylifecycle.c:3392
#13 0x00007f826a28bfac in handle_system_exit () at Python/pythonrun.c:604
#14 0x00007f826a28c34b in _PyErr_PrintEx (tstate=0x7f826a5aebc0 <_PyRuntime+282816>, set_sys_last_vars=set_sys_last_vars@entry=1)
    at Python/pythonrun.c:613
#15 0x00007f826a28c69b in PyErr_PrintEx (set_sys_last_vars=set_sys_last_vars@entry=1) at Python/pythonrun.c:690
#16 0x00007f826a28c6af in PyErr_Print () at Python/pythonrun.c:696
#17 0x00007f826a28cb46 in _PyRun_SimpleFileObject (fp=fp@entry=0x558a97e49fa0, filename=filename@entry=0x7f8269030870, 
    closeit=closeit@entry=1, flags=flags@entry=0x7ffc5d6bc5a8) at Python/pythonrun.c:465
#18 0x00007f826a28ccea in _PyRun_AnyFileObject (fp=fp@entry=0x558a97e49fa0, filename=filename@entry=0x7f8269030870, 
    closeit=closeit@entry=1, flags=flags@entry=0x7ffc5d6bc5a8) at Python/pythonrun.c:77
#19 0x00007f826a2b27dc in pymain_run_file_obj (program_name=program_name@entry=0x7f8269088cf0, 
    filename=filename@entry=0x7f8269030870, skip_source_first_line=0) at Modules/main.c:409
#20 0x00007f826a2b28fd in pymain_run_file (config=config@entry=0x7f826a5812b8 <_PyRuntime+96184>) at Modules/main.c:428
#21 0x00007f826a2b3467 in pymain_run_python (exitcode=exitcode@entry=0x7ffc5d6bc714) at Modules/main.c:696
#22 0x00007f826a2b36bd in Py_RunMain () at Modules/main.c:775
#23 0x00007f826a2b373e in pymain_main (args=args@entry=0x7ffc5d6bc770) at Modules/main.c:805
#24 0x00007f826a2b3815 in Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at Modules/main.c:829
#25 0x0000558a8a2b4186 in main (argc=<optimized out>, argv=<optimized out>) at ./Programs/python.c:15

But I suppose that's a separate problem to report, and ideally I'd try to pinpoint it better first.

@ZeroIntensity
Copy link
Member

I'm guessing something changed recently with immortality, but this could be a PyO3 issue depending on what APIs they're using. Has this been reported to them yet?

@mgorny
Copy link
Contributor Author

mgorny commented Aug 17, 2024

We've reported similar issues (i.e. regarding immortality changes in 3.13) to them before, and the conclusion was that since they're using the stable ABI here, CPython needs to preserve compatibility for the sake of extensions built against earlier versions. PyO3 already have done a major fix that causes these issues to disappear, but the existing extensions will continue crashing until new wheels are built against newer PyO3 versions (and things move slowly). I've CC-ed David Hewitt here for completeness, but it feels weird to report issues if I know that they are fixed on PyO3's end — so I'm filing them on this end for completeness.

@ZeroIntensity
Copy link
Member

Is PyO3 itself using the stable ABI, or just qiskit? I'm wondering if they're using some private API regarding immortality that changed recently.

@picnixz picnixz changed the title [3.13] Stable ABI: Objects/bytesobject.c:122: PyBytes_FromStringAndSize: Assertion '_Py_IsImmortal(op)' failed. Stable ABI: Objects/bytesobject.c:122: PyBytes_FromStringAndSize: Assertion '_Py_IsImmortal(op)' failed. Aug 17, 2024
@picnixz picnixz added the 3.13 bugs and security fixes label Aug 17, 2024
@ZeroIntensity
Copy link
Member

@picnixz this is interpreter-core as well.

@picnixz picnixz added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Aug 17, 2024
@davidhewitt
Copy link
Contributor

I assume this is indeed one of the cases already "fixed" on PyO3's side by moving to use FFI calls for all refcounting with the stable ABI - as qiskit is currently still on PyO3 0.21 https://github.com/Qiskit/qiskit/blob/76eb568c14f79ab9dad17d61c49380a5c7ef5e85/Cargo.toml#L33

(We released the fix in 0.22.2; I think based on PyO3/pyo3#4428 the qiskit team is working on updating to PyO3 0.22)

The main point I see here is that assertions of immortality are broken when compiling against stable ABI versions which used inline reference counting i.e. before immortality was added and the stable API switched to use function calls.

@mtreinish
Copy link

I think based on PyO3/pyo3#4428 the qiskit team is working on updating to PyO3 0.22

We are planning to upgrade to pyo3 0.22.x asap, but we're blocked on the next rust-numpy release before we can really start the process as we rely fairly heavily on numpy.

@encukou
Copy link
Member

encukou commented Aug 30, 2024

The string interning changes involve PyUnicode (str); this report shows PyBytes (bytes).
For the reproducer, I also needed cmake and https://github.com/symengine/symengine


Yes, this looks like another issue like #118997 and #121528. Turns out assert(_Py_IsImmortal) is dangerous, and when this assert was added (#107605 -- cc @brandtbucher) we didn't have _Py_IsImmortalLoose yet.

I guess next week I'll audit all the uses of _Py_IsImmortal.

@vstinner
Copy link
Member

To reproduce: pip install qiskit pytest ddt

(...)
  Downloading rustworkx-0.15.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (9.9 kB)
Downloading qiskit-1.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.8 MB)
Downloading numpy-2.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (16.0 MB)
Downloading scipy-1.14.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (40.8 MB)
(...)

I see at least 2 dependencies installed from stable ABI binaries built with Python 3.8: rustworkx and qiskit.

As @encukou wrote, it reminds me issues #118997 and #121528.

Maybe it's another place where _Py_IsImmortalLoose() is needed.

@vstinner
Copy link
Member

@mgorny: Would you be be able to test my fix gh-123511 on qiskit?

@mgorny
Copy link
Contributor Author

mgorny commented Aug 30, 2024

Sure, will get to it right away.

@mgorny
Copy link
Contributor Author

mgorny commented Aug 30, 2024

Well, that PR fixes makes the test pass, but pytest crashes on exit:

python: Objects/typeobject.c:5660: fini_static_type: Assertion `_Py_IsImmortal((PyObject *)type)' failed.
(gdb) bt
#0  0x00007fc0422b739c in ?? () from /usr/lib64/libc.so.6
#1  0x00007fc04225fc96 in raise () from /usr/lib64/libc.so.6
#2  0x00007fc0422478fa in abort () from /usr/lib64/libc.so.6
#3  0x00007fc04224781e in ?? () from /usr/lib64/libc.so.6
#4  0x00007fc042257fd6 in __assert_fail () from /usr/lib64/libc.so.6
#5  0x0000556c61acadf1 in fini_static_type (interp=0x556c61f26420 <_PyRuntime+88352>, type=0x556c61eddd80 <_PyExc_IndexError>, 
    isbuiltin=1, final=1) at Objects/typeobject.c:5656
#6  fini_static_type (interp=0x556c61f26420 <_PyRuntime+88352>, type=0x556c61eddd80 <_PyExc_IndexError>, isbuiltin=1, final=1)
    at Objects/typeobject.c:5656
#7  _PyStaticType_FiniBuiltin (interp=interp@entry=0x556c61f26420 <_PyRuntime+88352>, type=0x556c61eddd80 <_PyExc_IndexError>)
    at Objects/typeobject.c:5696
#8  0x0000556c61a28cab in _PyExc_FiniTypes (interp=<optimized out>) at Objects/exceptions.c:3692
#9  _PyExc_Fini (interp=interp@entry=0x556c61f26420 <_PyRuntime+88352>) at Objects/exceptions.c:3823
#10 0x0000556c61c25322 in finalize_interp_types (interp=0x556c61f26420 <_PyRuntime+88352>) at Python/pylifecycle.c:1825
#11 finalize_interp_clear (tstate=0x556c61f55c60 <_PyRuntime+282976>) at Python/pylifecycle.c:1885
#12 0x0000556c61c2a649 in _Py_Finalize (runtime=0x556c61f10b00 <_PyRuntime>) at Python/pylifecycle.c:2166
#13 0x0000556c61c2b0ee in _Py_Finalize (runtime=0x556c61f10b00 <_PyRuntime>) at Python/pylifecycle.c:3396
#14 Py_Exit (sts=0) at Python/pylifecycle.c:3392
#15 0x0000556c61c333eb in handle_system_exit () at Python/pythonrun.c:604
#16 _PyErr_PrintEx (tstate=0x556c61f55c60 <_PyRuntime+282976>, set_sys_last_vars=<optimized out>) at Python/pythonrun.c:654
#17 0x0000556c61c33a99 in PyErr_PrintEx (set_sys_last_vars=1) at Python/pythonrun.c:690
#18 PyErr_Print () at Python/pythonrun.c:696
#19 _PyRun_SimpleFileObject (fp=fp@entry=0x556c9cf9dbe0, filename=filename@entry=0x7fc04157ea60, closeit=closeit@entry=1, 
    flags=flags@entry=0x7ffd6840e348) at Python/pythonrun.c:465
#20 0x0000556c61c33de0 in _PyRun_AnyFileObject (fp=0x556c9cf9dbe0, filename=filename@entry=0x7fc04157ea60, closeit=closeit@entry=1, 
    flags=flags@entry=0x7ffd6840e348) at Python/pythonrun.c:77
#21 0x0000556c61c64819 in pymain_run_file_obj (program_name=0x7fc04157e9c0, filename=0x7fc04157ea60, skip_source_first_line=0)
    at Modules/main.c:409
#22 pymain_run_file (config=0x556c61f28358 <_PyRuntime+96344>) at Modules/main.c:428
#23 pymain_run_python (exitcode=exitcode@entry=0x7ffd6840e4a0) at Modules/main.c:696
#24 0x0000556c61c651ff in Py_RunMain () at Modules/main.c:775
#25 pymain_main (args=0x7ffd6840e460) at Modules/main.c:805
#26 Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at Modules/main.c:829
--Type <RET> for more, q to quit, c to continue without paging--c
#27 0x00007fc0422493ee in ?? () from /usr/lib64/libc.so.6
#28 0x00007fc0422494a9 in __libc_start_main () from /usr/lib64/libc.so.6
#29 0x0000556c6199a245 in _start ()

@vstinner
Copy link
Member

Well, that PR fixes makes the test pass, but pytest crashes on exit:
python: Objects/typeobject.c:5660: fini_static_type: Assertion `_Py_IsImmortal((PyObject *)type)' failed.

Thanks for testing!

Well, I tried to write a minimum patch. I saw this assertion in typeobject.c but I skipped it.

I updated my PR to also patch this assertion and 2 others in typeobject.c. Would you mind to test again with the updated PR?

@mgorny
Copy link
Contributor Author

mgorny commented Aug 31, 2024

One down, more to go:

python: Python/generated_cases.c.h:5942: _PyEval_EvalFrameDefault: Assertion `_Py_IsImmortal(value)' failed.
Fatal Python error: Aborted
(gdb) bt
#0  0x00007ffff7d3439c in ?? () from /usr/lib64/libc.so.6
#1  0x00007ffff7cdcc96 in raise () from /usr/lib64/libc.so.6
#2  0x00007ffff7cc48fa in abort () from /usr/lib64/libc.so.6
#3  0x00007ffff7cc481e in ?? () from /usr/lib64/libc.so.6
#4  0x00007ffff7cd4fd6 in __assert_fail () from /usr/lib64/libc.so.6
#5  0x0000555555765a18 in _PyEval_EvalFrameDefault (tstate=0x555555aedc60 <_PyRuntime+282976>, frame=0x7ffff7f95680, throwflag=0)
    at Python/generated_cases.c.h:5942
#6  0x0000555555766dc6 in _PyEval_EvalFrame (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, frame=<optimized out>, 
    throwflag=throwflag@entry=0) at ./Include/internal/pycore_ceval.h:119
#7  0x0000555555766ee9 in _PyEval_Vector (tstate=0x555555aedc60 <_PyRuntime+282976>, func=0x7ffff682fd80, locals=locals@entry=0x0, 
    args=0x7fffd51b81b0, argcount=1, kwnames=0x7fffdefaf3d0) at Python/ceval.c:1806
#8  0x000055555563354f in _PyFunction_Vectorcall (func=<optimized out>, stack=<optimized out>, nargsf=<optimized out>, 
    kwnames=<optimized out>) at Objects/call.c:413
#9  0x0000555555636659 in _PyObject_VectorcallTstate (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, 
    callable=callable@entry=0x7ffff682fd80, args=args@entry=0x7fffd51b81b0, nargsf=nargsf@entry=1, 
    kwnames=kwnames@entry=0x7fffdefaf3d0) at ./Include/internal/pycore_call.h:168
#10 0x0000555555636846 in method_vectorcall (method=<optimized out>, args=0x7fffd51b81b8, nargsf=<optimized out>, 
    kwnames=0x7fffdefaf3d0) at Objects/classobject.c:62
#11 0x0000555555635272 in _PyVectorcall_Call (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, 
    func=0x5555556366db <method_vectorcall>, callable=callable@entry=0x7ffccf30ad00, 
    tuple=tuple@entry=0x555555abe3b8 <_PyRuntime+88248>, kwargs=kwargs@entry=0x7fffd2db4b40) at Objects/call.c:285
#12 0x00005555556354c8 in _PyObject_Call (tstate=0x555555aedc60 <_PyRuntime+282976>, callable=callable@entry=0x7ffccf30ad00, 
    args=args@entry=0x555555abe3b8 <_PyRuntime+88248>, kwargs=kwargs@entry=0x7fffd2db4b40) at Objects/call.c:348
#13 0x0000555555635504 in PyObject_Call (callable=callable@entry=0x7ffccf30ad00, args=args@entry=0x555555abe3b8 <_PyRuntime+88248>, 
    kwargs=kwargs@entry=0x7fffd2db4b40) at Objects/call.c:373
#14 0x000055555575a576 in _PyEval_EvalFrameDefault (tstate=0x555555aedc60 <_PyRuntime+282976>, frame=0x7ffff7f95408, throwflag=0)
    at Python/generated_cases.c.h:1355
#15 0x0000555555766dc6 in _PyEval_EvalFrame (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, frame=<optimized out>, 
    throwflag=throwflag@entry=0) at ./Include/internal/pycore_ceval.h:119
#16 0x0000555555766ee9 in _PyEval_Vector (tstate=0x555555aedc60 <_PyRuntime+282976>, func=0x7ffff682ff60, locals=locals@entry=0x0, 
    args=0x7ffff63cbbb8, argcount=1, kwnames=0x7ffff68f3010) at Python/ceval.c:1806
#17 0x000055555563354f in _PyFunction_Vectorcall (func=<optimized out>, stack=<optimized out>, nargsf=<optimized out>, 
    kwnames=<optimized out>) at Objects/call.c:413
--Type <RET> for more, q to quit, c to continue without paging--c
#18 0x0000555555634fcd in _PyObject_VectorcallDictTstate (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, 
    callable=callable@entry=0x7ffff682ff60, args=args@entry=0x7fffffffb850, nargsf=<optimized out>, nargsf@entry=1, 
    kwargs=kwargs@entry=0x7fffd33cfec0) at Objects/call.c:146
#19 0x00005555556350bb in _PyObject_Call_Prepend (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, 
    callable=callable@entry=0x7ffff682ff60, obj=obj@entry=0x7fffd5122490, args=args@entry=0x555555abe3b8 <_PyRuntime+88248>, 
    kwargs=kwargs@entry=0x7fffd33cfec0) at Objects/call.c:504
#20 0x00005555556baf77 in slot_tp_call (self=0x7fffd5122490, args=0x555555abe3b8 <_PyRuntime+88248>, kwds=0x7fffd33cfec0)
    at Objects/typeobject.c:9534
#21 0x00005555556336fa in _PyObject_MakeTpCall (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, 
    callable=callable@entry=0x7fffd5122490, args=args@entry=0x7ffff7f953e8, nargs=<optimized out>, 
    keywords=keywords@entry=0x7ffff6536530) at Objects/call.c:242
#22 0x000055555563394a in _PyObject_VectorcallTstate (tstate=0x555555aedc60 <_PyRuntime+282976>, 
    callable=callable@entry=0x7fffd5122490, args=args@entry=0x7ffff7f953e8, nargsf=<optimized out>, 
    kwnames=kwnames@entry=0x7ffff6536530) at ./Include/internal/pycore_call.h:166
#23 0x00005555556339a3 in PyObject_Vectorcall (callable=callable@entry=0x7fffd5122490, args=args@entry=0x7ffff7f953e8, 
    nargsf=<optimized out>, kwnames=kwnames@entry=0x7ffff6536530) at Objects/call.c:327
#24 0x000055555575acbb in _PyEval_EvalFrameDefault (tstate=0x555555aedc60 <_PyRuntime+282976>, frame=0x7ffff7f95370, throwflag=0)
    at Python/generated_cases.c.h:1502
#25 0x0000555555766dc6 in _PyEval_EvalFrame (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, frame=<optimized out>, 
    throwflag=throwflag@entry=0) at ./Include/internal/pycore_ceval.h:119
#26 0x0000555555766ee9 in _PyEval_Vector (tstate=0x555555aedc60 <_PyRuntime+282976>, func=0x7ffff6c3f9c0, locals=locals@entry=0x0, 
    args=0x7ffff63cbb98, argcount=1, kwnames=0x7ffff5b96560) at Python/ceval.c:1806
#27 0x000055555563354f in _PyFunction_Vectorcall (func=<optimized out>, stack=<optimized out>, nargsf=<optimized out>, 
    kwnames=<optimized out>) at Objects/call.c:413
#28 0x0000555555634fcd in _PyObject_VectorcallDictTstate (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, 
    callable=callable@entry=0x7ffff6c3f9c0, args=args@entry=0x7fffffffbbe0, nargsf=<optimized out>, nargsf@entry=1, 
    kwargs=kwargs@entry=0x7ffccef67400) at Objects/call.c:146
#29 0x00005555556350bb in _PyObject_Call_Prepend (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, 
    callable=callable@entry=0x7ffff6c3f9c0, obj=obj@entry=0x7ffff6558040, args=args@entry=0x555555abe3b8 <_PyRuntime+88248>, 
    kwargs=kwargs@entry=0x7ffccef67400) at Objects/call.c:504
#30 0x00005555556baf77 in slot_tp_call (self=self@entry=0x7ffff6558040, args=args@entry=0x555555abe3b8 <_PyRuntime+88248>, 
    kwds=kwds@entry=0x7ffccef67400) at Objects/typeobject.c:9534
#31 0x0000555555635426 in _PyObject_Call (tstate=0x555555aedc60 <_PyRuntime+282976>, callable=callable@entry=0x7ffff6558040, 
    args=args@entry=0x555555abe3b8 <_PyRuntime+88248>, kwargs=kwargs@entry=0x7ffccef67400) at Objects/call.c:361
#32 0x0000555555635504 in PyObject_Call (callable=callable@entry=0x7ffff6558040, args=args@entry=0x555555abe3b8 <_PyRuntime+88248>, 
    kwargs=kwargs@entry=0x7ffccef67400) at Objects/call.c:373
#33 0x000055555575a576 in _PyEval_EvalFrameDefault (tstate=0x555555aedc60 <_PyRuntime+282976>, frame=0x7ffff7f95008, throwflag=0)
    at Python/generated_cases.c.h:1355
#34 0x0000555555766dc6 in _PyEval_EvalFrame (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, frame=<optimized out>, 
    throwflag=throwflag@entry=0) at ./Include/internal/pycore_ceval.h:119
#35 0x0000555555766ee9 in _PyEval_Vector (tstate=0x555555aedc60 <_PyRuntime+282976>, func=0x7ffff6c3f9c0, locals=locals@entry=0x0, 
    args=0x7fffd9b0bd38, argcount=1, kwnames=0x7fffd511fac0) at Python/ceval.c:1806
#36 0x000055555563354f in _PyFunction_Vectorcall (func=<optimized out>, stack=<optimized out>, nargsf=<optimized out>, 
    kwnames=<optimized out>) at Objects/call.c:413
#37 0x0000555555634fcd in _PyObject_VectorcallDictTstate (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, 
    callable=callable@entry=0x7ffff6c3f9c0, args=args@entry=0x7fffffffbf30, nargsf=<optimized out>, nargsf@entry=1, 
    kwargs=kwargs@entry=0x7fffd51acc00) at Objects/call.c:146
#38 0x00005555556350bb in _PyObject_Call_Prepend (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, 
    callable=callable@entry=0x7ffff6c3f9c0, obj=obj@entry=0x7ffff65581d0, args=args@entry=0x555555abe3b8 <_PyRuntime+88248>, 
    kwargs=kwargs@entry=0x7fffd51acc00) at Objects/call.c:504
#39 0x00005555556baf77 in slot_tp_call (self=0x7ffff65581d0, args=0x555555abe3b8 <_PyRuntime+88248>, kwds=0x7fffd51acc00)
    at Objects/typeobject.c:9534
#40 0x00005555556336fa in _PyObject_MakeTpCall (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, 
    callable=callable@entry=0x7ffff65581d0, args=args@entry=0x7ffff7f94a90, nargs=<optimized out>, 
    keywords=keywords@entry=0x7ffff690e9c0) at Objects/call.c:242
#41 0x000055555563394a in _PyObject_VectorcallTstate (tstate=0x555555aedc60 <_PyRuntime+282976>, 
    callable=callable@entry=0x7ffff65581d0, args=args@entry=0x7ffff7f94a90, nargsf=<optimized out>, 
    kwnames=kwnames@entry=0x7ffff690e9c0) at ./Include/internal/pycore_call.h:166
#42 0x00005555556339a3 in PyObject_Vectorcall (callable=callable@entry=0x7ffff65581d0, args=args@entry=0x7ffff7f94a90, 
    nargsf=<optimized out>, kwnames=kwnames@entry=0x7ffff690e9c0) at Objects/call.c:327
#43 0x000055555575acbb in _PyEval_EvalFrameDefault (tstate=0x555555aedc60 <_PyRuntime+282976>, frame=0x7ffff7f94a10, throwflag=0)
    at Python/generated_cases.c.h:1502
#44 0x0000555555766dc6 in _PyEval_EvalFrame (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, frame=<optimized out>, 
    throwflag=throwflag@entry=0) at ./Include/internal/pycore_ceval.h:119
#45 0x0000555555766ee9 in _PyEval_Vector (tstate=0x555555aedc60 <_PyRuntime+282976>, func=0x7ffff6c3f9c0, locals=locals@entry=0x0, 
    args=0x7fffdf93f258, argcount=1, kwnames=0x7ffff6465060) at Python/ceval.c:1806
#46 0x000055555563354f in _PyFunction_Vectorcall (func=<optimized out>, stack=<optimized out>, nargsf=<optimized out>, 
    kwnames=<optimized out>) at Objects/call.c:413
#47 0x0000555555634fcd in _PyObject_VectorcallDictTstate (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, 
    callable=callable@entry=0x7ffff6c3f9c0, args=args@entry=0x7fffffffc2c0, nargsf=<optimized out>, nargsf@entry=1, 
    kwargs=kwargs@entry=0x7ffff5a06180) at Objects/call.c:146
#48 0x00005555556350bb in _PyObject_Call_Prepend (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, 
    callable=callable@entry=0x7ffff6c3f9c0, obj=obj@entry=0x7ffff65582c0, args=args@entry=0x555555abe3b8 <_PyRuntime+88248>, 
    kwargs=kwargs@entry=0x7ffff5a06180) at Objects/call.c:504
#49 0x00005555556baf77 in slot_tp_call (self=0x7ffff65582c0, args=0x555555abe3b8 <_PyRuntime+88248>, kwds=0x7ffff5a06180)
    at Objects/typeobject.c:9534
#50 0x00005555556336fa in _PyObject_MakeTpCall (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, 
    callable=callable@entry=0x7ffff65582c0, args=args@entry=0x7ffff7f94798, nargs=<optimized out>, 
    keywords=keywords@entry=0x7ffff6a339d0) at Objects/call.c:242
#51 0x000055555563394a in _PyObject_VectorcallTstate (tstate=0x555555aedc60 <_PyRuntime+282976>, 
    callable=callable@entry=0x7ffff65582c0, args=args@entry=0x7ffff7f94798, nargsf=<optimized out>, 
    kwnames=kwnames@entry=0x7ffff6a339d0) at ./Include/internal/pycore_call.h:166
#52 0x00005555556339a3 in PyObject_Vectorcall (callable=callable@entry=0x7ffff65582c0, args=args@entry=0x7ffff7f94798, 
    nargsf=<optimized out>, kwnames=kwnames@entry=0x7ffff6a339d0) at Objects/call.c:327
#53 0x000055555575acbb in _PyEval_EvalFrameDefault (tstate=0x555555aedc60 <_PyRuntime+282976>, frame=0x7ffff7f94730, throwflag=0)
    at Python/generated_cases.c.h:1502
#54 0x0000555555766dc6 in _PyEval_EvalFrame (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, frame=<optimized out>, 
    throwflag=throwflag@entry=0) at ./Include/internal/pycore_ceval.h:119
#55 0x0000555555766ee9 in _PyEval_Vector (tstate=0x555555aedc60 <_PyRuntime+282976>, func=0x7ffff6c3f9c0, locals=locals@entry=0x0, 
    args=0x7ffff64db5d8, argcount=1, kwnames=0x7ffff65353c0) at Python/ceval.c:1806
#56 0x000055555563354f in _PyFunction_Vectorcall (func=<optimized out>, stack=<optimized out>, nargsf=<optimized out>, 
    kwnames=<optimized out>) at Objects/call.c:413
#57 0x0000555555634fcd in _PyObject_VectorcallDictTstate (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, 
    callable=callable@entry=0x7ffff6c3f9c0, args=args@entry=0x7fffffffc650, nargsf=<optimized out>, nargsf@entry=1, 
    kwargs=kwargs@entry=0x7ffff647efc0) at Objects/call.c:146
#58 0x00005555556350bb in _PyObject_Call_Prepend (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, 
    callable=callable@entry=0x7ffff6c3f9c0, obj=obj@entry=0x7ffff651b4c0, args=args@entry=0x555555abe3b8 <_PyRuntime+88248>, 
    kwargs=kwargs@entry=0x7ffff647efc0) at Objects/call.c:504
#59 0x00005555556baf77 in slot_tp_call (self=0x7ffff651b4c0, args=0x555555abe3b8 <_PyRuntime+88248>, kwds=0x7ffff647efc0)
    at Objects/typeobject.c:9534
#60 0x00005555556336fa in _PyObject_MakeTpCall (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, 
    callable=callable@entry=0x7ffff651b4c0, args=args@entry=0x7ffff7f94368, nargs=<optimized out>, 
    keywords=keywords@entry=0x7ffff6a500d0) at Objects/call.c:242
#61 0x000055555563394a in _PyObject_VectorcallTstate (tstate=0x555555aedc60 <_PyRuntime+282976>, 
    callable=callable@entry=0x7ffff651b4c0, args=args@entry=0x7ffff7f94368, nargsf=<optimized out>, 
    kwnames=kwnames@entry=0x7ffff6a500d0) at ./Include/internal/pycore_call.h:166
#62 0x00005555556339a3 in PyObject_Vectorcall (callable=callable@entry=0x7ffff651b4c0, args=args@entry=0x7ffff7f94368, 
    nargsf=<optimized out>, kwnames=kwnames@entry=0x7ffff6a500d0) at Objects/call.c:327
#63 0x000055555575acbb in _PyEval_EvalFrameDefault (tstate=0x555555aedc60 <_PyRuntime+282976>, frame=0x7ffff7f942b0, throwflag=0)
    at Python/generated_cases.c.h:1502
#64 0x0000555555766dc6 in _PyEval_EvalFrame (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, frame=<optimized out>, 
    throwflag=throwflag@entry=0) at ./Include/internal/pycore_ceval.h:119
#65 0x0000555555766ee9 in _PyEval_Vector (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, func=func@entry=0x7ffff7c714e0, 
    locals=locals@entry=0x7ffff6f34640, args=args@entry=0x0, argcount=argcount@entry=0, kwnames=kwnames@entry=0x0)
    at Python/ceval.c:1806
#66 0x0000555555766fb2 in PyEval_EvalCode (co=co@entry=0x7ffff650c6f0, globals=globals@entry=0x7ffff6f34640, 
    locals=locals@entry=0x7ffff6f34640) at Python/ceval.c:596
#67 0x000055555574f304 in builtin_exec_impl (module=module@entry=0x7ffff7c3d800, source=0x7ffff650c6f0, globals=0x7ffff6f34640, 
    locals=0x7ffff6f34640, closure=0x0) at Python/bltinmodule.c:1145
#68 0x000055555574f479 in builtin_exec (module=0x7ffff7c3d800, args=<optimized out>, args@entry=0x7ffff7f94180, nargs=nargs@entry=2, 
    kwnames=kwnames@entry=0x0) at Python/clinic/bltinmodule.c.h:556
#69 0x0000555555683d5e in cfunction_vectorcall_FASTCALL_KEYWORDS (func=0x7ffff7c3dd00, args=0x7ffff7f94180, nargsf=<optimized out>, 
    kwnames=0x0) at Objects/methodobject.c:441
#70 0x00005555556338ca in _PyObject_VectorcallTstate (tstate=0x555555aedc60 <_PyRuntime+282976>, 
    callable=callable@entry=0x7ffff7c3dd00, args=args@entry=0x7ffff7f94180, nargsf=9223372036854775810, kwnames=kwnames@entry=0x0)
    at ./Include/internal/pycore_call.h:168
#71 0x00005555556339a3 in PyObject_Vectorcall (callable=callable@entry=0x7ffff7c3dd00, args=args@entry=0x7ffff7f94180, 
    nargsf=<optimized out>, kwnames=kwnames@entry=0x0) at Objects/call.c:327
#72 0x0000555555758f01 in _PyEval_EvalFrameDefault (tstate=0x555555aedc60 <_PyRuntime+282976>, frame=0x7ffff7f940d8, throwflag=0)
    at Python/generated_cases.c.h:813
#73 0x0000555555766dc6 in _PyEval_EvalFrame (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, frame=<optimized out>, 
    throwflag=throwflag@entry=0) at ./Include/internal/pycore_ceval.h:119
#74 0x0000555555766ee9 in _PyEval_Vector (tstate=0x555555aedc60 <_PyRuntime+282976>, func=0x7ffff6fa5f80, locals=locals@entry=0x0, 
    args=0x7ffff6f9f2d8, argcount=2, kwnames=0x0) at Python/ceval.c:1806
#75 0x000055555563354f in _PyFunction_Vectorcall (func=<optimized out>, stack=<optimized out>, nargsf=<optimized out>, 
    kwnames=<optimized out>) at Objects/call.c:413
#76 0x00005555556351c9 in _PyVectorcall_Call (tstate=tstate@entry=0x555555aedc60 <_PyRuntime+282976>, 
    func=0x5555556334f7 <_PyFunction_Vectorcall>, callable=callable@entry=0x7ffff6fa5f80, tuple=tuple@entry=0x7ffff6f9f2c0, 
    kwargs=kwargs@entry=0x0) at Objects/call.c:273
#77 0x00005555556354c8 in _PyObject_Call (tstate=0x555555aedc60 <_PyRuntime+282976>, callable=callable@entry=0x7ffff6fa5f80, 
    args=args@entry=0x7ffff6f9f2c0, kwargs=kwargs@entry=0x0) at Objects/call.c:348
#78 0x0000555555635504 in PyObject_Call (callable=callable@entry=0x7ffff6fa5f80, args=args@entry=0x7ffff6f9f2c0, 
    kwargs=kwargs@entry=0x0) at Objects/call.c:373
#79 0x00005555557f498f in pymain_run_module (modname=<optimized out>, set_argv0=set_argv0@entry=1) at Modules/main.c:349
#80 0x00005555557f58c7 in pymain_run_python (exitcode=exitcode@entry=0x7fffffffce54) at Modules/main.c:690
#81 0x00005555557f5b57 in Py_RunMain () at Modules/main.c:775
#82 0x00005555557f5bd1 in pymain_main (args=args@entry=0x7fffffffceb0) at Modules/main.c:805
#83 0x00005555557f5ca8 in Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at Modules/main.c:829
#84 0x00005555555d48e6 in main (argc=<optimized out>, argv=<optimized out>) at ./Programs/python.c:15

@vstinner
Copy link
Member

One down, more to go

I'm not sure if my "whack-a-mole" approach makes sense :-( Well, I updated my PR to change also ceval.c.

Remaining unpatched code:

$ git grep 'assert.*_Py_IsImmortal\>'
Include/internal/pycore_object.h:// This function should only be used in assertions. Otherwise, _Py_IsImmortal()
Include/internal/pycore_object.h:        assert(_Py_IsImmortal(type));
Include/internal/pycore_object.h:        assert(_Py_IsImmortal(type));

Include/internal/pycore_stackref.h:    assert(_Py_IsImmortal(obj));

Modules/_asynciomodule.c:    assert(_Py_IsImmortal(ret));

Modules/_testcapi/immortal.c:    assert(_Py_IsImmortal(object));

Objects/codeobject.c:    assert(_Py_IsImmortal(entry->value));

Objects/object.c:    assert(!_Py_IsImmortal(op));
Objects/object.c:        assert(_Py_IsImmortal(constants[i]));

Objects/structseq.c:        assert(_Py_IsImmortal(type));
Objects/structseq.c:    assert(_Py_IsImmortal(type));

Objects/typeobject.c:    assert(_Py_IsImmortal((PyObject *)self));

Objects/unicodeobject.c:    assert(!_Py_IsImmortal(s));

Programs/_testembed.c:        assert(_Py_IsImmortal(str1));

Python/crossinterp.c:        assert(_Py_IsImmortal((PyObject *)type));
Python/crossinterp.c:        assert(_Py_IsImmortal((PyObject *)info->builtin));

Python/import.c:    assert(value->def == NULL || _Py_IsImmortal(value->def));

Python/optimizer_symbols.c:    assert(_Py_IsImmortal(val_42));
Python/optimizer_symbols.c:    assert(_Py_IsImmortal(val_43));

@mgorny
Copy link
Contributor Author

mgorny commented Aug 31, 2024

Yeah, makes you wonder if we'd not eventually end up replacing all of them. However, at least this won't happen with qiskit — the newest version of the PR seems to resolve all the crashes (I had to redo the last commit for 3.13).

vstinner added a commit that referenced this issue Sep 2, 2024
Use _Py_IsImmortalLoose() in bytesobject.c, typeobject.c
and ceval.c.
vstinner added a commit to vstinner/cpython that referenced this issue Sep 2, 2024
Use _Py_IsImmortalLoose() in bytesobject.c, typeobject.c
and ceval.c.

(cherry picked from commit f1a0d96)
@vstinner
Copy link
Member

vstinner commented Sep 2, 2024

Yeah, makes you wonder if we'd not eventually end up replacing all of them. However, at least this won't happen with qiskit — the newest version of the PR seems to resolve all the crashes (I had to redo the last commit for 3.13).

Good. I merged my PR.

I also created a backport to Python 3.13: PR gh-123600.

@mgorny
Copy link
Contributor Author

mgorny commented Sep 2, 2024

Thanks a lot!

vstinner added a commit that referenced this issue Sep 2, 2024
gh-123091: Use _Py_IsImmortalLoose() (#123511)

Use _Py_IsImmortalLoose() in bytesobject.c, typeobject.c
and ceval.c.

(cherry picked from commit f1a0d96)
@encukou
Copy link
Member

encukou commented Sep 2, 2024

I guess next week I'll audit all the uses of _Py_IsImmortal.

I sent PR #123602 for the remaining ones.

encukou added a commit that referenced this issue Sep 2, 2024
Switch more _Py_IsImmortal(...) assertions to _Py_IsImmortalLoose(...)

The remaining calls to _Py_IsImmortal are in free-threaded-only code,
initialization of core objects, tests, and guards that fall back to
code that works with mortal objects.
encukou added a commit to encukou/cpython that referenced this issue Sep 3, 2024
Switch more _Py_IsImmortal(...) assertions to _Py_IsImmortalLoose(...)

The remaining calls to _Py_IsImmortal are in free-threaded-only code,
initialization of core objects, tests, and guards that fall back to
code that works with mortal objects.

(cherry picked from commit 57c471a)
encukou added a commit that referenced this issue Sep 3, 2024
Switch more _Py_IsImmortal(...) assertions to _Py_IsImmortalLoose(...)

The remaining calls to _Py_IsImmortal are in free-threaded-only code,
initialization of core objects, tests, and guards that fall back to
code that works with mortal objects.

(cherry picked from commit 57c471a)
@encukou
Copy link
Member

encukou commented Sep 4, 2024

Thanks to everyone involved!
The PRs are merged, so I'll close. Please reopen (or open a new issue) if you find another similar assertion failure.

@encukou encukou closed this as completed Sep 4, 2024
encukou pushed a commit to encukou/cpython that referenced this issue Oct 3, 2024
Use _Py_IsImmortalLoose() in bytesobject.c, typeobject.c
and ceval.c.
encukou added a commit to encukou/cpython that referenced this issue Oct 3, 2024
Switch more _Py_IsImmortal(...) assertions to _Py_IsImmortalLoose(...)

The remaining calls to _Py_IsImmortal are in free-threaded-only code,
initialization of core objects, tests, and guards that fall back to
code that works with mortal objects.

(For this 3.12 backport commit, I re-checked all calls to _Py_IsImmortal;
the changed calls are different from the commits to 3.13 & 3.14.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump
Projects
None yet
Development

No branches or pull requests

7 participants