summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 955f6c5..66b7429 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 0000000..9b905d9
--- /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 0000000..299da27
--- /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 3b7f79d..8bc8019 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 0000000..e0e2a72
--- /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