Skip to content

Commit 76d36da

Browse files
committed
avoid Py_DECREF(Py_None)
1 parent 6328662 commit 76d36da

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/_imagingft.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,7 @@ setup_module(PyObject *m) {
13651365
FT_Library_Version(library, &major, &minor, &patch);
13661366

13671367
v = PyUnicode_FromFormat("%d.%d.%d", major, minor, patch);
1368-
PyDict_SetItemString(d, "freetype2_version", v);
1368+
PyDict_SetItemString(d, "freetype2_version", v ? v : Py_None);
13691369
Py_XDECREF(v);
13701370

13711371
#ifdef HAVE_RAQM
@@ -1386,35 +1386,32 @@ setup_module(PyObject *m) {
13861386
PyDict_SetItemString(d, "HAVE_HARFBUZZ", v);
13871387
Py_DECREF(v);
13881388
if (have_raqm) {
1389+
v = NULL;
13891390
#ifdef RAQM_VERSION_MAJOR
13901391
v = PyUnicode_FromString(raqm_version_string());
1391-
#else
1392-
v = Py_None;
13931392
#endif
1394-
PyDict_SetItemString(d, "raqm_version", v);
1393+
PyDict_SetItemString(d, "raqm_version", v ? v : Py_None);
13951394
Py_XDECREF(v);
13961395

1396+
v = NULL;
13971397
#ifdef FRIBIDI_MAJOR_VERSION
13981398
{
13991399
const char *a = strchr(fribidi_version_info, ')');
14001400
const char *b = strchr(fribidi_version_info, '\n');
14011401
if (a && b && a + 2 < b) {
14021402
v = PyUnicode_FromStringAndSize(a + 2, b - (a + 2));
1403-
} else {
1404-
v = Py_None;
14051403
}
14061404
}
1407-
#else
1408-
v = Py_None;
14091405
#endif
1410-
PyDict_SetItemString(d, "fribidi_version", v);
1406+
PyDict_SetItemString(d, "fribidi_version", v ? v : Py_None);
1407+
Py_XDECREF(v);
14111408

1409+
v = NULL;
14121410
#ifdef HB_VERSION_STRING
14131411
v = PyUnicode_FromString(hb_version_string());
1414-
#else
1415-
v = Py_None;
14161412
#endif
1417-
PyDict_SetItemString(d, "harfbuzz_version", v);
1413+
PyDict_SetItemString(d, "harfbuzz_version", v ? v : Py_None);
1414+
Py_XDECREF(v);
14181415
}
14191416

14201417
return 0;

0 commit comments

Comments
 (0)