gh-122854: Add Py_HashBuffer() function (#122855)

This commit is contained in:
Victor Stinner 2024-08-30 17:42:27 +02:00 committed by GitHub
parent 3d60dfbe17
commit d8e69b2c1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 80 additions and 25 deletions

View file

@ -89,6 +89,25 @@ See also the :c:member:`PyTypeObject.tp_hash` member and :ref:`numeric-hash`.
.. versionadded:: 3.13
.. c:function:: Py_hash_t Py_HashBuffer(const void *ptr, Py_ssize_t len)
Compute and return the hash value of a buffer of *len* bytes
starting at address *ptr*. The hash is guaranteed to match that of
:class:`bytes`, :class:`memoryview`, and other built-in objects
that implement the :ref:`buffer protocol <bufferobjects>`.
Use this function to implement hashing for immutable objects whose
:c:member:`~PyTypeObject.tp_richcompare` function compares to another
object's buffer.
*len* must be greater than or equal to ``0``.
This function always succeeds.
.. versionadded:: 3.14
.. c:function:: Py_hash_t PyObject_GenericHash(PyObject *obj)
Generic hashing function that is meant to be put into a type