ruby-changes:40861
From: nobu <ko1@a...>
Date: Tue, 8 Dec 2015 14:20:53 +0900 (JST)
Subject: [ruby-changes:40861] nobu:r52940 (trunk): marshal.c: skip internal names
nobu 2015-12-08 14:20:41 +0900 (Tue, 08 Dec 2015) New Revision: 52940 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52940 Log: marshal.c: skip internal names * marshal.c (w_objivar): skip internal instance variables in T_OBJECT too. Added directories: trunk/ext/-test-/marshal/internal_ivar/ Added files: trunk/ext/-test-/marshal/internal_ivar/extconf.rb trunk/ext/-test-/marshal/internal_ivar/internal_ivar.c trunk/test/-ext-/marshal/test_internal_ivar.rb Modified files: trunk/ChangeLog trunk/marshal.c Index: ChangeLog =================================================================== --- ChangeLog (revision 52939) +++ ChangeLog (revision 52940) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Dec 8 14:20:38 2015 Nobuyoshi Nakada <nobu@r...> + + * marshal.c (w_objivar): skip internal instance variables in + T_OBJECT too. + Tue Dec 8 12:58:04 2015 Naohisa Goto <ngotogenome@g...> * test/io/console/test_io_console.rb (test_getpass): s.getpass Index: ext/-test-/marshal/internal_ivar/extconf.rb =================================================================== --- ext/-test-/marshal/internal_ivar/extconf.rb (revision 0) +++ ext/-test-/marshal/internal_ivar/extconf.rb (revision 52940) @@ -0,0 +1 @@ +create_makefile("-test-/marshal/internal_ivar") Property changes on: ext/-test-/marshal/internal_ivar/extconf.rb ___________________________________________________________________ Added: svn:eol-style + LF Index: ext/-test-/marshal/internal_ivar/internal_ivar.c =================================================================== --- ext/-test-/marshal/internal_ivar/internal_ivar.c (revision 0) +++ ext/-test-/marshal/internal_ivar/internal_ivar.c (revision 52940) @@ -0,0 +1,39 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/marshal/internal_ivar/internal_ivar.c#L1 +#include <ruby.h> + +static ID id_normal_ivar, id_internal_ivar; + +static VALUE +init(VALUE self, VALUE arg1, VALUE arg2) +{ + rb_ivar_set(self, id_normal_ivar, arg1); + rb_ivar_set(self, id_internal_ivar, arg2); + return self; +} + +static VALUE +get_normal(VALUE self) +{ + return rb_attr_get(self, id_normal_ivar); +} + +static VALUE +get_internal(VALUE self) +{ + return rb_attr_get(self, id_internal_ivar); +} + +void +Init_internal_ivar(void) +{ + VALUE mMarshal = rb_define_module_under(rb_define_module("Bug"), "Marshal"); + VALUE newclass = rb_define_class_under(mMarshal, "InternalIVar", rb_cObject); + + id_normal_ivar = rb_intern_const("normal"); +#if 0 + /* leave id_internal_ivar being 0 */ + id_internal_ivar = rb_make_internal_id(); +#endif + rb_define_method(newclass, "initialize", init, 2); + rb_define_method(newclass, "normal", get_normal, 0); + rb_define_method(newclass, "internal", get_internal, 0); +} Property changes on: ext/-test-/marshal/internal_ivar/internal_ivar.c ___________________________________________________________________ Added: svn:eol-style + LF Index: marshal.c =================================================================== --- marshal.c (revision 52939) +++ marshal.c (revision 52940) @@ -637,16 +637,9 @@ w_ivar(st_index_t num, VALUE ivobj, VALU https://github.com/ruby/ruby/blob/trunk/marshal.c#L637 static void w_objivar(VALUE obj, struct dump_call_arg *arg) { - VALUE *ptr; - long i, len, num; - - len = ROBJECT_NUMIV(obj); - ptr = ROBJECT_IVPTR(obj); - num = 0; - for (i = 0; i < len; i++) - if (ptr[i] != Qundef) - num += 1; + st_data_t num = 0; + rb_ivar_foreach(obj, obj_count_ivars, (st_data_t)&num); w_long(num, arg->arg); if (num != 0) { rb_ivar_foreach(obj, w_obj_each, (st_data_t)arg); Index: test/-ext-/marshal/test_internal_ivar.rb =================================================================== --- test/-ext-/marshal/test_internal_ivar.rb (revision 0) +++ test/-ext-/marshal/test_internal_ivar.rb (revision 52940) @@ -0,0 +1,19 @@ https://github.com/ruby/ruby/blob/trunk/test/-ext-/marshal/test_internal_ivar.rb#L1 +require 'test/unit' +require '-test-/marshal/internal_ivar' + +module Bug end + +module Bug::Marshal + class TestInternalIVar < Test::Unit::TestCase + def test_marshal + v = InternalIVar.new("hello", "world") + assert_equal("hello", v.normal) + assert_equal("world", v.internal) + dump = ::Marshal.dump(v) + v = assert_nothing_raised {break ::Marshal.load(dump)} + assert_instance_of(InternalIVar, v) + assert_equal("hello", v.normal) + assert_nil(v.internal) + end + end +end Property changes on: test/-ext-/marshal/test_internal_ivar.rb ___________________________________________________________________ Added: svn:eol-style + LF -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/