Skip to content

Commit 7539c7f

Browse files
authored
Add hash constants (python#85)
1 parent 52486a9 commit 7539c7f

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

docs/changelog.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Changelog
22
=========
33

4+
* 2024-03-09: Add hash constants:
5+
6+
* ``PyHASH_BITS``
7+
* ``PyHASH_IMAG``
8+
* ``PyHASH_INF``
9+
* ``PyHASH_MODULUS``
10+
411
* 2024-02-20: Add PyTime API:
512

613
* ``PyTime_t`` type

pythoncapi_compat.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,18 @@ static inline int PyTime_PerfCounter(PyTime_t *result)
11961196

11971197
#endif
11981198

1199+
// gh-111389 added hash constants to Python 3.13.0a5. These constants were
1200+
// added first as private macros to Python 3.4.0b1 and PyPy 7.3.9.
1201+
#if (!defined(PyHASH_BITS) \
1202+
&& ((!defined(PYPY_VERSION) && PY_VERSION_HEX >= 0x030400B1) \
1203+
|| (defined(PYPY_VERSION) && PY_VERSION_HEX >= 0x03070000 \
1204+
&& PYPY_VERSION_NUM >= 0x07090000)))
1205+
# define PyHASH_BITS _PyHASH_BITS
1206+
# define PyHASH_MODULUS _PyHASH_MODULUS
1207+
# define PyHASH_INF _PyHASH_INF
1208+
# define PyHASH_IMAG _PyHASH_IMAG
1209+
#endif
1210+
11991211

12001212
#ifdef __cplusplus
12011213
}

tests/test_pythoncapi_compat_cext.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,20 @@ test_hash(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
15221522
assert(Py_HashPointer(ptr1) == (Py_hash_t)ptr1);
15231523
#endif
15241524

1525+
#if ((!defined(PYPY_VERSION) && PY_VERSION_HEX >= 0x030400B1) \
1526+
|| (defined(PYPY_VERSION) && PY_VERSION_HEX >= 0x03070000 \
1527+
&& PYPY_VERSION_NUM >= 0x07090000))
1528+
// Just check that constants are available
1529+
size_t bits = PyHASH_BITS;
1530+
assert(bits >= 8);
1531+
size_t mod = PyHASH_MODULUS;
1532+
assert(mod >= 7);
1533+
size_t inf = PyHASH_INF;
1534+
assert(inf != 0);
1535+
size_t imag = PyHASH_IMAG;
1536+
assert(imag != 0);
1537+
#endif
1538+
15251539
Py_RETURN_NONE;
15261540
}
15271541

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy