Skip to content

Fix for BSON timestamp serialization issue for C extension - #54

Merged
banker merged 1 commit into
mongodb:masterfrom
renctan:master
Aug 24, 2011
Merged

Fix for BSON timestamp serialization issue for C extension#54
banker merged 1 commit into
mongodb:masterfrom
renctan:master

Conversation

@renctan

@renctan renctan commented Aug 24, 2011

Copy link
Copy Markdown
Member

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

Development

Successfully merging this pull request may close these issues.

2 participants