From 0ce377a5933a55b05e0ba5cdac243f978f8efb11 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Sat, 28 Oct 2023 05:03:20 +0300 Subject: [PATCH 01/15] gh-111389: restoring _PyHASH_INF/BITS/MODULUS/IMAG macroses as public This partially reverts #107026. --- Include/internal/pycore_pyhash.h | 17 ----------------- Include/pyhash.h | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/Include/internal/pycore_pyhash.h b/Include/internal/pycore_pyhash.h index 78bf0c7d07eb10..50280d1ed8fd2f 100644 --- a/Include/internal/pycore_pyhash.h +++ b/Include/internal/pycore_pyhash.h @@ -17,23 +17,6 @@ extern Py_hash_t _Py_HashPointerRaw(const void*); // Export for '_datetime' shared extension PyAPI_FUNC(Py_hash_t) _Py_HashBytes(const void*, Py_ssize_t); -/* Prime multiplier used in string and various other hashes. */ -#define _PyHASH_MULTIPLIER 1000003UL /* 0xf4243 */ - -/* Parameters used for the numeric hash implementation. See notes for - _Py_HashDouble in Python/pyhash.c. Numeric hashes are based on - reduction modulo the prime 2**_PyHASH_BITS - 1. */ - -#if SIZEOF_VOID_P >= 8 -# define _PyHASH_BITS 61 -#else -# define _PyHASH_BITS 31 -#endif - -#define _PyHASH_MODULUS (((size_t)1 << _PyHASH_BITS) - 1) -#define _PyHASH_INF 314159 -#define _PyHASH_IMAG _PyHASH_MULTIPLIER - /* Hash secret * * memory layout on 64 bit systems diff --git a/Include/pyhash.h b/Include/pyhash.h index 6e969f86fa2625..bfda4c973463ac 100644 --- a/Include/pyhash.h +++ b/Include/pyhash.h @@ -16,6 +16,22 @@ typedef struct { PyAPI_FUNC(PyHash_FuncDef*) PyHash_GetFuncDef(void); #endif +/* Prime multiplier used in string and various other hashes. */ +#define _PyHASH_MULTIPLIER 1000003UL /* 0xf4243 */ + +/* Parameters used for the numeric hash implementation. See notes for + _Py_HashDouble in Python/pyhash.c. Numeric hashes are based on + reduction modulo the prime 2**_PyHASH_BITS - 1. */ + +#if SIZEOF_VOID_P >= 8 +# define _PyHASH_BITS 61 +#else +# define _PyHASH_BITS 31 +#endif + +#define _PyHASH_MODULUS (((size_t)1 << _PyHASH_BITS) - 1) +#define _PyHASH_INF 314159 +#define _PyHASH_IMAG _PyHASH_MULTIPLIER /* Cutoff for small string DJBX33A optimization in range [1, cutoff). * From 2c6002f521bb78d11340b267104b9a64eaa2096f Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Sun, 29 Oct 2023 06:43:54 +0300 Subject: [PATCH 02/15] Mention public macros in docs --- Doc/library/stdtypes.rst | 3 ++- Doc/library/sys.rst | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 8160740c7a05bd..93d9df30583dad 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -723,7 +723,8 @@ made available to Python as the :attr:`modulus` attribute of .. impl-detail:: Currently, the prime used is ``P = 2**31 - 1`` on machines with 32-bit C - longs and ``P = 2**61 - 1`` on machines with 64-bit C longs. + longs and ``P = 2**61 - 1`` on machines with 64-bit C longs. The exponent + of this Mersenne prime is available as ``_PyHASH_BITS`` macro. Here are the rules in detail: diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 5ef6f83030958f..b2b1c9f708ff73 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -1022,11 +1022,13 @@ always available. .. attribute:: hash_info.modulus - The prime modulus P used for numeric hash scheme + The prime modulus P used for numeric hash scheme. Available also as + ``_PyHASH_MODULUS`` macro. .. attribute:: hash_info.inf - The hash value returned for a positive infinity + The hash value returned for a positive infinity. Available also as + ``_PyHASH_INF`` macro. .. attribute:: hash_info.nan @@ -1034,7 +1036,8 @@ always available. .. attribute:: hash_info.imag - The multiplier used for the imaginary part of a complex number + The multiplier used for the imaginary part of a complex number. + Available also as ``_PyHASH_IMAG`` macro. .. attribute:: hash_info.algorithm From 5c42caedfdd5255454f1c8734af6a34af42b9438 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Mon, 30 Oct 2023 16:29:34 +0300 Subject: [PATCH 03/15] Revert "Mention public macros in docs" This reverts commit 2c6002f521bb78d11340b267104b9a64eaa2096f. --- Doc/library/stdtypes.rst | 3 +-- Doc/library/sys.rst | 9 +++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 93d9df30583dad..8160740c7a05bd 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -723,8 +723,7 @@ made available to Python as the :attr:`modulus` attribute of .. impl-detail:: Currently, the prime used is ``P = 2**31 - 1`` on machines with 32-bit C - longs and ``P = 2**61 - 1`` on machines with 64-bit C longs. The exponent - of this Mersenne prime is available as ``_PyHASH_BITS`` macro. + longs and ``P = 2**61 - 1`` on machines with 64-bit C longs. Here are the rules in detail: diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index b2b1c9f708ff73..5ef6f83030958f 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -1022,13 +1022,11 @@ always available. .. attribute:: hash_info.modulus - The prime modulus P used for numeric hash scheme. Available also as - ``_PyHASH_MODULUS`` macro. + The prime modulus P used for numeric hash scheme .. attribute:: hash_info.inf - The hash value returned for a positive infinity. Available also as - ``_PyHASH_INF`` macro. + The hash value returned for a positive infinity .. attribute:: hash_info.nan @@ -1036,8 +1034,7 @@ always available. .. attribute:: hash_info.imag - The multiplier used for the imaginary part of a complex number. - Available also as ``_PyHASH_IMAG`` macro. + The multiplier used for the imaginary part of a complex number .. attribute:: hash_info.algorithm From de4e3aef3b4fcae549e847441ffa27a1e23819d0 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Mon, 30 Oct 2023 17:22:08 +0300 Subject: [PATCH 04/15] Add Doc/c-api/hashing.rst for hash-related C macros --- Doc/c-api/hashing.rst | 20 ++++++++++++++++++++ Doc/c-api/utilities.rst | 1 + 2 files changed, 21 insertions(+) create mode 100644 Doc/c-api/hashing.rst diff --git a/Doc/c-api/hashing.rst b/Doc/c-api/hashing.rst new file mode 100644 index 00000000000000..c6d976fd1a6de2 --- /dev/null +++ b/Doc/c-api/hashing.rst @@ -0,0 +1,20 @@ +Parameters of the numeric hash implementation +============================================= + +See :ref:`numeric-hash` for more details about hashing of numeric types. + +.. c:macro:: _PyHASH_MODULUS + + The Mersenne prime ``P = 2**n -1``, used for numeric hash scheme. + +.. c:macro:: _PyHASH_BITS + + The exponent ``n`` of ``P``. + +.. c:macro:: _PyHASH_INF + + The hash value returned for a positive infinity. + +.. c:macro:: _PyHASH_IMAG + + The multiplier used for the imaginary part of a complex number. diff --git a/Doc/c-api/utilities.rst b/Doc/c-api/utilities.rst index ccbf14e1850f68..4290ff5ddf9a3f 100644 --- a/Doc/c-api/utilities.rst +++ b/Doc/c-api/utilities.rst @@ -20,3 +20,4 @@ and parsing function arguments and constructing Python values from C values. reflection.rst codec.rst perfmaps.rst + hashing.rst From 1a50a7b427314e3df54b3b7e6f8105ce29da9c2d Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Tue, 31 Oct 2023 09:16:33 +0300 Subject: [PATCH 05/15] Expose macroses as unstable API --- Doc/c-api/hashing.rst | 8 ++++---- Include/pyhash.h | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Doc/c-api/hashing.rst b/Doc/c-api/hashing.rst index c6d976fd1a6de2..14a2492cd1ab86 100644 --- a/Doc/c-api/hashing.rst +++ b/Doc/c-api/hashing.rst @@ -3,18 +3,18 @@ Parameters of the numeric hash implementation See :ref:`numeric-hash` for more details about hashing of numeric types. -.. c:macro:: _PyHASH_MODULUS +.. c:macro:: PyUnstable_PyHASH_MODULUS The Mersenne prime ``P = 2**n -1``, used for numeric hash scheme. -.. c:macro:: _PyHASH_BITS +.. c:macro:: PyUnstable_PyHASH_BITS The exponent ``n`` of ``P``. -.. c:macro:: _PyHASH_INF +.. c:macro:: PyUnstable_PyHASH_INF The hash value returned for a positive infinity. -.. c:macro:: _PyHASH_IMAG +.. c:macro:: PyUnstable_PyHASH_IMAG The multiplier used for the imaginary part of a complex number. diff --git a/Include/pyhash.h b/Include/pyhash.h index bfda4c973463ac..cae425c23f7350 100644 --- a/Include/pyhash.h +++ b/Include/pyhash.h @@ -29,9 +29,14 @@ PyAPI_FUNC(PyHash_FuncDef*) PyHash_GetFuncDef(void); # define _PyHASH_BITS 31 #endif +#define PyUnstable_PyHASH_BITS _PyHASH_BITS + #define _PyHASH_MODULUS (((size_t)1 << _PyHASH_BITS) - 1) +#define PyUnstable_PyHASH_MODULUS _PyHASH_MODULUS #define _PyHASH_INF 314159 +#define PyUnstable_PyHASH_INF _PyHASH_INF #define _PyHASH_IMAG _PyHASH_MULTIPLIER +#define PyUnstable_PyHASH_IMAG _PyHASH_IMAG /* Cutoff for small string DJBX33A optimization in range [1, cutoff). * From 7080fa91065d61860338221be9e4a7ac776cd51f Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Wed, 15 Nov 2023 09:21:21 +0300 Subject: [PATCH 06/15] Expose macros as public and move docs to Doc/c-api/hash.rst --- Doc/c-api/hash.rst | 15 +++++++++++++++ Doc/c-api/hashing.rst | 20 -------------------- Doc/c-api/utilities.rst | 1 - Include/pyhash.h | 8 ++++---- 4 files changed, 19 insertions(+), 25 deletions(-) delete mode 100644 Doc/c-api/hashing.rst diff --git a/Doc/c-api/hash.rst b/Doc/c-api/hash.rst index 4dc121d7fbaa9b..a5f3bc1a4e14b3 100644 --- a/Doc/c-api/hash.rst +++ b/Doc/c-api/hash.rst @@ -17,6 +17,21 @@ See also the :c:member:`PyTypeObject.tp_hash` member. .. versionadded:: 3.2 +.. c:macro:: PyHASH_MODULUS + + The Mersenne prime ``P = 2**n -1``, used for numeric hash scheme. + +.. c:macro:: PyHASH_BITS + + The exponent ``n`` of ``P``. + +.. c:macro:: PyHASH_INF + + The hash value returned for a positive infinity. + +.. c:macro:: PyHASH_IMAG + + The multiplier used for the imaginary part of a complex number. .. c:type:: PyHash_FuncDef diff --git a/Doc/c-api/hashing.rst b/Doc/c-api/hashing.rst deleted file mode 100644 index 14a2492cd1ab86..00000000000000 --- a/Doc/c-api/hashing.rst +++ /dev/null @@ -1,20 +0,0 @@ -Parameters of the numeric hash implementation -============================================= - -See :ref:`numeric-hash` for more details about hashing of numeric types. - -.. c:macro:: PyUnstable_PyHASH_MODULUS - - The Mersenne prime ``P = 2**n -1``, used for numeric hash scheme. - -.. c:macro:: PyUnstable_PyHASH_BITS - - The exponent ``n`` of ``P``. - -.. c:macro:: PyUnstable_PyHASH_INF - - The hash value returned for a positive infinity. - -.. c:macro:: PyUnstable_PyHASH_IMAG - - The multiplier used for the imaginary part of a complex number. diff --git a/Doc/c-api/utilities.rst b/Doc/c-api/utilities.rst index bb9402c0f6237a..48ae54acebe887 100644 --- a/Doc/c-api/utilities.rst +++ b/Doc/c-api/utilities.rst @@ -21,4 +21,3 @@ and parsing function arguments and constructing Python values from C values. reflection.rst codec.rst perfmaps.rst - hashing.rst diff --git a/Include/pyhash.h b/Include/pyhash.h index 3f6ef7ca51b5ba..91d9f46e2b9e85 100644 --- a/Include/pyhash.h +++ b/Include/pyhash.h @@ -17,14 +17,14 @@ extern "C" { # define _PyHASH_BITS 31 #endif -#define PyUnstable_PyHASH_BITS _PyHASH_BITS +#define PyHASH_BITS _PyHASH_BITS #define _PyHASH_MODULUS (((size_t)1 << _PyHASH_BITS) - 1) -#define PyUnstable_PyHASH_MODULUS _PyHASH_MODULUS +#define PyHASH_MODULUS _PyHASH_MODULUS #define _PyHASH_INF 314159 -#define PyUnstable_PyHASH_INF _PyHASH_INF +#define PyHASH_INF _PyHASH_INF #define _PyHASH_IMAG _PyHASH_MULTIPLIER -#define PyUnstable_PyHASH_IMAG _PyHASH_IMAG +#define PyHASH_IMAG _PyHASH_IMAG /* Cutoff for small string DJBX33A optimization in range [1, cutoff). * From 9fcd93e69bfccd3c54396f4b676f57ac309f79b5 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Wed, 15 Nov 2023 09:24:56 +0300 Subject: [PATCH 07/15] news entry --- .../next/C API/2023-11-15-09-24-51.gh-issue-111418.FYYetY.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/C API/2023-11-15-09-24-51.gh-issue-111418.FYYetY.rst diff --git a/Misc/NEWS.d/next/C API/2023-11-15-09-24-51.gh-issue-111418.FYYetY.rst b/Misc/NEWS.d/next/C API/2023-11-15-09-24-51.gh-issue-111418.FYYetY.rst new file mode 100644 index 00000000000000..676a9c457c89c4 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2023-11-15-09-24-51.gh-issue-111418.FYYetY.rst @@ -0,0 +1,2 @@ +Add :c:macro:`PyHASH_MODULUS`, :c:macro:`PyHASH_BITS`, :c:macro:`PyHASH_INF` +and :c:macro:`PyHASH_IMAG` C macroses. Patch by Sergey B Kirpichev. From 0cc4ff35a8927a6bf49cefbc54d8be6b6f081dbf Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Wed, 15 Nov 2023 10:26:34 +0300 Subject: [PATCH 08/15] restore link to hashing algorithms --- Doc/c-api/hash.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/c-api/hash.rst b/Doc/c-api/hash.rst index a5f3bc1a4e14b3..35a9869e308946 100644 --- a/Doc/c-api/hash.rst +++ b/Doc/c-api/hash.rst @@ -3,7 +3,8 @@ PyHash API ---------- -See also the :c:member:`PyTypeObject.tp_hash` member. +See also the :c:member:`PyTypeObject.tp_hash` member and :ref:`numeric-hash` +for more details about hashing of numeric types. .. c:type:: Py_hash_t From 00bc891bddd55525f23f302362b88b13adaecca8 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Thu, 16 Nov 2023 03:33:21 +0300 Subject: [PATCH 09/15] Update Misc/NEWS.d/next/C API/2023-11-15-09-24-51.gh-issue-111418.FYYetY.rst Co-authored-by: Victor Stinner --- .../next/C API/2023-11-15-09-24-51.gh-issue-111418.FYYetY.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/C API/2023-11-15-09-24-51.gh-issue-111418.FYYetY.rst b/Misc/NEWS.d/next/C API/2023-11-15-09-24-51.gh-issue-111418.FYYetY.rst index 676a9c457c89c4..5f76ec1443fb44 100644 --- a/Misc/NEWS.d/next/C API/2023-11-15-09-24-51.gh-issue-111418.FYYetY.rst +++ b/Misc/NEWS.d/next/C API/2023-11-15-09-24-51.gh-issue-111418.FYYetY.rst @@ -1,2 +1,2 @@ Add :c:macro:`PyHASH_MODULUS`, :c:macro:`PyHASH_BITS`, :c:macro:`PyHASH_INF` -and :c:macro:`PyHASH_IMAG` C macroses. Patch by Sergey B Kirpichev. +and :c:macro:`PyHASH_IMAG` C macros. Patch by Sergey B Kirpichev. From 6aaa610443e3fcd9cc563271d721de888aa3db77 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Thu, 16 Nov 2023 03:36:28 +0300 Subject: [PATCH 10/15] address review: versionadded --- Doc/c-api/hash.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Doc/c-api/hash.rst b/Doc/c-api/hash.rst index 35a9869e308946..e123d33c45dba2 100644 --- a/Doc/c-api/hash.rst +++ b/Doc/c-api/hash.rst @@ -22,18 +22,26 @@ for more details about hashing of numeric types. The Mersenne prime ``P = 2**n -1``, used for numeric hash scheme. + .. versionadded:: 3.13 + .. c:macro:: PyHASH_BITS The exponent ``n`` of ``P``. + .. versionadded:: 3.13 + .. c:macro:: PyHASH_INF The hash value returned for a positive infinity. + .. versionadded:: 3.13 + .. c:macro:: PyHASH_IMAG The multiplier used for the imaginary part of a complex number. + .. versionadded:: 3.13 + .. c:type:: PyHash_FuncDef Hash function definition used by :c:func:`PyHash_GetFuncDef`. From a8dec64eb606d0e980cf55410ea09da0f4ad19f5 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Thu, 16 Nov 2023 03:39:06 +0300 Subject: [PATCH 11/15] Move to Include/cpython/pyhash.h --- Include/cpython/pyhash.h | 5 +++++ Include/pyhash.h | 22 ---------------------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/Include/cpython/pyhash.h b/Include/cpython/pyhash.h index 6f7113daa5fe4d..fa51ea7b0a9510 100644 --- a/Include/cpython/pyhash.h +++ b/Include/cpython/pyhash.h @@ -15,9 +15,14 @@ # define _PyHASH_BITS 31 #endif +#define PyHASH_BITS _PyHASH_BITS + #define _PyHASH_MODULUS (((size_t)1 << _PyHASH_BITS) - 1) +#define PyHASH_MODULUS _PyHASH_MODULUS #define _PyHASH_INF 314159 +#define PyHASH_INF _PyHASH_INF #define _PyHASH_IMAG _PyHASH_MULTIPLIER +#define PyHASH_IMAG _PyHASH_IMAG /* Helpers for hash functions */ PyAPI_FUNC(Py_hash_t) _Py_HashDouble(PyObject *, double); diff --git a/Include/pyhash.h b/Include/pyhash.h index 91d9f46e2b9e85..3e23e2758808d7 100644 --- a/Include/pyhash.h +++ b/Include/pyhash.h @@ -4,28 +4,6 @@ extern "C" { #endif -/* Prime multiplier used in string and various other hashes. */ -#define _PyHASH_MULTIPLIER 1000003UL /* 0xf4243 */ - -/* Parameters used for the numeric hash implementation. See notes for - _Py_HashDouble in Python/pyhash.c. Numeric hashes are based on - reduction modulo the prime 2**_PyHASH_BITS - 1. */ - -#if SIZEOF_VOID_P >= 8 -# define _PyHASH_BITS 61 -#else -# define _PyHASH_BITS 31 -#endif - -#define PyHASH_BITS _PyHASH_BITS - -#define _PyHASH_MODULUS (((size_t)1 << _PyHASH_BITS) - 1) -#define PyHASH_MODULUS _PyHASH_MODULUS -#define _PyHASH_INF 314159 -#define PyHASH_INF _PyHASH_INF -#define _PyHASH_IMAG _PyHASH_MULTIPLIER -#define PyHASH_IMAG _PyHASH_IMAG - /* Cutoff for small string DJBX33A optimization in range [1, cutoff). * * About 50% of the strings in a typical Python application are smaller than From d3a61ced93a3fe2ef3d40cd7f69e01fa619ed1a3 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Thu, 16 Nov 2023 03:50:58 +0300 Subject: [PATCH 12/15] docs nitpick Was rendered: "See also the PyTypeObject.tp_hash member and Hashing of numeric types for more details about hashing of numeric types." --- Doc/c-api/hash.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Doc/c-api/hash.rst b/Doc/c-api/hash.rst index e123d33c45dba2..a6e5a184b64216 100644 --- a/Doc/c-api/hash.rst +++ b/Doc/c-api/hash.rst @@ -3,8 +3,7 @@ PyHash API ---------- -See also the :c:member:`PyTypeObject.tp_hash` member and :ref:`numeric-hash` -for more details about hashing of numeric types. +See also the :c:member:`PyTypeObject.tp_hash` member and :ref:`numeric-hash`. .. c:type:: Py_hash_t From 1f3b623b37fdfe67053cbb5462ff740fafa790f3 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Fri, 8 Mar 2024 13:22:08 +0300 Subject: [PATCH 13/15] Apply suggestions from code review Co-authored-by: Victor Stinner --- Doc/c-api/hash.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/c-api/hash.rst b/Doc/c-api/hash.rst index a6e5a184b64216..d0e90c34f62638 100644 --- a/Doc/c-api/hash.rst +++ b/Doc/c-api/hash.rst @@ -19,13 +19,13 @@ See also the :c:member:`PyTypeObject.tp_hash` member and :ref:`numeric-hash`. .. c:macro:: PyHASH_MODULUS - The Mersenne prime ``P = 2**n -1``, used for numeric hash scheme. + The `Mersenne prime `_ ``P = 2**n -1``, used for numeric hash scheme. .. versionadded:: 3.13 .. c:macro:: PyHASH_BITS - The exponent ``n`` of ``P``. + The exponent ``n`` of ``P`` in :c:macro:`PyHASH_MODULUS`. .. versionadded:: 3.13 From 1dd0fe709218e9eda2d1aa2a079516c7560c9903 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Fri, 8 Mar 2024 13:28:56 +0300 Subject: [PATCH 14/15] Apply suggestions from review: keep deprecated names as aliases --- Include/cpython/pyhash.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Include/cpython/pyhash.h b/Include/cpython/pyhash.h index fa51ea7b0a9510..20c465240759a6 100644 --- a/Include/cpython/pyhash.h +++ b/Include/cpython/pyhash.h @@ -10,19 +10,19 @@ reduction modulo the prime 2**_PyHASH_BITS - 1. */ #if SIZEOF_VOID_P >= 8 -# define _PyHASH_BITS 61 +# define PyHASH_BITS 61 #else -# define _PyHASH_BITS 31 +# define PyHASH_BITS 31 #endif -#define PyHASH_BITS _PyHASH_BITS +#define PyHASH_MODULUS (((size_t)1 << _PyHASH_BITS) - 1) +#define PyHASH_INF 314159 +#define PyHASH_IMAG _PyHASH_MULTIPLIER -#define _PyHASH_MODULUS (((size_t)1 << _PyHASH_BITS) - 1) -#define PyHASH_MODULUS _PyHASH_MODULUS -#define _PyHASH_INF 314159 -#define PyHASH_INF _PyHASH_INF -#define _PyHASH_IMAG _PyHASH_MULTIPLIER -#define PyHASH_IMAG _PyHASH_IMAG +#define _PyHASH_BITS PyHASH_BITS +#define _PyHASH_MODULUS PyHASH_MODULUS +#define _PyHASH_INF PyHASH_INF +#define _PyHASH_IMAG PyHASH_IMAG /* Helpers for hash functions */ PyAPI_FUNC(Py_hash_t) _Py_HashDouble(PyObject *, double); From 553c66352cd8dee7b011e2422310b783acf2f23f Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Fri, 8 Mar 2024 13:48:06 +0300 Subject: [PATCH 15/15] Add comment --- Include/cpython/pyhash.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Include/cpython/pyhash.h b/Include/cpython/pyhash.h index 20c465240759a6..5ee9c766ab1b2f 100644 --- a/Include/cpython/pyhash.h +++ b/Include/cpython/pyhash.h @@ -19,6 +19,7 @@ #define PyHASH_INF 314159 #define PyHASH_IMAG _PyHASH_MULTIPLIER +/* Aliases kept for backward compatibility with Python 3.12 */ #define _PyHASH_BITS PyHASH_BITS #define _PyHASH_MODULUS PyHASH_MODULUS #define _PyHASH_INF PyHASH_INF