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-21 13:02:20 +0000
commitb811c874dedd14fd8b072bc73761d39255216073 (patch)
treec41b7c72d0e1920e9036b343b45dcfe8ad7b2792
parente909528a77172bbd129ca08c12a62ba182dcbf8c (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>
-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;
}