diff options
author | Sam Gross <colesbury@gmail.com> | 2024-06-21 20:20:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-21 20:20:41 (GMT) |
commit | 4dc27bc0b76aa5985ccef2901f7a4f5d36b97995 (patch) | |
tree | 3219748fd1c47dec959096aed7457cf1fad5d43a /Modules | |
parent | e748805f2a0f783723ef02809f86cd3d8fb8bf2e (diff) | |
download | cpython-4dc27bc0b76aa5985ccef2901f7a4f5d36b97995.zip cpython-4dc27bc0b76aa5985ccef2901f7a4f5d36b97995.tar.gz cpython-4dc27bc0b76aa5985ccef2901f7a4f5d36b97995.tar.bz2 |
[3.13] gh-119344: Make critical section API public (GH-119353) (#120856)
This makes the following macros public as part of the non-limited C-API for
locking a single object or two objects at once.
* `Py_BEGIN_CRITICAL_SECTION(op)` / `Py_END_CRITICAL_SECTION()`
* `Py_BEGIN_CRITICAL_SECTION2(a, b)` / `Py_END_CRITICAL_SECTION2()`
The supporting functions and structs used by the macros are also exposed for
cases where C macros are not available.
(cherry picked from commit 8f17d69b7bc906e8407095317842cc0fd52cd84a)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_sre/sre.c | 2 | ||||
-rw-r--r-- | Modules/_testcapimodule.c | 13 |
2 files changed, 14 insertions, 1 deletions
diff --git a/Modules/_sre/sre.c b/Modules/_sre/sre.c index 0c656b4..0a888af 100644 --- a/Modules/_sre/sre.c +++ b/Modules/_sre/sre.c @@ -2371,7 +2371,7 @@ _sre_SRE_Match_groupdict_impl(MatchObject *self, PyObject *default_value) goto exit; } } -exit: +exit:; Py_END_CRITICAL_SECTION(); return result; diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 8b40821..1fa7c37 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -3320,6 +3320,18 @@ function_set_warning(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args)) Py_RETURN_NONE; } +static PyObject * +test_critical_sections(PyObject *module, PyObject *Py_UNUSED(args)) +{ + Py_BEGIN_CRITICAL_SECTION(module); + Py_END_CRITICAL_SECTION(); + + Py_BEGIN_CRITICAL_SECTION2(module, module); + Py_END_CRITICAL_SECTION2(); + + Py_RETURN_NONE; +} + static PyMethodDef TestMethods[] = { {"set_errno", set_errno, METH_VARARGS}, {"test_config", test_config, METH_NOARGS}, @@ -3463,6 +3475,7 @@ static PyMethodDef TestMethods[] = { {"check_pyimport_addmodule", check_pyimport_addmodule, METH_VARARGS}, {"test_weakref_capi", test_weakref_capi, METH_NOARGS}, {"function_set_warning", function_set_warning, METH_NOARGS}, + {"test_critical_sections", test_critical_sections, METH_NOARGS}, {NULL, NULL} /* sentinel */ }; |