merge revision(s) 52856,52906: [Backport #11760]

* encoding.c (enc_m_loader): defer finding encoding object not to
	  be infected by marshal source.  [ruby-core:71793] [Bug #11760]

	* marshal.c (r_object0): enable compatible loader on USERDEF
	  class.  the loader function is called with the class itself,
	  instead of an allocated object, and the loaded data.

	* marshal.c (compat_allocator_table): intialize
	  compat_allocator_tbl on demand.

	* object.c (rb_undefined_alloc): extract from rb_obj_alloc.

	* marshal.c (compat_allocator_table): initialize


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@52974 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagachika 2015-12-08 16:44:45 +00:00
parent 4cd4556f95
commit bd4364acb1
7 changed files with 60 additions and 6 deletions

View file

@ -1214,6 +1214,14 @@ enc_compatible_p(VALUE klass, VALUE str1, VALUE str2)
return rb_enc_from_encoding(enc);
}
/* :nodoc: */
static VALUE
enc_s_alloc(VALUE klass)
{
rb_undefined_alloc(klass);
return Qnil;
}
/* :nodoc: */
static VALUE
enc_dump(int argc, VALUE *argv, VALUE self)
@ -1225,6 +1233,13 @@ enc_dump(int argc, VALUE *argv, VALUE self)
/* :nodoc: */
static VALUE
enc_load(VALUE klass, VALUE str)
{
return str;
}
/* :nodoc: */
static VALUE
enc_m_loader(VALUE klass, VALUE str)
{
return enc_find(klass, str);
}
@ -1879,7 +1894,7 @@ Init_Encoding(void)
int i;
rb_cEncoding = rb_define_class("Encoding", rb_cObject);
rb_undef_alloc_func(rb_cEncoding);
rb_define_alloc_func(rb_cEncoding, enc_s_alloc);
rb_undef_method(CLASS_OF(rb_cEncoding), "new");
rb_define_method(rb_cEncoding, "to_s", enc_name, 0);
rb_define_method(rb_cEncoding, "inspect", enc_inspect, 0);
@ -1911,6 +1926,8 @@ Init_Encoding(void)
for (i = 0; i < enc_table.count; ++i) {
rb_ary_push(list, enc_new(enc_table.list[i].enc));
}
rb_marshal_define_compat(rb_cEncoding, Qnil, NULL, enc_m_loader);
}
/* locale insensitive ctype functions */