[BUG]: static numpy array_t leads to segfault on exit on Python 3.12
Les mainteneurs répondent en général sous 4 jours
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 35/100
Piste de recherche
Commencez par reproduire l’échec de Python 3.12 avec le module test_static fourni et comparez-le à Python 3.11, puis inspectez pybind11/numpy.h et la durée de vie du tableau statique Static::PYARRAY(). Vérifiez à la fois la commande de construction de base et la séquence construction/suppression. Le travail est terminé lorsqu’aucun des deux scénarios ne provoque de segmentation fault à la sortie de l’interpréteur ou lors de la suppression et de la recréation d’instances de Static.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Required prerequisites
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- Consider asking first in the Gitter chat room or in a Discussion.
What version (or hash if on master) of pybind11 are you using?
2.13.1
Problem description
Observed behaviour: When exiting a Python script after constructing a bound class with an initialized static pybind11::array_t, there is a segfault calling decref on the array on Python 3.12.
Expected behaviour: No segfault, as is the case on Python < 3.12.
I have tested with several combinations of package version but can definitely confirm that on a Fedora 40 conda env with gxx=14.1.0, numpy=2.0.0 and pybind11=2.13.1 the segfault occurs with Python 3.12 but not 3.11, so this does not appear to be a regression in pybind11.
I compiled the module as follows:
g++ -Wall -shared -fPIC -std=c++17 $(python3 -m pybind11 --includes) test_image.cc -o test_static$(python3-config --extension-suffix)
and tested with:
python -c "from test_static import Static; Static()"
It is possible to defer the problem by adding a destructor like so:
~Static() { PYARRAY().release(); }
... however, this only fixes the trivial example and fails as soon as one instance is deleted, and the following example fails upon constructing a second instance:
python -c "from test_static import Static; x = Static(); del x; y = Static()"
Reproducible example code
#include <cassert>
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
namespace py = pybind11;
using namespace pybind11::literals;
struct Static {
public:
Static() { assert(this->PYARRAY().ndim() == 2); }
py::array_t<double>& PYARRAY() const {
static py::array_t<double> array(py::array::ShapeContainer({1, 1}));
return array;
}
};
PYBIND11_MODULE(test_static, m) {
py::class_<Static, std::shared_ptr<Static>>(m, "Static").def(py::init<>());
}
Is this a regression? Put the last known working version here if it is.
Not a regression in pybind11 but perhaps in CPython?
- Langage dominant
- C++
- Étoiles
- 18k
- Forks
- 2.3k
- Merge moyen
- 5 j 7 h
- PR mergées (30 j)
- 53
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de pybind/pybind11
-
triage
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
Les mainteneurs répondent en général sous 4 jours
-
triage
Difficulté 1/5 Moins d'une heure Accessibilité débutants 62/100
pybind/pybind11#5604 · 1 commentaire ·
Les mainteneurs répondent en général sous 4 jours
-
triage
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
Les mainteneurs répondent en général sous 4 jours
-
docs
Difficulté 2/5 1-3 heures Accessibilité débutants 60/100
pybind/pybind11#747 · 2 commentaires ·
Les mainteneurs répondent en général sous 4 jours
-
array_t::at() returns a misaligned reference when the stride is not a multiple of alignof(T)Peut-être pris @henryiii l’a pris aujourd’hui. Ouverte
Difficulté 4/5 3-5 jours Accessibilité débutants 35/100
Les mainteneurs répondent en général sous 4 jours
Toutes les issues de pybind/pybind11
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
jesdga95/basalt#747 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
[Bug] Windows Ghidra provider rejects a PATH-only JDK: bare `java.exe` probe fails with Win32 87Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
type:bug
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
tenstorrent/tt-umd#4084 ·
Les mainteneurs répondent en général sous 5 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
ToffelsKater/X4_VR#34 ·