Closed
Description
Describe the issue:
numpy segfaults on import with current CPython main.
Reproduce the code example:
import numpy as np
Error message:
$ python
Python 3.12.0a7+ (heads/main:46f1c78eeb, May 13 2023, 16:09:15) [GCC 13.1.1 20230429] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
Segmentation fault (core dumped)
Runtime information:
Due to segfault on import can not get this 🤣
I can reproduce this with the ~current main branch of numpy + current cython master branch or with the lastest stable cython (0.29.31) + numpy (1.24.x) from pypi.
discovered via https://github.com/tacaswell/build_the_world
Context for the issue:
I bisected this back to
$ git bisect bad
de64e7561680fdc5358001e9488091e75d4174a3 is the first bad commit
commit de64e7561680fdc5358001e9488091e75d4174a3
Author: Eric Snow <ericsnowcurrently@gmail.com>
Date: Tue May 2 21:30:03 2023 -0600
gh-94673: More Per-Interpreter Fields for Builtin Static Types (gh-103912)
his involves moving tp_dict, tp_bases, and tp_mro to PyInterpreterState, in the same way we did for tp_subclasses. Those three fields are effectively const for builtin static types (unlike tp_subclasses). In theory we only need to make their values immortal, along with their contents. However, that isn't such a simple proposition. (See gh-103823.) In the meantime the simplest solution is to move the fields into the interpreter.
One alternative is to statically allocate the values, but that's its own can of worms.
Include/internal/pycore_typeobject.h | 7 ++
Modules/_abc.c | 1 +
Modules/gcmodule.c | 31 +----
Objects/structseq.c | 9 +-
Objects/typeobject.c | 223 +++++++++++++++++++++++++++--------
5 files changed, 185 insertions(+), 86 deletions(-)
which came in via python/cpython#103912