pybind11/tests/test_embed
Jason Rhinelander 326deef2ae
Fix segfault when reloading interpreter with external modules (#1092)
* Fix segfault when reloading interpreter with external modules

When embedding the interpreter and loading external modules in that
embedded interpreter, the external module correctly shares its
internals_ptr with the one in the embedded interpreter.  When the
interpreter is shut down, however, only the `internals_ptr` local to
the embedded code is actually reset to nullptr: the external module
remains set.

The result is that loading an external pybind11 module, letting the
interpreter go through a finalize/initialize, then attempting to use
something in the external module fails because this external module is
still trying to use the old (destroyed) internals.  This causes
undefined behaviour (typically a segfault).

This commit fixes it by adding a level of indirection in the internals
path, converting the local internals variable to `internals **` instead
of `internals *`.  With this change, we can detect a stale internals
pointer and reload the internals pointer (either from a capsule or by
creating a new internals instance).

(No issue number: this was reported on gitter by @henryiii and @aoloe).
2018-01-11 19:46:10 -04:00
..
CMakeLists.txt Fix segfault when reloading interpreter with external modules (#1092) 2018-01-11 19:46:10 -04:00
catch.cpp Silence new MSVC C++17 deprecation warnings 2017-12-23 09:00:45 -04:00
external_module.cpp Fix segfault when reloading interpreter with external modules (#1092) 2018-01-11 19:46:10 -04:00
test_interpreter.cpp Fix segfault when reloading interpreter with external modules (#1092) 2018-01-11 19:46:10 -04:00
test_interpreter.py Add Catch framework for testing embedding support and C++-side features 2017-05-28 02:12:24 +02:00