mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-03-19 13:02:13 +01:00
Ruby binding: add MessagePack::unpack_limit, MessagePack::Unpacker#execute_limit
git-svn-id: file:///Users/frsyuki/project/msgpack-git/svn/x@96 5a5092ae-2292-43ba-b2d5-dcab9c1a2731
This commit is contained in:
parent
e893dde57e
commit
2c7cdd5f40
@ -1,5 +1,5 @@
|
|||||||
AC_INIT(msgpack/unpack_template.h)
|
AC_INIT(msgpack/unpack_template.h)
|
||||||
AM_INIT_AUTOMAKE(msgpack, 0.2.2)
|
AM_INIT_AUTOMAKE(msgpack, 0.3.0)
|
||||||
AC_CONFIG_HEADER(config.h)
|
AC_CONFIG_HEADER(config.h)
|
||||||
|
|
||||||
AC_PROG_LIBTOOL
|
AC_PROG_LIBTOOL
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
module MessagePack
|
module MessagePack
|
||||||
module VERSION #:nodoc:
|
module VERSION #:nodoc:
|
||||||
MAJOR = 0
|
MAJOR = 0
|
||||||
MINOR = 2
|
MINOR = 3
|
||||||
TINY = 2
|
TINY = 0
|
||||||
|
|
||||||
STRING = [MAJOR, MINOR, TINY].join('.')
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
||||||
end
|
end
|
||||||
|
@ -169,12 +169,11 @@ static VALUE MessagePack_Unpacker_execute_impl(VALUE args)
|
|||||||
{
|
{
|
||||||
VALUE self = ((VALUE*)args)[0];
|
VALUE self = ((VALUE*)args)[0];
|
||||||
VALUE data = ((VALUE*)args)[1];
|
VALUE data = ((VALUE*)args)[1];
|
||||||
VALUE off = ((VALUE*)args)[2];
|
|
||||||
|
|
||||||
UNPACKER(self, mp);
|
UNPACKER(self, mp);
|
||||||
size_t from = NUM2UINT(off);
|
size_t from = NUM2UINT(((VALUE*)args)[2]);
|
||||||
char* dptr = RSTRING_PTR(data);
|
char* dptr = RSTRING_PTR(data);
|
||||||
long dlen = RSTRING_LEN(data);
|
long dlen = FIX2LONG(((VALUE*)args)[3]);
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if(from >= dlen) {
|
if(from >= dlen) {
|
||||||
@ -206,17 +205,24 @@ static VALUE MessagePack_Unpacker_execute_rescue(VALUE nouse)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE MessagePack_Unpacker_execute(VALUE self, VALUE data, VALUE off)
|
static VALUE MessagePack_Unpacker_execute_limit(VALUE self, VALUE data,
|
||||||
|
VALUE off, VALUE limit)
|
||||||
{
|
{
|
||||||
// FIXME execute実行中はmp->topが更新されないのでGC markが機能しない
|
// FIXME execute実行中はmp->topが更新されないのでGC markが機能しない
|
||||||
rb_gc_disable();
|
rb_gc_disable();
|
||||||
VALUE args[3] = {self, data, off};
|
VALUE args[4] = {self, data, off, limit};
|
||||||
VALUE ret = rb_rescue(MessagePack_Unpacker_execute_impl, (VALUE)args,
|
VALUE ret = rb_rescue(MessagePack_Unpacker_execute_impl, (VALUE)args,
|
||||||
MessagePack_Unpacker_execute_rescue, Qnil);
|
MessagePack_Unpacker_execute_rescue, Qnil);
|
||||||
rb_gc_enable();
|
rb_gc_enable();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE MessagePack_Unpacker_execute(VALUE self, VALUE data, VALUE off)
|
||||||
|
{
|
||||||
|
return MessagePack_Unpacker_execute_limit(self, data, off,
|
||||||
|
LONG2FIX(RSTRING_LEN(data)));
|
||||||
|
}
|
||||||
|
|
||||||
static VALUE MessagePack_Unpacker_finished_p(VALUE self)
|
static VALUE MessagePack_Unpacker_finished_p(VALUE self)
|
||||||
{
|
{
|
||||||
UNPACKER(self, mp);
|
UNPACKER(self, mp);
|
||||||
@ -240,7 +246,7 @@ static VALUE MessagePack_unpack_impl(VALUE args)
|
|||||||
|
|
||||||
size_t from = 0;
|
size_t from = 0;
|
||||||
char* dptr = RSTRING_PTR(data);
|
char* dptr = RSTRING_PTR(data);
|
||||||
long dlen = RSTRING_LEN(data);
|
long dlen = FIX2LONG(((VALUE*)args)[2]);
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
mp->user.origstr = data;
|
mp->user.origstr = data;
|
||||||
@ -269,7 +275,7 @@ static VALUE MessagePack_unpack_rescue(VALUE args)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE MessagePack_unpack(VALUE self, VALUE data)
|
static VALUE MessagePack_unpack_limit(VALUE self, VALUE data, VALUE limit)
|
||||||
{
|
{
|
||||||
CHECK_STRING_TYPE(data);
|
CHECK_STRING_TYPE(data);
|
||||||
msgpack_unpacker mp;
|
msgpack_unpacker mp;
|
||||||
@ -278,13 +284,19 @@ static VALUE MessagePack_unpack(VALUE self, VALUE data)
|
|||||||
mp.user = ctx;
|
mp.user = ctx;
|
||||||
|
|
||||||
rb_gc_disable();
|
rb_gc_disable();
|
||||||
VALUE args[2] = {(VALUE)&mp, data};
|
VALUE args[3] = {(VALUE)&mp, data, limit};
|
||||||
VALUE ret = rb_rescue(MessagePack_unpack_impl, (VALUE)args,
|
VALUE ret = rb_rescue(MessagePack_unpack_impl, (VALUE)args,
|
||||||
MessagePack_unpack_rescue, Qnil);
|
MessagePack_unpack_rescue, Qnil);
|
||||||
rb_gc_enable();
|
rb_gc_enable();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE MessagePack_unpack(VALUE self, VALUE data)
|
||||||
|
{
|
||||||
|
return MessagePack_unpack_limit(self, data,
|
||||||
|
LONG2FIX(RSTRING_LEN(data)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Init_msgpack_unpack(VALUE mMessagePack)
|
void Init_msgpack_unpack(VALUE mMessagePack)
|
||||||
{
|
{
|
||||||
@ -293,10 +305,12 @@ void Init_msgpack_unpack(VALUE mMessagePack)
|
|||||||
rb_define_alloc_func(cUnpacker, MessagePack_Unpacker_alloc);
|
rb_define_alloc_func(cUnpacker, MessagePack_Unpacker_alloc);
|
||||||
rb_define_method(cUnpacker, "initialize", MessagePack_Unpacker_initialize, 0);
|
rb_define_method(cUnpacker, "initialize", MessagePack_Unpacker_initialize, 0);
|
||||||
rb_define_method(cUnpacker, "execute", MessagePack_Unpacker_execute, 2);
|
rb_define_method(cUnpacker, "execute", MessagePack_Unpacker_execute, 2);
|
||||||
|
rb_define_method(cUnpacker, "execute_limit", MessagePack_Unpacker_execute_limit, 3);
|
||||||
rb_define_method(cUnpacker, "finished?", MessagePack_Unpacker_finished_p, 0);
|
rb_define_method(cUnpacker, "finished?", MessagePack_Unpacker_finished_p, 0);
|
||||||
rb_define_method(cUnpacker, "data", MessagePack_Unpacker_data, 0);
|
rb_define_method(cUnpacker, "data", MessagePack_Unpacker_data, 0);
|
||||||
rb_define_method(cUnpacker, "reset", MessagePack_Unpacker_reset, 0);
|
rb_define_method(cUnpacker, "reset", MessagePack_Unpacker_reset, 0);
|
||||||
rb_define_module_function(mMessagePack, "unpack", MessagePack_unpack, 1);
|
rb_define_module_function(mMessagePack, "unpack", MessagePack_unpack, 1);
|
||||||
|
rb_define_module_function(mMessagePack, "unpack_limit", MessagePack_unpack_limit, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user