mongodb-mongo_ext 0.4.1 → 0.11

Sign up to get free protection for your applications and to get access to all the features.
data/ext/cbson/cbson.c CHANGED
@@ -21,8 +21,21 @@
21
21
  */
22
22
 
23
23
  #include "ruby.h"
24
+
25
+ #if HAVE_RUBY_ST_H
26
+ #include "ruby/st.h"
27
+ #endif
28
+ #if HAVE_ST_H
24
29
  #include "st.h"
30
+ #endif
31
+
32
+ #if HAVE_RUBY_REGEX_H
33
+ #include "ruby/regex.h"
34
+ #endif
35
+ #if HAVE_REGEX_H
25
36
  #include "regex.h"
37
+ #endif
38
+
26
39
  #include <assert.h>
27
40
  #include <math.h>
28
41
 
@@ -181,25 +194,24 @@ static int write_element_allow_id(VALUE key, VALUE value, VALUE extra, int allow
181
194
 
182
195
  switch(TYPE(value)) {
183
196
  case T_BIGNUM:
184
- {
185
- VALUE as_f;
186
- int int_value;
187
- if (rb_funcall(value, rb_intern(">"), 1, INT2NUM(2147483647)) == Qtrue ||
188
- rb_funcall(value, rb_intern("<"), 1, INT2NUM(-2147483648)) == Qtrue) {
189
- rb_raise(rb_eRangeError, "MongoDB can only handle 4-byte ints"
190
- " - try converting to a double before saving");
191
- }
192
- write_name_and_type(buffer, key, 0x10);
193
- as_f = rb_funcall(value, rb_intern("to_f"), 0);
194
- int_value = NUM2LL(as_f);
195
- buffer_write_bytes(buffer, (char*)&int_value, 4);
196
- break;
197
- }
198
197
  case T_FIXNUM:
199
198
  {
200
- int int_value = FIX2INT(value);
201
- write_name_and_type(buffer, key, 0x10);
202
- buffer_write_bytes(buffer, (char*)&int_value, 4);
199
+ if (rb_funcall(value, rb_intern(">"), 1, LL2NUM(9223372036854775807LL)) == Qtrue ||
200
+ rb_funcall(value, rb_intern("<"), 1, LL2NUM(-9223372036854775808LL)) == Qtrue) {
201
+ rb_raise(rb_eRangeError, "MongoDB can only handle 8-byte ints");
202
+ }
203
+ if (rb_funcall(value, rb_intern(">"), 1, INT2NUM(2147483647L)) == Qtrue ||
204
+ rb_funcall(value, rb_intern("<"), 1, INT2NUM(-2147483648L)) == Qtrue) {
205
+ long long ll_value;
206
+ write_name_and_type(buffer, key, 0x12);
207
+ ll_value = NUM2LL(value);
208
+ buffer_write_bytes(buffer, (char*)&ll_value, 8);
209
+ } else {
210
+ int int_value;
211
+ write_name_and_type(buffer, key, 0x10);
212
+ int_value = NUM2LL(value);
213
+ buffer_write_bytes(buffer, (char*)&int_value, 4);
214
+ }
203
215
  break;
204
216
  }
205
217
  case T_TRUE:
@@ -680,6 +692,14 @@ static VALUE get_value(const char* buffer, int* position, int type) {
680
692
  *position += 8;
681
693
  break;
682
694
  }
695
+ case 18:
696
+ {
697
+ long long ll;
698
+ memcpy(&ll, buffer + *position, 8);
699
+ value = LL2NUM(ll);
700
+ *position += 8;
701
+ break;
702
+ }
683
703
  default:
684
704
  {
685
705
  rb_raise(rb_eTypeError, "no c decoder for this type yet (%d)", type);
data/ext/cbson/extconf.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'mkmf'
2
2
 
3
- find_header("st.h")
4
- find_header("regex.h")
3
+ have_header("ruby/st.h") || have_header("st.h")
4
+ have_header("ruby/regex.h") || have_header("regex.h")
5
+
5
6
  dir_config('cbson')
6
7
  create_makefile('mongo_ext/cbson')
@@ -7,7 +7,8 @@ TEST_FILES = []
7
7
 
8
8
  Gem::Specification.new do |s|
9
9
  s.name = 'mongo_ext'
10
- s.version = '0.4.1'
10
+
11
+ s.version = '0.11'
11
12
  s.platform = Gem::Platform::RUBY
12
13
  s.summary = 'C extensions for the MongoDB Ruby driver'
13
14
  s.description = 'C extensions to accelerate the MondoDB Ruby driver. For more information about Mongo, see http://www.mongodb.org.'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongodb-mongo_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: "0.11"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Dirolf