mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
[3.13] gh-122581: Avoid data races when collecting parser statistics (GH-122694) (#122733)
gh-122581: Avoid data races when collecting parser statistics (GH-122694)
(cherry picked from commit ce0d66c8d2
)
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
This commit is contained in:
parent
5c161cb832
commit
9fb6bfbef0
2 changed files with 36 additions and 0 deletions
|
@ -21,6 +21,9 @@ extern "C" {
|
|||
struct _parser_runtime_state {
|
||||
#ifdef Py_DEBUG
|
||||
long memo_statistics[_PYPEGEN_NSTATISTICS];
|
||||
#ifdef Py_GIL_DISABLED
|
||||
PyMutex mutex;
|
||||
#endif
|
||||
#else
|
||||
int _not_used;
|
||||
#endif
|
||||
|
@ -28,6 +31,21 @@ struct _parser_runtime_state {
|
|||
};
|
||||
|
||||
_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), \
|
||||
.v.Name.ctx = Load, \
|
||||
.lineno = 1, \
|
||||
.col_offset = 0, \
|
||||
.end_lineno = 1, \
|
||||
.end_col_offset = 0, \
|
||||
}, \
|
||||
}
|
||||
#else
|
||||
#define _parser_runtime_state_INIT \
|
||||
{ \
|
||||
.dummy_name = { \
|
||||
|
@ -40,6 +58,7 @@ _Py_DECLARE_STR(empty, "")
|
|||
.end_col_offset = 0, \
|
||||
}, \
|
||||
}
|
||||
#endif
|
||||
|
||||
extern struct _mod* _PyParser_ASTFromString(
|
||||
const char *str,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue