Merge pull request #2 from cremno/mri-marshal-utf8proc

MRI binding: changes to Marshal::load mkxp's custom proc
This commit is contained in:
Jonas Kulla 2013-10-22 20:29:51 -07:00
commit 655707b2e4
1 changed files with 15 additions and 8 deletions

View File

@ -159,14 +159,20 @@ RB_METHOD(kernelSaveData)
static VALUE stringForceUTF8(VALUE arg)
{
if (rb_type(arg) != RUBY_T_STRING)
return arg;
rb_enc_associate(arg, rb_utf8_encoding());
if (rb_type(arg) == RUBY_T_STRING && ENCODING_IS_ASCII8BIT(arg))
rb_enc_associate_index(arg, rb_utf8_encindex());
return arg;
}
static VALUE customProc(VALUE arg, VALUE proc)
{
VALUE obj = stringForceUTF8(arg);
obj = rb_funcall2(proc, rb_intern("call"), 1, &obj);
return obj;
}
RB_METHOD(_marshalLoad)
{
RB_UNUSED_PARAM;
@ -175,10 +181,11 @@ RB_METHOD(_marshalLoad)
rb_get_args(argc, argv, "o|o", &port, &proc, RB_ARG_END);
if (rb_type(proc) != RUBY_T_NIL)
rb_raise(rb_eNotImpError, "MKXP: Marshal with custom proc not (yet) implemented");
VALUE utf8Proc = rb_proc_new(RUBY_METHOD_FUNC(stringForceUTF8), Qnil);
VALUE utf8Proc;
if (NIL_P(proc))
utf8Proc = rb_proc_new(RUBY_METHOD_FUNC(stringForceUTF8), Qnil);
else
utf8Proc = rb_proc_new(RUBY_METHOD_FUNC(customProc), proc);
VALUE marsh = rb_const_get(rb_cObject, rb_intern("Marshal"));