gh-113024: C API: Add PyObject_GenericHash() function (GH-113025)

This commit is contained in:
Serhiy Storchaka 2024-03-22 20:19:10 +02:00 committed by GitHub
parent 567ab3bd15
commit e2e0b4b4b9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 51 additions and 13 deletions

View file

@ -301,7 +301,7 @@ static Py_hash_t
method_hash(PyMethodObject *a)
{
Py_hash_t x, y;
x = _Py_HashPointer(a->im_self);
x = PyObject_GenericHash(a->im_self);
y = PyObject_Hash(a->im_func);
if (y == -1)
return -1;

View file

@ -1346,7 +1346,7 @@ wrapper_hash(PyObject *self)
{
wrapperobject *wp = (wrapperobject *)self;
Py_hash_t x, y;
x = _Py_HashPointer(wp->self);
x = PyObject_GenericHash(wp->self);
y = _Py_HashPointer(wp->descr);
x = x ^ y;
if (x == -1)

View file

@ -320,7 +320,7 @@ static Py_hash_t
meth_hash(PyCFunctionObject *a)
{
Py_hash_t x, y;
x = _Py_HashPointer(a->m_self);
x = PyObject_GenericHash(a->m_self);
y = _Py_HashPointer((void*)(a->m_ml->ml_meth));
x ^= y;
if (x == -1)

View file

@ -6891,12 +6891,6 @@ PyDoc_STRVAR(object_doc,
"When called, it accepts no arguments and returns a new featureless\n"
"instance that has no instance attributes and cannot be given any.\n");
static Py_hash_t
object_hash(PyObject *obj)
{
return _Py_HashPointer(obj);
}
PyTypeObject PyBaseObject_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"object", /* tp_name */
@ -6911,7 +6905,7 @@ PyTypeObject PyBaseObject_Type = {
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
object_hash, /* tp_hash */
PyObject_GenericHash, /* tp_hash */
0, /* tp_call */
object_str, /* tp_str */
PyObject_GenericGetAttr, /* tp_getattro */