Skip to content

Decrement reference count #7003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Decrement reference count
  • Loading branch information
radarhere committed Mar 11, 2023
commit c63b0ca2106d452311b201f52d4ecb107ffe0c31
66 changes: 44 additions & 22 deletions src/_imaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -3820,15 +3820,29 @@ _get_stats(PyObject *self, PyObject *args) {
if (!d) {
return NULL;
}
PyDict_SetItemString(d, "new_count", PyLong_FromLong(arena->stats_new_count));
PyDict_SetItemString(
d, "allocated_blocks", PyLong_FromLong(arena->stats_allocated_blocks));
PyDict_SetItemString(
d, "reused_blocks", PyLong_FromLong(arena->stats_reused_blocks));
PyDict_SetItemString(
d, "reallocated_blocks", PyLong_FromLong(arena->stats_reallocated_blocks));
PyDict_SetItemString(d, "freed_blocks", PyLong_FromLong(arena->stats_freed_blocks));
PyDict_SetItemString(d, "blocks_cached", PyLong_FromLong(arena->blocks_cached));
PyObject *new_count = PyLong_FromLong(arena->stats_new_count);
PyDict_SetItemString(d, "new_count", new_count);
Py_XDECREF(new_count);

PyObject *allocated_blocks = PyLong_FromLong(arena->stats_allocated_blocks);
PyDict_SetItemString(d, "allocated_blocks", allocated_blocks);
Py_XDECREF(allocated_blocks);

PyObject *reused_blocks = PyLong_FromLong(arena->stats_reused_blocks);
PyDict_SetItemString(d, "reused_blocks", reused_blocks);
Py_XDECREF(reused_blocks);

PyObject *reallocated_blocks = PyLong_FromLong(arena->stats_reallocated_blocks);
PyDict_SetItemString(d, "reallocated_blocks", reallocated_blocks);
Py_XDECREF(reallocated_blocks);

PyObject *freed_blocks = PyLong_FromLong(arena->stats_freed_blocks);
PyDict_SetItemString(d, "freed_blocks", freed_blocks);
Py_XDECREF(freed_blocks);

PyObject *blocks_cached = PyLong_FromLong(arena->blocks_cached);
PyDict_SetItemString(d, "blocks_cached", blocks_cached);
Py_XDECREF(blocks_cached);
return d;
}

Expand Down Expand Up @@ -4197,16 +4211,18 @@ setup_module(PyObject *m) {
#ifdef HAVE_LIBJPEG
{
extern const char *ImagingJpegVersion(void);
PyDict_SetItemString(
d, "jpeglib_version", PyUnicode_FromString(ImagingJpegVersion()));
PyObject *jpeglib_version = PyUnicode_FromString(ImagingJpegVersion());
PyDict_SetItemString(d, "jpeglib_version", jpeglib_version);
Py_DECREF(jpeglib_version);
}
#endif

#ifdef HAVE_OPENJPEG
{
extern const char *ImagingJpeg2KVersion(void);
PyDict_SetItemString(
d, "jp2klib_version", PyUnicode_FromString(ImagingJpeg2KVersion()));
PyObject *jp2klib_version = PyUnicode_FromString(ImagingJpeg2KVersion());
PyDict_SetItemString(d, "jp2klib_version", jp2klib_version);
Py_DECREF(jp2klib_version);
}
#endif

Expand All @@ -4215,8 +4231,9 @@ setup_module(PyObject *m) {
have_libjpegturbo = Py_True;
#define tostr1(a) #a
#define tostr(a) tostr1(a)
PyDict_SetItemString(
d, "libjpeg_turbo_version", PyUnicode_FromString(tostr(LIBJPEG_TURBO_VERSION)));
PyObject *libjpeg_turbo_version = PyUnicode_FromString(tostr(LIBJPEG_TURBO_VERSION));
PyDict_SetItemString(d, "libjpeg_turbo_version", libjpeg_turbo_version);
Py_DECREF(libjpeg_turbo_version);
#undef tostr
#undef tostr1
#else
Expand All @@ -4230,8 +4247,9 @@ setup_module(PyObject *m) {
have_libimagequant = Py_True;
{
extern const char *ImagingImageQuantVersion(void);
PyDict_SetItemString(
d, "imagequant_version", PyUnicode_FromString(ImagingImageQuantVersion()));
PyObject *imagequant_version = PyUnicode_FromString(ImagingImageQuantVersion());
PyDict_SetItemString(d, "imagequant_version", imagequant_version);
Py_DECREF(imagequant_version);
}
#else
have_libimagequant = Py_False;
Expand All @@ -4248,16 +4266,18 @@ setup_module(PyObject *m) {
PyModule_AddIntConstant(m, "FIXED", Z_FIXED);
{
extern const char *ImagingZipVersion(void);
PyDict_SetItemString(
d, "zlib_version", PyUnicode_FromString(ImagingZipVersion()));
PyObject *zlibversion = PyUnicode_FromString(ImagingZipVersion());
PyDict_SetItemString(d, "zlib_version", zlibversion);
Py_DECREF(zlibversion);
}
#endif

#ifdef HAVE_LIBTIFF
{
extern const char *ImagingTiffVersion(void);
PyDict_SetItemString(
d, "libtiff_version", PyUnicode_FromString(ImagingTiffVersion()));
PyObject *libtiff_version = PyUnicode_FromString(ImagingTiffVersion());
PyDict_SetItemString(d, "libtiff_version", libtiff_version);
Py_DECREF(libtiff_version);

// Test for libtiff 4.0 or later, excluding libtiff 3.9.6 and 3.9.7
PyObject *support_custom_tags;
Expand All @@ -4280,7 +4300,9 @@ setup_module(PyObject *m) {
Py_INCREF(have_xcb);
PyModule_AddObject(m, "HAVE_XCB", have_xcb);

PyDict_SetItemString(d, "PILLOW_VERSION", PyUnicode_FromString(version));
PyObject *pillow_version = PyUnicode_FromString(version);
PyDict_SetItemString(d, "PILLOW_VERSION", pillow_version);
Py_DECREF(pillow_version);

return 0;
}
Expand Down
3 changes: 3 additions & 0 deletions src/_imagingcms.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,8 @@ _is_intent_supported(CmsProfileObject *self, int clut) {
return Py_None;
}
PyDict_SetItem(result, id, entry);
Py_DECREF(id);
Py_DECREF(entry);
}
return result;
}
Expand Down Expand Up @@ -1532,6 +1534,7 @@ setup_module(PyObject *m) {
v = PyUnicode_FromFormat("%d.%d", vn / 1000, (vn / 10) % 100);
}
PyDict_SetItemString(d, "littlecms_version", v);
Py_DECREF(v);

return 0;
}
Expand Down
20 changes: 15 additions & 5 deletions src/_imagingft.c
Original file line number Diff line number Diff line change
Expand Up @@ -1129,11 +1129,17 @@ font_getvaraxes(FontObject *self) {
axis = master->axis[i];

list_axis = PyDict_New();
PyDict_SetItemString(
list_axis, "minimum", PyLong_FromLong(axis.minimum / 65536));
PyDict_SetItemString(list_axis, "default", PyLong_FromLong(axis.def / 65536));
PyDict_SetItemString(
list_axis, "maximum", PyLong_FromLong(axis.maximum / 65536));
PyObject *minimum = PyLong_FromLong(axis.minimum / 65536);
PyDict_SetItemString(list_axis, "minimum", minimum);
Py_XDECREF(minimum);

PyObject *def = PyLong_FromLong(axis.def / 65536);
PyDict_SetItemString(list_axis, "default", def);
Py_XDECREF(def);

PyObject *maximum = PyLong_FromLong(axis.maximum / 65536);
PyDict_SetItemString(list_axis, "maximum", maximum);
Py_XDECREF(maximum);

for (j = 0; j < name_count; j++) {
error = FT_Get_Sfnt_Name(self->face, j, &name);
Expand All @@ -1144,6 +1150,7 @@ font_getvaraxes(FontObject *self) {
if (name.name_id == axis.strid) {
axis_name = Py_BuildValue("y#", name.string, name.string_len);
PyDict_SetItemString(list_axis, "name", axis_name);
Py_XDECREF(axis_name);
break;
}
}
Expand Down Expand Up @@ -1359,6 +1366,7 @@ setup_module(PyObject *m) {

v = PyUnicode_FromFormat("%d.%d.%d", major, minor, patch);
PyDict_SetItemString(d, "freetype2_version", v);
Py_DECREF(v);

#ifdef HAVE_RAQM
#if defined(HAVE_RAQM_SYSTEM) || defined(HAVE_FRIBIDI_SYSTEM)
Expand All @@ -1376,13 +1384,15 @@ setup_module(PyObject *m) {
PyDict_SetItemString(d, "HAVE_RAQM", v);
PyDict_SetItemString(d, "HAVE_FRIBIDI", v);
PyDict_SetItemString(d, "HAVE_HARFBUZZ", v);
Py_DECREF(v);
if (have_raqm) {
#ifdef RAQM_VERSION_MAJOR
v = PyUnicode_FromString(raqm_version_string());
#else
v = Py_None;
#endif
PyDict_SetItemString(d, "raqm_version", v);
Py_DECREF(v);

#ifdef FRIBIDI_MAJOR_VERSION
{
Expand Down
6 changes: 5 additions & 1 deletion src/_imagingmorph.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ match(PyObject *self, PyObject *args) {
if (lut[lut_idx]) {
PyObject *coordObj = Py_BuildValue("(nn)", col_idx, row_idx);
PyList_Append(ret, coordObj);
Py_XDECREF(coordObj);
}
}
}
Expand Down Expand Up @@ -230,6 +231,7 @@ get_on_pixels(PyObject *self, PyObject *args) {
if (row[col_idx]) {
PyObject *coordObj = Py_BuildValue("(nn)", col_idx, row_idx);
PyList_Append(ret, coordObj);
Py_XDECREF(coordObj);
}
}
}
Expand All @@ -240,7 +242,9 @@ static int
setup_module(PyObject *m) {
PyObject *d = PyModule_GetDict(m);

PyDict_SetItemString(d, "__version", PyUnicode_FromString("0.1"));
PyObject *version = PyUnicode_FromString("0.1");
PyDict_SetItemString(d, "__version", version);
Py_DECREF(version);

return 0;
}
Expand Down
11 changes: 7 additions & 4 deletions src/_webp.c
Original file line number Diff line number Diff line change
Expand Up @@ -949,8 +949,10 @@ addAnimFlagToModule(PyObject *m) {

void
addTransparencyFlagToModule(PyObject *m) {
PyModule_AddObject(
m, "HAVE_TRANSPARENCY", PyBool_FromLong(!WebPDecoderBuggyAlpha()));
PyObject *have_transparency = PyBool_FromLong(!WebPDecoderBuggyAlpha());
if (PyModule_AddObject(m, "HAVE_TRANSPARENCY", have_transparency)) {
Py_DECREF(have_transparency);
}
}

static int
Expand All @@ -960,8 +962,9 @@ setup_module(PyObject *m) {
addAnimFlagToModule(m);
addTransparencyFlagToModule(m);

PyDict_SetItemString(
d, "webpdecoder_version", PyUnicode_FromString(WebPDecoderVersion_str()));
PyObject *webpdecoder_version = PyUnicode_FromString(WebPDecoderVersion_str());
PyDict_SetItemString(d, "webpdecoder_version", webpdecoder_version);
Py_DECREF(webpdecoder_version);

#ifdef HAVE_WEBPANIM
/* Ready object types */
Expand Down