mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-05-29 18:23:24 +03:00
Merge pull request #8216 from hugovk/free-threading
This commit is contained in:
commit
6944e9e183
|
@ -2251,6 +2251,11 @@ _getcolors(ImagingObject *self, PyObject *args) {
|
||||||
ImagingColorItem *v = &items[i];
|
ImagingColorItem *v = &items[i];
|
||||||
PyObject *item = Py_BuildValue(
|
PyObject *item = Py_BuildValue(
|
||||||
"iN", v->count, getpixel(self->image, self->access, v->x, v->y));
|
"iN", v->count, getpixel(self->image, self->access, v->x, v->y));
|
||||||
|
if (item == NULL) {
|
||||||
|
Py_DECREF(out);
|
||||||
|
free(items);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
PyList_SetItem(out, i, item);
|
PyList_SetItem(out, i, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4448,5 +4453,9 @@ PyInit__imaging(void) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef Py_GIL_DISABLED
|
||||||
|
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
|
||||||
|
#endif
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1538,5 +1538,9 @@ PyInit__imagingcms(void) {
|
||||||
|
|
||||||
PyDateTime_IMPORT;
|
PyDateTime_IMPORT;
|
||||||
|
|
||||||
|
#ifdef Py_GIL_DISABLED
|
||||||
|
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
|
||||||
|
#endif
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
#define PY_SSIZE_T_CLEAN
|
#define PY_SSIZE_T_CLEAN
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
|
#include "thirdparty/pythoncapi_compat.h"
|
||||||
#include "libImaging/Imaging.h"
|
#include "libImaging/Imaging.h"
|
||||||
|
|
||||||
#include <ft2build.h>
|
#include <ft2build.h>
|
||||||
|
@ -1209,30 +1210,49 @@ font_getvarnames(FontObject *self) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int *list_names_filled = PyMem_Malloc(num_namedstyles * sizeof(int));
|
||||||
|
if (list_names_filled == NULL) {
|
||||||
|
Py_DECREF(list_names);
|
||||||
|
FT_Done_MM_Var(library, master);
|
||||||
|
return PyErr_NoMemory();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < num_namedstyles; i++) {
|
||||||
|
list_names_filled[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
name_count = FT_Get_Sfnt_Name_Count(self->face);
|
name_count = FT_Get_Sfnt_Name_Count(self->face);
|
||||||
for (i = 0; i < name_count; i++) {
|
for (i = 0; i < name_count; i++) {
|
||||||
error = FT_Get_Sfnt_Name(self->face, i, &name);
|
error = FT_Get_Sfnt_Name(self->face, i, &name);
|
||||||
if (error) {
|
if (error) {
|
||||||
|
PyMem_Free(list_names_filled);
|
||||||
Py_DECREF(list_names);
|
Py_DECREF(list_names);
|
||||||
FT_Done_MM_Var(library, master);
|
FT_Done_MM_Var(library, master);
|
||||||
return geterror(error);
|
return geterror(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (j = 0; j < num_namedstyles; j++) {
|
for (j = 0; j < num_namedstyles; j++) {
|
||||||
if (PyList_GetItem(list_names, j) != NULL) {
|
if (list_names_filled[j]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (master->namedstyle[j].strid == name.name_id) {
|
if (master->namedstyle[j].strid == name.name_id) {
|
||||||
list_name = Py_BuildValue("y#", name.string, name.string_len);
|
list_name = Py_BuildValue("y#", name.string, name.string_len);
|
||||||
|
if (list_name == NULL) {
|
||||||
|
PyMem_Free(list_names_filled);
|
||||||
|
Py_DECREF(list_names);
|
||||||
|
FT_Done_MM_Var(library, master);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
PyList_SetItem(list_names, j, list_name);
|
PyList_SetItem(list_names, j, list_name);
|
||||||
|
list_names_filled[j] = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyMem_Free(list_names_filled);
|
||||||
FT_Done_MM_Var(library, master);
|
FT_Done_MM_Var(library, master);
|
||||||
|
|
||||||
return list_names;
|
return list_names;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1289,9 +1309,15 @@ 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);
|
||||||
|
if (axis_name == NULL) {
|
||||||
|
Py_DECREF(list_axis);
|
||||||
|
Py_DECREF(list_axes);
|
||||||
|
FT_Done_MM_Var(library, master);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
PyDict_SetItemString(
|
PyDict_SetItemString(
|
||||||
list_axis, "name", axis_name ? axis_name : Py_None);
|
list_axis, "name", axis_name ? axis_name : Py_None);
|
||||||
Py_XDECREF(axis_name);
|
Py_DECREF(axis_name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1345,7 +1371,12 @@ font_setvaraxes(FontObject *self, PyObject *args) {
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
}
|
}
|
||||||
for (i = 0; i < num_coords; i++) {
|
for (i = 0; i < num_coords; i++) {
|
||||||
item = PyList_GET_ITEM(axes, i);
|
item = PyList_GetItemRef(axes, i);
|
||||||
|
if (item == NULL) {
|
||||||
|
free(coords);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (PyFloat_Check(item)) {
|
if (PyFloat_Check(item)) {
|
||||||
coord = PyFloat_AS_DOUBLE(item);
|
coord = PyFloat_AS_DOUBLE(item);
|
||||||
} else if (PyLong_Check(item)) {
|
} else if (PyLong_Check(item)) {
|
||||||
|
@ -1353,10 +1384,12 @@ font_setvaraxes(FontObject *self, PyObject *args) {
|
||||||
} else if (PyNumber_Check(item)) {
|
} else if (PyNumber_Check(item)) {
|
||||||
coord = PyFloat_AsDouble(item);
|
coord = PyFloat_AsDouble(item);
|
||||||
} else {
|
} else {
|
||||||
|
Py_DECREF(item);
|
||||||
free(coords);
|
free(coords);
|
||||||
PyErr_SetString(PyExc_TypeError, "list must contain numbers");
|
PyErr_SetString(PyExc_TypeError, "list must contain numbers");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Py_DECREF(item);
|
||||||
coords[i] = coord * 65536;
|
coords[i] = coord * 65536;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1576,5 +1609,9 @@ PyInit__imagingft(void) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef Py_GIL_DISABLED
|
||||||
|
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
|
||||||
|
#endif
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
|
@ -290,5 +290,9 @@ PyInit__imagingmath(void) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef Py_GIL_DISABLED
|
||||||
|
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
|
||||||
|
#endif
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
|
@ -269,5 +269,9 @@ PyInit__imagingmorph(void) {
|
||||||
|
|
||||||
m = PyModule_Create(&module_def);
|
m = PyModule_Create(&module_def);
|
||||||
|
|
||||||
|
#ifdef Py_GIL_DISABLED
|
||||||
|
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
|
||||||
|
#endif
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,5 +62,10 @@ PyInit__imagingtk(void) {
|
||||||
Py_DECREF(m);
|
Py_DECREF(m);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef Py_GIL_DISABLED
|
||||||
|
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
|
||||||
|
#endif
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1005,5 +1005,9 @@ PyInit__webp(void) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef Py_GIL_DISABLED
|
||||||
|
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
|
||||||
|
#endif
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
26
src/encode.c
26
src/encode.c
|
@ -25,6 +25,7 @@
|
||||||
#define PY_SSIZE_T_CLEAN
|
#define PY_SSIZE_T_CLEAN
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
|
|
||||||
|
#include "thirdparty/pythoncapi_compat.h"
|
||||||
#include "libImaging/Imaging.h"
|
#include "libImaging/Imaging.h"
|
||||||
#include "libImaging/Gif.h"
|
#include "libImaging/Gif.h"
|
||||||
|
|
||||||
|
@ -671,11 +672,17 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
|
||||||
tags_size = PyList_Size(tags);
|
tags_size = PyList_Size(tags);
|
||||||
TRACE(("tags size: %d\n", (int)tags_size));
|
TRACE(("tags size: %d\n", (int)tags_size));
|
||||||
for (pos = 0; pos < tags_size; pos++) {
|
for (pos = 0; pos < tags_size; pos++) {
|
||||||
item = PyList_GetItem(tags, pos);
|
item = PyList_GetItemRef(tags, pos);
|
||||||
|
if (item == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (!PyTuple_Check(item) || PyTuple_Size(item) != 2) {
|
if (!PyTuple_Check(item) || PyTuple_Size(item) != 2) {
|
||||||
|
Py_DECREF(item);
|
||||||
PyErr_SetString(PyExc_ValueError, "Invalid tags list");
|
PyErr_SetString(PyExc_ValueError, "Invalid tags list");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Py_DECREF(item);
|
||||||
}
|
}
|
||||||
pos = 0;
|
pos = 0;
|
||||||
}
|
}
|
||||||
|
@ -703,11 +710,17 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
|
||||||
|
|
||||||
num_core_tags = sizeof(core_tags) / sizeof(int);
|
num_core_tags = sizeof(core_tags) / sizeof(int);
|
||||||
for (pos = 0; pos < tags_size; pos++) {
|
for (pos = 0; pos < tags_size; pos++) {
|
||||||
item = PyList_GetItem(tags, pos);
|
item = PyList_GetItemRef(tags, pos);
|
||||||
|
if (item == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// We already checked that tags is a 2-tuple list.
|
// We already checked that tags is a 2-tuple list.
|
||||||
key = PyTuple_GetItem(item, 0);
|
key = PyTuple_GET_ITEM(item, 0);
|
||||||
key_int = (int)PyLong_AsLong(key);
|
key_int = (int)PyLong_AsLong(key);
|
||||||
value = PyTuple_GetItem(item, 1);
|
value = PyTuple_GET_ITEM(item, 1);
|
||||||
|
Py_DECREF(item);
|
||||||
|
|
||||||
status = 0;
|
status = 0;
|
||||||
is_core_tag = 0;
|
is_core_tag = 0;
|
||||||
is_var_length = 0;
|
is_var_length = 0;
|
||||||
|
@ -721,7 +734,10 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_core_tag) {
|
if (!is_core_tag) {
|
||||||
PyObject *tag_type = PyDict_GetItem(types, key);
|
PyObject *tag_type;
|
||||||
|
if (PyDict_GetItemRef(types, key, &tag_type) < 0) {
|
||||||
|
return NULL; // Exception has been already set
|
||||||
|
}
|
||||||
if (tag_type) {
|
if (tag_type) {
|
||||||
int type_int = PyLong_AsLong(tag_type);
|
int type_int = PyLong_AsLong(tag_type);
|
||||||
if (type_int >= TIFF_BYTE && type_int <= TIFF_DOUBLE) {
|
if (type_int >= TIFF_BYTE && type_int <= TIFF_DOUBLE) {
|
||||||
|
|
13
src/path.c
13
src/path.c
|
@ -26,6 +26,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
|
#include "thirdparty/pythoncapi_compat.h"
|
||||||
#include "libImaging/Imaging.h"
|
#include "libImaging/Imaging.h"
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
@ -179,14 +180,21 @@ PyPath_Flatten(PyObject *data, double **pxy) {
|
||||||
} \
|
} \
|
||||||
free(xy); \
|
free(xy); \
|
||||||
return -1; \
|
return -1; \
|
||||||
|
} \
|
||||||
|
if (decref) { \
|
||||||
|
Py_DECREF(op); \
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy table to path array */
|
/* Copy table to path array */
|
||||||
if (PyList_Check(data)) {
|
if (PyList_Check(data)) {
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
double x, y;
|
double x, y;
|
||||||
PyObject *op = PyList_GET_ITEM(data, i);
|
PyObject *op = PyList_GetItemRef(data, i);
|
||||||
assign_item_to_array(op, 0);
|
if (op == NULL) {
|
||||||
|
free(xy);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
assign_item_to_array(op, 1);
|
||||||
}
|
}
|
||||||
} else if (PyTuple_Check(data)) {
|
} else if (PyTuple_Check(data)) {
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
|
@ -209,7 +217,6 @@ PyPath_Flatten(PyObject *data, double **pxy) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assign_item_to_array(op, 1);
|
assign_item_to_array(op, 1);
|
||||||
Py_DECREF(op);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1360
src/thirdparty/pythoncapi_compat.h
vendored
Normal file
1360
src/thirdparty/pythoncapi_compat.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user