[BUG] calling multiple pybind11 scoped env which calls cppyy
Les mainteneurs répondent en général sous 3 jours
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 28/100
Piste de recherche
Reproduisez le deuxième appel de Test002 dans main.cpp, en particulier autour des lignes 32 et 147, en utilisant la configuration Python embarqué et cppyy présentée. Lisez pybind11::exec et pybind11::eval dans eval.h en parallèle de la trace du crash. Le travail est terminé lorsque la même opération peut être appelée plusieurs fois sans l’abandon invalid-size signalé, avec une vérification de non-régression pour les appels répétés.
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.6
Problem description
i have embedded python with my QT (c++) solution. i call a c++ function which uses pybind11 to get me into python, which in turn sets up a cppyy encapsualtion of a simpe c++ function. it works fine, but call it again it crashes. below is the crash report
"
Hello, World!
['/home/simon/Desktop/Code/VirtEnv/lib/python3.12/site-packages/', '/home/simon/Code/QT/Test_pybind11/Test_pybind11_cppyy_001/', '', '/usr/lib/python312.zip', '/usr/lib/python3.12', '/usr/lib/python3.12/lib-dynload', '/usr/local/lib/python3.12/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.12/dist-packages']
here
there
done
free(): invalid size
*** Break *** abort
#0 0x00007f9cb8710893 in __GI___wait4 (pid=4609, stat_loc=stat_loc
entry=0x7fff23a04f68, options=options
entry=0, usage=usage
entry=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:30
#1 0x00007f9cb87109e7 in __GI___waitpid (pid=, stat_loc=stat_loc
entry=0x7fff23a04f68, options=options
entry=0) at ./posix/waitpid.c:38
#2 0x00007f9cb866891b in do_system (line=) at ../sysdeps/posix/system.c:172
#3 0x00007f9cb5ba1c15 in CppyyLegacy::TUnixSystem::StackTrace() () from /home/simon/Desktop/Code/VirtEnv/lib/python3.12/site-packages/cppyy_backend/lib/libCoreLegacy.so
#4 0x00007f9cb5cd94bf in (anonymous namespace)::do_trace (sig=5) at src/clingwrapper.cxx:249
#5 (anonymous namespace)::TExceptionHandlerImp::HandleException (this=, sig=5) at src/clingwrapper.cxx:262
.....
#42 0x00007f9cb8ef0ae6 in ?? () from /lib/x86_64-linux-gnu/libpython3.12.so.1.0
#43 0x00007f9cb8ef0bf9 in ?? () from /lib/x86_64-linux-gnu/libpython3.12.so.1.0
#44 0x00007f9cb8ef41bf in PyRun_StringFlags () from /lib/x86_64-linux-gnu/libpython3.12.so.1.0
#45 0x000055ea7e523055 in pybind11::eval<(pybind11::eval_mode)2> (expr=..., global=..., local=...) at /usr/include/pybind11/eval.h:74
#46 0x000055ea7e4fcb2b in pybind11::exec (expr=..., global=..., local=...) at /usr/include/pybind11/eval.h:89
#47 0x000055ea7e4fb462 in Test002 () at /home/simon/Code/QT/Test_pybind11/Test_pybind11_cppyy_001/main.cpp:147
#48 0x000055ea7e4fb1bb in main (argc=1, argv=0x7fff23a09058) at /home/simon/Code/QT/Test_pybind11/Test_pybind11_cppyy_001/main.cpp:32
*** Break *** abort
#0 0x00007f9cb8710893 in __GI___wait4 (pid=4848, stat_loc=stat_loc
entry=0x7fff23a04f68, options=options
entry=0, usage=usage
entry=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:30
#1 0x00007f9cb87109e7 in __GI___waitpid (pid=, stat_loc=stat_loc
entry=0x7fff23a04f68, options=options
entry=0) at ./posix/waitpid.c:38
#2 0x00007f9cb866891b in do_system (line=) at ../sysdeps/posix/system.c:172
#3 0x00007f9cb5ba1c15 in CppyyLegacy::TUnixSystem::StackTrace() () from /home/simon/Desktop/Code/VirtEnv/lib/python3.12/site-packages/cppyy_backend/lib/libCoreLegacy.so
#4 0x00007f9cb5cd93cf in (anonymous namespace)::do_trace (sig=5) at src/clingwrapper.cxx:249
#5 (anonymous namespace)::TExceptionHandlerImp::HandleException (this=, sig=5) at src/clingwrapper.cxx:268
....
#41 0x00007f9cb8e97507 in PyEval_EvalCode () from /lib/x86_64-linux-gnu/libpython3.12.so.1.0
#42 0x00007f9cb8ef0ae6 in ?? () from /lib/x86_64-linux-gnu/libpython3.12.so.1.0
#43 0x00007f9cb8ef0bf9 in ?? () from /lib/x86_64-linux-gnu/libpython3.12.so.1.0
#44 0x00007f9cb8ef41bf in PyRun_StringFlags () from /lib/x86_64-linux-gnu/libpython3.12.so.1.0
#45 0x000055ea7e523055 in pybind11::eval<(pybind11::eval_mode)2> (expr=..., global=..., local=...) at /usr/include/pybind11/eval.h:74
#46 0x000055ea7e4fcb2b in pybind11::exec (expr=..., global=..., local=...) at /usr/include/pybind11/eval.h:89
#47 0x000055ea7e4fb462 in Test002 () at /home/simon/Code/QT/Test_pybind11/Test_pybind11_cppyy_001/main.cpp:147
#48 0x000055ea7e4fb1bb in main (argc=1, argv=0x7fff23a09058) at /home/simon/Code/QT/Test_pybind11/Test_pybind11_cppyy_001/main.cpp:32
13:33:11: /home/simon/Code/QT/Test_pybind11/Test_pybind11_cppyy_001/build/Desktop_Qt_6_7_2-Debug/Test_pybind11_cppyy_001 exited with code 133
"
when run from with a debugger:
"
Hello, World!
['/home/simon/Desktop/Code/VirtEnv/lib/python3.12/site-packages/', '/home/simon/Code/QT/Test_pybind11/Test_pybind11_cppyy_001/', '', '/usr/lib/python312.zip', '/usr/lib/python3.12', '/usr/lib/python3.12/lib-dynload', '/usr/local/lib/python3.12/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.12/dist-packages']
here
there
done
free(): invalid size
44 ./nptl/pthread_kill.c: No such file or directory
81 ../sysdeps/unix/sysv/linux/internal-signals.h: No such file or directory
50 ./nptl/pthread_kill.c: No such file or directory
89 ../sysdeps/unix/sysv/linux/internal-signals.h: No such file or directory
69 ./nptl/pthread_kill.c: No such file or directory
"
Reproducible example code
as called from my QT solution:
"
//
void Test002()
{
//
py::scoped_interpreter guard{};
//
QString qPythonDir("/home/simon/Code/QT/Test_pybind11/Test_pybind11_cppyy_001/");
QString qPythonCommand("");
//
auto locals = py::dict();
auto globals = py::dict();
//
qPythonCommand += "import sys\n";
qPythonCommand += "sys.path.insert(0, '";
qPythonCommand += qPythonDir.toStdString().c_str();
qPythonCommand += "')\n";
qPythonCommand += "sys.path.insert(0, '/home/simon/Desktop/Code/VirtEnv/lib/python3.12/site-packages/')\n";
qPythonCommand += "print(sys.path)\n";
py::exec(qPythonCommand.toStdString().c_str(), py::globals(), locals);
//
qPythonCommand =
R"PY(
import cppyy
cppyy.cppdef("""
#include
void hello()
{
std::cout << "Hello, World!" << std::endl;
}
""")
def runCPP():
global cppyy
print("here")
try:
cppyy.gbl.hello()
print("there")
except Exception as e:
print("Exception: ", e)
print("done")
)PY";
//
py::exec(qPythonCommand.toStdString().c_str(), py::globals(), locals);
//
py::object func = locals["runCPP"];
func();
//
}
"
similar idea to above, but this time no pybind11 and directly from with python. works multiple times.
"
import cppyy
cppyy.cppdef(r"""
#include
void hello() {
std::cout << "Hello, World!" << std::endl;
}
""")
def runCPP():
print("here")
try:
cppyy.gbl.hello()
print("there")
except Exception as e:
print("Exception: ", e)
print("done")
"
Is this a regression? Put the last known working version here if it is.
Not a regression
- 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 3 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 3 jours
-
triage
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
Les mainteneurs répondent en général sous 3 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 3 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 3 jours
Toutes les issues de pybind/pybind11
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 64/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
patrick-hudson/put.gd-desktop#2044 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
uxlfoundation/oneDNN#6604 · 1 commentaire ·
Les mainteneurs répondent en général sous 2 jours
-
[Bug]: RoundToNearest truncates in plugins compiled with spcomp 1.13Peut-être pris @fmu1337 l’a pris aujourd’hui. OuverteBug
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
alliedmodders/sourcemod#2627 ·
Les mainteneurs répondent en général sous 1 jour