Commit 9f08f97f authored by Tres Seaver's avatar Tres Seaver

Merge branch 'master' of https://github.com/zerodb/persistent into zerodb-master

parents ed211197 533908c1
...@@ -269,16 +269,14 @@ class PyAndCComparisonTests(unittest.TestCase): ...@@ -269,16 +269,14 @@ class PyAndCComparisonTests(unittest.TestCase):
# platform and test the same; also verify 64 bit # platform and test the same; also verify 64 bit
bit_32_hash = -1419374591 bit_32_hash = -1419374591
bit_64_hash = -3850693964765720575 bit_64_hash = -3850693964765720575
import persistent.timestamp import sys
import ctypes orig_maxint = sys.maxint
orig_c_long = persistent.timestamp.c_long
try: try:
persistent.timestamp.c_long = ctypes.c_int32 sys.maxint = int(2 ** 31 - 1)
py = self._makePy(*self.now_ts_args) py = self._makePy(*self.now_ts_args)
self.assertEqual(hash(py), bit_32_hash) self.assertEqual(hash(py), bit_32_hash)
sys.maxint = int(2 ** 63 - 1)
persistent.timestamp.c_long = ctypes.c_int64
# call __hash__ directly to avoid interpreter truncation # call __hash__ directly to avoid interpreter truncation
# in hash() on 32-bit platforms # in hash() on 32-bit platforms
if not _is_jython: if not _is_jython:
...@@ -292,13 +290,13 @@ class PyAndCComparisonTests(unittest.TestCase): ...@@ -292,13 +290,13 @@ class PyAndCComparisonTests(unittest.TestCase):
# 32-bit ints for its hashCode methods. # 32-bit ints for its hashCode methods.
self.assertEqual(py.__hash__(), 384009219096809580920179179233996861765753210540033) self.assertEqual(py.__hash__(), 384009219096809580920179179233996861765753210540033)
finally: finally:
persistent.timestamp.c_long = orig_c_long sys.maxint = orig_maxint
# These are *usually* aliases, but aren't required # These are *usually* aliases, but aren't required
# to be (and aren't under Jython 2.7). # to be (and aren't under Jython 2.7).
if orig_c_long is ctypes.c_int32: if orig_maxint == 2 ** 31 - 1:
self.assertEqual(py.__hash__(), bit_32_hash) self.assertEqual(py.__hash__(), bit_32_hash)
elif orig_c_long is ctypes.c_int64: elif orig_maxint == 2 ** 63 - 1:
self.assertEqual(py.__hash__(), bit_64_hash) self.assertEqual(py.__hash__(), bit_64_hash)
def test_hash_equal_constants(self): def test_hash_equal_constants(self):
...@@ -307,7 +305,7 @@ class PyAndCComparisonTests(unittest.TestCase): ...@@ -307,7 +305,7 @@ class PyAndCComparisonTests(unittest.TestCase):
import persistent.timestamp import persistent.timestamp
import ctypes import ctypes
# We get 32-bit hash values of 32-bit platforms, or on the JVM # We get 32-bit hash values of 32-bit platforms, or on the JVM
is_32_bit = persistent.timestamp.c_long == ctypes.c_int32 or _is_jython is_32_bit = persistent.timestamp.sys.maxint == (2**31 - 1) or _is_jython
c, py = self._make_C_and_Py(b'\x00\x00\x00\x00\x00\x00\x00\x00') c, py = self._make_C_and_Py(b'\x00\x00\x00\x00\x00\x00\x00\x00')
self.assertEqual(hash(c), 8) self.assertEqual(hash(c), 8)
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
############################################################################## ##############################################################################
__all__ = ('TimeStamp',) __all__ = ('TimeStamp',)
from ctypes import c_long
import datetime import datetime
import math import math
import struct import struct
...@@ -158,7 +157,7 @@ class pyTimeStamp(object): ...@@ -158,7 +157,7 @@ class pyTimeStamp(object):
# Make sure to overflow and wraparound just # Make sure to overflow and wraparound just
# like the C code does. # like the C code does.
x = c_long(x).value x = int(((x + (sys.maxint + 1)) & ((sys.maxint << 1) + 1)) - (sys.maxint + 1))
if x == -1: #pragma: no cover if x == -1: #pragma: no cover
# The C version has this condition, but it's not clear # The C version has this condition, but it's not clear
# why; it's also not immediately obvious what bytestring # why; it's also not immediately obvious what bytestring
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment