mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-20 22:31:33 +02:00
ruby: set mp->user.source = Qnil before tempalte_execute_do on Unpacker#each
This commit is contained in:
@@ -156,15 +156,25 @@ static inline int template_callback_raw(unpack_user* u, const char* b, const cha
|
|||||||
rb_raise(rb_eTypeError, "instance of String needed"); \
|
rb_raise(rb_eTypeError, "instance of String needed"); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef RUBY_VM
|
||||||
|
#define RERAISE rb_exc_raise(rb_errinfo())
|
||||||
|
#else
|
||||||
|
#define RERAISE rb_exc_raise(ruby_errinfo)
|
||||||
|
#endif
|
||||||
|
|
||||||
static VALUE template_execute_rescue(VALUE nouse)
|
|
||||||
|
static VALUE template_execute_rescue(VALUE data)
|
||||||
{
|
{
|
||||||
rb_gc_enable();
|
rb_gc_enable();
|
||||||
#ifdef RUBY_VM
|
VALUE* resc = (VALUE*)data;
|
||||||
rb_exc_raise(rb_errinfo());
|
rb_enc_set_index(resc[0], (int)resc[1]);
|
||||||
#else
|
RERAISE;
|
||||||
rb_exc_raise(ruby_errinfo);
|
}
|
||||||
#endif
|
|
||||||
|
static VALUE template_execute_rescue_each(VALUE nouse)
|
||||||
|
{
|
||||||
|
rb_gc_enable();
|
||||||
|
RERAISE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE template_execute_do(VALUE argv)
|
static VALUE template_execute_do(VALUE argv)
|
||||||
@@ -192,7 +202,6 @@ static int template_execute_wrap(msgpack_unpack_t* mp,
|
|||||||
};
|
};
|
||||||
|
|
||||||
#ifdef HAVE_RUBY_ENCODING_H
|
#ifdef HAVE_RUBY_ENCODING_H
|
||||||
// FIXME encodingをASCII-8BITにする
|
|
||||||
int enc_orig = rb_enc_get_index(str);
|
int enc_orig = rb_enc_get_index(str);
|
||||||
rb_enc_set_index(str, s_ascii_8bit);
|
rb_enc_set_index(str, s_ascii_8bit);
|
||||||
#endif
|
#endif
|
||||||
@@ -202,10 +211,10 @@ static int template_execute_wrap(msgpack_unpack_t* mp,
|
|||||||
|
|
||||||
mp->user.source = str;
|
mp->user.source = str;
|
||||||
|
|
||||||
int ret = (int)rb_rescue(template_execute_do, (VALUE)args,
|
VALUE resc[2] = {str, enc_orig};
|
||||||
template_execute_rescue, Qnil);
|
|
||||||
|
|
||||||
mp->user.source = Qnil;
|
int ret = (int)rb_rescue(template_execute_do, (VALUE)args,
|
||||||
|
template_execute_rescue, (VALUE)resc);
|
||||||
|
|
||||||
rb_gc_enable();
|
rb_gc_enable();
|
||||||
|
|
||||||
@@ -229,8 +238,10 @@ static int template_execute_wrap_each(msgpack_unpack_t* mp,
|
|||||||
// FIXME execute実行中はmp->topが更新されないのでGC markが機能しない
|
// FIXME execute実行中はmp->topが更新されないのでGC markが機能しない
|
||||||
rb_gc_disable();
|
rb_gc_disable();
|
||||||
|
|
||||||
|
mp->user.source = Qnil;
|
||||||
|
|
||||||
int ret = (int)rb_rescue(template_execute_do, (VALUE)args,
|
int ret = (int)rb_rescue(template_execute_do, (VALUE)args,
|
||||||
template_execute_rescue, Qnil);
|
template_execute_rescue_each, Qnil);
|
||||||
|
|
||||||
rb_gc_enable();
|
rb_gc_enable();
|
||||||
|
|
||||||
@@ -401,8 +412,7 @@ static void feed_buffer(msgpack_unpack_t* mp, const char* ptr, size_t len)
|
|||||||
struct unpack_buffer* buffer = &mp->user.buffer;
|
struct unpack_buffer* buffer = &mp->user.buffer;
|
||||||
|
|
||||||
if(buffer->size == 0) {
|
if(buffer->size == 0) {
|
||||||
char* tmp = (char*)malloc(MSGPACK_UNPACKER_BUFFER_INIT_SIZE);
|
char* tmp = ALLOC_N(char, MSGPACK_UNPACKER_BUFFER_INIT_SIZE);
|
||||||
// FIXME check tmp == NULL
|
|
||||||
buffer->ptr = tmp;
|
buffer->ptr = tmp;
|
||||||
buffer->free = MSGPACK_UNPACKER_BUFFER_INIT_SIZE;
|
buffer->free = MSGPACK_UNPACKER_BUFFER_INIT_SIZE;
|
||||||
buffer->size = 0;
|
buffer->size = 0;
|
||||||
@@ -430,8 +440,7 @@ static void feed_buffer(msgpack_unpack_t* mp, const char* ptr, size_t len)
|
|||||||
while(csize < buffer->size + len) {
|
while(csize < buffer->size + len) {
|
||||||
csize *= 2;
|
csize *= 2;
|
||||||
}
|
}
|
||||||
char* tmp = (char*)realloc(buffer->ptr, csize);
|
char* tmp = REALLOC_N(buffer->ptr, char, csize);
|
||||||
// FIXME check tmp == NULL
|
|
||||||
memcpy(tmp + buffer->size, ptr, len);
|
memcpy(tmp + buffer->size, ptr, len);
|
||||||
buffer->ptr = tmp;
|
buffer->ptr = tmp;
|
||||||
buffer->free = csize - buffer->size;
|
buffer->free = csize - buffer->size;
|
||||||
@@ -446,8 +455,7 @@ static void feed_buffer(msgpack_unpack_t* mp, const char* ptr, size_t len)
|
|||||||
while(csize < not_parsed + len) {
|
while(csize < not_parsed + len) {
|
||||||
csize *= 2;
|
csize *= 2;
|
||||||
}
|
}
|
||||||
char* tmp = (char*)realloc(buffer->ptr, csize);
|
char* tmp = REALLOC_N(buffer->ptr, char, csize);
|
||||||
// FIXME check tmp == NULL
|
|
||||||
buffer->ptr = tmp;
|
buffer->ptr = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user