summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-08 05:20:41 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-08 05:20:41 +0000
commit1fadd438811426523a79ccea93a45f0a202a50f6 (patch)
tree4b6ed75880270e5280b4f051d96945f48ea20e35
parent95184065445e2888a624911214db67fe3695ec85 (diff)
downloadruby-1fadd438811426523a79ccea93a45f0a202a50f6.tar.gz
marshal.c: skip internal names
* marshal.c (w_objivar): skip internal instance variables in T_OBJECT too. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52940 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--ext/-test-/marshal/internal_ivar/extconf.rb1
-rw-r--r--ext/-test-/marshal/internal_ivar/internal_ivar.c39
-rw-r--r--marshal.c11
-rw-r--r--test/-ext-/marshal/test_internal_ivar.rb19
5 files changed, 66 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 955f6c5245..66b7429542 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Dec 8 14:20:38 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * marshal.c (w_objivar): skip internal instance variables in
+ T_OBJECT too.
+
Tue Dec 8 12:58:04 2015 Naohisa Goto <ngotogenome@gmail.com>
* test/io/console/test_io_console.rb (test_getpass): s.getpass
diff --git a/ext/-test-/marshal/internal_ivar/extconf.rb b/ext/-test-/marshal/internal_ivar/extconf.rb
new file mode 100644
index 0000000000..9b905d91d7
--- /dev/null
+++ b/ext/-test-/marshal/internal_ivar/extconf.rb
@@ -0,0 +1 @@
+create_makefile("-test-/marshal/internal_ivar")
diff --git a/ext/-test-/marshal/internal_ivar/internal_ivar.c b/ext/-test-/marshal/internal_ivar/internal_ivar.c
new file mode 100644
index 0000000000..299da27f23
--- /dev/null
+++ b/ext/-test-/marshal/internal_ivar/internal_ivar.c
@@ -0,0 +1,39 @@
+#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);
+}
diff --git a/marshal.c b/marshal.c
index 3b7f79d614..8bc80194c0 100644
--- a/marshal.c
+++ b/marshal.c
@@ -637,16 +637,9 @@ w_ivar(st_index_t num, VALUE ivobj, VALUE encname, struct dump_call_arg *arg)
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);
diff --git a/test/-ext-/marshal/test_internal_ivar.rb b/test/-ext-/marshal/test_internal_ivar.rb
new file mode 100644
index 0000000000..e0e2a72f54
--- /dev/null
+++ b/test/-ext-/marshal/test_internal_ivar.rb
@@ -0,0 +1,19 @@
+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