mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
gh-113024: C API: Add PyObject_GenericHash() function (GH-113025)
This commit is contained in:
parent
567ab3bd15
commit
e2e0b4b4b9
14 changed files with 51 additions and 13 deletions
|
|
@ -4780,7 +4780,7 @@ _dec_hash(PyDecObject *v)
|
|||
return -1;
|
||||
}
|
||||
else if (mpd_isnan(MPD(v))) {
|
||||
return _Py_HashPointer(v);
|
||||
return PyObject_GenericHash((PyObject *)v);
|
||||
}
|
||||
else {
|
||||
return py_hash_inf * mpd_arith_sign(MPD(v));
|
||||
|
|
|
|||
|
|
@ -59,9 +59,20 @@ hash_pointer(PyObject *Py_UNUSED(module), PyObject *arg)
|
|||
}
|
||||
|
||||
|
||||
static PyObject *
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef test_methods[] = {
|
||||
{"hash_getfuncdef", hash_getfuncdef, METH_NOARGS},
|
||||
{"hash_pointer", hash_pointer, METH_O},
|
||||
{"object_generichash", object_generichash, METH_O},
|
||||
{NULL},
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue