https://github.com/python/cpython/commit/2b4feee648b7af0ccca8dee167fdd21cfb0bd23a
commit: 2b4feee648b7af0ccca8dee167fdd21cfb0bd23a
branch: main
author: Sam Gross <[email protected]>
committer: colesbury <[email protected]>
date: 2025-12-20T15:37:31-05:00
summary:

gh-122581: Use parser mutex in default build for subinterpreters (gh-142959)

files:
M Include/internal/pycore_parser.h
M Include/internal/pycore_runtime_structs.h
M Parser/pegen.c

diff --git a/Include/internal/pycore_parser.h b/Include/internal/pycore_parser.h
index 2c46f59ab7da9f..b89d02035db71f 100644
--- a/Include/internal/pycore_parser.h
+++ b/Include/internal/pycore_parser.h
@@ -14,10 +14,8 @@ extern "C" {
 #include "pycore_pyarena.h"         // PyArena
 
 _Py_DECLARE_STR(empty, "")
-#if defined(Py_DEBUG) && defined(Py_GIL_DISABLED)
 #define _parser_runtime_state_INIT \
     { \
-        .mutex = {0}, \
         .dummy_name = { \
             .kind = Name_kind, \
             .v.Name.id = &_Py_STR(empty), \
@@ -28,20 +26,6 @@ _Py_DECLARE_STR(empty, "")
             .end_col_offset = 0, \
         }, \
     }
-#else
-#define _parser_runtime_state_INIT \
-    { \
-        .dummy_name = { \
-            .kind = Name_kind, \
-            .v.Name.id = &_Py_STR(empty), \
-            .v.Name.ctx = Load, \
-            .lineno = 1, \
-            .col_offset = 0, \
-            .end_lineno = 1, \
-            .end_col_offset = 0, \
-        }, \
-    }
-#endif
 
 extern struct _mod* _PyParser_ASTFromString(
     const char *str,
diff --git a/Include/internal/pycore_runtime_structs.h 
b/Include/internal/pycore_runtime_structs.h
index 995f49e78dcda3..92387031ad7465 100644
--- a/Include/internal/pycore_runtime_structs.h
+++ b/Include/internal/pycore_runtime_structs.h
@@ -77,9 +77,7 @@ struct _fileutils_state {
 struct _parser_runtime_state {
 #ifdef Py_DEBUG
     long memo_statistics[_PYPEGEN_NSTATISTICS];
-#ifdef Py_GIL_DISABLED
     PyMutex mutex;
-#endif
 #else
     int _not_used;
 #endif
diff --git a/Parser/pegen.c b/Parser/pegen.c
index a38e973b3f64c6..7ecc55eee13775 100644
--- a/Parser/pegen.c
+++ b/Parser/pegen.c
@@ -3,9 +3,8 @@
 #include "pycore_pystate.h"       // _PyThreadState_GET()
 #include "pycore_parser.h"        // _PYPEGEN_NSTATISTICS
 #include "pycore_pyerrors.h"      // PyExc_IncompleteInputError
-#include "pycore_runtime.h"     // _PyRuntime
+#include "pycore_runtime.h"       // _PyRuntime
 #include "pycore_unicodeobject.h" // _PyUnicode_InternImmortal
-#include "pycore_pyatomic_ft_wrappers.h"
 #include <errcode.h>
 
 #include "lexer/lexer.h"
@@ -303,11 +302,11 @@ _PyPegen_fill_token(Parser *p)
 void
 _PyPegen_clear_memo_statistics(void)
 {
-    FT_MUTEX_LOCK(&_PyRuntime.parser.mutex);
+    PyMutex_Lock(&_PyRuntime.parser.mutex);
     for (int i = 0; i < NSTATISTICS; i++) {
         memo_statistics[i] = 0;
     }
-    FT_MUTEX_UNLOCK(&_PyRuntime.parser.mutex);
+    PyMutex_Unlock(&_PyRuntime.parser.mutex);
 }
 
 PyObject *
@@ -318,22 +317,22 @@ _PyPegen_get_memo_statistics(void)
         return NULL;
     }
 
-    FT_MUTEX_LOCK(&_PyRuntime.parser.mutex);
+    PyMutex_Lock(&_PyRuntime.parser.mutex);
     for (int i = 0; i < NSTATISTICS; i++) {
         PyObject *value = PyLong_FromLong(memo_statistics[i]);
         if (value == NULL) {
-            FT_MUTEX_UNLOCK(&_PyRuntime.parser.mutex);
+            PyMutex_Unlock(&_PyRuntime.parser.mutex);
             Py_DECREF(ret);
             return NULL;
         }
         // PyList_SetItem borrows a reference to value.
         if (PyList_SetItem(ret, i, value) < 0) {
-            FT_MUTEX_UNLOCK(&_PyRuntime.parser.mutex);
+            PyMutex_Unlock(&_PyRuntime.parser.mutex);
             Py_DECREF(ret);
             return NULL;
         }
     }
-    FT_MUTEX_UNLOCK(&_PyRuntime.parser.mutex);
+    PyMutex_Unlock(&_PyRuntime.parser.mutex);
     return ret;
 }
 #endif
@@ -359,9 +358,9 @@ _PyPegen_is_memoized(Parser *p, int type, void *pres)
                 if (count <= 0) {
                     count = 1;
                 }
-                FT_MUTEX_LOCK(&_PyRuntime.parser.mutex);
+                PyMutex_Lock(&_PyRuntime.parser.mutex);
                 memo_statistics[type] += count;
-                FT_MUTEX_UNLOCK(&_PyRuntime.parser.mutex);
+                PyMutex_Unlock(&_PyRuntime.parser.mutex);
             }
 #endif
             p->mark = m->mark;

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to