Skip to content

Commit 0d25798

Browse files
committed
Add support for Python subinterpreters
Note, at this time, NumPy does not support subinterpreters, and so we do not either.
1 parent 629be3f commit 0d25798

File tree

6 files changed

+49
-6
lines changed

6 files changed

+49
-6
lines changed

src/_backend_agg_wrapper.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#include <pybind11/pybind11.h>
22
#include <pybind11/numpy.h>
33
#include <pybind11/stl.h>
4+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
5+
#include <pybind11/subinterpreter.h>
6+
#endif
7+
48
#include "mplutils.h"
59
#include "py_converters.h"
610
#include "_backend_agg.h"
@@ -214,7 +218,11 @@ PyRendererAgg_draw_gouraud_triangles(RendererAgg *self,
214218
self->draw_gouraud_triangles(gc, points, colors, trans);
215219
}
216220

217-
PYBIND11_MODULE(_backend_agg, m, py::mod_gil_not_used())
221+
PYBIND11_MODULE(_backend_agg, m, py::mod_gil_not_used()
222+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
223+
,py::multiple_interpreters::per_interpreter_gil()
224+
#endif
225+
)
218226
{
219227
py::classh<RendererAgg>(m, "RendererAgg", py::buffer_protocol())
220228
.def(py::init<unsigned int, unsigned int, double>(),

src/_image_wrapper.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include <pybind11/pybind11.h>
22
#include <pybind11/native_enum.h>
33
#include <pybind11/numpy.h>
4+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
5+
#include <pybind11/subinterpreter.h>
6+
#endif
47

58
#include <algorithm>
69

@@ -279,7 +282,11 @@ calculate_rms_and_diff(py::array_t<unsigned char> expected_image,
279282
}
280283

281284

282-
PYBIND11_MODULE(_image, m, py::mod_gil_not_used())
285+
PYBIND11_MODULE(_image, m, py::mod_gil_not_used()
286+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
287+
,py::multiple_interpreters::per_interpreter_gil()
288+
#endif
289+
)
283290
{
284291
py::native_enum<interpolation_e>(m, "_InterpolationType", "enum.Enum")
285292
.value("NEAREST", NEAREST)

src/_path_wrapper.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include <pybind11/pybind11.h>
22
#include <pybind11/stl.h>
3+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
4+
#include <pybind11/subinterpreter.h>
5+
#endif
36

47
#include <array>
58
#include <limits>
@@ -310,7 +313,11 @@ Py_is_sorted_and_has_non_nan(py::object obj)
310313
return result;
311314
}
312315

313-
PYBIND11_MODULE(_path, m, py::mod_gil_not_used())
316+
PYBIND11_MODULE(_path, m, py::mod_gil_not_used()
317+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
318+
,py::multiple_interpreters::per_interpreter_gil()
319+
#endif
320+
)
314321
{
315322
m.def("point_in_path", &Py_point_in_path,
316323
"x"_a, "y"_a, "radius"_a, "path"_a, "trans"_a);

src/_qhull_wrapper.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
*/
88
#include <pybind11/pybind11.h>
99
#include <pybind11/numpy.h>
10+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
11+
#include <pybind11/subinterpreter.h>
12+
#endif
1013

1114
#ifdef _MSC_VER
1215
/* The Qhull header does not declare this as extern "C", but only MSVC seems to
@@ -276,7 +279,11 @@ delaunay(const CoordArray& x, const CoordArray& y, int verbose)
276279
return delaunay_impl(npoints, x.data(), y.data(), verbose == 0);
277280
}
278281

279-
PYBIND11_MODULE(_qhull, m, py::mod_gil_not_used())
282+
PYBIND11_MODULE(_qhull, m, py::mod_gil_not_used()
283+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
284+
,py::multiple_interpreters::per_interpreter_gil()
285+
#endif
286+
)
280287
{
281288
m.doc() = "Computing Delaunay triangulations.\n";
282289

src/ft2font_wrapper.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#include <pybind11/native_enum.h>
44
#include <pybind11/numpy.h>
55
#include <pybind11/stl.h>
6+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
7+
#include <pybind11/subinterpreter.h>
8+
#endif
69

710
#include "ft2font.h"
811

@@ -1475,7 +1478,11 @@ ft2font__getattr__(std::string name) {
14751478
"module 'matplotlib.ft2font' has no attribute {!r}"_s.format(name));
14761479
}
14771480

1478-
PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
1481+
PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used()
1482+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
1483+
,py::multiple_interpreters::per_interpreter_gil()
1484+
#endif
1485+
)
14791486
{
14801487
FT_Library ft2Library = nullptr;
14811488

src/tri/_tri_wrapper.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
#include "_tri.h"
2+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
3+
#include <pybind11/subinterpreter.h>
4+
#endif
25

36
using namespace pybind11::literals;
47

5-
PYBIND11_MODULE(_tri, m, py::mod_gil_not_used())
8+
PYBIND11_MODULE(_tri, m, py::mod_gil_not_used()
9+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
10+
,py::multiple_interpreters::per_interpreter_gil()
11+
#endif
12+
)
613
{
714
py::classh<Triangulation>(m, "Triangulation", py::is_final())
815
.def(py::init<const Triangulation::CoordinateArray&,

0 commit comments

Comments
 (0)