mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +00:00
fix: allow subinterp support to be disabled
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
This commit is contained in:
committed by
Henry Schreiner
parent
33fb53335e
commit
e4873e8f59
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -92,7 +92,7 @@ jobs:
|
|||||||
cmake-args: -DCMAKE_CXX_STANDARD=20 -DPYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION=ON
|
cmake-args: -DCMAKE_CXX_STANDARD=20 -DPYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION=ON
|
||||||
- runs-on: ubuntu-latest
|
- runs-on: ubuntu-latest
|
||||||
python-version: '3.14'
|
python-version: '3.14'
|
||||||
cmake-args: -DCMAKE_CXX_STANDARD=14
|
cmake-args: -DCMAKE_CXX_STANDARD=14 -DCMAKE_CXX_FLAGS="-DPYBIND11_HAS_SUBINTERPRETER_SUPPORT=0"
|
||||||
- runs-on: ubuntu-latest
|
- runs-on: ubuntu-latest
|
||||||
python-version: 'pypy-3.10'
|
python-version: 'pypy-3.10'
|
||||||
cmake-args: -DCMAKE_CXX_STANDARD=14
|
cmake-args: -DCMAKE_CXX_STANDARD=14
|
||||||
|
|||||||
@@ -256,9 +256,13 @@
|
|||||||
|
|
||||||
// Slightly faster code paths are available when PYBIND11_HAS_SUBINTERPRETER_SUPPORT is *not*
|
// Slightly faster code paths are available when PYBIND11_HAS_SUBINTERPRETER_SUPPORT is *not*
|
||||||
// defined, so avoid defining it for implementations that do not support subinterpreters. However,
|
// defined, so avoid defining it for implementations that do not support subinterpreters. However,
|
||||||
// defining it unnecessarily is not expected to break anything.
|
// defining it unnecessarily is not expected to break anything (other than old iOS targets).
|
||||||
#if PY_VERSION_HEX >= 0x030C0000 && !defined(PYPY_VERSION) && !defined(GRAALVM_PYTHON)
|
#ifndef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
|
||||||
# define PYBIND11_HAS_SUBINTERPRETER_SUPPORT
|
# if PY_VERSION_HEX >= 0x030C0000 && !defined(PYPY_VERSION) && !defined(GRAALVM_PYTHON)
|
||||||
|
# define PYBIND11_HAS_SUBINTERPRETER_SUPPORT 1
|
||||||
|
# else
|
||||||
|
# define PYBIND11_HAS_SUBINTERPRETER_SUPPORT 0
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// 3.12 Compatibility
|
// 3.12 Compatibility
|
||||||
|
|||||||
@@ -324,7 +324,7 @@ inline std::atomic<int> &get_num_interpreters_seen() {
|
|||||||
|
|
||||||
template <typename InternalsType>
|
template <typename InternalsType>
|
||||||
inline std::unique_ptr<InternalsType> *&get_internals_pp() {
|
inline std::unique_ptr<InternalsType> *&get_internals_pp() {
|
||||||
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
|
#if PYBIND11_HAS_SUBINTERPRETER_SUPPORT
|
||||||
if (get_num_interpreters_seen() > 1) {
|
if (get_num_interpreters_seen() > 1) {
|
||||||
// Internals is one per interpreter. When multiple interpreters are alive in different
|
// Internals is one per interpreter. When multiple interpreters are alive in different
|
||||||
// threads we have to allow them to have different internals, so we need a thread_local.
|
// threads we have to allow them to have different internals, so we need a thread_local.
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#if !defined(PYBIND11_HAS_SUBINTERPRETER_SUPPORT)
|
#if !PYBIND11_HAS_SUBINTERPRETER_SUPPORT
|
||||||
# error "This platform does not support subinterpreters, do not include this file."
|
# error "This platform does not support subinterpreters, do not include this file."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -12,4 +12,5 @@ PYBIND11_MODULE(mod_per_interpreter_gil,
|
|||||||
py::multiple_interpreters::per_interpreter_gil()) {
|
py::multiple_interpreters::per_interpreter_gil()) {
|
||||||
m.def("internals_at",
|
m.def("internals_at",
|
||||||
[]() { return reinterpret_cast<uintptr_t>(&py::detail::get_internals()); });
|
[]() { return reinterpret_cast<uintptr_t>(&py::detail::get_internals()); });
|
||||||
|
m.attr("PYBIND11_HAS_SUBINTERPRETER_SUPPORT") = PYBIND11_HAS_SUBINTERPRETER_SUPPORT;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,4 +9,5 @@ namespace py = pybind11;
|
|||||||
PYBIND11_MODULE(mod_shared_interpreter_gil, m, py::multiple_interpreters::shared_gil()) {
|
PYBIND11_MODULE(mod_shared_interpreter_gil, m, py::multiple_interpreters::shared_gil()) {
|
||||||
m.def("internals_at",
|
m.def("internals_at",
|
||||||
[]() { return reinterpret_cast<uintptr_t>(&py::detail::get_internals()); });
|
[]() { return reinterpret_cast<uintptr_t>(&py::detail::get_internals()); });
|
||||||
|
m.attr("PYBIND11_HAS_SUBINTERPRETER_SUPPORT") = PYBIND11_HAS_SUBINTERPRETER_SUPPORT;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include <pybind11/embed.h>
|
#include <pybind11/embed.h>
|
||||||
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
|
#if PYBIND11_HAS_SUBINTERPRETER_SUPPORT
|
||||||
# include <pybind11/subinterpreter.h>
|
# include <pybind11/subinterpreter.h>
|
||||||
|
|
||||||
// Silence MSVC C++17 deprecation warning from Catch regarding std::uncaught_exceptions (up to
|
// Silence MSVC C++17 deprecation warning from Catch regarding std::uncaught_exceptions (up to
|
||||||
|
|||||||
@@ -23,9 +23,12 @@ def test_independent_subinterpreters():
|
|||||||
elif sys.version_info >= (3, 12):
|
elif sys.version_info >= (3, 12):
|
||||||
import _xxsubinterpreters as interpreters
|
import _xxsubinterpreters as interpreters
|
||||||
else:
|
else:
|
||||||
pytest.skip("Test requires a the interpreters stdlib module")
|
pytest.skip("Test requires the interpreters stdlib module")
|
||||||
|
|
||||||
import mod_per_interpreter_gil as m
|
m = pytest.importorskip("mod_per_interpreter_gil")
|
||||||
|
|
||||||
|
if not m.PYBIND11_HAS_SUBINTERPRETER_SUPPORT:
|
||||||
|
pytest.skip("Does not have subinterpreter support compiled in")
|
||||||
|
|
||||||
code = """
|
code = """
|
||||||
import mod_per_interpreter_gil as m
|
import mod_per_interpreter_gil as m
|
||||||
@@ -94,9 +97,12 @@ def test_dependent_subinterpreters():
|
|||||||
elif sys.version_info >= (3, 12):
|
elif sys.version_info >= (3, 12):
|
||||||
import _xxsubinterpreters as interpreters
|
import _xxsubinterpreters as interpreters
|
||||||
else:
|
else:
|
||||||
pytest.skip("Test requires a the interpreters stdlib module")
|
pytest.skip("Test requires the interpreters stdlib module")
|
||||||
|
|
||||||
import mod_shared_interpreter_gil as m
|
m = pytest.importorskip("mod_shared_interpreter_gil")
|
||||||
|
|
||||||
|
if not m.PYBIND11_HAS_SUBINTERPRETER_SUPPORT:
|
||||||
|
pytest.skip("Does not have subinterpreter support compiled in")
|
||||||
|
|
||||||
code = """
|
code = """
|
||||||
import mod_shared_interpreter_gil as m
|
import mod_shared_interpreter_gil as m
|
||||||
|
|||||||
Reference in New Issue
Block a user