mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
[3.13] gh-129983: fix data race in compile_template in sre.c (#130038)
gh-129983: fix data race in compile_template in sre.c (#130015)
(cherry picked from commit 3cf68cdd3e
)
Co-authored-by: Tomasz Pytel <tompytel@gmail.com>
This commit is contained in:
parent
fbe18bdc9a
commit
4cb251d06f
2 changed files with 10 additions and 1 deletions
|
@ -0,0 +1 @@
|
|||
Fix data race in compile_template in :file:`sre.c`.
|
|
@ -1160,13 +1160,21 @@ compile_template(_sremodulestate *module_state,
|
|||
PatternObject *pattern, PyObject *template)
|
||||
{
|
||||
/* delegate to Python code */
|
||||
PyObject *func = module_state->compile_template;
|
||||
PyObject *func = FT_ATOMIC_LOAD_PTR(module_state->compile_template);
|
||||
if (func == NULL) {
|
||||
func = _PyImport_GetModuleAttrString("re", "_compile_template");
|
||||
if (func == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
#ifdef Py_GIL_DISABLED
|
||||
PyObject *other_func = NULL;
|
||||
if (!_Py_atomic_compare_exchange_ptr(&module_state->compile_template, &other_func, func)) {
|
||||
Py_DECREF(func);
|
||||
func = other_func;
|
||||
}
|
||||
#else
|
||||
Py_XSETREF(module_state->compile_template, func);
|
||||
#endif
|
||||
}
|
||||
|
||||
PyObject *args[] = {(PyObject *)pattern, template};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue