@@ -16,7 +16,7 @@ Copyright (c) Corporation for National Research Initiatives.
16
16
#include "pycore_runtime.h" // _Py_ID()
17
17
#include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI
18
18
#include "pycore_unicodeobject.h" // _PyUnicode_InternMortal()
19
-
19
+ #include "pycore_pyatomic_ft_wrappers.h"
20
20
21
21
static const char * codecs_builtin_error_handlers [] = {
22
22
"strict" , "ignore" , "replace" ,
@@ -40,13 +40,10 @@ int PyCodec_Register(PyObject *search_function)
40
40
PyErr_SetString (PyExc_TypeError , "argument must be callable" );
41
41
goto onError ;
42
42
}
43
- #ifdef Py_GIL_DISABLED
44
- PyMutex_Lock (& interp -> codecs .search_path_mutex );
45
- #endif
43
+ FT_MUTEX_LOCK (& interp -> codecs .search_path_mutex );
46
44
int ret = PyList_Append (interp -> codecs .search_path , search_function );
47
- #ifdef Py_GIL_DISABLED
48
- PyMutex_Unlock (& interp -> codecs .search_path_mutex );
49
- #endif
45
+ FT_MUTEX_UNLOCK (& interp -> codecs .search_path_mutex );
46
+
50
47
return ret ;
51
48
52
49
onError :
@@ -66,19 +63,15 @@ PyCodec_Unregister(PyObject *search_function)
66
63
PyObject * codec_search_path = interp -> codecs .search_path ;
67
64
assert (PyList_CheckExact (codec_search_path ));
68
65
for (Py_ssize_t i = 0 ; i < PyList_GET_SIZE (codec_search_path ); i ++ ) {
69
- #ifdef Py_GIL_DISABLED
70
- PyMutex_Lock (& interp -> codecs .search_path_mutex );
71
- #endif
66
+ FT_MUTEX_LOCK (& interp -> codecs .search_path_mutex );
72
67
PyObject * item = PyList_GetItemRef (codec_search_path , i );
73
68
int ret = 1 ;
74
69
if (item == search_function ) {
75
70
// We hold a reference to the item, so its destructor can't run
76
71
// while we hold search_path_mutex.
77
72
ret = PyList_SetSlice (codec_search_path , i , i + 1 , NULL );
78
73
}
79
- #ifdef Py_GIL_DISABLED
80
- PyMutex_Unlock (& interp -> codecs .search_path_mutex );
81
- #endif
74
+ FT_MUTEX_UNLOCK (& interp -> codecs .search_path_mutex );
82
75
Py_DECREF (item );
83
76
if (ret != 1 ) {
84
77
assert (interp -> codecs .search_cache != NULL );
0 commit comments