Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
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
base:main
Are you sure you want to change the base?
Conversation
PyUnstable_Unicode_GET_CACHED_HASH(PyObject *op) { | ||
return _PyASCIIObject_CAST(op)->hash; | ||
} |
There was a problem hiding this comment.
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
:
cpython/Objects/unicodeobject.c
Lines 170 to 175 ind963436
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)); |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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, |
Uh oh!
There was an error while loading.Please reload this page.
PyUnstable_Unicode_GET_CACHED_HASH
#134891📚 Documentation preview 📚:https://cpython-previews--134892.org.readthedocs.build/