mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-24 22:25:10 +00:00
Ensure PYBIND11_TLS_REPLACE_VALUE evaluates its arguments only once (#3290)
This commit is contained in:
parent
5f46e47da8
commit
2a78abffd8
@ -84,12 +84,13 @@ inline PyObject *make_object_base_type(PyTypeObject *metaclass);
|
|||||||
// On CPython < 3.4 and on PyPy, `PyThread_set_key_value` strangely does not set
|
// On CPython < 3.4 and on PyPy, `PyThread_set_key_value` strangely does not set
|
||||||
// the value if it has already been set. Instead, it must first be deleted and
|
// the value if it has already been set. Instead, it must first be deleted and
|
||||||
// then set again.
|
// then set again.
|
||||||
|
inline void tls_replace_value(PYBIND11_TLS_KEY_REF key, void *value) {
|
||||||
|
PyThread_delete_key_value(key);
|
||||||
|
PyThread_set_key_value(key, value);
|
||||||
|
}
|
||||||
# define PYBIND11_TLS_DELETE_VALUE(key) PyThread_delete_key_value(key)
|
# define PYBIND11_TLS_DELETE_VALUE(key) PyThread_delete_key_value(key)
|
||||||
# define PYBIND11_TLS_REPLACE_VALUE(key, value) \
|
# define PYBIND11_TLS_REPLACE_VALUE(key, value) \
|
||||||
do { \
|
::pybind11::detail::tls_replace_value((key), (value))
|
||||||
PyThread_delete_key_value((key)); \
|
|
||||||
PyThread_set_key_value((key), (value)); \
|
|
||||||
} while (false)
|
|
||||||
# else
|
# else
|
||||||
# define PYBIND11_TLS_DELETE_VALUE(key) PyThread_set_key_value((key), nullptr)
|
# define PYBIND11_TLS_DELETE_VALUE(key) PyThread_set_key_value((key), nullptr)
|
||||||
# define PYBIND11_TLS_REPLACE_VALUE(key, value) PyThread_set_key_value((key), (value))
|
# define PYBIND11_TLS_REPLACE_VALUE(key, value) PyThread_set_key_value((key), (value))
|
||||||
|
Loading…
Reference in New Issue
Block a user