]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-129701: Fix a data race in `intern_common` in the free threaded build (GH-130089)
authorSam Gross <colesbury@gmail.com>
Mon, 17 Feb 2025 13:15:40 +0000 (08:15 -0500)
committerGitHub <noreply@github.com>
Mon, 17 Feb 2025 13:15:40 +0000 (14:15 +0100)
commitb9d2ee687cfca6365e26e156b1e22824b16dabb8
tree3d526f7841f6dfe029dbc1c8150ef00abd8dde1d
parentfc8c99a8ce483db23fa624592457e350e99193f6
gh-129701: Fix a data race in `intern_common` in the free threaded build (GH-130089)

* gh-129701: Fix a data race in `intern_common` in the free threaded build

* Use a mutex to avoid potentially returning a non-immortalized string,
  because immortalization happens after the insertion into the interned
  dict.

* Use `Py_DECREF()` calls instead of `Py_SET_REFCNT(s, Py_REFCNT(s) - 2)`
  for thread-safety. This code path isn't performance sensistive, so
  just use `Py_DECREF()` unconditionally for simplicity.
Include/internal/pycore_global_objects.h
Objects/unicodeobject.c