__hash__ may now return long int; the final hash
value is obtained by invoking hash on the long int.
Fixes #1536021.
diff --git a/Objects/classobject.c b/Objects/classobject.c
index c69ba74..56bf29c 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -934,11 +934,9 @@
Py_DECREF(func);
if (res == NULL)
return -1;
- if (PyInt_Check(res)) {
- outcome = PyInt_AsLong(res);
- if (outcome == -1)
- outcome = -2;
- }
+ if (PyInt_Check(res) || PyLong_Check(res))
+ /* This already converts a -1 result to -2. */
+ outcome = res->ob_type->tp_hash(res);
else {
PyErr_SetString(PyExc_TypeError,
"__hash__() should return an int");
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 67e6104..652009b 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -4559,7 +4559,10 @@
Py_DECREF(func);
if (res == NULL)
return -1;
- h = PyInt_AsLong(res);
+ if (PyLong_Check(res))
+ h = res->ob_type->tp_hash(res);
+ else
+ h = PyInt_AsLong(res);
Py_DECREF(res);
}
else {