mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-20 14:02:40 +02:00
ruby: remove init_stack, adopt rb_gc_mark_maybe
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
|
||||
|
Reference in New Issue
Block a user