diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2022-10-05 23:18:15 +0100 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2022-10-05 23:18:15 +0100 |
commit | 45f4b4d9360e1a85f00d7f80c124ce5e249275c0 (patch) | |
tree | b478522d84efd46a6a31a0d16cf32975ad8affe8 /Lib/python/pyrun.swg | |
parent | ba279ae9392b36e2de857a08a4f5266c27b5c930 (diff) | |
parent | 117a917dd155258891a4557526b0888284128d2d (diff) | |
download | swig-45f4b4d9360e1a85f00d7f80c124ce5e249275c0.tar.gz |
Merge branch 'python_subinterpreter_issues'
* python_subinterpreter_issues:
added comment in CHANGES.current
always get the type_pointer from capsule instead of using a static variable as the value may change after re-initilization/due to subinterpreters
added interpreter_counter to deinitialize only once in case of subinterpreters
Conflicts:
CHANGES.current
Lib/python/pyrun.swg
Diffstat (limited to 'Lib/python/pyrun.swg')
-rw-r--r-- | Lib/python/pyrun.swg | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 0dcbc1ce5..eb8ae1673 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -1656,28 +1656,33 @@ SWIG_Python_TypeCache(void) { SWIGRUNTIME swig_module_info * SWIG_Python_GetModule(void *SWIGUNUSEDPARM(clientdata)) { +#ifdef SWIG_LINK_RUNTIME static void *type_pointer = (void *)0; /* first check if module already created */ if (!type_pointer) { -#ifdef SWIG_LINK_RUNTIME type_pointer = SWIG_ReturnGlobalTypeList((void *)0); + } #else - type_pointer = PyCapsule_Import(SWIGPY_CAPSULE_NAME, 0); - if (PyErr_Occurred()) { - PyErr_Clear(); - type_pointer = (void *)0; - } -#endif + void *type_pointer = PyCapsule_Import(SWIGPY_CAPSULE_NAME, 0); + if (PyErr_Occurred()) { + PyErr_Clear(); + type_pointer = (void *)0; } +#endif 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) { @@ -1707,6 +1712,7 @@ SWIG_Python_SetModule(swig_module_info *swig_module) { PyObject *pointer = PyCapsule_New((void *) swig_module, SWIGPY_CAPSULE_NAME, SWIG_Python_DestroyModule); if (pointer && module) { if (PyModule_AddObject(module, SWIGPY_CAPSULE_ATTR_NAME, pointer) == 0) { + ++interpreter_counter; Swig_Capsule_global = pointer; } else { Py_DECREF(pointer); |