msgpack 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/ext/unpack.c +45 -25
  2. data/test/test_helper.rb +1 -1
  3. metadata +3 -3
@@ -220,15 +220,18 @@ static VALUE MessagePack_Unpacker_initialize(int argc, VALUE *argv, VALUE self)
220
220
  }
221
221
 
222
222
 
223
- static VALUE MessagePack_Unpacker_execute_impl(VALUE args)
223
+ static VALUE MessagePack_Unpacker_execute_do(VALUE argv)
224
224
  {
225
- VALUE self = ((VALUE*)args)[0];
226
- VALUE data = ((VALUE*)args)[1];
225
+ VALUE* args = (VALUE*)argv;
227
226
 
227
+ VALUE self = args[0];
228
228
  UNPACKER(self, mp);
229
- size_t from = NUM2UINT(((VALUE*)args)[2]);
229
+
230
+ VALUE data = args[1];
231
+
232
+ size_t from = (unsigned long)args[2];
230
233
  char* dptr = RSTRING_PTR(data);
231
- long dlen = FIX2LONG(((VALUE*)args)[3]);
234
+ size_t dlen = (unsigned long)args[3];
232
235
  int ret;
233
236
 
234
237
  if(from >= dlen) {
@@ -236,7 +239,7 @@ static VALUE MessagePack_Unpacker_execute_impl(VALUE args)
236
239
  }
237
240
 
238
241
  mp->user.source = data;
239
- ret = template_execute(mp, dptr, (size_t)dlen, &from);
242
+ ret = template_execute(mp, dptr, dlen, &from);
240
243
  mp->user.source = Qnil;
241
244
 
242
245
  if(ret < 0) {
@@ -260,22 +263,32 @@ static VALUE MessagePack_Unpacker_execute_rescue(VALUE nouse)
260
263
  #endif
261
264
  }
262
265
 
263
- static VALUE MessagePack_Unpacker_execute_limit(VALUE self, VALUE data,
264
- VALUE off, VALUE limit)
266
+ static inline VALUE MessagePack_Unpacker_execute_impl(VALUE self, VALUE data,
267
+ unsigned long off, unsigned long dlen)
265
268
  {
266
269
  // FIXME execute実行中はmp->topが更新されないのでGC markが機能しない
267
270
  rb_gc_disable();
268
- VALUE args[4] = {self, data, off, limit};
269
- VALUE ret = rb_rescue(MessagePack_Unpacker_execute_impl, (VALUE)args,
271
+ VALUE args[4] = {self, data, (VALUE)off, (VALUE)dlen};
272
+ VALUE ret = rb_rescue(MessagePack_Unpacker_execute_do, (VALUE)args,
270
273
  MessagePack_Unpacker_execute_rescue, Qnil);
271
274
  rb_gc_enable();
275
+
272
276
  return ret;
273
277
  }
274
278
 
279
+ static VALUE MessagePack_Unpacker_execute_limit(VALUE self, VALUE data,
280
+ VALUE off, VALUE limit)
281
+ {
282
+ CHECK_STRING_TYPE(data);
283
+ return MessagePack_Unpacker_execute_impl(self, data,
284
+ NUM2ULONG(off), NUM2ULONG(limit));
285
+ }
286
+
275
287
  static VALUE MessagePack_Unpacker_execute(VALUE self, VALUE data, VALUE off)
276
288
  {
277
- return MessagePack_Unpacker_execute_limit(self, data, off,
278
- LONG2FIX(RSTRING_LEN(data)));
289
+ CHECK_STRING_TYPE(data);
290
+ return MessagePack_Unpacker_execute_impl(self, data,
291
+ NUM2ULONG(off), RSTRING_LEN(data));
279
292
  }
280
293
 
281
294
  static VALUE MessagePack_Unpacker_finished_p(VALUE self)
@@ -379,18 +392,20 @@ static VALUE MessagePack_Unpacker_each(VALUE self)
379
392
  }
380
393
 
381
394
 
382
- static VALUE MessagePack_unpack_impl(VALUE args)
395
+ static VALUE MessagePack_unpack_do(VALUE argv)
383
396
  {
384
- msgpack_unpack_t* mp = (msgpack_unpack_t*)((VALUE*)args)[0];
385
- VALUE data = ((VALUE*)args)[1];
397
+ VALUE* args = (VALUE*)argv;
398
+
399
+ msgpack_unpack_t* mp = (msgpack_unpack_t*)args[0];
400
+ VALUE data = args[1];
386
401
 
387
402
  size_t from = 0;
388
403
  char* dptr = RSTRING_PTR(data);
389
- long dlen = FIX2LONG(((VALUE*)args)[2]);
404
+ size_t dlen = (unsigned long)args[2];
390
405
  int ret;
391
406
 
392
407
  mp->user.source = data;
393
- ret = template_execute(mp, dptr, (size_t)dlen, &from);
408
+ ret = template_execute(mp, dptr, dlen, &from);
394
409
  mp->user.source = Qnil;
395
410
 
396
411
  if(ret < 0) {
@@ -405,7 +420,7 @@ static VALUE MessagePack_unpack_impl(VALUE args)
405
420
  }
406
421
  }
407
422
 
408
- static VALUE MessagePack_unpack_rescue(VALUE args)
423
+ static VALUE MessagePack_unpack_rescue(VALUE nouse)
409
424
  {
410
425
  rb_gc_enable();
411
426
  #ifdef RUBY_VM
@@ -415,29 +430,34 @@ static VALUE MessagePack_unpack_rescue(VALUE args)
415
430
  #endif
416
431
  }
417
432
 
418
- static VALUE MessagePack_unpack_limit(VALUE self, VALUE data, VALUE limit)
433
+ static inline VALUE MessagePack_unpack_impl(VALUE self, VALUE data, unsigned long dlen)
419
434
  {
420
- CHECK_STRING_TYPE(data);
421
-
422
435
  msgpack_unpack_t mp;
423
436
  template_init(&mp);
424
437
  init_stack(&mp);
425
438
  unpack_user u = {0, Qnil, 0, 0, Qnil, Qnil, Qnil};
426
439
  mp.user = u;
427
440
 
441
+ // FIXME execute実行中はmp->topが更新されないのでGC markが機能しない
428
442
  rb_gc_disable();
429
- VALUE args[3] = {(VALUE)&mp, data, limit};
430
- VALUE ret = rb_rescue(MessagePack_unpack_impl, (VALUE)args,
443
+ VALUE args[3] = {(VALUE)&mp, data, (VALUE)dlen};
444
+ VALUE ret = rb_rescue(MessagePack_unpack_do, (VALUE)args,
431
445
  MessagePack_unpack_rescue, Qnil);
432
446
  rb_gc_enable();
433
447
 
434
448
  return ret;
435
449
  }
436
450
 
451
+ static VALUE MessagePack_unpack_limit(VALUE self, VALUE data, VALUE limit)
452
+ {
453
+ CHECK_STRING_TYPE(data);
454
+ return MessagePack_unpack_impl(self, data, NUM2ULONG(limit));
455
+ }
456
+
437
457
  static VALUE MessagePack_unpack(VALUE self, VALUE data)
438
458
  {
439
- return MessagePack_unpack_limit(self, data,
440
- LONG2FIX(RSTRING_LEN(data)));
459
+ CHECK_STRING_TYPE(data);
460
+ return MessagePack_unpack_impl(self, data, RSTRING_LEN(data));
441
461
  }
442
462
 
443
463
 
@@ -1,3 +1,3 @@
1
1
  require 'test/unit'
2
- require File.dirname(__FILE__) + '/../ext/msgpack'
2
+ require File.dirname(__FILE__) + '/../lib/msgpack'
3
3
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: msgpack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - FURUHASHI Sadayuki
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-04-02 00:00:00 +09:00
12
+ date: 2010-04-06 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -48,7 +48,7 @@ post_install_message:
48
48
  rdoc_options: []
49
49
 
50
50
  require_paths:
51
- - ext
51
+ - lib
52
52
  required_ruby_version: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - ">="