Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C and Python TimeStamp objects have different .raw() and repr() values for same input and are not equal #18

Closed
jamadden opened this issue Apr 7, 2015 · 1 comment · Fixed by #19

Comments

@jamadden
Copy link
Member

jamadden commented Apr 7, 2015

This cropped up in testing ZODB (see zopefoundation/ZODB#33), which relies on the particular repr of known TimeStamp objects, but it's not hard to imagine this having implications in many other ways.

Here's a doctest-like example:

First, verify we have access to a C implementation:

>>> import sys
>>> sys.version
'2.7.9 (default, Dec 13 2014, 15:13:49) \n[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)]'
>>> import persistent.TimeStamp
>>> persistent.TimeStamp.TimeStamp
<built-in function TimeStamp>

Next, set up a constant time (this exact floating point value and timestamp come from ZODB tests):

>>> import time
>>> now = 1229959248.3
>>> val = (time.gmtime(now)[:5] + (now % 60,))
>>> val
(2008, 12, 22, 15, 20, 48.299999952316284)

Create a C and Python TimeStamp:

>>> C_ts = persistent.TimeStamp.TimeStamp(*val)
>>> Py_ts = persistent.TimeStamp.pyTimeStamp(*val)

Not only do they have different reprs and raw values (different in the last character):

>>> print(repr(C_ts))
'\x03z\xbd\xd8\xce\x14z\xdd'
>>> print(repr(Py_ts))
'\x03z\xbd\xd8\xce\x14z\xde'
>>> C_ts.raw()
'\x03z\xbd\xd8\xce\x14z\xdd'
>>> Py_ts.raw()
'\x03z\xbd\xd8\xce\x14z\xde'

They're not even equal to each other, despite having the same input:

>>> C_ts == Py_ts
False

To me this seems like a bug. I can try to put together a PR, but I'm not familiar with the code so it might take me awhile.

@jamadden
Copy link
Member Author

jamadden commented Apr 7, 2015

I've got this now, preparing a PR.

fabiomaggio pushed a commit to fabiomaggio/persistent that referenced this issue Feb 20, 2017
…meStamp match the C version in more cases. Also, make the behaviour of comparisons and hashing match as well; test all this.
fabiomaggio pushed a commit to fabiomaggio/persistent that referenced this issue Feb 20, 2017
…meStamp match the C version in more cases. Also, make the behaviour of comparisons and hashing match as well; test all this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant