mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-14 03:21:44 +03:00
Merge pull request #7003 from radarhere/reference_count
Decrement reference count
This commit is contained in:
commit
e7fa3091a0
|
@ -3810,6 +3810,7 @@ static PyTypeObject PixelAccess_Type = {
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_get_stats(PyObject *self, PyObject *args) {
|
_get_stats(PyObject *self, PyObject *args) {
|
||||||
PyObject *d;
|
PyObject *d;
|
||||||
|
PyObject *v;
|
||||||
ImagingMemoryArena arena = &ImagingDefaultArena;
|
ImagingMemoryArena arena = &ImagingDefaultArena;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, ":get_stats")) {
|
if (!PyArg_ParseTuple(args, ":get_stats")) {
|
||||||
|
@ -3820,15 +3821,29 @@ _get_stats(PyObject *self, PyObject *args) {
|
||||||
if (!d) {
|
if (!d) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
PyDict_SetItemString(d, "new_count", PyLong_FromLong(arena->stats_new_count));
|
v = PyLong_FromLong(arena->stats_new_count);
|
||||||
PyDict_SetItemString(
|
PyDict_SetItemString(d, "new_count", v ? v : Py_None);
|
||||||
d, "allocated_blocks", PyLong_FromLong(arena->stats_allocated_blocks));
|
Py_XDECREF(v);
|
||||||
PyDict_SetItemString(
|
|
||||||
d, "reused_blocks", PyLong_FromLong(arena->stats_reused_blocks));
|
v = PyLong_FromLong(arena->stats_allocated_blocks);
|
||||||
PyDict_SetItemString(
|
PyDict_SetItemString(d, "allocated_blocks", v ? v : Py_None);
|
||||||
d, "reallocated_blocks", PyLong_FromLong(arena->stats_reallocated_blocks));
|
Py_XDECREF(v);
|
||||||
PyDict_SetItemString(d, "freed_blocks", PyLong_FromLong(arena->stats_freed_blocks));
|
|
||||||
PyDict_SetItemString(d, "blocks_cached", PyLong_FromLong(arena->blocks_cached));
|
v = PyLong_FromLong(arena->stats_reused_blocks);
|
||||||
|
PyDict_SetItemString(d, "reused_blocks", v ? v : Py_None);
|
||||||
|
Py_XDECREF(v);
|
||||||
|
|
||||||
|
v = PyLong_FromLong(arena->stats_reallocated_blocks);
|
||||||
|
PyDict_SetItemString(d, "reallocated_blocks", v ? v : Py_None);
|
||||||
|
Py_XDECREF(v);
|
||||||
|
|
||||||
|
v = PyLong_FromLong(arena->stats_freed_blocks);
|
||||||
|
PyDict_SetItemString(d, "freed_blocks", v ? v : Py_None);
|
||||||
|
Py_XDECREF(v);
|
||||||
|
|
||||||
|
v = PyLong_FromLong(arena->blocks_cached);
|
||||||
|
PyDict_SetItemString(d, "blocks_cached", v ? v : Py_None);
|
||||||
|
Py_XDECREF(v);
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4197,28 +4212,33 @@ setup_module(PyObject *m) {
|
||||||
#ifdef HAVE_LIBJPEG
|
#ifdef HAVE_LIBJPEG
|
||||||
{
|
{
|
||||||
extern const char *ImagingJpegVersion(void);
|
extern const char *ImagingJpegVersion(void);
|
||||||
PyDict_SetItemString(
|
PyObject *v = PyUnicode_FromString(ImagingJpegVersion());
|
||||||
d, "jpeglib_version", PyUnicode_FromString(ImagingJpegVersion()));
|
PyDict_SetItemString(d, "jpeglib_version", v ? v : Py_None);
|
||||||
|
Py_XDECREF(v);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_OPENJPEG
|
#ifdef HAVE_OPENJPEG
|
||||||
{
|
{
|
||||||
extern const char *ImagingJpeg2KVersion(void);
|
extern const char *ImagingJpeg2KVersion(void);
|
||||||
PyDict_SetItemString(
|
PyObject *v = PyUnicode_FromString(ImagingJpeg2KVersion());
|
||||||
d, "jp2klib_version", PyUnicode_FromString(ImagingJpeg2KVersion()));
|
PyDict_SetItemString(d, "jp2klib_version", v ? v : Py_None);
|
||||||
|
Py_XDECREF(v);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
PyObject *have_libjpegturbo;
|
PyObject *have_libjpegturbo;
|
||||||
#ifdef LIBJPEG_TURBO_VERSION
|
#ifdef LIBJPEG_TURBO_VERSION
|
||||||
have_libjpegturbo = Py_True;
|
have_libjpegturbo = Py_True;
|
||||||
|
{
|
||||||
#define tostr1(a) #a
|
#define tostr1(a) #a
|
||||||
#define tostr(a) tostr1(a)
|
#define tostr(a) tostr1(a)
|
||||||
PyDict_SetItemString(
|
PyObject *v = PyUnicode_FromString(tostr(LIBJPEG_TURBO_VERSION));
|
||||||
d, "libjpeg_turbo_version", PyUnicode_FromString(tostr(LIBJPEG_TURBO_VERSION)));
|
PyDict_SetItemString(d, "libjpeg_turbo_version", v ? v : Py_None);
|
||||||
|
Py_XDECREF(v);
|
||||||
#undef tostr
|
#undef tostr
|
||||||
#undef tostr1
|
#undef tostr1
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
have_libjpegturbo = Py_False;
|
have_libjpegturbo = Py_False;
|
||||||
#endif
|
#endif
|
||||||
|
@ -4230,8 +4250,9 @@ setup_module(PyObject *m) {
|
||||||
have_libimagequant = Py_True;
|
have_libimagequant = Py_True;
|
||||||
{
|
{
|
||||||
extern const char *ImagingImageQuantVersion(void);
|
extern const char *ImagingImageQuantVersion(void);
|
||||||
PyDict_SetItemString(
|
PyObject *v = PyUnicode_FromString(ImagingImageQuantVersion());
|
||||||
d, "imagequant_version", PyUnicode_FromString(ImagingImageQuantVersion()));
|
PyDict_SetItemString(d, "imagequant_version", v ? v : Py_None);
|
||||||
|
Py_XDECREF(v);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
have_libimagequant = Py_False;
|
have_libimagequant = Py_False;
|
||||||
|
@ -4248,16 +4269,18 @@ setup_module(PyObject *m) {
|
||||||
PyModule_AddIntConstant(m, "FIXED", Z_FIXED);
|
PyModule_AddIntConstant(m, "FIXED", Z_FIXED);
|
||||||
{
|
{
|
||||||
extern const char *ImagingZipVersion(void);
|
extern const char *ImagingZipVersion(void);
|
||||||
PyDict_SetItemString(
|
PyObject *v = PyUnicode_FromString(ImagingZipVersion());
|
||||||
d, "zlib_version", PyUnicode_FromString(ImagingZipVersion()));
|
PyDict_SetItemString(d, "zlib_version", v ? v : Py_None);
|
||||||
|
Py_XDECREF(v);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_LIBTIFF
|
#ifdef HAVE_LIBTIFF
|
||||||
{
|
{
|
||||||
extern const char *ImagingTiffVersion(void);
|
extern const char *ImagingTiffVersion(void);
|
||||||
PyDict_SetItemString(
|
PyObject *v = PyUnicode_FromString(ImagingTiffVersion());
|
||||||
d, "libtiff_version", PyUnicode_FromString(ImagingTiffVersion()));
|
PyDict_SetItemString(d, "libtiff_version", v ? v : Py_None);
|
||||||
|
Py_XDECREF(v);
|
||||||
|
|
||||||
// Test for libtiff 4.0 or later, excluding libtiff 3.9.6 and 3.9.7
|
// Test for libtiff 4.0 or later, excluding libtiff 3.9.6 and 3.9.7
|
||||||
PyObject *support_custom_tags;
|
PyObject *support_custom_tags;
|
||||||
|
@ -4280,7 +4303,9 @@ setup_module(PyObject *m) {
|
||||||
Py_INCREF(have_xcb);
|
Py_INCREF(have_xcb);
|
||||||
PyModule_AddObject(m, "HAVE_XCB", 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 ? pillow_version : Py_None);
|
||||||
|
Py_XDECREF(pillow_version);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -950,6 +950,8 @@ _is_intent_supported(CmsProfileObject *self, int clut) {
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
PyDict_SetItem(result, id, entry);
|
PyDict_SetItem(result, id, entry);
|
||||||
|
Py_DECREF(id);
|
||||||
|
Py_DECREF(entry);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -1531,7 +1533,8 @@ setup_module(PyObject *m) {
|
||||||
} else {
|
} else {
|
||||||
v = PyUnicode_FromFormat("%d.%d", vn / 1000, (vn / 10) % 100);
|
v = PyUnicode_FromFormat("%d.%d", vn / 1000, (vn / 10) % 100);
|
||||||
}
|
}
|
||||||
PyDict_SetItemString(d, "littlecms_version", v);
|
PyDict_SetItemString(d, "littlecms_version", v ? v : Py_None);
|
||||||
|
Py_XDECREF(v);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1129,11 +1129,17 @@ font_getvaraxes(FontObject *self) {
|
||||||
axis = master->axis[i];
|
axis = master->axis[i];
|
||||||
|
|
||||||
list_axis = PyDict_New();
|
list_axis = PyDict_New();
|
||||||
PyDict_SetItemString(
|
PyObject *minimum = PyLong_FromLong(axis.minimum / 65536);
|
||||||
list_axis, "minimum", PyLong_FromLong(axis.minimum / 65536));
|
PyDict_SetItemString(list_axis, "minimum", minimum ? minimum : Py_None);
|
||||||
PyDict_SetItemString(list_axis, "default", PyLong_FromLong(axis.def / 65536));
|
Py_XDECREF(minimum);
|
||||||
PyDict_SetItemString(
|
|
||||||
list_axis, "maximum", PyLong_FromLong(axis.maximum / 65536));
|
PyObject *def = PyLong_FromLong(axis.def / 65536);
|
||||||
|
PyDict_SetItemString(list_axis, "default", def ? def : Py_None);
|
||||||
|
Py_XDECREF(def);
|
||||||
|
|
||||||
|
PyObject *maximum = PyLong_FromLong(axis.maximum / 65536);
|
||||||
|
PyDict_SetItemString(list_axis, "maximum", maximum ? maximum : Py_None);
|
||||||
|
Py_XDECREF(maximum);
|
||||||
|
|
||||||
for (j = 0; j < name_count; j++) {
|
for (j = 0; j < name_count; j++) {
|
||||||
error = FT_Get_Sfnt_Name(self->face, j, &name);
|
error = FT_Get_Sfnt_Name(self->face, j, &name);
|
||||||
|
@ -1143,7 +1149,8 @@ font_getvaraxes(FontObject *self) {
|
||||||
|
|
||||||
if (name.name_id == axis.strid) {
|
if (name.name_id == axis.strid) {
|
||||||
axis_name = Py_BuildValue("y#", name.string, name.string_len);
|
axis_name = Py_BuildValue("y#", name.string, name.string_len);
|
||||||
PyDict_SetItemString(list_axis, "name", axis_name);
|
PyDict_SetItemString(list_axis, "name", axis_name ? axis_name : Py_None);
|
||||||
|
Py_XDECREF(axis_name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1358,7 +1365,8 @@ setup_module(PyObject *m) {
|
||||||
FT_Library_Version(library, &major, &minor, &patch);
|
FT_Library_Version(library, &major, &minor, &patch);
|
||||||
|
|
||||||
v = PyUnicode_FromFormat("%d.%d.%d", major, minor, patch);
|
v = PyUnicode_FromFormat("%d.%d.%d", major, minor, patch);
|
||||||
PyDict_SetItemString(d, "freetype2_version", v);
|
PyDict_SetItemString(d, "freetype2_version", v ? v : Py_None);
|
||||||
|
Py_XDECREF(v);
|
||||||
|
|
||||||
#ifdef HAVE_RAQM
|
#ifdef HAVE_RAQM
|
||||||
#if defined(HAVE_RAQM_SYSTEM) || defined(HAVE_FRIBIDI_SYSTEM)
|
#if defined(HAVE_RAQM_SYSTEM) || defined(HAVE_FRIBIDI_SYSTEM)
|
||||||
|
@ -1376,35 +1384,34 @@ setup_module(PyObject *m) {
|
||||||
PyDict_SetItemString(d, "HAVE_RAQM", v);
|
PyDict_SetItemString(d, "HAVE_RAQM", v);
|
||||||
PyDict_SetItemString(d, "HAVE_FRIBIDI", v);
|
PyDict_SetItemString(d, "HAVE_FRIBIDI", v);
|
||||||
PyDict_SetItemString(d, "HAVE_HARFBUZZ", v);
|
PyDict_SetItemString(d, "HAVE_HARFBUZZ", v);
|
||||||
|
Py_DECREF(v);
|
||||||
if (have_raqm) {
|
if (have_raqm) {
|
||||||
|
v = NULL;
|
||||||
#ifdef RAQM_VERSION_MAJOR
|
#ifdef RAQM_VERSION_MAJOR
|
||||||
v = PyUnicode_FromString(raqm_version_string());
|
v = PyUnicode_FromString(raqm_version_string());
|
||||||
#else
|
|
||||||
v = Py_None;
|
|
||||||
#endif
|
#endif
|
||||||
PyDict_SetItemString(d, "raqm_version", v);
|
PyDict_SetItemString(d, "raqm_version", v ? v : Py_None);
|
||||||
|
Py_XDECREF(v);
|
||||||
|
|
||||||
|
v = NULL;
|
||||||
#ifdef FRIBIDI_MAJOR_VERSION
|
#ifdef FRIBIDI_MAJOR_VERSION
|
||||||
{
|
{
|
||||||
const char *a = strchr(fribidi_version_info, ')');
|
const char *a = strchr(fribidi_version_info, ')');
|
||||||
const char *b = strchr(fribidi_version_info, '\n');
|
const char *b = strchr(fribidi_version_info, '\n');
|
||||||
if (a && b && a + 2 < b) {
|
if (a && b && a + 2 < b) {
|
||||||
v = PyUnicode_FromStringAndSize(a + 2, b - (a + 2));
|
v = PyUnicode_FromStringAndSize(a + 2, b - (a + 2));
|
||||||
} else {
|
|
||||||
v = Py_None;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
v = Py_None;
|
|
||||||
#endif
|
#endif
|
||||||
PyDict_SetItemString(d, "fribidi_version", v);
|
PyDict_SetItemString(d, "fribidi_version", v ? v : Py_None);
|
||||||
|
Py_XDECREF(v);
|
||||||
|
|
||||||
|
v = NULL;
|
||||||
#ifdef HB_VERSION_STRING
|
#ifdef HB_VERSION_STRING
|
||||||
v = PyUnicode_FromString(hb_version_string());
|
v = PyUnicode_FromString(hb_version_string());
|
||||||
#else
|
|
||||||
v = Py_None;
|
|
||||||
#endif
|
#endif
|
||||||
PyDict_SetItemString(d, "harfbuzz_version", v);
|
PyDict_SetItemString(d, "harfbuzz_version", v ? v : Py_None);
|
||||||
|
Py_XDECREF(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -194,6 +194,7 @@ match(PyObject *self, PyObject *args) {
|
||||||
if (lut[lut_idx]) {
|
if (lut[lut_idx]) {
|
||||||
PyObject *coordObj = Py_BuildValue("(nn)", col_idx, row_idx);
|
PyObject *coordObj = Py_BuildValue("(nn)", col_idx, row_idx);
|
||||||
PyList_Append(ret, coordObj);
|
PyList_Append(ret, coordObj);
|
||||||
|
Py_XDECREF(coordObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -230,21 +231,13 @@ get_on_pixels(PyObject *self, PyObject *args) {
|
||||||
if (row[col_idx]) {
|
if (row[col_idx]) {
|
||||||
PyObject *coordObj = Py_BuildValue("(nn)", col_idx, row_idx);
|
PyObject *coordObj = Py_BuildValue("(nn)", col_idx, row_idx);
|
||||||
PyList_Append(ret, coordObj);
|
PyList_Append(ret, coordObj);
|
||||||
|
Py_XDECREF(coordObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
setup_module(PyObject *m) {
|
|
||||||
PyObject *d = PyModule_GetDict(m);
|
|
||||||
|
|
||||||
PyDict_SetItemString(d, "__version", PyUnicode_FromString("0.1"));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyMethodDef functions[] = {
|
static PyMethodDef functions[] = {
|
||||||
/* Functions */
|
/* Functions */
|
||||||
{"apply", (PyCFunction)apply, METH_VARARGS, NULL},
|
{"apply", (PyCFunction)apply, METH_VARARGS, NULL},
|
||||||
|
@ -266,9 +259,5 @@ PyInit__imagingmorph(void) {
|
||||||
|
|
||||||
m = PyModule_Create(&module_def);
|
m = PyModule_Create(&module_def);
|
||||||
|
|
||||||
if (setup_module(m) < 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
11
src/_webp.c
11
src/_webp.c
|
@ -949,8 +949,10 @@ addAnimFlagToModule(PyObject *m) {
|
||||||
|
|
||||||
void
|
void
|
||||||
addTransparencyFlagToModule(PyObject *m) {
|
addTransparencyFlagToModule(PyObject *m) {
|
||||||
PyModule_AddObject(
|
PyObject *have_transparency = PyBool_FromLong(!WebPDecoderBuggyAlpha());
|
||||||
m, "HAVE_TRANSPARENCY", PyBool_FromLong(!WebPDecoderBuggyAlpha()));
|
if (PyModule_AddObject(m, "HAVE_TRANSPARENCY", have_transparency)) {
|
||||||
|
Py_DECREF(have_transparency);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -967,8 +969,9 @@ setup_module(PyObject *m) {
|
||||||
addAnimFlagToModule(m);
|
addAnimFlagToModule(m);
|
||||||
addTransparencyFlagToModule(m);
|
addTransparencyFlagToModule(m);
|
||||||
|
|
||||||
PyDict_SetItemString(
|
PyObject *v = PyUnicode_FromString(WebPDecoderVersion_str());
|
||||||
d, "webpdecoder_version", PyUnicode_FromString(WebPDecoderVersion_str()));
|
PyDict_SetItemString(d, "webpdecoder_version", v ? v : Py_None);
|
||||||
|
Py_XDECREF(v);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user