[issue1646068] Dict lookups fail if sizeof(Py_ssize_t) < sizeof(long)

Alexander Belopolsky report at bugs.python.org
Wed Jul 14 19:41:40 CEST 2010


Alexander Belopolsky <belopolsky at users.sourceforge.net> added the comment:

On the second thought, this comment:

-	/* 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.
-	 */

suggests that a union may be appropriate here.  I am not sure of the standards standing of anonymous unions, but if we could do

union {
  Py_ssize_t me_finger;
  long me_hash;
};

it would cleanly solve the problem.  If anonymous unions are not available, a regular union could also do the trick:

union {
  Py_ssize_t finger;
  long hash;
} me;

and use me.finger where me is used as search finger and me.hash where it stores hash.  Less clever naming scheme would be welcome, though.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1646068>
_______________________________________


More information about the Python-bugs-list mailing list