]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-146227: Fix wrong type in _Py_atomic_load_uint16 in pyatomic_std.h (gh...
authorSam Gross <colesbury@gmail.com>
Fri, 20 Mar 2026 20:08:20 +0000 (16:08 -0400)
committerGitHub <noreply@github.com>
Fri, 20 Mar 2026 20:08:20 +0000 (20:08 +0000)
Also fix a few related issues in the pyatomic headers:

* Fix _Py_atomic_store_uint_release in pyatomic_msc.h to use __stlr32
  on ARM64 instead of a plain volatile store (which is only relaxed on
  ARM64).

* Add missing _Py_atomic_store_uint_release to pyatomic_gcc.h.

* Fix pseudo-code comment for _Py_atomic_store_ptr_release in
  pyatomic.h.

(cherry picked from commit 1eff27f2c0452b3114bcf139062c87c025842c3e)

Include/cpython/pyatomic.h
Include/cpython/pyatomic_gcc.h
Include/cpython/pyatomic_msc.h
Include/cpython/pyatomic_std.h
Misc/NEWS.d/next/Core_and_Builtins/2026-03-20-13-07-33.gh-issue-146227.MqBPEo.rst [new file with mode: 0644]

index 790640309f1e034d7c6a0f206d4cbd82841bd2a1..3a71ed689d88d8fbf8e907a41161596c27a458c6 100644 (file)
@@ -72,8 +72,8 @@
 //   def _Py_atomic_load_ptr_acquire(obj):
 //       return obj  # acquire
 //
-//   def _Py_atomic_store_ptr_release(obj):
-//       return obj  # release
+//   def _Py_atomic_store_ptr_release(obj, value):
+//       obj = value  # release
 //
 //   def _Py_atomic_fence_seq_cst():
 //       # sequential consistency
@@ -529,6 +529,9 @@ _Py_atomic_store_int_release(int *obj, int value);
 static inline int
 _Py_atomic_load_int_acquire(const int *obj);
 
+static inline void
+_Py_atomic_store_uint_release(unsigned int *obj, unsigned int value);
+
 static inline void
 _Py_atomic_store_uint32_release(uint32_t *obj, uint32_t value);
 
index 1566b83b9f6a1b6e33ffe80803a36a63aa0f869d..465226a76ab2556b7c771ddb0fee8ce92d7daddd 100644 (file)
@@ -576,6 +576,10 @@ static inline void
 _Py_atomic_store_ssize_release(Py_ssize_t *obj, Py_ssize_t value)
 { __atomic_store_n(obj, value, __ATOMIC_RELEASE); }
 
+static inline void
+_Py_atomic_store_uint_release(unsigned int *obj, unsigned int value)
+{ __atomic_store_n(obj, value, __ATOMIC_RELEASE); }
+
 static inline int
 _Py_atomic_load_int_acquire(const int *obj)
 { return __atomic_load_n(obj, __ATOMIC_ACQUIRE); }
index d155955df0cddf641e2f0a9c5a7a085bc72029a4..eb6df819fa7ee88482e51836adf9d4200477b4bc 100644 (file)
@@ -971,12 +971,6 @@ _Py_atomic_store_ushort_relaxed(unsigned short *obj, unsigned short value)
     *(volatile unsigned short *)obj = value;
 }
 
-static inline void
-_Py_atomic_store_uint_release(unsigned int *obj, unsigned int value)
-{
-    *(volatile unsigned int *)obj = value;
-}
-
 static inline void
 _Py_atomic_store_long_relaxed(long *obj, long value)
 {
@@ -1066,6 +1060,19 @@ _Py_atomic_store_int_release(int *obj, int value)
 #endif
 }
 
+static inline void
+_Py_atomic_store_uint_release(unsigned int *obj, unsigned int value)
+{
+#if defined(_M_X64) || defined(_M_IX86)
+    *(volatile unsigned int *)obj = value;
+#elif defined(_M_ARM64)
+    _Py_atomic_ASSERT_ARG_TYPE(unsigned __int32);
+    __stlr32((unsigned __int32 volatile *)obj, (unsigned __int32)value);
+#else
+#  error "no implementation of _Py_atomic_store_uint_release"
+#endif
+}
+
 static inline void
 _Py_atomic_store_ssize_release(Py_ssize_t *obj, Py_ssize_t value)
 {
index 7176f667a4082cff50aa6226f1a099b62b48173f..1a2ccd0cc12b4886fe708270e4d066f697d1cbaf 100644 (file)
@@ -459,7 +459,7 @@ static inline uint16_t
 _Py_atomic_load_uint16(const uint16_t *obj)
 {
     _Py_USING_STD;
-    return atomic_load((const _Atomic(uint32_t)*)obj);
+    return atomic_load((const _Atomic(uint16_t)*)obj);
 }
 
 static inline uint32_t
diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-03-20-13-07-33.gh-issue-146227.MqBPEo.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-03-20-13-07-33.gh-issue-146227.MqBPEo.rst
new file mode 100644 (file)
index 0000000..11e19eb
--- /dev/null
@@ -0,0 +1,3 @@
+Fix wrong type in ``_Py_atomic_load_uint16`` in the C11 atomics backend
+(``pyatomic_std.h``), which used a 32-bit atomic load instead of 16-bit.
+Found by Mohammed Zuhaib.