Merge branch 'adr26-master'

* adr26-master:
  Cleanup accessing/decref of globals, to avoid code bloat in init function.
  Fix ISOC build errors.
  Fix unused variable warning.
  #1360: Leak of SWIG var link object

Conflicts:
	CHANGES.current
This commit is contained in:
William S Fulton 2018-12-04 20:12:42 +00:00
commit 9fe2b05faa
3 changed files with 22 additions and 4 deletions

View file

@ -12,6 +12,11 @@ Version 4.0.0 (in progress)
Similar to the earlier PEP 366 conforming fix for non-builtin. Similar to the earlier PEP 366 conforming fix for non-builtin.
2018-11-29: adr26
[Python] #1360 Leak of SWIG var link object
Fix reference counting on _SWIG_globals to allow var link to be freed on module unload.
2018-11-28: wsfulton 2018-11-28: wsfulton
[Python] When using -builtin, the two step C-extension module import is now [Python] When using -builtin, the two step C-extension module import is now
one step and the wrapped API is only available once and not in an underlying one step and the wrapped API is only available once and not in an underlying

View file

@ -326,7 +326,8 @@ SWIGEXPORT
void void
#endif #endif
SWIG_init(void) { SWIG_init(void) {
PyObject *m, *d, *md; PyObject *m, *d, *md, *globals;
#if PY_VERSION_HEX >= 0x03000000 #if PY_VERSION_HEX >= 0x03000000
static struct PyModuleDef SWIG_module = { static struct PyModuleDef SWIG_module = {
PyModuleDef_HEAD_INIT, PyModuleDef_HEAD_INIT,
@ -379,6 +380,8 @@ SWIG_init(void) {
assert(metatype); assert(metatype);
#endif #endif
(void)globals;
/* Create singletons now to avoid potential deadlocks with multi-threaded usage after module initialization */ /* Create singletons now to avoid potential deadlocks with multi-threaded usage after module initialization */
SWIG_This(); SWIG_This();
SWIG_Python_TypeCache(); SWIG_Python_TypeCache();

View file

@ -3319,7 +3319,17 @@ public:
Python dictionary. */ Python dictionary. */
if (!have_globals) { if (!have_globals) {
Printf(f_init, "\t PyDict_SetItemString(md, \"%s\", SWIG_globals());\n", global_name); Printf(f_init, "\t globals = SWIG_globals();\n");
Printf(f_init, "\t if (!globals) {\n");
Printf(f_init, " PyErr_SetString(PyExc_TypeError, \"Failure to create SWIG globals.\");\n");
Printf(f_init, "#if PY_VERSION_HEX >= 0x03000000\n");
Printf(f_init, "\t return NULL;\n");
Printf(f_init, "#else\n");
Printf(f_init, "\t return;\n");
Printf(f_init, "#endif\n");
Printf(f_init, "\t }\n");
Printf(f_init, "\t PyDict_SetItemString(md, \"%s\", globals);\n", global_name);
Printf(f_init, "\t Py_DECREF(globals);\n");
if (builtin) if (builtin)
Printf(f_init, "\t SwigPyBuiltin_AddPublicSymbol(public_interface, \"%s\");\n", global_name); Printf(f_init, "\t SwigPyBuiltin_AddPublicSymbol(public_interface, \"%s\");\n", global_name);
have_globals = 1; have_globals = 1;
@ -3407,9 +3417,9 @@ public:
Wrapper_print(getf, f_wrappers); Wrapper_print(getf, f_wrappers);
/* Now add this to the variable linking mechanism */ /* Now add this to the variable linking mechanism */
Printf(f_init, "\t SWIG_addvarlink(SWIG_globals(), \"%s\", %s, %s);\n", iname, vargetname, varsetname); Printf(f_init, "\t SWIG_addvarlink(globals, \"%s\", %s, %s);\n", iname, vargetname, varsetname);
if (builtin && shadow && !assignable && !in_class) { if (builtin && shadow && !assignable && !in_class) {
Printf(f_init, "\t PyDict_SetItemString(md, \"%s\", PyObject_GetAttrString(SWIG_globals(), \"%s\"));\n", iname, iname); Printf(f_init, "\t PyDict_SetItemString(md, \"%s\", PyObject_GetAttrString(globals, \"%s\"));\n", iname, iname);
Printf(f_init, "\t SwigPyBuiltin_AddPublicSymbol(public_interface, \"%s\");\n", iname); Printf(f_init, "\t SwigPyBuiltin_AddPublicSymbol(public_interface, \"%s\");\n", iname);
} }
Delete(vargetname); Delete(vargetname);