summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorbenjamin-sch <Benjamin.Schiller@vector.de>2022-01-12 14:22:11 +0100
committerbenjamin-sch <Benjamin.Schiller@vector.com>2022-02-08 09:09:00 +0100
commita9f76c89ec0f4b2b60f2edc3d705c14cc6aec5f6 (patch)
tree658a63c776d41e15d8ffb5ae25d21e61489bf7f2 /Lib
parenta5315e115907bfd67efec7697e560535e048a8da (diff)
downloadswig-a9f76c89ec0f4b2b60f2edc3d705c14cc6aec5f6.tar.gz
added interpreter_counter to deinitialize only once in case of subinterpreters
Diffstat (limited to 'Lib')
-rw-r--r--Lib/python/pyrun.swg6
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg
index a49cbb5b3..d42dc0f0f 100644
--- a/Lib/python/pyrun.swg
+++ b/Lib/python/pyrun.swg
@@ -1643,12 +1643,17 @@ SWIG_Python_GetModule(void *SWIGUNUSEDPARM(clientdata)) {
return (swig_module_info *) type_pointer;
}
+
+static int interpreter_counter = 0; // how many (sub-)interpreters are using swig_module's types
+
SWIGRUNTIME void
SWIG_Python_DestroyModule(PyObject *obj)
{
swig_module_info *swig_module = (swig_module_info *) PyCapsule_GetPointer(obj, SWIGPY_CAPSULE_NAME);
swig_type_info **types = swig_module->types;
size_t i;
+ if (--interpreter_counter != 0) // another sub-interpreter may still be using the swig_module's types
+ return;
for (i =0; i < swig_module->size; ++i) {
swig_type_info *ty = types[i];
if (ty->owndata) {
@@ -1676,6 +1681,7 @@ SWIG_Python_SetModule(swig_module_info *swig_module) {
#endif
PyObject *pointer = PyCapsule_New((void *) swig_module, SWIGPY_CAPSULE_NAME, SWIG_Python_DestroyModule);
if (pointer && module) {
+ ++interpreter_counter;
if (PyModule_AddObject(module, "type_pointer_capsule" SWIG_TYPE_TABLE_NAME, pointer) != 0) {
Py_DECREF(pointer);
}