@@ -16,7 +16,7 @@ Copyright (c) Corporation for National Research Initiatives.
1616#include "pycore_runtime.h" // _Py_ID()
1717#include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI
1818#include "pycore_unicodeobject.h" // _PyUnicode_InternMortal()
19-
19+ #include "pycore_pyatomic_ft_wrappers.h"
2020
2121static const char * codecs_builtin_error_handlers [] = {
2222 "strict" , "ignore" , "replace" ,
@@ -40,13 +40,10 @@ int PyCodec_Register(PyObject *search_function)
4040 PyErr_SetString (PyExc_TypeError , "argument must be callable" );
4141 goto onError ;
4242 }
43- #ifdef Py_GIL_DISABLED
44- PyMutex_Lock (& interp -> codecs .search_path_mutex );
45- #endif
43+ FT_MUTEX_LOCK (& interp -> codecs .search_path_mutex );
4644 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+
5047 return ret ;
5148
5249 onError :
@@ -66,19 +63,15 @@ PyCodec_Unregister(PyObject *search_function)
6663 PyObject * codec_search_path = interp -> codecs .search_path ;
6764 assert (PyList_CheckExact (codec_search_path ));
6865 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 );
7267 PyObject * item = PyList_GetItemRef (codec_search_path , i );
7368 int ret = 1 ;
7469 if (item == search_function ) {
7570 // We hold a reference to the item, so its destructor can't run
7671 // while we hold search_path_mutex.
7772 ret = PyList_SetSlice (codec_search_path , i , i + 1 , NULL );
7873 }
79- #ifdef Py_GIL_DISABLED
80- PyMutex_Unlock (& interp -> codecs .search_path_mutex );
81- #endif
74+ FT_MUTEX_UNLOCK (& interp -> codecs .search_path_mutex );
8275 Py_DECREF (item );
8376 if (ret != 1 ) {
8477 assert (interp -> codecs .search_cache != NULL );
0 commit comments