GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `_Py_atomic_load_uint16` incorrect in `pyatomic_std.h` · Issue #146227 · python/cpython

_Py_atomic_load_uint16 incorrect in pyatomic_std.h #146227

New issue
Copy link
New issue
Copy link
Closed
Closed
_Py_atomic_load_uint16 incorrect in pyatomic_std.h#146227
Copy link
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixestopic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@colesbury
colesbury
opened on Mar 20, 2026
Issue body actions

Bug report

Found by Mohammed Zuhaib in https://discuss.python.org/t/code-explanation-for-absence-of-stdatomic-h-for-python-build/101623/30.

cpython/Include/cpython/pyatomic_std.h

Lines 458 to 463 in 6450b1d

static inline uint16_t
_Py_atomic_load_uint16(const uint16_t *obj)
{
_Py_USING_STD;
return atomic_load((const _Atomic(uint32_t)*)obj);
}

We cast to a uint32_t instead of uint16_t. I suspect this probably doesn't have noticeable effects on little-endian systems, but would load the wrong value on big-endian systems. We also mostly use pyatomic_gcc.h or pyatomic_msvc.h, which is probably why we didn't catch this in big-endian buildbots.

I asked Claude to review these files. In addition to the above bug:

  2. pyatomic_msc.h:974-978 — _Py_atomic_store_uint_release broken on ARM64

  static inline void
  _Py_atomic_store_uint_release(unsigned int *obj, unsigned int value)
  {
      *(volatile unsigned int *)obj = value;
  }

  This is placed among the relaxed stores and uses only a volatile store. On x86/x64, volatile stores have release semantics, so this happens to work. But on ARM64, volatile accesses are only relaxed
  (as stated in the file's header comment). Every other _release function in this file (e.g., _Py_atomic_store_int_release at line 1057, _Py_atomic_store_uint32_release at line 1108) properly uses
  __stlr32 on ARM64. This function is missing the #if/#elif ARM64 branch.

  3. pyatomic_gcc.h — Missing _Py_atomic_store_uint_release

  Both pyatomic_std.h (line 1035) and pyatomic_msc.h (line 975) define _Py_atomic_store_uint_release, but pyatomic_gcc.h does not. If any code calls it when compiled with GCC/Clang, it would fail to
  link/compile.

  4. pyatomic.h:75-76 — Incorrect pseudo-code comment

  def _Py_atomic_store_ptr_release(obj):
      return obj  # release

  This is documented as a one-arg function that returns a value, but it's actually a two-arg store (like the real declaration at line 518). Should be:
  def _Py_atomic_store_ptr_release(obj, value):
      obj = value  # release

Linked PRs

  • gh-146227: Fix wrong type in _Py_atomic_load_uint16 in pyatomic_std.h #146229
  • [3.14] gh-146227: Fix wrong type in _Py_atomic_load_uint16 in pyatomic_std.h (gh-146229) #146232
  • [3.13] gh-146227: Fix wrong type in _Py_atomic_load_uint16 in pyatomic_std.h (gh-146229) #146233

Activity

  1. colesbury
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    3.13only security fixesonly security fixes
    topic-free-threading
    3.14bugs and security fixesbugs and security fixes
    3.15bugs and security fixesbugs and security fixes
    on Mar 20, 2026
  2. colesbury
    added 6 commits that reference this issue on Mar 20, 2026

    pythongh-146227: Fix wrong type in _Py_atomic_load_uint16 in pyatomic…

    b6c6f53

    gh-146227: Fix wrong type in _Py_atomic_load_uint16 in pyatomic_std.h (…

    1eff27f

    [3.14] pythongh-146227: Fix wrong type in _Py_atomic_load_uint16 in p…

    e3423b5

    [3.13] pythongh-146227: Fix wrong type in _Py_atomic_load_uint16 in p…

    ff99aaa

    [3.14] gh-146227: Fix wrong type in _Py_atomic_load_uint16 in pyatomi…

    73e74ee

    [3.13] gh-146227: Fix wrong type in _Py_atomic_load_uint16 in pyatomi…

    fa2f9a3
  3. colesbury
    closed this as completedon Mar 20, 2026
  4. CuriousLearner
    added a commit that references this issue on Mar 22, 2026

    Merge remote-tracking branch 'upstream/main' into fix-pythongh-138577

    2691ad9
  5. ljfp
    added a commit that references this issue on Apr 25, 2026

    pythongh-146227: Fix wrong type in _Py_atomic_load_uint16 in pyatomic…

    6931c55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixestopic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.