Skip to content

unicode: make ucnhash_capi initialization thread-safe in --disable-gil builds #111972

Description

@colesbury

Feature or enhancement

The _PyUnicode_Name_CAPI provides functions to get the name for a given Unicode character code and vice versa. It is lazily initialized and stored in the per-interpreter _Py_unicode_state:

struct _Py_unicode_state {
struct _Py_unicode_fs_codec fs_codec;
_PyUnicode_Name_CAPI *ucnhash_capi;
// Unicode identifiers (_Py_Identifier): see _PyUnicode_FromId()
struct _Py_unicode_ids ids;
};

The initialization of the ucnhash_capi isn't thread-safe without the GIL. (There can be a data race on reading and writing ucnhash_capi).

Mostly for my own reference, here are the similar modifications in the nogil-3.12 fork: colesbury/nogil-3.12@5d006db9fa

Linked PRs

Activity

  1. added a commit that references this issue on Nov 18, 2023
  2. Eclips4 commented on Nov 18, 2023

    @Eclips4
    Member

    This seems quite easy 😄
    Please, take a look at the #112249.

  3. self-assigned this
    on Nov 18, 2023
  4. added a commit that references this issue on Nov 30, 2023
  5. erlend-aasland commented on Nov 30, 2023

    @erlend-aasland
    Contributor

    Resolved by #112249

  6. added a commit that references this issue on Feb 11, 2024
  7. added a commit that references this issue on Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions