mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-20 14:02:40 +02:00
ruby: converts encodings into UTF-8 on Ruby 1.9
This commit is contained in:
@@ -16,17 +16,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "ruby.h"
|
||||
#include "encoding.h"
|
||||
|
||||
#include "msgpack/unpack_define.h"
|
||||
|
||||
static ID s_sysread;
|
||||
static ID s_readpartial;
|
||||
|
||||
#ifdef HAVE_RUBY_ENCODING_H
|
||||
#include "ruby/encoding.h"
|
||||
int s_ascii_8bit;
|
||||
#endif
|
||||
|
||||
struct unpack_buffer {
|
||||
size_t size;
|
||||
size_t free;
|
||||
@@ -136,6 +132,9 @@ static inline int template_callback_raw(unpack_user* u, const char* b, const cha
|
||||
} else {
|
||||
*o = rb_str_substr(u->source, p - b, l);
|
||||
}
|
||||
#ifdef MSGPACK_RUBY_ENCODING
|
||||
ENCODING_SET(*o, s_enc_utf8);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -163,16 +162,6 @@ static inline int template_callback_raw(unpack_user* u, const char* b, const cha
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_RUBY_ENCODING_H
|
||||
static VALUE template_execute_rescue_enc(VALUE data)
|
||||
{
|
||||
rb_gc_enable();
|
||||
VALUE* resc = (VALUE*)data;
|
||||
rb_enc_set_index(resc[0], (int)resc[1]);
|
||||
RERAISE;
|
||||
}
|
||||
#endif
|
||||
|
||||
static VALUE template_execute_rescue(VALUE nouse)
|
||||
{
|
||||
rb_gc_enable();
|
||||
@@ -203,31 +192,16 @@ static int template_execute_wrap(msgpack_unpack_t* mp,
|
||||
(VALUE)from,
|
||||
};
|
||||
|
||||
#ifdef HAVE_RUBY_ENCODING_H
|
||||
int enc_orig = rb_enc_get_index(str);
|
||||
rb_enc_set_index(str, s_ascii_8bit);
|
||||
#endif
|
||||
|
||||
// FIXME execute実行中はmp->topが更新されないのでGC markが機能しない
|
||||
rb_gc_disable();
|
||||
|
||||
mp->user.source = str;
|
||||
|
||||
#ifdef HAVE_RUBY_ENCODING_H
|
||||
VALUE resc[2] = {str, enc_orig};
|
||||
int ret = (int)rb_rescue(template_execute_do, (VALUE)args,
|
||||
template_execute_rescue_enc, (VALUE)resc);
|
||||
#else
|
||||
int ret = (int)rb_rescue(template_execute_do, (VALUE)args,
|
||||
template_execute_rescue, Qnil);
|
||||
#endif
|
||||
|
||||
rb_gc_enable();
|
||||
|
||||
#ifdef HAVE_RUBY_ENCODING_H
|
||||
rb_enc_set_index(str, enc_orig);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -746,10 +720,6 @@ void Init_msgpack_unpack(VALUE mMessagePack)
|
||||
s_sysread = rb_intern("sysread");
|
||||
s_readpartial = rb_intern("readpartial");
|
||||
|
||||
#ifdef HAVE_RUBY_ENCODING_H
|
||||
s_ascii_8bit = rb_enc_find_index("ASCII-8BIT");
|
||||
#endif
|
||||
|
||||
eUnpackError = rb_define_class_under(mMessagePack, "UnpackError", rb_eStandardError);
|
||||
cUnpacker = rb_define_class_under(mMessagePack, "Unpacker", rb_cObject);
|
||||
rb_define_alloc_func(cUnpacker, MessagePack_Unpacker_alloc);
|
||||
|
Reference in New Issue
Block a user