@@ -82,6 +82,9 @@ struct {
82
82
/* font objects */
83
83
84
84
static FT_Library library ;
85
+ #ifdef Py_GIL_DISABLED
86
+ static PyMutex ft_library_mutex ;
87
+ #endif
85
88
86
89
typedef struct {
87
90
PyObject_HEAD FT_Face face ;
@@ -187,7 +190,9 @@ getfont(PyObject *self_, PyObject *args, PyObject *kw) {
187
190
188
191
if (filename && font_bytes_size <= 0 ) {
189
192
self -> font_bytes = NULL ;
193
+ MUTEX_LOCK (& ft_library_mutex );
190
194
error = FT_New_Face (library , filename , index , & self -> face );
195
+ MUTEX_UNLOCK (& ft_library_mutex );
191
196
} else {
192
197
/* need to have allocated storage for font_bytes for the life of the object.*/
193
198
/* Don't free this before FT_Done_Face */
@@ -197,13 +202,15 @@ getfont(PyObject *self_, PyObject *args, PyObject *kw) {
197
202
}
198
203
if (!error ) {
199
204
memcpy (self -> font_bytes , font_bytes , (size_t )font_bytes_size );
205
+ MUTEX_LOCK (& ft_library_mutex );
200
206
error = FT_New_Memory_Face (
201
207
library ,
202
208
(FT_Byte * )self -> font_bytes ,
203
209
font_bytes_size ,
204
210
index ,
205
211
& self -> face
206
212
);
213
+ MUTEX_UNLOCK (& ft_library_mutex );
207
214
}
208
215
}
209
216
@@ -1433,7 +1440,9 @@ font_setvaraxes(FontObject *self, PyObject *args) {
1433
1440
static void
1434
1441
font_dealloc (FontObject * self ) {
1435
1442
if (self -> face ) {
1443
+ MUTEX_LOCK (& ft_library_mutex );
1436
1444
FT_Done_Face (self -> face );
1445
+ MUTEX_UNLOCK (& ft_library_mutex );
1437
1446
}
1438
1447
if (self -> font_bytes ) {
1439
1448
PyMem_Free (self -> font_bytes );
0 commit comments