[BUG]: static numpy array_t leads to segfault on exit on Python 3.12
I maintainer di solito rispondono entro 4 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Inizia riproducendo il malfunzionamento di Python 3.12 con il modulo test_static fornito e confrontalo con Python 3.11, quindi esamina pybind11/numpy.h e il ciclo di vita dell’array statico Static::PYARRAY(). Verifica sia il comando di costruzione di base sia la sequenza di costruzione/eliminazione. Il lavoro è completato quando nessuno dei due scenari causa un segmentation fault all’uscita dell’interprete o durante l’eliminazione e la ricreazione di istanze di Static.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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?
- Lingua principale
- C++
- Stelle
- 18k
- Fork
- 2.3k
- Merge medio
- 5g 7h
- PR unite (30g)
- 53
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di pybind/pybind11
-
triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 4 giorni
-
triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
pybind/pybind11#5604 · 1 commento ·
I maintainer di solito rispondono entro 4 giorni
-
triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 4 giorni
-
docs
Difficoltà 2/5 1-3 ore Idoneità per principianti 60/100
pybind/pybind11#747 · 2 commenti ·
I maintainer di solito rispondono entro 4 giorni
-
array_t::at() returns a misaligned reference when the stride is not a multiple of alignof(T)Forse già presa @henryiii l’ha presa oggi. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
I maintainer di solito rispondono entro 4 giorni
Tutte le issue di pybind/pybind11
Issue simili
-
[Bug] Windows Ghidra provider rejects a PATH-only JDK: bare `java.exe` probe fails with Win32 87Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
type:bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
tenstorrent/tt-umd#4084 ·
I maintainer di solito rispondono entro 5 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
ToffelsKater/X4_VR#34 ·
-
difficulty:easy prio:low refactor
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
NatronGitHub/openfx-supportext#220 ·
I maintainer di solito rispondono entro 1 giorno