--- Objects/dictobject.c 2006-09-05 02:54:06.000000000 +0100 +++ Objects/new/dictobject.c 2007-02-04 13:55:47.378303376 +0000 @@ -402,7 +402,7 @@ Py_DECREF(dummy); } ep->me_key = key; - ep->me_hash = (Py_ssize_t)hash; + ep->me_hash = (Py_dicthashcache_t)hash; ep->me_value = value; mp->ma_used++; } @@ -436,7 +436,7 @@ assert(ep->me_value == NULL); mp->ma_fill++; ep->me_key = key; - ep->me_hash = (Py_ssize_t)hash; + ep->me_hash = (Py_dicthashcache_t)hash; ep->me_value = value; mp->ma_used++; } @@ -1758,7 +1758,7 @@ static PyObject * dict_popitem(dictobject *mp) { - Py_ssize_t i = 0; + Py_dicthashcache_t i = 0; dictentry *ep; PyObject *res; --- Include/dictobject.h 2006-05-30 05:16:25.000000000 +0100 +++ Include/new/dictobject.h 2007-02-04 13:58:56.058619608 +0000 @@ -47,12 +47,21 @@ */ #define PyDict_MINSIZE 8 +/* Type to hold cached hash code of me_key. Note that hash codes are C longs. */ +#if SIZEOF_LONG > SIZEOF_SSIZE_T +/* We have to use long instead of 'Py_ssize_t' otherwise the cached hash will + * be truncated. + */ +typedef long Py_dicthashcache_t; +#else +/* We have to use Py_ssize_t instead of 'long' because dict_popitem() abuses + * me_hash to hold a search finger. + */ +typedef Py_ssize_t Py_dicthashcache_t; +#endif + typedef struct { - /* Cached hash code of me_key. Note that hash codes are C longs. - * We have to use Py_ssize_t instead because dict_popitem() abuses - * me_hash to hold a search finger. - */ - Py_ssize_t me_hash; + Py_dicthashcache_t me_hash; PyObject *me_key; PyObject *me_value; } PyDictEntry;