Description
Describe the issue:
Numpy 2.1.3 works fine but with 2.2.0 the interpreter segfaults at exit.
Both Python 3.13.0t and 3.13.1t segfault at exit, both 3.13.0 and 3.13.1 do not.
I can reproduce this on macOS (amd64), Debian 11 (amd64) and Debian 12 (arm64). However also other combinations might be affected.
All the interpreters are built in debug mode with pyenv, ex. pyenv install -g 3.13.1t
. Did not check if non-debug builds are affected as well. Python 3.13.1t non-debug (pyenv install 3.13.1t
), at least on macOS, does not exhibit the segfault.
The discriminating Python build options seem to be:
- debug mode
- free threading
Reproduce the code example:
import numpy
Error message (from gdb on Debian 12 arm64):
Thread 1 "python3" received signal SIGSEGV, Segmentation fault.
__GI___libc_free (mem=<optimized out>) at ./malloc/malloc.c:3362
3362 ./malloc/malloc.c: No such file or directory.
(gdb) bt
#0 __GI___libc_free (mem=<optimized out>) at ./malloc/malloc.c:3362
#1 0x0000fffff447e5ac in ufunc_dealloc ()
from /home/cavok/.pyenv/versions/3.13.1t-debug/lib/python3.13t/site-packages/numpy/_core/_multiarray_umath.cpython-313t-aarch64-linux-gnu.so
#2 0x0000fffff799daf8 in _Py_Dealloc (op=0x2000f4d1a50) at Objects/object.c:2918
#3 0x0000fffff7999794 in _Py_MergeZeroLocalRefcount (op=0x2000f4d1a50) at Objects/object.c:423
#4 0x0000fffff7972ea0 in Py_DECREF (filename=0xfffff7c918f8 "./Include/object.h", lineno=1042, op=0x2000f4d1a50) at ./Include/object.h:892
#5 0x0000fffff7972f1c in Py_XDECREF (op=0x2000f4d1a50) at ./Include/object.h:1042
#6 0x0000fffff79753dc in dictkeys_decref (interp=0xfffff7f10280 <_PyRuntime+128704>, dk=0x2000f858c10, use_qsbr=false) at Objects/dictobject.c:496
#7 0x0000fffff797c284 in dict_dealloc (self=0x2000f78fcd0) at Objects/dictobject.c:3179
#8 0x0000fffff799daf8 in _Py_Dealloc (op=0x2000f78fcd0) at Objects/object.c:2918
#9 0x0000fffff7999794 in _Py_MergeZeroLocalRefcount (op=0x2000f78fcd0) at Objects/object.c:423
#10 0x0000fffff7b38344 in Py_DECREF (filename=0xfffff7d023d8 "./Include/object.h", lineno=1042, op=0x2000f78fcd0) at ./Include/object.h:892
#11 0x0000fffff7b383c0 in Py_XDECREF (op=0x2000f78fcd0) at ./Include/object.h:1042
#12 0x0000fffff7b3adb8 in del_cached_m_dict (value=0xaaaaaab10780) at Python/import.c:1119
#13 0x0000fffff7b3aeac in del_extensions_cache_value (value=0xaaaaaab10780) at Python/import.c:1149
#14 0x0000fffff7b37d00 in _Py_hashtable_destroy_entry (ht=0xaaaaaaad7e50, entry=0xaaaaaab107e0) at Python/hashtable.c:385
#15 0x0000fffff7b37e1c in _Py_hashtable_destroy (ht=0xaaaaaaad7e50) at Python/hashtable.c:417
#16 0x0000fffff7b3b7f0 in _extensions_cache_clear_all () at Python/import.c:1452
#17 0x0000fffff7b40d98 in _PyImport_Fini () at Python/import.c:4014
#18 0x0000fffff7b754f8 in _Py_Finalize (runtime=0xfffff7ef0bc0 <_PyRuntime>) at Python/pylifecycle.c:2129
#19 0x0000fffff7b7557c in Py_FinalizeEx () at Python/pylifecycle.c:2215
#20 0x0000fffff7bb98a0 in Py_RunMain () at Modules/main.c:777
#21 0x0000fffff7bb9938 in pymain_main (args=0xfffffffff2c0) at Modules/main.c:805
#22 0x0000fffff7bb99ac in Py_BytesMain (argc=6, argv=0xfffffffff478) at Modules/main.c:829
#23 0x0000aaaaaaaa0970 in main (argc=6, argv=0xfffffffff478) at ./Programs/python.c:15
Python and NumPy Versions:
3.13.1 experimental free-threading build (main, Dec 9 2024, 11:53:27) [Clang 16.0.0 (clang-1600.0.26.4)]
2.2.0
Context for the issue:
This affects the Pygolo Project CI pipeline (logs) which has a minimal interoperability extension test based on Numpy. I will pin the release of Numpy so to use 2.1.3 but I'll be happy to revert that as soon as this bug is fixed.