mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +00:00
fix: follow rest of pybind11 closer with PYBIND11_HAS_SUBINTERPRETER_SUPPORT (#5710)
* fix: follow rest of pybind11 closer with PYBIND11_HAS_SUBINTERPRETER_SUPPORT Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * style: pre-commit fixes --------- Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -257,11 +257,14 @@
|
||||
// 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,
|
||||
// defining it unnecessarily is not expected to break anything (other than old iOS targets).
|
||||
// This can be overridden by the user with -DPYBIND11_HAS_SUBINTERPRETER_SUPPORT=1 or 0
|
||||
#ifndef 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
|
||||
#else
|
||||
# if PYBIND11_HAS_SUBINTERPRETER_SUPPORT == 0
|
||||
# undef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
@@ -324,7 +324,7 @@ inline std::atomic<int> &get_num_interpreters_seen() {
|
||||
|
||||
template <typename InternalsType>
|
||||
inline std::unique_ptr<InternalsType> *&get_internals_pp() {
|
||||
#if PYBIND11_HAS_SUBINTERPRETER_SUPPORT
|
||||
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
|
||||
if (get_num_interpreters_seen() > 1) {
|
||||
// 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.
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#if !PYBIND11_HAS_SUBINTERPRETER_SUPPORT
|
||||
#ifndef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
|
||||
# error "This platform does not support subinterpreters, do not include this file."
|
||||
#endif
|
||||
|
||||
|
||||
@@ -12,5 +12,9 @@ PYBIND11_MODULE(mod_per_interpreter_gil,
|
||||
py::multiple_interpreters::per_interpreter_gil()) {
|
||||
m.def("internals_at",
|
||||
[]() { return reinterpret_cast<uintptr_t>(&py::detail::get_internals()); });
|
||||
m.attr("PYBIND11_HAS_SUBINTERPRETER_SUPPORT") = PYBIND11_HAS_SUBINTERPRETER_SUPPORT;
|
||||
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
|
||||
m.attr("defined_PYBIND11_HAS_SUBINTERPRETER_SUPPORT") = true;
|
||||
#else
|
||||
m.attr("defined_PYBIND11_HAS_SUBINTERPRETER_SUPPORT") = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -9,5 +9,9 @@ namespace py = pybind11;
|
||||
PYBIND11_MODULE(mod_shared_interpreter_gil, m, py::multiple_interpreters::shared_gil()) {
|
||||
m.def("internals_at",
|
||||
[]() { return reinterpret_cast<uintptr_t>(&py::detail::get_internals()); });
|
||||
m.attr("PYBIND11_HAS_SUBINTERPRETER_SUPPORT") = PYBIND11_HAS_SUBINTERPRETER_SUPPORT;
|
||||
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
|
||||
m.attr("defined_PYBIND11_HAS_SUBINTERPRETER_SUPPORT") = true;
|
||||
#else
|
||||
m.attr("defined_PYBIND11_HAS_SUBINTERPRETER_SUPPORT") = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <pybind11/embed.h>
|
||||
#if PYBIND11_HAS_SUBINTERPRETER_SUPPORT
|
||||
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
|
||||
# include <pybind11/subinterpreter.h>
|
||||
|
||||
// Silence MSVC C++17 deprecation warning from Catch regarding std::uncaught_exceptions (up to
|
||||
|
||||
@@ -27,7 +27,7 @@ def test_independent_subinterpreters():
|
||||
|
||||
m = pytest.importorskip("mod_per_interpreter_gil")
|
||||
|
||||
if not m.PYBIND11_HAS_SUBINTERPRETER_SUPPORT:
|
||||
if not m.defined_PYBIND11_HAS_SUBINTERPRETER_SUPPORT:
|
||||
pytest.skip("Does not have subinterpreter support compiled in")
|
||||
|
||||
code = """
|
||||
@@ -101,7 +101,7 @@ def test_dependent_subinterpreters():
|
||||
|
||||
m = pytest.importorskip("mod_shared_interpreter_gil")
|
||||
|
||||
if not m.PYBIND11_HAS_SUBINTERPRETER_SUPPORT:
|
||||
if not m.defined_PYBIND11_HAS_SUBINTERPRETER_SUPPORT:
|
||||
pytest.skip("Does not have subinterpreter support compiled in")
|
||||
|
||||
code = """
|
||||
|
||||
Reference in New Issue
Block a user