gh-122581: Use parser mutex in default build for subinterpreters (gh-… · python/cpython@2b4feee

GitHub

GitHub CopilotWrite better code with AI | MCP RegistryIntegrate external tools | ActionsAutomate any workflow | CodespacesInstant dev environments | IssuesPlan and track work | Code ReviewManage code changes | Code QualityEnforce quality at merge | Why GitHub | Marketplace | View all features | Enterprises | Small and medium teams | Startups | View all use cases | View all industries | View all solutions | AI | Software Development | DevOps | Security | View all topics | Customer stories | Events & webinars | Ebooks & reports | Business insights | Trust center | Partners | View all resources

@@ -3,9 +3,8 @@

33#include"pycore_pystate.h"// _PyThreadState_GET()

44#include"pycore_parser.h"// _PYPEGEN_NSTATISTICS

55#include"pycore_pyerrors.h"// PyExc_IncompleteInputError

6-#include"pycore_runtime.h"// _PyRuntime

6+#include"pycore_runtime.h"// _PyRuntime

77#include"pycore_unicodeobject.h"// _PyUnicode_InternImmortal

8-#include"pycore_pyatomic_ft_wrappers.h"

98#include<errcode.h>

1091110#include"lexer/lexer.h"

@@ -303,11 +302,11 @@ _PyPegen_fill_token(Parser *p)

303302void

304303_PyPegen_clear_memo_statistics(void)

305304{

306-FT_MUTEX_LOCK(&_PyRuntime.parser.mutex);

305+PyMutex_Lock(&_PyRuntime.parser.mutex);

307306for (inti=0; i<NSTATISTICS; i++) {

308307memo_statistics[i] =0;

309308 }

310-FT_MUTEX_UNLOCK(&_PyRuntime.parser.mutex);

309+PyMutex_Unlock(&_PyRuntime.parser.mutex);

311310}

312311313312PyObject*

@@ -318,22 +317,22 @@ _PyPegen_get_memo_statistics(void)

318317returnNULL;

319318 }

320319321-FT_MUTEX_LOCK(&_PyRuntime.parser.mutex);

320+PyMutex_Lock(&_PyRuntime.parser.mutex);

322321for (inti=0; i<NSTATISTICS; i++) {

323322PyObject*value=PyLong_FromLong(memo_statistics[i]);

324323if (value==NULL) {

325-FT_MUTEX_UNLOCK(&_PyRuntime.parser.mutex);

324+PyMutex_Unlock(&_PyRuntime.parser.mutex);

326325Py_DECREF(ret);

327326returnNULL;

328327 }

329328// PyList_SetItem borrows a reference to value.

330329if (PyList_SetItem(ret, i, value) <0) {

331-FT_MUTEX_UNLOCK(&_PyRuntime.parser.mutex);

330+PyMutex_Unlock(&_PyRuntime.parser.mutex);

332331Py_DECREF(ret);

333332returnNULL;

334333 }

335334 }

336-FT_MUTEX_UNLOCK(&_PyRuntime.parser.mutex);

335+PyMutex_Unlock(&_PyRuntime.parser.mutex);

337336returnret;

338337}

339338#endif

@@ -359,9 +358,9 @@ _PyPegen_is_memoized(Parser *p, int type, void *pres)

359358if (count <= 0) {

360359count=1;

361360 }

362-FT_MUTEX_LOCK(&_PyRuntime.parser.mutex);

361+PyMutex_Lock(&_PyRuntime.parser.mutex);

363362memo_statistics[type] +=count;

364-FT_MUTEX_UNLOCK(&_PyRuntime.parser.mutex);

363+PyMutex_Unlock(&_PyRuntime.parser.mutex);

365364 }

366365#endif

367366p->mark=m->mark;