Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-134891: Add PyUnstable_Unicode_GET_CACHED_HASH#134892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
encukou wants to merge3 commits intopython:main
base:main
Choose a base branch
Loading
fromencukou:get_cached_hash

Conversation

encukou
Copy link
Member

@encukouencukou commentedMay 29, 2025
edited by github-actionsbot
Loading

Comment on lines +305 to +307
PyUnstable_Unicode_GET_CACHED_HASH(PyObject *op) {
return _PyASCIIObject_CAST(op)->hash;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Hash can be computed and assigned concurrently so to avoid a data race in free-threaded build:

#ifdefPy_GIL_DISABLEDreturn_Py_atomic_load_ssize_relaxed(&_PyASCIIObject_CAST(op)->hash);#elsereturn_PyASCIIObject_CAST(op)->hash;#endif

For example, inunicodeobject.c:

staticinlinePy_hash_tPyUnicode_HASH(PyObject*op)
{
assert(_PyUnicode_CHECK(op));
returnFT_ATOMIC_LOAD_SSIZE_RELAXED(_PyASCIIObject_CAST(op)->hash);
}

static PyObject*
unicode_GET_CACHED_HASH(PyObject *self, PyObject *arg)
{
return PyLong_FromLong((long)PyUnstable_Unicode_GET_CACHED_HASH(arg));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

UsePyLong_FromSSize_t.Py_hash_t is an alias forPy_ssize_t, but it might be a different size than long.


This function never fails with an exception.

Note that there are no guarantees on when a object's hash is cached,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
Note that there are no guarantees on whena object's hash is cached,
Note that there are no guarantees on whenan object's hash is cached,

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@cmarqucmarqucmarqu left review comments

@colesburycolesburycolesbury left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@encukou@cmarqu@colesbury

[8]ページ先頭

©2009-2025 Movatter.jp