Skip to content

Commit

Permalink
Detect the bitness of the current process in order to better match th…
Browse files Browse the repository at this point in the history
…e C TimeStamp hashcode. Fixes #21
  • Loading branch information
jamadden committed Apr 9, 2015
1 parent 663497d commit 679a64b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions persistent/timestamp.py
Expand Up @@ -13,12 +13,21 @@
##############################################################################
__all__ = ('TimeStamp',)

from ctypes import c_int64
import datetime
import math
import struct
import sys

# We need to use a native ctype to get the overflow behaviour in the
# __hash__ function to match the C implementation. However, which one
# to use depends on whether we were built 64-bit or 32-bit.
if sys.maxsize > 2**32:
# the `platform` docs say this is the most reliable way to
# detect 64-bit
from ctypes import c_int64 as c_long
else:
from ctypes import c_long

_RAWTYPE = bytes

def _makeOctets(s):
Expand Down Expand Up @@ -158,7 +167,7 @@ def __hash__(self):

# Make sure to overflow and wraparound just
# like the C code does.
x = c_int64(x).value
x = c_long(x).value
if x == -1: #pragma: no cover
# The C version has this condition, but it's not clear
# why; it's also not immediately obvious what bytestring
Expand Down

0 comments on commit 679a64b

Please sign in to comment.