From 68807b8df5001f75435fd27dec1916baf43bd11a Mon Sep 17 00:00:00 2001 From: Mike Dirolf Date: Wed, 11 Mar 2009 10:49:30 -0400 Subject: [PATCH] a couple of fixes --- ext/cbson/cbson.c | 21 ++++++++++++--------- tests/test_round_trip.rb | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/ext/cbson/cbson.c b/ext/cbson/cbson.c index fa23657..beba060 100644 --- a/ext/cbson/cbson.c +++ b/ext/cbson/cbson.c @@ -493,16 +493,19 @@ static VALUE get_value(const char* buffer, int* position, int type) { int flags_length = strlen(buffer + *position); int i = 0; - char flags[4]; - flags[0] = 0; + int flags; char extra[10]; extra[0] = 0; for (i = 0; i < flags_length; i++) { char flag = buffer[*position + i]; - if (flag == 'i' || flag == 'm' || flag == 'x') { - if (strlen(flags) < 3) { - strncat(flags, &flag, 1); - } + if (flag == 'i') { + flags |= RE_OPTION_IGNORECASE; + } + else if (flag == 'm') { + flags |= RE_OPTION_MULTILINE; + } + else if (flag == 'x') { + flags |= RE_OPTION_EXTENDED; } else if (strlen(extra) < 9) { strncat(extra, &flag, 1); @@ -510,7 +513,7 @@ static VALUE get_value(const char* buffer, int* position, int type) { } VALUE argv[3] = { pattern, - rb_str_new2(flags), + INT2FIX(flags), rb_str_new2(extra) }; value = rb_class_new_instance(3, argv, RegexpOfHolding); @@ -538,14 +541,14 @@ static VALUE get_value(const char* buffer, int* position, int type) { int value_length; memcpy(&value_length, buffer + *position, 4); value = ID2SYM(rb_intern(buffer + *position + 4)); - *position += value_length + 5; + *position += value_length + 4; break; } case 16: { int i; memcpy(&i, buffer + *position, 4); - value = INT2FIX(i); + value = LL2NUM(i); *position += 4; break; } diff --git a/tests/test_round_trip.rb b/tests/test_round_trip.rb index c17bc42..91bf9cb 100644 --- a/tests/test_round_trip.rb +++ b/tests/test_round_trip.rb @@ -93,7 +93,7 @@ EOS # Turn those BSON bytes back into a Ruby object. # # We're passing a nil db to the contructor here, but that's OK because - # the BSON DBFef bytes don't contain the db object in any case, and we + # the BSON DBRef bytes don't contain the db object in any case, and we # don't care what the database is. obj_from_bson = BSON.new.deserialize(ByteBuffer.new(bson_from_ruby)) assert_kind_of OrderedHash, obj_from_bson