Skip to content
Merged
4 changes: 4 additions & 0 deletions src/_imaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -4448,5 +4448,9 @@ PyInit__imaging(void) {
return NULL;
}

#ifdef Py_GIL_DISABLED
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
#endif

return m;
}
4 changes: 4 additions & 0 deletions src/_imagingcms.c
Original file line number Diff line number Diff line change
Expand Up @@ -1538,5 +1538,9 @@ PyInit__imagingcms(void) {

PyDateTime_IMPORT;

#ifdef Py_GIL_DISABLED
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
#endif

return m;
}
18 changes: 17 additions & 1 deletion src/_imagingft.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "thirdparty/pythoncapi_compat.h"
#include "libImaging/Imaging.h"

#include <ft2build.h>
Expand Down Expand Up @@ -1204,6 +1205,16 @@ font_getvarnames(FontObject *self) {

num_namedstyles = master->num_namedstyles;
list_names = PyList_New(num_namedstyles);

int *list_names_filled = PyMem_Malloc(num_namedstyles * sizeof(int));
if (list_names_filled == NULL) {
return PyErr_NoMemory();
}

for (int i = 0; i < num_namedstyles; i++) {
list_names_filled[i] = 0;
}

if (list_names == NULL) {
FT_Done_MM_Var(library, master);
return NULL;
Expand All @@ -1219,13 +1230,14 @@ font_getvarnames(FontObject *self) {
}

for (j = 0; j < num_namedstyles; j++) {
if (PyList_GetItem(list_names, j) != NULL) {
if (list_names_filled[j]) {
continue;
}

if (master->namedstyle[j].strid == name.name_id) {
list_name = Py_BuildValue("y#", name.string, name.string_len);
PyList_SetItem(list_names, j, list_name);
list_names_filled[j] = 1;
break;
}
}
Expand Down Expand Up @@ -1576,5 +1588,9 @@ PyInit__imagingft(void) {
return NULL;
}

#ifdef Py_GIL_DISABLED
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
#endif

return m;
}
4 changes: 4 additions & 0 deletions src/_imagingmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,5 +290,9 @@ PyInit__imagingmath(void) {
return NULL;
}

#ifdef Py_GIL_DISABLED
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
#endif

return m;
}
4 changes: 4 additions & 0 deletions src/_imagingmorph.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,5 +269,9 @@ PyInit__imagingmorph(void) {

m = PyModule_Create(&module_def);

#ifdef Py_GIL_DISABLED
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
#endif

return m;
}
5 changes: 5 additions & 0 deletions src/_imagingtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,10 @@ PyInit__imagingtk(void) {
Py_DECREF(m);
return NULL;
}

#ifdef Py_GIL_DISABLED
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
#endif

return m;
}
4 changes: 4 additions & 0 deletions src/_webp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1005,5 +1005,9 @@ PyInit__webp(void) {
return NULL;
}

#ifdef Py_GIL_DISABLED
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
#endif

return m;
}
10 changes: 7 additions & 3 deletions src/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#define PY_SSIZE_T_CLEAN
#include "Python.h"

#include "thirdparty/pythoncapi_compat.h"
#include "libImaging/Imaging.h"
#include "libImaging/Gif.h"

Expand Down Expand Up @@ -671,7 +672,7 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
tags_size = PyList_Size(tags);
TRACE(("tags size: %d\n", (int)tags_size));
for (pos = 0; pos < tags_size; pos++) {
item = PyList_GetItem(tags, pos);
item = PyList_GetItemRef(tags, pos);
if (!PyTuple_Check(item) || PyTuple_Size(item) != 2) {
PyErr_SetString(PyExc_ValueError, "Invalid tags list");
return NULL;
Expand Down Expand Up @@ -703,7 +704,7 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {

num_core_tags = sizeof(core_tags) / sizeof(int);
for (pos = 0; pos < tags_size; pos++) {
item = PyList_GetItem(tags, pos);
item = PyList_GetItemRef(tags, pos);
// We already checked that tags is a 2-tuple list.
key = PyTuple_GetItem(item, 0);
key_int = (int)PyLong_AsLong(key);
Expand All @@ -721,7 +722,10 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
}

if (!is_core_tag) {
PyObject *tag_type = PyDict_GetItem(types, key);
PyObject *tag_type;
if (PyDict_GetItemRef(types, key, &tag_type) == 0) {
PyErr_SetString(PyExc_KeyError, "unknown tag type");
}
if (tag_type) {
int type_int = PyLong_AsLong(tag_type);
if (type_int >= TIFF_BYTE && type_int <= TIFF_DOUBLE) {
Expand Down
Loading