2525
2626#define INITIAL_SPECIALIZED_CODE_SIZE 16
2727
28- // copypaste from unicodeobject.c
29- #define INTERNED_STRINGS _PyRuntime.cached_objects.interned_strings
30-
3128static const char *
3229code_event_name (PyCodeEvent event ) {
3330 switch (event ) {
@@ -206,15 +203,17 @@ static int
206203intern_constants (PyObject * tuple , int * modified )
207204{
208205 PyInterpreterState * interp = _PyInterpreterState_GET ();
206+ #if !defined(Py_GIL_DISABLED )
209207 PyObject * interned_dict = _Py_INTERP_CACHED_OBJECT (interp , interned_strings );
210208 Py_INCREF (interned_dict );
209+ #endif
211210 for (Py_ssize_t i = PyTuple_GET_SIZE (tuple ); -- i >= 0 ; ) {
212211 PyObject * v = PyTuple_GET_ITEM (tuple , i );
213212 if (PyUnicode_CheckExact (v ) && PyUnicode_GET_LENGTH (v ) > 1 ) {
214213 if (PyUnicode_CHECK_INTERNED (v ) != 0 ) {
215214 continue ;
216215 }
217- Py_BEGIN_CRITICAL_SECTION ( interned_dict );
216+ #if !defined( Py_GIL_DISABLED )
218217 PyObject * interned = PyDict_GetItemWithError (interned_dict , v );
219218 if (interned == NULL && PyErr_Occurred ()) {
220219 goto error ;
@@ -232,7 +231,9 @@ intern_constants(PyObject *tuple, int *modified)
232231 if (modified ) {
233232 * modified = 1 ;
234233 }
235- } else if (should_intern_string (v )) {
234+ } else
235+ #endif
236+ if (should_intern_string (v )) {
236237 PyObject * w = v ;
237238 _PyUnicode_InternMortal (interp , & v );
238239 if (w != v ) {
@@ -242,7 +243,6 @@ intern_constants(PyObject *tuple, int *modified)
242243 }
243244 }
244245 }
245- Py_END_CRITICAL_SECTION ();
246246 }
247247 else if (PyTuple_CheckExact (v )) {
248248 if (intern_constants (v , NULL ) < 0 ) {
@@ -327,11 +327,15 @@ intern_constants(PyObject *tuple, int *modified)
327327 }
328328#endif
329329 }
330+ #if !defined(Py_GIL_DISABLED )
330331 Py_DECREF (interned_dict );
332+ #endif
331333 return 0 ;
332334
333335error :
336+ #if !defined(Py_GIL_DISABLED )
334337 Py_DECREF (interned_dict );
338+ #endif
335339 return -1 ;
336340}
337341
0 commit comments