summaryrefslogtreecommitdiff
path: root/ruby
diff options
context:
space:
mode:
authorfrsyuki <frsyuki@users.sourceforge.jp>2010-04-17 20:02:47 +0900
committerfrsyuki <frsyuki@users.sourceforge.jp>2010-04-17 20:02:47 +0900
commit228f742b2f4bfba8bc97f16b3fb85ca616b07768 (patch)
tree96e665f17ca3a0724d4edb5c54327485d22b7924 /ruby
parenta55affe4d5bce92ee692fd80b10365b6ec49804c (diff)
downloadmsgpack-python-228f742b2f4bfba8bc97f16b3fb85ca616b07768.tar.gz
ruby: set encoding to 'ASCII-8BIT' before deserializing on ruby-1.9
Diffstat (limited to 'ruby')
-rw-r--r--ruby/unpack.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/ruby/unpack.c b/ruby/unpack.c
index 5f5b64b..11572c3 100644
--- a/ruby/unpack.c
+++ b/ruby/unpack.c
@@ -16,11 +16,17 @@
* limitations under the License.
*/
#include "ruby.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
+
typedef struct {
int finished;
VALUE source;
@@ -426,6 +432,12 @@ static inline VALUE MessagePack_unpack_impl(VALUE self, VALUE data, unsigned lon
unpack_user u = {0, Qnil, 0, 0, Qnil, Qnil, Qnil};
mp.user = u;
+#ifdef HAVE_RUBY_ENCODING_H
+ // FIXME encodingをASCII-8BITにする
+ int enc_orig = rb_enc_get_index(data);
+ rb_enc_set_index(data, s_ascii_8bit);
+#endif
+
// FIXME execute実行中はmp->topが更新されないのでGC markが機能しない
rb_gc_disable();
VALUE args[3] = {(VALUE)&mp, data, (VALUE)dlen};
@@ -433,6 +445,10 @@ static inline VALUE MessagePack_unpack_impl(VALUE self, VALUE data, unsigned lon
MessagePack_unpack_rescue, Qnil);
rb_gc_enable();
+#ifdef HAVE_RUBY_ENCODING_H
+ rb_enc_set_index(data, enc_orig);
+#endif
+
return ret;
}
@@ -453,6 +469,11 @@ 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);