Skip to content
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

Move away from APIs that use borrowed references under the free-threaded build #8216

Merged
merged 10 commits into from
Jul 13, 2024
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 @@

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

int *list_names_filled = PyMem_Malloc(num_namedstyles * sizeof(int));
hugovk marked this conversation as resolved.
Show resolved Hide resolved
if (list_names_filled == NULL) {
return PyErr_NoMemory();

Check warning on line 1211 in src/_imagingft.c

View check run for this annotation

Codecov / codecov/patch

src/_imagingft.c#L1211

Added line #L1211 was not covered by tests
}

for (int i = 0; i < num_namedstyles; i++) {

Check warning on line 1214 in src/_imagingft.c

View workflow job for this annotation

GitHub Actions / ubuntu-latest Python 3.12

comparison of integer expressions of different signedness: ‘int’ and ‘FT_UInt’ {aka ‘unsigned int’} [-Wsign-compare]
list_names_filled[i] = 0;
}

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

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 @@
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 @@
Py_DECREF(m);
return NULL;
}

#ifdef Py_GIL_DISABLED
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);

Check warning on line 67 in src/_imagingtk.c

View check run for this annotation

Codecov / codecov/patch

src/_imagingtk.c#L67

Added line #L67 was not covered by tests
#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 @@
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 @@

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 @@
}

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");

Check warning on line 727 in src/encode.c

View check run for this annotation

Codecov / codecov/patch

src/encode.c#L727

Added line #L727 was not covered by tests
}
hugovk marked this conversation as resolved.
Show resolved Hide resolved
if (tag_type) {
int type_int = PyLong_AsLong(tag_type);
if (type_int >= TIFF_BYTE && type_int <= TIFF_DOUBLE) {
Expand Down
Loading
Loading