Project

General

Profile

Feature #16175 » freeze-true.patch

zverok (Victor Shepelev), 09/22/2019 09:59 AM

View differences:

object.c
if (!NIL_P(opt)) {
rb_get_kwargs(opt, keyword_ids, 0, 1, &kwfreeze);
if (kwfreeze == Qfalse) return FALSE;
if (kwfreeze != Qundef && kwfreeze != Qtrue) {
if (kwfreeze == Qtrue) return TRUE;
if (kwfreeze != Qundef) {
rb_raise(rb_eArgError, "unexpected value for freeze: %"PRIsVALUE,
rb_obj_class(kwfreeze));
}
}
return TRUE;
return -1; // neither true nor false
}
static VALUE
......
init_copy(clone, obj);
rb_funcall(clone, id_init_clone, 1, obj);
if (kwfreeze) {
if (kwfreeze == TRUE) {
// true: always freeze
RBASIC(clone)->flags |= FL_FREEZE;
} else if (kwfreeze == FALSE) {
// false: don't copy frozen flag = always unfreeze
} else {
// not set: copy frozen flag without changing it
RBASIC(clone)->flags |= RBASIC(obj)->flags & FL_FREEZE;
}
test/ruby/test_object.rb
assert_equal(2, d.b)
assert_equal(3, d.e)
e = d.clone(freeze: true)
assert_equal(true, e.frozen?)
assert_equal 1, 1.clone
assert_equal true, true.clone
assert_equal nil, nil.clone
(1-1/2)