From a14a1a5626a4d8e661a3e606f8f92b8c455b9a04 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Thu, 1 Dec 2022 17:26:45 +0900 Subject: [Feature #19163] Data object should be frozen --- struct.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'struct.c') diff --git a/struct.c b/struct.c index 6f67984cf2..def15b0186 100644 --- a/struct.c +++ b/struct.c @@ -1818,9 +1818,19 @@ rb_data_initialize_m(int argc, const VALUE *argv, VALUE self) if (arg.unknown_keywords != Qnil) { rb_exc_raise(rb_keyword_error_new("unknown", arg.unknown_keywords)); } + OBJ_FREEZE_RAW(self); return Qnil; } +/* :nodoc: */ +static VALUE +rb_data_init_copy(VALUE copy, VALUE s) +{ + copy = rb_struct_init_copy(copy, s); + RB_OBJ_FREEZE_RAW(copy); + return copy; +} + /* * call-seq: * inspect -> string @@ -2180,7 +2190,7 @@ InitVM_Struct(void) #endif rb_define_method(rb_cData, "initialize", rb_data_initialize_m, -1); - rb_define_method(rb_cData, "initialize_copy", rb_struct_init_copy, 1); + rb_define_method(rb_cData, "initialize_copy", rb_data_init_copy, 1); rb_define_method(rb_cData, "==", rb_data_equal, 1); rb_define_method(rb_cData, "eql?", rb_data_eql, 1); -- cgit v1.2.1