From 333757c0733bdefe4b8c8fc73785cd2c378706d7 Mon Sep 17 00:00:00 2001 From: Cristian Maureira-Fredes Date: Tue, 20 Mar 2018 15:53:54 +0100 Subject: 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 (cherry picked from commit b811c874dedd14fd8b072bc73761d39255216073) Reviewed-by: Friedemann Kleint --- sources/shiboken2/libshiboken/qapp_macro.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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; } -- cgit v1.2.3