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

[py3.13] rustworkx: python: ./Include/internal/pycore_object.h:268: _PyObject_Init: Assertion '_PyType_HasFeature(typeobj, Py_TPFLAGS_HEAPTYPE) || _Py_IsImmortal(typeobj)' failed. #4311

Closed
mgorny opened this issue Jul 4, 2024 · 9 comments
Labels

Comments

@mgorny
Copy link

mgorny commented Jul 4, 2024

Bug Description

Here's another problem that I've seen with a subset of rustworkx. This time I've confirmed that the issue happens both with a debug build made using Python 3.13 and a wheel built using Python 3.8 (i.e. the stable ABI).

The error is:

python: ./Include/internal/pycore_object.h:268: _PyObject_Init: Assertion `_PyType_HasFeature(typeobj, Py_TPFLAGS_HEAPTYPE) || _Py_IsImmortal(typeobj)' failed.
Fatal Python error: Aborted

Steps to Reproduce

  1. Build Python 3.13 --with-assertions.
  2. git clone https://github.com/Qiskit/rustworkx/
  3. Build and install rustworkx and pytest.
  4. python -m pytest tests/digraph/test_adjacency_matrix.py::TestDAGAdjacencyMatrix::test_graph_to_digraph_adjacency_matrix -s

Backtrace

========================================================= test session starts =========================================================
platform linux -- Python 3.13.0a5+, pytest-8.2.2, pluggy-1.5.0
rootdir: /tmp/rustworkx
configfile: pyproject.toml
plugins: forked-1.6.0
collected 1 item                                                                                                                      

tests/digraph/test_adjacency_matrix.py python: ./Include/internal/pycore_object.h:268: _PyObject_Init: Assertion `_PyType_HasFeature(typeobj, Py_TPFLAGS_HEAPTYPE) || _Py_IsImmortal(typeobj)' failed.
Fatal Python error: Aborted

Current thread 0x00007fc6b8da9740 (most recent call first):
  File "/home/mgorny/git/cpython/Lib/unittest/case.py", line 238 in handle
  File "/home/mgorny/git/cpython/Lib/unittest/case.py", line 778 in assertRaises
  File "/tmp/rustworkx/tests/digraph/test_adjacency_matrix.py", line 100 in test_graph_to_digraph_adjacency_matrix
  File "/home/mgorny/git/cpython/Lib/unittest/case.py", line 589 in _callTestMethod
  File "/home/mgorny/git/cpython/Lib/unittest/case.py", line 634 in run
  File "/home/mgorny/git/cpython/Lib/unittest/case.py", line 690 in __call__
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/_pytest/unittest.py", line 344 in runtest
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/_pytest/runner.py", line 173 in pytest_runtest_call
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/pluggy/_callers.py", line 103 in _multicall
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/pluggy/_hooks.py", line 513 in __call__
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/_pytest/runner.py", line 241 in <lambda>
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/_pytest/runner.py", line 341 in from_call
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/_pytest/runner.py", line 240 in call_and_report
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/_pytest/runner.py", line 135 in runtestprotocol
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/_pytest/runner.py", line 116 in pytest_runtest_protocol
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/pluggy/_callers.py", line 103 in _multicall
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/pluggy/_hooks.py", line 513 in __call__
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/_pytest/main.py", line 364 in pytest_runtestloop
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/pluggy/_callers.py", line 103 in _multicall
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/pluggy/_hooks.py", line 513 in __call__
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/_pytest/main.py", line 339 in _main
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/_pytest/main.py", line 285 in wrap_session
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/_pytest/main.py", line 332 in pytest_cmdline_main
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/pluggy/_callers.py", line 103 in _multicall
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/pluggy/_hooks.py", line 513 in __call__
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/_pytest/config/__init__.py", line 178 in main
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/_pytest/config/__init__.py", line 206 in console_main
  File "/tmp/rustworkx/.venv/lib/python3.13/site-packages/pytest/__main__.py", line 7 in <module>
  File "<frozen runpy>", line 88 in _run_code
  File "<frozen runpy>", line 198 in _run_module_as_main

Extension modules: numpy._core._multiarray_umath, numpy._core._multiarray_tests, numpy.linalg._umath_linalg (total: 3)
Aborted (core dumped)



(gdb) bt
#0  0x00007fc6b8e3f5ac in ?? () from /usr/lib64/libc.so.6
#1  0x00007fc6b8de8816 in raise () from /usr/lib64/libc.so.6
#2  0x00005574c156e2ac in faulthandler_fatal_error (signum=6) at ./Modules/faulthandler.c:338
#3  <signal handler called>
#4  0x00007fc6b8e3f5ac in ?? () from /usr/lib64/libc.so.6
#5  0x00007fc6b8de8816 in raise () from /usr/lib64/libc.so.6
#6  0x00007fc6b8dd08fa in abort () from /usr/lib64/libc.so.6
#7  0x00007fc6b8dd081e in ?? () from /usr/lib64/libc.so.6
#8  0x00007fc6b8de0cd6 in __assert_fail () from /usr/lib64/libc.so.6
#9  0x00005574c143ba67 in _PyObject_Init (op=op@entry=0x7fc6b71e1120, typeobj=typeobj@entry=0x5574c17e15a0 <_PyExc_TypeError>)
    at ./Include/internal/pycore_object.h:268
#10 0x00005574c1442757 in _PyType_AllocNoTrack (type=type@entry=0x5574c17e15a0 <_PyExc_TypeError>, nitems=0)
    at Objects/typeobject.c:1908
#11 0x00005574c14427ce in PyType_GenericAlloc (type=0x5574c17e15a0 <_PyExc_TypeError>, nitems=<optimized out>)
    at Objects/typeobject.c:1922
#12 0x00005574c13d9d8d in BaseException_new (type=<optimized out>, args=0x7fc6b7489270, kwds=<optimized out>)
    at Objects/exceptions.c:48
#13 0x00005574c1443bd0 in type_call (self=0x5574c17e15a0 <_PyExc_TypeError>, args=0x7fc6b7489270, kwds=0x0)
    at Objects/typeobject.c:1837
#14 0x00005574c13ca023 in _PyObject_MakeTpCall (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, 
    callable=callable@entry=0x5574c17e15a0 <_PyExc_TypeError>, args=args@entry=0x7ffe47b63e58, nargs=<optimized out>, 
    keywords=keywords@entry=0x0) at Objects/call.c:242
#15 0x00005574c13ca22d in _PyObject_VectorcallTstate (tstate=0x5574c184fce0 <_PyRuntime+264640>, 
    callable=0x5574c17e15a0 <_PyExc_TypeError>, args=args@entry=0x7ffe47b63e58, nargsf=<optimized out>, 
    nargsf@entry=9223372036854775809, kwnames=kwnames@entry=0x0) at ./Include/internal/pycore_call.h:166
#16 0x00005574c13ca2d8 in PyObject_CallOneArg (func=<optimized out>, arg=<optimized out>) at Objects/call.c:395
#17 0x00005574c1502ed1 in _PyErr_CreateException (exception_type=exception_type@entry=0x5574c17e15a0 <_PyExc_TypeError>, 
    value=value@entry=0x7fc6b745da10) at Python/errors.c:44
#18 0x00005574c1502f87 in _PyErr_SetObject (tstate=0x5574c184fce0 <_PyRuntime+264640>, exception=0x5574c17e15a0 <_PyExc_TypeError>, 
    value=0x7fc6b745da10) at Python/errors.c:184
#19 0x00005574c15031c2 in PyErr_SetObject (exception=<optimized out>, value=<optimized out>) at Python/errors.c:250
#20 0x00007fc6b6dd90d3 in pyo3::err::err_state::raise_lazy (lazy=...) at src/err/err_state.rs:236
#21 0x00007fc6b6dd8f08 in pyo3::err::err_state::lazy_into_normalized_ffi_tuple (lazy=...) at src/err/err_state.rs:207
--Type <RET> for more, q to quit, c to continue without paging--c
#22 0x00007fc6b6dd8750 in pyo3::err::err_state::PyErrState::normalize (self=...) at src/err/err_state.rs:132
#23 0x00007fc6b6ded526 in pyo3::err::PyErr::make_normalized (self=0x7ffe47b644f0) at src/err/mod.rs:927
#24 0x00007fc6b6ded42b in pyo3::err::PyErr::normalized (self=0x7ffe47b644f0) at src/err/mod.rs:908
#25 0x00007fc6b6debdde in pyo3::err::PyErr::get_type_bound (self=0x7ffe47b644f0) at src/err/mod.rs:310
#26 0x00007fc6b6df2041 in pyo3::impl_::extract_argument::argument_extraction_error (arg_name=..., error=...)
    at src/impl_/extract_argument.rs:203
#27 0x00007fc6b6b3fd0b in pyo3::impl_::extract_argument::extract_argument<&rustworkx::digraph::PyDiGraph> (obj=0x7ffe47b64670, 
    holder=0x7ffe47b64710, arg_name=...)
    at /home/mgorny/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-0.21.2/src/impl_/extract_argument.rs:123
#28 0x00007fc6b68dde85 in rustworkx::connectivity::__pyfunction_digraph_adjacency_matrix (_slf=0x0, _args=0x7fc6b7548700, 
    _kwargs=0x7fc6b506a000) at src/connectivity/mod.rs:355
#29 0x00007fc6b69b078c in pyo3::impl_::trampoline::cfunction_with_keywords::{closure#0} ()
    at /home/mgorny/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-0.21.2/src/impl_/trampoline.rs:45
#30 0x00007fc6b69b03e9 in pyo3::impl_::trampoline::trampoline::{closure#0}<pyo3::impl_::trampoline::cfunction_with_keywords::{closure_env#0}, *mut pyo3_ffi::object::PyObject> ()
    at /home/mgorny/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-0.21.2/src/impl_/trampoline.rs:187
#31 0x00007fc6b6621cda in std::panicking::try::do_call<pyo3::impl_::trampoline::trampoline::{closure_env#0}<pyo3::impl_::trampoline::cfunction_with_keywords::{closure_env#0}, *mut pyo3_ffi::object::PyObject>, core::result::Result<*mut pyo3_ffi::object::PyObject, pyo3::err::PyErr>> (data=0x7ffe47b64bc0) at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:559
#32 0x00007fc6b662ee1b in __rust_try () from /tmp/rustworkx/rustworkx/rustworkx.cpython-313-x86_64-linux-gnu.so
#33 0x00007fc6b661a920 in std::panicking::try<core::result::Result<*mut pyo3_ffi::object::PyObject, pyo3::err::PyErr>, pyo3::impl_::trampoline::trampoline::{closure_env#0}<pyo3::impl_::trampoline::cfunction_with_keywords::{closure_env#0}, *mut pyo3_ffi::object::PyObject>> (f=...) at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:523
#34 0x00007fc6b663fb4d in std::panic::catch_unwind<pyo3::impl_::trampoline::trampoline::{closure_env#0}<pyo3::impl_::trampoline::cfunction_with_keywords::{closure_env#0}, *mut pyo3_ffi::object::PyObject>, core::result::Result<*mut pyo3_ffi::object::PyObject, pyo3::err::PyErr>> (f=<error reading variable: Cannot access memory at address 0xb288d>)
    at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panic.rs:149
#35 0x00007fc6b69b0229 in pyo3::impl_::trampoline::trampoline<pyo3::impl_::trampoline::cfunction_with_keywords::{closure_env#0}, *mut pyo3_ffi::object::PyObject> (body=...)
    at /home/mgorny/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-0.21.2/src/impl_/trampoline.rs:187
#36 0x00007fc6b6a395ca in pyo3::impl_::trampoline::cfunction_with_keywords (slf=0x0, args=0x7fc6b7548700, kwargs=0x7fc6b506a000, 
    f=0x7fc6b68ddc30 <rustworkx::connectivity::__pyfunction_digraph_adjacency_matrix>)
    at /home/mgorny/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-0.21.2/src/impl_/trampoline.rs:45
#37 0x00007fc6b68ddc1e in rustworkx::connectivity::{impl#12}::_PYO3_DEF::trampoline (_slf=0x0, _args=0x7fc6b7548700, 
    _kwargs=0x7fc6b506a000) at src/connectivity/mod.rs:348
#38 0x00005574c1415905 in cfunction_call (func=func@entry=0x7fc6b7200f40, args=args@entry=0x7fc6b7548700, 
    kwargs=kwargs@entry=0x7fc6b506a000) at Objects/methodobject.c:540
#39 0x00005574c13cbc26 in _PyObject_Call (tstate=0x5574c184fce0 <_PyRuntime+264640>, callable=callable@entry=0x7fc6b7200f40, 
    args=args@entry=0x7fc6b7548700, kwargs=kwargs@entry=0x7fc6b506a000) at Objects/call.c:361
#40 0x00005574c13cbd04 in PyObject_Call (callable=callable@entry=0x7fc6b7200f40, args=args@entry=0x7fc6b7548700, 
    kwargs=kwargs@entry=0x7fc6b506a000) at Objects/call.c:373
#41 0x00005574c14cebe5 in _PyEval_EvalFrameDefault (tstate=<optimized out>, frame=0x7fc6b90956f0, throwflag=0)
    at Python/generated_cases.c.h:1267
#42 0x00005574c14e1e5c in _PyEval_EvalFrame (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, frame=<optimized out>, 
    throwflag=throwflag@entry=0) at ./Include/internal/pycore_ceval.h:114
#43 0x00005574c14e1f89 in _PyEval_Vector (tstate=0x5574c184fce0 <_PyRuntime+264640>, func=0x7fc6b79b0400, locals=locals@entry=0x0, 
    args=0x7fc6b817ef50, argcount=1, kwnames=0x7fc6b750c790) at Python/ceval.c:1807
#44 0x00005574c13c9e7c in _PyFunction_Vectorcall (func=<optimized out>, stack=<optimized out>, nargsf=<optimized out>, 
    kwnames=<optimized out>) at Objects/call.c:413
#45 0x00005574c13cce42 in _PyObject_VectorcallTstate (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, 
    callable=callable@entry=0x7fc6b79b0400, args=args@entry=0x7fc6b817ef50, nargsf=nargsf@entry=1, 
    kwnames=kwnames@entry=0x7fc6b750c790) at ./Include/internal/pycore_call.h:168
#46 0x00005574c13cd02f in method_vectorcall (method=<optimized out>, args=0x7fc6b817ef58, nargsf=<optimized out>, 
    kwnames=0x7fc6b750c790) at Objects/classobject.c:62
#47 0x00005574c13cba72 in _PyVectorcall_Call (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, 
    func=0x5574c13ccec4 <method_vectorcall>, callable=callable@entry=0x7fc6b5988e80, 
    tuple=tuple@entry=0x5574c18225b0 <_PyRuntime+78480>, kwargs=kwargs@entry=0x7fc6b5945440) at Objects/call.c:285
#48 0x00005574c13cbcc8 in _PyObject_Call (tstate=0x5574c184fce0 <_PyRuntime+264640>, callable=callable@entry=0x7fc6b5988e80, 
    args=args@entry=0x5574c18225b0 <_PyRuntime+78480>, kwargs=kwargs@entry=0x7fc6b5945440) at Objects/call.c:348
#49 0x00005574c13cbd04 in PyObject_Call (callable=callable@entry=0x7fc6b5988e80, args=args@entry=0x5574c18225b0 <_PyRuntime+78480>, 
    kwargs=kwargs@entry=0x7fc6b5945440) at Objects/call.c:373
#50 0x00005574c14cebe5 in _PyEval_EvalFrameDefault (tstate=<optimized out>, frame=0x7fc6b9095408, throwflag=0)
    at Python/generated_cases.c.h:1267
#51 0x00005574c14e1e5c in _PyEval_EvalFrame (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, frame=<optimized out>, 
    throwflag=throwflag@entry=0) at ./Include/internal/pycore_ceval.h:114
#52 0x00005574c14e1f89 in _PyEval_Vector (tstate=0x5574c184fce0 <_PyRuntime+264640>, func=0x7fc6b79b05e0, locals=locals@entry=0x0, 
    args=0x7fc6b75346f8, argcount=1, kwnames=0x7fc6b750ffd0) at Python/ceval.c:1807
#53 0x00005574c13c9e7c in _PyFunction_Vectorcall (func=<optimized out>, stack=<optimized out>, nargsf=<optimized out>, 
    kwnames=<optimized out>) at Objects/call.c:413
#54 0x00005574c13cb7cd in _PyObject_VectorcallDictTstate (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, 
    callable=callable@entry=0x7fc6b79b05e0, args=args@entry=0x7ffe47b65460, nargsf=<optimized out>, nargsf@entry=1, 
    kwargs=kwargs@entry=0x7fc6b592e400) at Objects/call.c:146
#55 0x00005574c13cb8bb in _PyObject_Call_Prepend (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, 
    callable=callable@entry=0x7fc6b79b05e0, obj=obj@entry=0x7fc6b50a8910, args=args@entry=0x5574c18225b0 <_PyRuntime+78480>, 
    kwargs=kwargs@entry=0x7fc6b592e400) at Objects/call.c:504
#56 0x00005574c1448be6 in slot_tp_call (self=0x7fc6b50a8910, args=0x5574c18225b0 <_PyRuntime+78480>, kwds=0x7fc6b592e400)
    at Objects/typeobject.c:9179
#57 0x00005574c13ca023 in _PyObject_MakeTpCall (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, 
    callable=callable@entry=0x7fc6b50a8910, args=args@entry=0x7fc6b90953e8, nargs=<optimized out>, 
    keywords=keywords@entry=0x7fc6b76a6920) at Objects/call.c:242
#58 0x00005574c13ca22d in _PyObject_VectorcallTstate (tstate=0x5574c184fce0 <_PyRuntime+264640>, 
    callable=callable@entry=0x7fc6b50a8910, args=args@entry=0x7fc6b90953e8, nargsf=<optimized out>, 
    kwnames=kwnames@entry=0x7fc6b76a6920) at ./Include/internal/pycore_call.h:166
#59 0x00005574c13ca286 in PyObject_Vectorcall (callable=callable@entry=0x7fc6b50a8910, args=args@entry=0x7fc6b90953e8, 
    nargsf=<optimized out>, kwnames=kwnames@entry=0x7fc6b76a6920) at Objects/call.c:327
#60 0x00005574c14cf31d in _PyEval_EvalFrameDefault (tstate=<optimized out>, frame=0x7fc6b9095370, throwflag=0)
    at Python/generated_cases.c.h:1414
#61 0x00005574c14e1e5c in _PyEval_EvalFrame (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, frame=<optimized out>, 
    throwflag=throwflag@entry=0) at ./Include/internal/pycore_ceval.h:114
#62 0x00005574c14e1f89 in _PyEval_Vector (tstate=0x5574c184fce0 <_PyRuntime+264640>, func=0x7fc6b7d53ce0, locals=locals@entry=0x0, 
    args=0x7fc6b75344f8, argcount=1, kwnames=0x7fc6b7584c40) at Python/ceval.c:1807
#63 0x00005574c13c9e7c in _PyFunction_Vectorcall (func=<optimized out>, stack=<optimized out>, nargsf=<optimized out>, 
    kwnames=<optimized out>) at Objects/call.c:413
#64 0x00005574c13cb7cd in _PyObject_VectorcallDictTstate (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, 
    callable=callable@entry=0x7fc6b7d53ce0, args=args@entry=0x7ffe47b65820, nargsf=<optimized out>, nargsf@entry=1, 
    kwargs=kwargs@entry=0x7fc6b597ce80) at Objects/call.c:146
#65 0x00005574c13cb8bb in _PyObject_Call_Prepend (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, 
    callable=callable@entry=0x7fc6b7d53ce0, obj=obj@entry=0x7fc6b76cc630, args=args@entry=0x5574c18225b0 <_PyRuntime+78480>, 
    kwargs=kwargs@entry=0x7fc6b597ce80) at Objects/call.c:504
#66 0x00005574c1448be6 in slot_tp_call (self=self@entry=0x7fc6b76cc630, args=args@entry=0x5574c18225b0 <_PyRuntime+78480>, 
    kwds=kwds@entry=0x7fc6b597ce80) at Objects/typeobject.c:9179
#67 0x00005574c13cbc26 in _PyObject_Call (tstate=0x5574c184fce0 <_PyRuntime+264640>, callable=callable@entry=0x7fc6b76cc630, 
    args=args@entry=0x5574c18225b0 <_PyRuntime+78480>, kwargs=kwargs@entry=0x7fc6b597ce80) at Objects/call.c:361
#68 0x00005574c13cbd04 in PyObject_Call (callable=callable@entry=0x7fc6b76cc630, args=args@entry=0x5574c18225b0 <_PyRuntime+78480>, 
    kwargs=kwargs@entry=0x7fc6b597ce80) at Objects/call.c:373
#69 0x00005574c14cebe5 in _PyEval_EvalFrameDefault (tstate=<optimized out>, frame=0x7fc6b9095008, throwflag=0)
    at Python/generated_cases.c.h:1267
#70 0x00005574c14e1e5c in _PyEval_EvalFrame (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, frame=<optimized out>, 
    throwflag=throwflag@entry=0) at ./Include/internal/pycore_ceval.h:114
#71 0x00005574c14e1f89 in _PyEval_Vector (tstate=0x5574c184fce0 <_PyRuntime+264640>, func=0x7fc6b7d53ce0, locals=locals@entry=0x0, 
    args=0x7fc6b7536ff8, argcount=1, kwnames=0x7fc6b753eac0) at Python/ceval.c:1807
#72 0x00005574c13c9e7c in _PyFunction_Vectorcall (func=<optimized out>, stack=<optimized out>, nargsf=<optimized out>, 
    kwnames=<optimized out>) at Objects/call.c:413
#73 0x00005574c13cb7cd in _PyObject_VectorcallDictTstate (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, 
    callable=callable@entry=0x7fc6b7d53ce0, args=args@entry=0x7ffe47b65ba0, nargsf=<optimized out>, nargsf@entry=1, 
    kwargs=kwargs@entry=0x7fc6b76d89c0) at Objects/call.c:146
#74 0x00005574c13cb8bb in _PyObject_Call_Prepend (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, 
    callable=callable@entry=0x7fc6b7d53ce0, obj=obj@entry=0x7fc6b76cc7c0, args=args@entry=0x5574c18225b0 <_PyRuntime+78480>, 
    kwargs=kwargs@entry=0x7fc6b76d89c0) at Objects/call.c:504
#75 0x00005574c1448be6 in slot_tp_call (self=0x7fc6b76cc7c0, args=0x5574c18225b0 <_PyRuntime+78480>, kwds=0x7fc6b76d89c0)
    at Objects/typeobject.c:9179
#76 0x00005574c13ca023 in _PyObject_MakeTpCall (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, 
    callable=callable@entry=0x7fc6b76cc7c0, args=args@entry=0x7fc6b9094a90, nargs=<optimized out>, 
    keywords=keywords@entry=0x7fc6b7a8ad80) at Objects/call.c:242
#77 0x00005574c13ca22d in _PyObject_VectorcallTstate (tstate=0x5574c184fce0 <_PyRuntime+264640>, 
    callable=callable@entry=0x7fc6b76cc7c0, args=args@entry=0x7fc6b9094a90, nargsf=<optimized out>, 
    kwnames=kwnames@entry=0x7fc6b7a8ad80) at ./Include/internal/pycore_call.h:166
#78 0x00005574c13ca286 in PyObject_Vectorcall (callable=callable@entry=0x7fc6b76cc7c0, args=args@entry=0x7fc6b9094a90, 
    nargsf=<optimized out>, kwnames=kwnames@entry=0x7fc6b7a8ad80) at Objects/call.c:327
#79 0x00005574c14cf31d in _PyEval_EvalFrameDefault (tstate=<optimized out>, frame=0x7fc6b9094a10, throwflag=0)
    at Python/generated_cases.c.h:1414
#80 0x00005574c14e1e5c in _PyEval_EvalFrame (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, frame=<optimized out>, 
    throwflag=throwflag@entry=0) at ./Include/internal/pycore_ceval.h:114
#81 0x00005574c14e1f89 in _PyEval_Vector (tstate=0x5574c184fce0 <_PyRuntime+264640>, func=0x7fc6b7d53ce0, locals=locals@entry=0x0, 
    args=0x7fc6b7536d78, argcount=1, kwnames=0x7fc6b7585120) at Python/ceval.c:1807
#82 0x00005574c13c9e7c in _PyFunction_Vectorcall (func=<optimized out>, stack=<optimized out>, nargsf=<optimized out>, 
    kwnames=<optimized out>) at Objects/call.c:413
#83 0x00005574c13cb7cd in _PyObject_VectorcallDictTstate (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, 
    callable=callable@entry=0x7fc6b7d53ce0, args=args@entry=0x7ffe47b65f60, nargsf=<optimized out>, nargsf@entry=1, 
    kwargs=kwargs@entry=0x7fc6b7564a40) at Objects/call.c:146
#84 0x00005574c13cb8bb in _PyObject_Call_Prepend (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, 
    callable=callable@entry=0x7fc6b7d53ce0, obj=obj@entry=0x7fc6b76cc8b0, args=args@entry=0x5574c18225b0 <_PyRuntime+78480>, 
    kwargs=kwargs@entry=0x7fc6b7564a40) at Objects/call.c:504
#85 0x00005574c1448be6 in slot_tp_call (self=0x7fc6b76cc8b0, args=0x5574c18225b0 <_PyRuntime+78480>, kwds=0x7fc6b7564a40)
    at Objects/typeobject.c:9179
#86 0x00005574c13ca023 in _PyObject_MakeTpCall (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, 
    callable=callable@entry=0x7fc6b76cc8b0, args=args@entry=0x7fc6b9094798, nargs=<optimized out>, 
    keywords=keywords@entry=0x7fc6b7c03f70) at Objects/call.c:242
#87 0x00005574c13ca22d in _PyObject_VectorcallTstate (tstate=0x5574c184fce0 <_PyRuntime+264640>, 
    callable=callable@entry=0x7fc6b76cc8b0, args=args@entry=0x7fc6b9094798, nargsf=<optimized out>, 
    kwnames=kwnames@entry=0x7fc6b7c03f70) at ./Include/internal/pycore_call.h:166
#88 0x00005574c13ca286 in PyObject_Vectorcall (callable=callable@entry=0x7fc6b76cc8b0, args=args@entry=0x7fc6b9094798, 
    nargsf=<optimized out>, kwnames=kwnames@entry=0x7fc6b7c03f70) at Objects/call.c:327
#89 0x00005574c14cf31d in _PyEval_EvalFrameDefault (tstate=<optimized out>, frame=0x7fc6b9094730, throwflag=0)
    at Python/generated_cases.c.h:1414
#90 0x00005574c14e1e5c in _PyEval_EvalFrame (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, frame=<optimized out>, 
    throwflag=throwflag@entry=0) at ./Include/internal/pycore_ceval.h:114
#91 0x00005574c14e1f89 in _PyEval_Vector (tstate=0x5574c184fce0 <_PyRuntime+264640>, func=0x7fc6b7d53ce0, locals=locals@entry=0x0, 
    args=0x7fc6b7534278, argcount=1, kwnames=0x7fc6b754b5e0) at Python/ceval.c:1807
#92 0x00005574c13c9e7c in _PyFunction_Vectorcall (func=<optimized out>, stack=<optimized out>, nargsf=<optimized out>, 
    kwnames=<optimized out>) at Objects/call.c:413
#93 0x00005574c13cb7cd in _PyObject_VectorcallDictTstate (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, 
    callable=callable@entry=0x7fc6b7d53ce0, args=args@entry=0x7ffe47b66320, nargsf=<optimized out>, nargsf@entry=1, 
    kwargs=kwargs@entry=0x7fc6b759a480) at Objects/call.c:146
#94 0x00005574c13cb8bb in _PyObject_Call_Prepend (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, 
    callable=callable@entry=0x7fc6b7d53ce0, obj=obj@entry=0x7fc6b7697ab0, args=args@entry=0x5574c18225b0 <_PyRuntime+78480>, 
    kwargs=kwargs@entry=0x7fc6b759a480) at Objects/call.c:504
#95 0x00005574c1448be6 in slot_tp_call (self=0x7fc6b7697ab0, args=0x5574c18225b0 <_PyRuntime+78480>, kwds=0x7fc6b759a480)
    at Objects/typeobject.c:9179
#96 0x00005574c13ca023 in _PyObject_MakeTpCall (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, 
    callable=callable@entry=0x7fc6b7697ab0, args=args@entry=0x7fc6b9094368, nargs=<optimized out>, 
    keywords=keywords@entry=0x7fc6b7c2c7f0) at Objects/call.c:242
#97 0x00005574c13ca22d in _PyObject_VectorcallTstate (tstate=0x5574c184fce0 <_PyRuntime+264640>, 
    callable=callable@entry=0x7fc6b7697ab0, args=args@entry=0x7fc6b9094368, nargsf=<optimized out>, 
    kwnames=kwnames@entry=0x7fc6b7c2c7f0) at ./Include/internal/pycore_call.h:166
#98 0x00005574c13ca286 in PyObject_Vectorcall (callable=callable@entry=0x7fc6b7697ab0, args=args@entry=0x7fc6b9094368, 
    nargsf=<optimized out>, kwnames=kwnames@entry=0x7fc6b7c2c7f0) at Objects/call.c:327
#99 0x00005574c14cf31d in _PyEval_EvalFrameDefault (tstate=<optimized out>, frame=0x7fc6b90942b0, throwflag=0)
    at Python/generated_cases.c.h:1414
#100 0x00005574c14e1e5c in _PyEval_EvalFrame (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, frame=<optimized out>, 
    throwflag=throwflag@entry=0) at ./Include/internal/pycore_ceval.h:114
#101 0x00005574c14e1f89 in _PyEval_Vector (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, func=func@entry=0x7fc6b81d1440, 
    locals=locals@entry=0x7fc6b8034400, args=args@entry=0x0, argcount=argcount@entry=0, kwnames=kwnames@entry=0x0)
    at Python/ceval.c:1807
#102 0x00005574c14e2052 in PyEval_EvalCode (co=co@entry=0x7fc6b76c0150, globals=globals@entry=0x7fc6b8034400, 
    locals=locals@entry=0x7fc6b8034400) at Python/ceval.c:600
#103 0x00005574c14c441b in builtin_exec_impl (module=module@entry=0x7fc6b819e2a0, source=0x7fc6b76c0150, globals=0x7fc6b8034400, 
    locals=0x7fc6b8034400, closure=0x0) at Python/bltinmodule.c:1132
#104 0x00005574c14c452c in builtin_exec (module=0x7fc6b819e2a0, args=<optimized out>, args@entry=0x7fc6b9094180, nargs=nargs@entry=2, 
    kwnames=kwnames@entry=0x0) at Python/clinic/bltinmodule.c.h:521
#105 0x00005574c14152bc in cfunction_vectorcall_FASTCALL_KEYWORDS (func=0x7fc6b819e7a0, args=0x7fc6b9094180, nargsf=<optimized out>, 
    kwnames=0x0) at Objects/methodobject.c:441
#106 0x00005574c13ca1ad in _PyObject_VectorcallTstate (tstate=0x5574c184fce0 <_PyRuntime+264640>, 
    callable=callable@entry=0x7fc6b819e7a0, args=args@entry=0x7fc6b9094180, nargsf=9223372036854775810, kwnames=kwnames@entry=0x0)
    at ./Include/internal/pycore_call.h:168
#107 0x00005574c13ca286 in PyObject_Vectorcall (callable=callable@entry=0x7fc6b819e7a0, args=args@entry=0x7fc6b9094180, 
    nargsf=<optimized out>, kwnames=kwnames@entry=0x0) at Objects/call.c:327
#108 0x00005574c14cd8f3 in _PyEval_EvalFrameDefault (tstate=<optimized out>, frame=0x7fc6b90940d8, throwflag=0)
    at Python/generated_cases.c.h:813
#109 0x00005574c14e1e5c in _PyEval_EvalFrame (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, frame=<optimized out>, 
    throwflag=throwflag@entry=0) at ./Include/internal/pycore_ceval.h:114
#110 0x00005574c14e1f89 in _PyEval_Vector (tstate=0x5574c184fce0 <_PyRuntime+264640>, func=0x7fc6b80e25c0, locals=locals@entry=0x0, 
    args=0x7fc6b80d3658, argcount=2, kwnames=0x0) at Python/ceval.c:1807
#111 0x00005574c13c9e7c in _PyFunction_Vectorcall (func=<optimized out>, stack=<optimized out>, nargsf=<optimized out>, 
    kwnames=<optimized out>) at Objects/call.c:413
#112 0x00005574c13cb9c9 in _PyVectorcall_Call (tstate=tstate@entry=0x5574c184fce0 <_PyRuntime+264640>, 
    func=0x5574c13c9e24 <_PyFunction_Vectorcall>, callable=callable@entry=0x7fc6b80e25c0, tuple=tuple@entry=0x7fc6b80d3640, 
    kwargs=kwargs@entry=0x0) at Objects/call.c:273
#113 0x00005574c13cbcc8 in _PyObject_Call (tstate=0x5574c184fce0 <_PyRuntime+264640>, callable=callable@entry=0x7fc6b80e25c0, 
    args=args@entry=0x7fc6b80d3640, kwargs=kwargs@entry=0x0) at Objects/call.c:348
#114 0x00005574c13cbd04 in PyObject_Call (callable=callable@entry=0x7fc6b80e25c0, args=args@entry=0x7fc6b80d3640, 
    kwargs=kwargs@entry=0x0) at Objects/call.c:373
#115 0x00005574c156a71b in pymain_run_module (modname=<optimized out>, set_argv0=set_argv0@entry=1) at Modules/main.c:297
#116 0x00005574c156b21f in pymain_run_python (exitcode=exitcode@entry=0x7ffe47b66b84) at Modules/main.c:622
#117 0x00005574c156b4af in Py_RunMain () at Modules/main.c:707
#118 0x00005574c156b529 in pymain_main (args=args@entry=0x7ffe47b66be0) at Modules/main.c:737
#119 0x00005574c156b600 in Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at Modules/main.c:761
#120 0x00005574c136d8a6 in main (argc=<optimized out>, argv=<optimized out>) at ./Programs/python.c:15
(gdb) up 9
#9  0x00005574c143ba67 in _PyObject_Init (op=op@entry=0x7fc6b71e1120, typeobj=typeobj@entry=0x5574c17e15a0 <_PyExc_TypeError>)
    at ./Include/internal/pycore_object.h:268
268	    assert(_PyType_HasFeature(typeobj, Py_TPFLAGS_HEAPTYPE) || _Py_IsImmortal(typeobj));
(gdb) p typeobj
$2 = (PyTypeObject *) 0x5574c17e15a0 <_PyExc_TypeError>

Your operating system and version

Gentoo Linux amd64

Your Python version (python --version)

3.13.0b3+ (with python/cpython#121358)

Your Rust version (rustc --version)

rustc 1.79.0 (129f3b996 2024-06-10) (gentoo)

Your PyO3 version

0.21.2

How did you install python? Did you use a virtualenv?

Built from source, used a pure venv without system site-packages.

Additional Info

According to bisect, it's caused by python/cpython@c32dc47. CC-ing @markshannon, since I suspect this change actually broke the stable ABI (presuming PyO3 implemented it correctly).

@mgorny mgorny added the bug label Jul 4, 2024
@davidhewitt
Copy link
Member

It looks to me like what's likely happened is a PyO3 extension using the 3.8 stable ABI has called Py_INCREF on the PyExc_TypeError type object, and that's caused the offending assertion to fail.

Very similar situation to #4309 (comment), I think. The understanding there is that PyO3 is doing the correct thing.

@mgorny
Copy link
Author

mgorny commented Jul 5, 2024

I'm a bit worried how many similar issues are we going to discover in 3.13…

@mgorny
Copy link
Author

mgorny commented Jul 7, 2024

Interesting enough, this seems to happen on a code path specific to Python < 3.12. If I use abi3-py312 instead, I don't get a crash anymore.

@davidhewitt
Copy link
Member

That sounds correct. From Python 3.12 the stable ABI was switched to use a function call to do reference counting (Py_IncRef) rather than directly modify reference counts in extensions. The function call will respect immortality.

One option we have is to change our implementation of the stable ABI for older versions to also use the function call. This will come at a performance cost, but given that those projects will hit that performance cost anyway when they upgrade to minimum version of 3.12 we'd just be bringing that change forward.

(That said, CPython is currently failing assertions against the older stable ABI so others in the C/C++ ecosystem will likely hit this too.)

@mgorny
Copy link
Author

mgorny commented Jul 9, 2024

Given no reply from the committer I've CC-ed here, I'll file a bug report on the CPython bug tracker now.

@mgorny
Copy link
Author

mgorny commented Jul 9, 2024

Filed python/cpython#121528.

@mgorny
Copy link
Author

mgorny commented Jul 10, 2024

@davidhewitt, could you take a look at python/cpython#121528 (comment) and below, please? I'm not sure if it's because my reproducer isn't accurate, or PyO3 actually did something outside of specified stable ABI.

@davidhewitt
Copy link
Member

Sure, commented on there.

@davidhewitt
Copy link
Member

Looks like the upstream issue is resolved, so I will close here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants