diff --git a/ruby/makegem.sh b/ruby/makegem.sh index c78769bd..8737d299 100755 --- a/ruby/makegem.sh +++ b/ruby/makegem.sh @@ -19,6 +19,10 @@ cat msgpack_test.rb | sed "s/require ['\"]msgpack['\"]/require File.dirname(__FI gem build msgpack.gemspec +if [ $? -eq 0 ]; then + rm -rf ext msgpack AUTHORS ChangeLog test/msgpack_test.rb +fi + # gem install gem-compile # on msys # gem compile msgpack-$version.gem # on msys # gem compile msgpack-$version.gem -p mswin32 # on msys diff --git a/ruby/msgpack_test.rb b/ruby/msgpack_test.rb index 4fbcea35..37db6a0d 100644 --- a/ruby/msgpack_test.rb +++ b/ruby/msgpack_test.rb @@ -202,6 +202,21 @@ class MessagePackTestFormat < Test::Unit::TestCase # #check_map 5, (1<<32)-1 # memory error # end + it "gc mark" do + obj = [{["a","b"]=>["c","d"]}, ["e","f"], "d"] + pac = MessagePack::Unpacker.new + parsed = 0 + obj.to_msgpack.split(//).each do |b| + pac.feed(b) + pac.each {|o| + assert_equal(obj, o) + parsed += 1 + } + GC.start + end + assert_equal(parsed, 1) + end + private def check(len, obj) v = obj.to_msgpack diff --git a/ruby/unpack.c b/ruby/unpack.c index 88a82395..5f5b64b0 100644 --- a/ruby/unpack.c +++ b/ruby/unpack.c @@ -141,15 +141,6 @@ static inline int template_callback_raw(unpack_user* u, const char* b, const cha static VALUE cUnpacker; static VALUE eUnpackError; -// FIXME slow operation -static void init_stack(msgpack_unpack_t* mp) -{ - size_t i; - for(i=0; i < MSGPACK_MAX_STACK_SIZE; ++i) { - mp->stack[i].map_key = Qnil; /* GC */ - } -} - static void MessagePack_Unpacker_free(void* data) { if(data) { free(data); } @@ -163,7 +154,7 @@ static void MessagePack_Unpacker_mark(msgpack_unpack_t *mp) rb_gc_mark(mp->user.streambuf); for(i=0; i < mp->top; ++i) { rb_gc_mark(mp->stack[i].obj); - rb_gc_mark(mp->stack[i].map_key); /* maybe map_key is not initialized */ + rb_gc_mark_maybe(mp->stack[i].map_key); } } @@ -180,7 +171,6 @@ static VALUE MessagePack_Unpacker_reset(VALUE self) { UNPACKER(self, mp); template_init(mp); - init_stack(mp); mp->user.finished = 0; return self; } @@ -381,7 +371,6 @@ static VALUE MessagePack_Unpacker_each(VALUE self) } else if(ret > 0) { VALUE data = template_data(mp); template_init(mp); - init_stack(mp); rb_yield(data); } else { goto do_fill; @@ -434,7 +423,6 @@ static inline VALUE MessagePack_unpack_impl(VALUE self, VALUE data, unsigned lon { msgpack_unpack_t mp; template_init(&mp); - init_stack(&mp); unpack_user u = {0, Qnil, 0, 0, Qnil, Qnil, Qnil}; mp.user = u;