Skip to content

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

Closed
@mgorny

Description

@mgorny

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

Activity

added
type-crashA hard crash of the interpreter, possibly with a core dump
on Aug 17, 2024
ZeroIntensity

ZeroIntensity commented on Aug 17, 2024

@ZeroIntensity
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

ZeroIntensity commented on Aug 17, 2024

@ZeroIntensity
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

mgorny commented on Aug 17, 2024

@mgorny
ContributorAuthor

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

ZeroIntensity commented on Aug 17, 2024

@ZeroIntensity
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

mgorny commented on Aug 17, 2024

@mgorny
ContributorAuthor

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

ZeroIntensity commented on Aug 17, 2024

@ZeroIntensity
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.

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.` on Aug 17, 2024
ZeroIntensity

ZeroIntensity commented on Aug 17, 2024

@ZeroIntensity
Member

@picnixz this is interpreter-core as well.

davidhewitt

davidhewitt commented on Aug 17, 2024

@davidhewitt
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

mtreinish commented on Aug 21, 2024

@mtreinish

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

encukou commented on Aug 30, 2024

@encukou
Member

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

vstinner commented on Aug 30, 2024

@vstinner
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.

25 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-crashA hard crash of the interpreter, possibly with a core dump

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

      Participants

      @mgorny@vstinner@encukou@davidhewitt@mtreinish

      Issue actions

        Stable ABI: `Objects/bytesobject.c:122: PyBytes_FromStringAndSize: Assertion '_Py_IsImmortal(op)' failed.` · Issue #123091 · python/cpython