Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make _Py_HashDouble public again as "unstable" API #111545

Open
seberg opened this issue Oct 31, 2023 · 4 comments
Open

Make _Py_HashDouble public again as "unstable" API #111545

seberg opened this issue Oct 31, 2023 · 4 comments
Labels
topic-C-API type-feature A feature request or enhancement

Comments

@seberg
Copy link
Contributor

seberg commented Oct 31, 2023

In NumPy we use _Py_HashDouble for our floating point hashing needs and that seems like a pretty good candiate for the unstable API to me: #91744 (comment) and #101101 (comment).

However, the function is currently removed rather than made unstable (to my understanding). While it should probably be easy enough to vendor what we needed, I would prefer the unstable API tier, it gives a better sense of having the required identical hashing.

NumPy issue: numpy/numpy#25035

Originally reported by @ngoldbaum in #111418 (comment)

Linked PRs

@AlexWaygood AlexWaygood added type-feature A feature request or enhancement topic-C-API labels Oct 31, 2023
@encukou
Copy link
Member

encukou commented Nov 2, 2023

cc @vstinner, per the What's New

@vstinner
Copy link
Member

vstinner commented Nov 2, 2023

In NumPy we use _Py_HashDouble for our floating point hashing needs and that seems like a pretty good candiate for the unstable API to me: #91744 (comment) and #101101 (comment).

I would prefer a public API rather than a private API. I don't expect Py_HashDouble() API to be unstable.

See also issue #111389.

cc @vstinner, per the What's New

Thanks. I'm trying to keep track of these issues under #111481 meta issue.

vstinner added a commit to vstinner/cpython that referenced this issue Nov 14, 2023
Move non-limited C API to a new Include/cpython/pyhash.h header file.
vstinner added a commit to vstinner/cpython that referenced this issue Nov 14, 2023
Move non-limited C API to a new Include/cpython/pyhash.h header file.
vstinner added a commit that referenced this issue Nov 15, 2023
Move non-limited C API to a new Include/cpython/pyhash.h header file.
vstinner added a commit to vstinner/cpython that referenced this issue Nov 15, 2023
* Cleanup _Py_HashDouble() implementation.
* Add Lib/test/test_capi/test_hash.py.
* Add Modules/_testcapi/hash.c.
vstinner added a commit to vstinner/cpython that referenced this issue Nov 15, 2023
* Cleanup _Py_HashDouble() implementation.
* Add Lib/test/test_capi/test_hash.py.
* Add Modules/_testcapi/hash.c.
vstinner added a commit to vstinner/cpython that referenced this issue Nov 15, 2023
* Cleanup _Py_HashDouble() implementation.
* Add tests: Modules/_testcapi/hash.c and
  Lib/test/test_capi/test_hash.py.
vstinner added a commit to vstinner/cpython that referenced this issue Nov 15, 2023
* Cleanup PyHash_Double() implementation based _Py_HashDouble():

  * Move variable declaration to their first assignment.
  * Add braces (PEP 7).
  * Cast result to signed Py_hash_t before the final "== -1" test, to
    reduce the number of casts.
  * Add an assertion on Py_IS_NAN(v) in the only code path which can
    return -1.

* Add tests: Modules/_testcapi/hash.c and
  Lib/test/test_capi/test_hash.py.
vstinner added a commit to vstinner/cpython that referenced this issue Nov 15, 2023
* Keep _Py_HashPointer() function as an alias to PyHash_Pointer().
* Add _Py_rotateright_uintptr() function with tests.
* Add tests on PyHash_Pointer() to test_capi.test_hash.
* Remove _Py_HashPointerRaw() function: inline code in
  _Py_hashtable_hash_ptr().
vstinner added a commit to vstinner/cpython that referenced this issue Nov 15, 2023
* Keep _Py_HashPointer() function as an alias to PyHash_Pointer().
* Add _Py_rotateright_uintptr() function with tests.
* Add PyHash_Pointer() tests to test_capi.test_hash.
* Remove _Py_HashPointerRaw() function: inline code in
  _Py_hashtable_hash_ptr().
vstinner added a commit to vstinner/cpython that referenced this issue Nov 15, 2023
Add Modules/_testcapi/hash.c and Lib/test/test_capi/test_hash.py.
vstinner added a commit that referenced this issue Nov 15, 2023
Add Modules/_testcapi/hash.c and Lib/test/test_capi/test_hash.py.
vstinner added a commit to vstinner/cpython that referenced this issue Nov 15, 2023
* Cleanup PyHash_Double() implementation based _Py_HashDouble():

  * Move variable declaration to their first assignment.
  * Add braces (PEP 7).
  * Cast result to signed Py_hash_t before the final "== -1" test, to
    reduce the number of casts.
  * Add an assertion on Py_IS_NAN(v) in the only code path which can
    return -1.

* Add tests: Modules/_testcapi/hash.c and
  Lib/test/test_capi/test_hash.py.
vstinner added a commit to vstinner/cpython that referenced this issue Nov 15, 2023
* Keep _Py_HashPointer() function as an alias to PyHash_Pointer().
* Add _Py_rotateright_uintptr() function with tests.
* Add PyHash_Pointer() tests to test_capi.test_hash.
* Remove _Py_HashPointerRaw() function: inline code in
  _Py_hashtable_hash_ptr().
vstinner added a commit to vstinner/cpython that referenced this issue Nov 15, 2023
* Keep _Py_HashPointer() function as an alias to PyHash_Pointer().
* Add _Py_rotateright_uintptr() function with tests.
* Add PyHash_Pointer() tests to test_capi.test_hash.
* Remove _Py_HashPointerRaw() function: inline code in
  _Py_hashtable_hash_ptr().
vstinner added a commit to vstinner/cpython that referenced this issue Nov 15, 2023
* Keep _Py_HashPointer() function as an alias to PyHash_Pointer().
* Add PyHash_Pointer() tests to test_capi.test_hash.
* Remove _Py_HashPointerRaw() function: inline code in
  _Py_hashtable_hash_ptr().
vstinner added a commit to vstinner/cpython that referenced this issue Nov 15, 2023
* Keep _Py_HashPointer() function as an alias to PyHash_Pointer().
* Add PyHash_Pointer() tests to test_capi.test_hash.
* Remove _Py_HashPointerRaw() function: inline code in
  _Py_hashtable_hash_ptr().
vstinner added a commit to vstinner/cpython that referenced this issue Nov 15, 2023
* Keep _Py_HashPointer() function as an alias to PyHash_Pointer().
* Add PyHash_Pointer() tests to test_capi.test_hash.
* Remove _Py_HashPointerRaw() function: inline code in
  _Py_hashtable_hash_ptr().
vstinner added a commit to vstinner/cpython that referenced this issue Nov 15, 2023
* Keep _Py_HashPointer() function as an alias to PyHash_Pointer().
* Add PyHash_Pointer() tests to test_capi.test_hash.
* Remove _Py_HashPointerRaw() function: inline code in
  _Py_hashtable_hash_ptr().
vstinner added a commit to vstinner/cpython that referenced this issue Nov 15, 2023
* Add again _PyHASH_NAN constant.
* _Py_HashDouble(NULL, value) now returns _PyHASH_NAN.
* Add tests: Modules/_testcapi/hash.c and
  Lib/test/test_capi/test_hash.py.
vstinner added a commit to vstinner/cpython that referenced this issue Nov 15, 2023
* Add again _PyHASH_NAN constant.
* _Py_HashDouble(NULL, value) now returns _PyHASH_NAN.
* Add tests: Modules/_testcapi/hash.c and
  Lib/test/test_capi/test_hash.py.
vstinner added a commit to vstinner/cpython that referenced this issue Nov 27, 2023
* Add again _PyHASH_NAN constant.
* Add tests: Modules/_testcapi/hash.c and
  Lib/test/test_capi/test_hash.py.
vstinner added a commit to vstinner/cpython that referenced this issue Nov 27, 2023
* Add again private _PyHASH_NAN constant.
* Add tests: Modules/_testcapi/hash.c and
  Lib/test/test_capi/test_hash.py.
vstinner added a commit to vstinner/cpython that referenced this issue Nov 27, 2023
* Add again the private _PyHASH_NAN constant.
* Add tests: Modules/_testcapi/hash.c and
  Lib/test/test_capi/test_hash.py.
vstinner added a commit to vstinner/cpython that referenced this issue Nov 27, 2023
* Add again the private _PyHASH_NAN constant.
* Add tests: Modules/_testcapi/hash.c and
  Lib/test/test_capi/test_hash.py.
vstinner added a commit to vstinner/cpython that referenced this issue Nov 27, 2023
vstinner added a commit to vstinner/cpython that referenced this issue Nov 30, 2023
* Add again the private _PyHASH_NAN constant.
* Add tests: Modules/_testcapi/hash.c and
  Lib/test/test_capi/test_hash.py.
vstinner added a commit to vstinner/cpython that referenced this issue Dec 1, 2023
* Implement _Py_HashPointerRaw() as a static inline function.
* Add Py_HashPointer() tests to test_capi.test_hash.
* Keep _Py_HashPointer() function as an alias to Py_HashPointer().
vstinner added a commit to vstinner/cpython that referenced this issue Dec 1, 2023
* Implement _Py_HashPointerRaw() as a static inline function.
* Add Py_HashPointer() tests to test_capi.test_hash.
* Keep _Py_HashPointer() function as an alias to Py_HashPointer().
vstinner added a commit to vstinner/cpython that referenced this issue Dec 1, 2023
* Implement _Py_HashPointerRaw() as a static inline function.
* Add Py_HashPointer() tests to test_capi.test_hash.
* Keep _Py_HashPointer() function as an alias to Py_HashPointer().
vstinner added a commit to vstinner/cpython that referenced this issue Dec 1, 2023
* Implement _Py_HashPointerRaw() as a static inline function.
* Add Py_HashPointer() tests to test_capi.test_hash.
* Keep _Py_HashPointer() function as an alias to Py_HashPointer().
@serhiy-storchaka
Copy link
Member

I wonder whether it is worth to add the PyObject_GenericHash() function that implements object.__hash__. Using PyHash_Pointer() for this is a CPython implementation detail and depends on the fact that id() returns the address of the object. In general, Python objects and pointers can use different hash functions.

vstinner added a commit to vstinner/cpython that referenced this issue Dec 3, 2023
* Add again the private _PyHASH_NAN constant.
* Add tests: Modules/_testcapi/hash.c and
  Lib/test/test_capi/test_hash.py.
vstinner added a commit to vstinner/cpython that referenced this issue Dec 3, 2023
vstinner added a commit to vstinner/cpython that referenced this issue Dec 4, 2023
* Add again the private _PyHASH_NAN constant.
* Add tests: Modules/_testcapi/hash.c and
  Lib/test/test_capi/test_hash.py.
vstinner added a commit to vstinner/cpython that referenced this issue Dec 5, 2023
* Implement _Py_HashPointerRaw() as a static inline function.
* Add Py_HashPointer() tests to test_capi.test_hash.
* Keep _Py_HashPointer() function as an alias to Py_HashPointer().
vstinner added a commit that referenced this issue Dec 6, 2023
* Implement _Py_HashPointerRaw() as a static inline function.
* Add Py_HashPointer() tests to test_capi.test_hash.
* Keep _Py_HashPointer() function as an alias to Py_HashPointer().
vstinner added a commit to vstinner/cpython that referenced this issue Dec 6, 2023
* Add again the private _PyHASH_NAN constant.
* Add tests: Modules/_testcapi/hash.c and
  Lib/test/test_capi/test_hash.py.
vstinner added a commit to vstinner/cpython that referenced this issue Dec 12, 2023
* Add again the private _PyHASH_NAN constant.
* Add tests: Modules/_testcapi/hash.c and
  Lib/test/test_capi/test_hash.py.
vstinner added a commit to vstinner/cpython that referenced this issue Dec 14, 2023
Add tests: Modules/_testcapi/hash.c and
Lib/test/test_capi/test_hash.py.
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
)

Move non-limited C API to a new Include/cpython/pyhash.h header file.
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
Add Modules/_testcapi/hash.c and Lib/test/test_capi/test_hash.py.
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
* Implement _Py_HashPointerRaw() as a static inline function.
* Add Py_HashPointer() tests to test_capi.test_hash.
* Keep _Py_HashPointer() function as an alias to Py_HashPointer().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-C-API type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

5 participants