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

Fix for BSON timestamp serialization issue for C extension #54

Merged
merged 1 commit into from Aug 24, 2011

Conversation

renctan
Copy link
Member

@renctan renctan commented Aug 24, 2011

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!

banker added a commit that referenced this pull request Aug 24, 2011
RUBY-296 fix for BSON timestamp serialization issue for C extension
@banker banker merged commit a3b28f7 into mongodb:master Aug 24, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants