aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristian Maureira-Fredes <cristian.maureira-fredes@qt.io>2018-03-20 15:53:54 +0100
committerCristian Maureira-Fredes <cristian.maureira-fredes@qt.io>2018-03-26 09:19:00 +0000
commit333757c0733bdefe4b8c8fc73785cd2c378706d7 (patch)
tree2c554dd0175fe92fc913628870c1659a2706438b
parentf9cae4967ee543685729bc1af682b299144ee9d8 (diff)
Fix qApp macro refcount
There are two borrowed references in the code, so we need to manually increase the refcount. Usually the PyEval_GetBuiltins and PyModule_GetDict functions are used locally, so there is no real need of taking care of the refcounts, but since we are using it globally, and adjusting the refcount by ourselves, it was necessary to add the missing references by hand. Task-number: PYSIDE-585 Change-Id: Icc1e7719a6b5d3654d12ab37cd509a096821d7a6 Reviewed-by: Christian Tismer <tismer@stackless.com> (cherry picked from commit b811c874dedd14fd8b072bc73761d39255216073) Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r--sources/shiboken2/libshiboken/qapp_macro.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/sources/shiboken2/libshiboken/qapp_macro.cpp b/sources/shiboken2/libshiboken/qapp_macro.cpp
index b31e98d06..9b940aaaa 100644
--- a/sources/shiboken2/libshiboken/qapp_macro.cpp
+++ b/sources/shiboken2/libshiboken/qapp_macro.cpp
@@ -97,9 +97,10 @@ reset_qApp_var()
for (mod_ptr = qApp_moduledicts; *mod_ptr != NULL; mod_ptr++) {
// We respect whatever the user may have set.
- if (PyDict_GetItem(*mod_ptr, qApp_var) == NULL)
+ if (PyDict_GetItem(*mod_ptr, qApp_var) == NULL) {
if (PyDict_SetItem(*mod_ptr, qApp_var, qApp_content) < 0)
return -1;
+ }
}
return 0;
}
@@ -157,7 +158,9 @@ setup_qApp_var(PyObject *module)
qApp_var = Py_BuildValue("s", "qApp");
if (qApp_var == NULL)
return -1;
+ // This is a borrowed reference
qApp_moduledicts[0] = PyEval_GetBuiltins();
+ Py_INCREF(qApp_content);
init_done = 1;
}
@@ -165,7 +168,9 @@ setup_qApp_var(PyObject *module)
// into __builtins__, to let it appear like a real macro.
module_index = qApp_module_index(module);
if (module_index) {
+ // This line gets a borrowed reference
qApp_moduledicts[module_index] = PyModule_GetDict(module);
+ Py_INCREF(qApp_content);
if (reset_qApp_var() < 0)
return -1;
}