Fix for BSON timestamp serialization issue for C extension #54
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi Kyle,
Please accept my pull request for the fix. Here's the background:
Problem:
The problem was that the serialization/deserialization code assumes that the seconds/increment is always Fixnum. Ruby documentation defines Fixnum as a number that fits the native machine word size minus 2 bits (one is used as signed bit, and another apparently for differentiating between an address and raw integer value). So, for 32bit machines, the maximum Fixnum is just 1073741823.
Fix:
I just changed the code to use a type conversion macro that will perform checks if the numeral is a Fixnum or Bignum. I have also modified the seconds/increment to be unsigned. Although the BSON spec does not explicitly mention whether it is signed or not, the mongo source code defines the i and secs member of OpTime as unsigned so I made the changes to make the serializer consistent with the mongo definition.
Reference:
This has been extremely helpful in analyzing the c extension code (especially on ch2) which you might also find useful:
http://i.loveruby.net/ja/rhg/book/
They also have a partially translated version available here:
http://rhg.rubyforge.org/
Thanks!