summaryrefslogtreecommitdiffstats
path: root/Modules/_testcapi
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_testcapi')
-rw-r--r--Modules/_testcapi/hash.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/Modules/_testcapi/hash.c b/Modules/_testcapi/hash.c
index 809d537..1525344 100644
--- a/Modules/_testcapi/hash.c
+++ b/Modules/_testcapi/hash.c
@@ -46,6 +46,14 @@ hash_getfuncdef(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
static PyObject *
+long_from_hash(Py_hash_t hash)
+{
+ Py_BUILD_ASSERT(sizeof(long long) >= sizeof(hash));
+ return PyLong_FromLongLong(hash);
+}
+
+
+static PyObject *
hash_pointer(PyObject *Py_UNUSED(module), PyObject *arg)
{
void *ptr = PyLong_AsVoidPtr(arg);
@@ -54,8 +62,21 @@ hash_pointer(PyObject *Py_UNUSED(module), PyObject *arg)
}
Py_hash_t hash = Py_HashPointer(ptr);
- Py_BUILD_ASSERT(sizeof(long long) >= sizeof(hash));
- return PyLong_FromLongLong(hash);
+ return long_from_hash(hash);
+}
+
+
+static PyObject *
+hash_buffer(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ char *ptr;
+ Py_ssize_t len;
+ if (!PyArg_ParseTuple(args, "y#", &ptr, &len)) {
+ return NULL;
+ }
+
+ Py_hash_t hash = Py_HashBuffer(ptr, len);
+ return long_from_hash(hash);
}
@@ -64,14 +85,14 @@ object_generichash(PyObject *Py_UNUSED(module), PyObject *arg)
{
NULLABLE(arg);
Py_hash_t hash = PyObject_GenericHash(arg);
- Py_BUILD_ASSERT(sizeof(long long) >= sizeof(hash));
- return PyLong_FromLongLong(hash);
+ return long_from_hash(hash);
}
static PyMethodDef test_methods[] = {
{"hash_getfuncdef", hash_getfuncdef, METH_NOARGS},
{"hash_pointer", hash_pointer, METH_O},
+ {"hash_buffer", hash_buffer, METH_VARARGS},
{"object_generichash", object_generichash, METH_O},
{NULL},
};