summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-12-06 14:09:22 (GMT)
committerGitHub <noreply@github.com>2023-12-06 14:09:22 (GMT)
commit828451dfde324f9499ffebc023a22b84dc5a125b (patch)
treeceee17c26f9c9238b602ef9156e6eb8530d032f1 /Modules
parentf8852634edf1232ac1aa4561e34796b52f9f7aa2 (diff)
downloadcpython-828451dfde324f9499ffebc023a22b84dc5a125b.zip
cpython-828451dfde324f9499ffebc023a22b84dc5a125b.tar.gz
cpython-828451dfde324f9499ffebc023a22b84dc5a125b.tar.bz2
gh-111545: Add Py_HashPointer() function (#112096)
* 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().
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testcapi/hash.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/Modules/_testcapi/hash.c b/Modules/_testcapi/hash.c
index d0b8127..aee7678 100644
--- a/Modules/_testcapi/hash.c
+++ b/Modules/_testcapi/hash.c
@@ -44,8 +44,24 @@ hash_getfuncdef(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
return result;
}
+
+static PyObject *
+hash_pointer(PyObject *Py_UNUSED(module), PyObject *arg)
+{
+ void *ptr = PyLong_AsVoidPtr(arg);
+ if (ptr == NULL && PyErr_Occurred()) {
+ return NULL;
+ }
+
+ Py_hash_t hash = Py_HashPointer(ptr);
+ Py_BUILD_ASSERT(sizeof(long long) >= sizeof(hash));
+ return PyLong_FromLongLong(hash);
+}
+
+
static PyMethodDef test_methods[] = {
{"hash_getfuncdef", hash_getfuncdef, METH_NOARGS},
+ {"hash_pointer", hash_pointer, METH_O},
{NULL},
};