зеркало из https://github.com/github/ruby.git
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
This commit is contained in:
Родитель
9518406544
Коммит
1fadd43881
|
@ -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
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
create_makefile("-test-/marshal/internal_ivar")
|
|
@ -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);
|
||||
}
|
11
marshal.c
11
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);
|
||||
|
|
|
@ -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
|
Загрузка…
Ссылка в новой задаче