animehunter-mongo_ext 0.4 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -63,26 +63,19 @@ static VALUE OrderedHash;
63
63
  #define EXTENDED RE_OPTION_EXTENDED
64
64
  #endif
65
65
 
66
- /* TODO we ought to check that the malloc or asprintf was successful
66
+ /* TODO we ought to check that the snprintf was successful
67
67
  * and raise an exception if not. */
68
68
  #ifdef _MSC_VER
69
- #define INT2STRING(buffer, i) \
70
- { \
71
- int vslength = _scprintf("%d", i) + 1; \
72
- *buffer = malloc(vslength); \
73
- _snprintf(*buffer, vslength, "%d", i); \
74
- }
75
- #elif defined(__MINGW32__)
76
- #define INT2STRING(buffer, i) \
77
- { \
78
- int vslength = log10(i) + 2; \
79
- *buffer = malloc(vslength); \
80
- _snprintf(*buffer, vslength, "%d", i); \
69
+ #define INT2STRING(buffer, len, i) \
70
+ { \
71
+ _snprintf(buffer, len, "%d", i); \
81
72
  }
82
73
  #else
83
- #define INT2STRING(buffer, i) asprintf(buffer, "%d", i);
74
+ #define INT2STRING(buffer, len, i) snprintf(buffer, len, "%d", i);
84
75
  #endif
85
76
 
77
+ #define I2S_BUFFER_SIZE 32
78
+
86
79
  // this sucks too.
87
80
  #ifndef RREGEXP_SRC_PTR
88
81
  #define RREGEXP_SRC_PTR(r) RREGEXP(r)->str
@@ -256,6 +249,7 @@ static int write_element_allow_id(VALUE key, VALUE value, VALUE extra, int allow
256
249
  }
257
250
  case T_ARRAY:
258
251
  {
252
+ char name[I2S_BUFFER_SIZE];
259
253
  int start_position, length_location, items, i, obj_length;
260
254
  VALUE* values;
261
255
 
@@ -268,12 +262,10 @@ static int write_element_allow_id(VALUE key, VALUE value, VALUE extra, int allow
268
262
  items = RARRAY_LEN(value);
269
263
  values = RARRAY_PTR(value);
270
264
  for(i = 0; i < items; i++) {
271
- char* name;
272
265
  VALUE key;
273
- INT2STRING(&name, i);
266
+ INT2STRING(name,I2S_BUFFER_SIZE,i);
274
267
  key = rb_str_new2(name);
275
268
  write_element(key, values[i], pack_extra(buffer, check_keys));
276
- free(name);
277
269
  }
278
270
 
279
271
  // write null byte and fill in length
@@ -7,7 +7,7 @@ TEST_FILES = []
7
7
 
8
8
  Gem::Specification.new do |s|
9
9
  s.name = 'mongo_ext'
10
- s.version = '0.4'
10
+ s.version = '0.5'
11
11
  s.platform = Gem::Platform::RUBY
12
12
  s.summary = 'C extensions for the MongoDB Ruby driver'
13
13
  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: animehunter-mongo_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.4"
4
+ version: "0.5"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Dirolf