[Python-Dev] returning longs from __hash__()
Armin Rigo
arigo at tunes.org
Wed Aug 9 11:47:25 CEST 2006
Hi Martin,
On Tue, Aug 08, 2006 at 11:14:56PM +0200, "Martin v. L?wis" wrote:
> - h = PyInt_AsLong(res);
> + if (PyLong_Check(res))
> + h = res->ob_type->tp_hash(res);
This bug will keep showing up forever :-) It's unsafe against a user
subclassing 'long' and overriding __hash__ of that subclass to return
the object itself -- it would cause an infinite C recursion.
Instead, we need either a new API like PyLong_Hash(), or call
'PyLong_Type.tp_hash(res)'.
Same in the other change.
A bientot,
Armin
More information about the Python-Dev
mailing list