Skip to content

Commit e504834

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 4d9a829 commit e504834

6 files changed

Lines changed: 49 additions & 4 deletions

File tree

src/_backend_agg_wrapper.cpp

Lines changed: 9 additions & 0 deletions
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"
@@ -185,7 +189,12 @@ PyRendererAgg_draw_gouraud_triangles(RendererAgg *self,
185189
self->draw_gouraud_triangles(gc, points, colors, trans);
186190
}
187191

192+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
193+
PYBIND11_MODULE(_backend_agg, m,
194+
py::mod_gil_not_used(), py::multiple_interpreters::per_interpreter_gil())
195+
#else
188196
PYBIND11_MODULE(_backend_agg, m, py::mod_gil_not_used())
197+
#endif
189198
{
190199
py::classh<RendererAgg>(m, "RendererAgg", py::buffer_protocol())
191200
.def(py::init<unsigned int, unsigned int, double>(),

src/_image_wrapper.cpp

Lines changed: 8 additions & 0 deletions
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

@@ -288,7 +291,12 @@ calculate_rms_and_diff(py::array_t<unsigned char> expected_image,
288291
}
289292

290293

294+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
295+
PYBIND11_MODULE(_image, m,
296+
py::mod_gil_not_used(), py::multiple_interpreters::per_interpreter_gil())
297+
#else
291298
PYBIND11_MODULE(_image, m, py::mod_gil_not_used())
299+
#endif
292300
{
293301
py::native_enum<interpolation_e>(m, "_InterpolationType", "enum.Enum")
294302
.value("NEAREST", NEAREST)

src/_path_wrapper.cpp

Lines changed: 8 additions & 0 deletions
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>
@@ -303,7 +306,12 @@ Py_is_sorted_and_has_non_nan(py::object obj)
303306
return result;
304307
}
305308

309+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
310+
PYBIND11_MODULE(_path, m,
311+
py::mod_gil_not_used(), py::multiple_interpreters::per_interpreter_gil())
312+
#else
306313
PYBIND11_MODULE(_path, m, py::mod_gil_not_used())
314+
#endif
307315
{
308316
m.def("point_in_path", &Py_point_in_path,
309317
"x"_a, "y"_a, "radius"_a, "path"_a, "trans"_a);

src/_qhull_wrapper.cpp

Lines changed: 8 additions & 0 deletions
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
@@ -284,7 +287,12 @@ delaunay(const CoordArray& x, const CoordArray& y, int verbose)
284287
return delaunay_impl(npoints, x.data(), y.data(), verbose == 0);
285288
}
286289

290+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
291+
PYBIND11_MODULE(_qhull, m,
292+
py::mod_gil_not_used(), py::multiple_interpreters::per_interpreter_gil())
293+
#else
287294
PYBIND11_MODULE(_qhull, m, py::mod_gil_not_used())
295+
#endif
288296
{
289297
m.doc() = "Computing Delaunay triangulations.\n";
290298

src/ft2font_wrapper.cpp

Lines changed: 8 additions & 4 deletions
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

@@ -1393,11 +1396,12 @@ PyFT2Font_layout(PyFT2Font *self, std::u32string text, LoadFlags flags,
13931396
return items;
13941397
}
13951398

1396-
/**********************************************************************
1397-
* Deprecations
1398-
* */
1399-
1399+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
1400+
PYBIND11_MODULE(ft2font, m,
1401+
py::mod_gil_not_used(), py::multiple_interpreters::per_interpreter_gil())
1402+
#else
14001403
PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
1404+
#endif
14011405
{
14021406
FT_Library ft2Library = nullptr;
14031407

src/tri/_tri_wrapper.cpp

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

36
using namespace pybind11::literals;
47

8+
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
9+
PYBIND11_MODULE(_tri, m,
10+
py::mod_gil_not_used(), py::multiple_interpreters::per_interpreter_gil())
11+
#else
512
PYBIND11_MODULE(_tri, m, py::mod_gil_not_used())
13+
#endif
614
{
715
py::classh<Triangulation>(m, "Triangulation", py::is_final())
816
.def(py::init<const Triangulation::CoordinateArray&,

0 commit comments

Comments
 (0)