File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change 171
171
#define PYBIND11_PLUGIN_IMPL (name ) \
172
172
extern " C" PYBIND11_EXPORT PyObject *PyInit_##name()
173
173
174
- #else
174
+ #define PYBIND11_CHECK_REIMPORT (m ) \
175
+ { \
176
+ static py::handle m##_original; \
177
+ if (m##_original) { \
178
+ m = py::reinterpret_borrow<py::module >(m##_original); \
179
+ return m.ptr (); \
180
+ } else { \
181
+ m##_original = m; \
182
+ } \
183
+ }
184
+
185
+ #else // PY_MAJOR_VERSION >= 3
175
186
#define PYBIND11_INSTANCE_METHOD_NEW (ptr, class_ ) PyMethod_New(ptr, nullptr , class_)
176
187
#define PYBIND11_INSTANCE_METHOD_CHECK PyMethod_Check
177
188
#define PYBIND11_INSTANCE_METHOD_GET_FUNCTION PyMethod_GET_FUNCTION
198
209
(void )pybind11_init_wrapper (); \
199
210
} \
200
211
PyObject *pybind11_init_wrapper ()
212
+ #define PYBIND11_CHECK_REIMPORT (variable )
201
213
#endif
202
214
203
215
#if PY_VERSION_HEX >= 0x03050000 && PY_VERSION_HEX < 0x03050200
@@ -285,6 +297,7 @@ extern "C" {
285
297
PYBIND11_PLUGIN_IMPL (name) { \
286
298
PYBIND11_CHECK_PYTHON_VERSION \
287
299
auto m = pybind11::module (PYBIND11_TOSTRING (name)); \
300
+ PYBIND11_CHECK_REIMPORT (m) \
288
301
try { \
289
302
PYBIND11_CONCAT (pybind11_init_, name)(m); \
290
303
return m.ptr (); \
You can’t perform that action at this time.
0 commit comments