From 6e64ef471619b68c29cdc838cd545da27037364d Mon Sep 17 00:00:00 2001 From: Matt Page Date: Wed, 14 Feb 2024 12:46:39 -0800 Subject: [PATCH] Use free-threaded atomic wrapper for loading deque_iter len --- Include/internal/pycore_pyatomic_ft_wrappers.h | 2 ++ Modules/_collectionsmodule.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Include/internal/pycore_pyatomic_ft_wrappers.h b/Include/internal/pycore_pyatomic_ft_wrappers.h index d1313976da1cfc..cbbe90e009c8d2 100644 --- a/Include/internal/pycore_pyatomic_ft_wrappers.h +++ b/Include/internal/pycore_pyatomic_ft_wrappers.h @@ -20,11 +20,13 @@ extern "C" { #endif #ifdef Py_GIL_DISABLED +#define FT_ATOMIC_LOAD_SSIZE(value) _Py_atomic_load_ssize(&value) #define FT_ATOMIC_LOAD_SSIZE_RELAXED(value) \ _Py_atomic_load_ssize_relaxed(&value) #define FT_ATOMIC_STORE_SSIZE_RELAXED(value, new_value) \ _Py_atomic_store_ssize_relaxed(&value, new_value) #else +#define FT_ATOMIC_LOAD_SSIZE(value) value #define FT_ATOMIC_LOAD_SSIZE_RELAXED(value) value #define FT_ATOMIC_STORE_SSIZE_RELAXED(value, new_value) value = new_value #endif diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 9098de6d2f143a..47898b1ae23257 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -3,6 +3,7 @@ #include "pycore_dict.h" // _PyDict_GetItem_KnownHash() #include "pycore_long.h" // _PyLong_GetZero() #include "pycore_moduleobject.h" // _PyModule_GetState() +#include "pycore_pyatomic_ft_wrappers.h" #include "pycore_typeobject.h" // _PyType_GetModuleState() #include @@ -2007,7 +2008,7 @@ dequeiter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) static PyObject * dequeiter_len(dequeiterobject *it, PyObject *Py_UNUSED(ignored)) { - Py_ssize_t len = _Py_atomic_load_ssize(&it->counter); + Py_ssize_t len = FT_ATOMIC_LOAD_SSIZE(it->counter); return PyLong_FromSsize_t(len); }