Skip to content

Commit 295a9ce

Browse files
Stylistic changes and refcount fixes in PythonQtImporter_load_module
1 parent 525ea41 commit 295a9ce

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

src/PythonQt.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ void PythonQt_init_QtCoreBuiltin(PyObject*);
7171
static inline int PyModule_AddObject_DECREF(PyObject *module, const char *name, PyObject *value)
7272
{
7373
int ret = PyModule_AddObject(module, name, value);
74-
if (ret < 0)
74+
if (ret < 0) {
7575
Py_XDECREF(value);
76+
}
7677
return ret;
7778
}
7879

@@ -2146,8 +2147,9 @@ const QMetaObject* PythonQtPrivate::buildDynamicMetaObject(PythonQtClassWrapper*
21462147
PyObject* value = NULL;
21472148
PyObject* key = NULL;
21482149
static PyObject* qtSlots = NULL;
2149-
if (!qtSlots)
2150-
qtSlots = PyString_FromString("_qtSlots");
2150+
if (!qtSlots) {
2151+
qtSlots = PyString_FromString("_qtSlots");
2152+
}
21512153

21522154
bool needsMetaObject = false;
21532155
// Iterate over all members and check if they affect the QMetaObject:

src/PythonQtImporter.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ PythonQtImporter_load_module(PyObject *obj, PyObject *args)
224224
PyObject *code = NULL, *mod = NULL, *dict = NULL;
225225
char *fullname;
226226

227-
if (!PyArg_ParseTuple(args, "s:PythonQtImporter.load_module",
228-
&fullname))
227+
if (!PyArg_ParseTuple(args, "s:PythonQtImporter.load_module", &fullname)) {
229228
return NULL;
229+
}
230230

231231
PythonQtImport::ModuleInfo info = PythonQtImport::getModuleInfo(self, fullname);
232232
if (info.type == PythonQtImport::MI_NOT_FOUND) {
@@ -250,7 +250,6 @@ PythonQtImporter_load_module(PyObject *obj, PyObject *args)
250250

251251
if (PyDict_SetItemString(dict, "__loader__", (PyObject *)self) != 0) {
252252
Py_DECREF(code);
253-
Py_DECREF(mod);
254253
return NULL;
255254
}
256255

@@ -265,22 +264,19 @@ PythonQtImporter_load_module(PyObject *obj, PyObject *args)
265264
QStringToPythonConstCharPointer(subname));
266265
if (fullpath == NULL) {
267266
Py_DECREF(code);
268-
Py_DECREF(mod);
269267
return NULL;
270268
}
271269

272270
pkgpath = Py_BuildValue("[O]", fullpath);
273271
Py_DECREF(fullpath);
274272
if (pkgpath == NULL) {
275273
Py_DECREF(code);
276-
Py_DECREF(mod);
277274
return NULL;
278275
}
279276
err = PyDict_SetItemString(dict, "__path__", pkgpath);
280277
Py_DECREF(pkgpath);
281278
if (err != 0) {
282279
Py_DECREF(code);
283-
Py_DECREF(mod);
284280
return NULL;
285281
}
286282

@@ -294,12 +290,10 @@ PythonQtImporter_load_module(PyObject *obj, PyObject *args)
294290
Py_XDECREF(fullnameObj);
295291
if (err != 0) {
296292
Py_DECREF(code);
297-
Py_DECREF(mod);
298293
return NULL;
299294
}
300295
#endif
301296
}
302-
Py_DECREF(mod);
303297

304298
#ifdef PY3K
305299
PyObject* fullnameObj = PyUnicode_FromString(fullname);

0 commit comments

Comments
 (0)