Project

General

Profile

Feature #16175 ยป freeze-true.patch

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

View differences:

object.c
428 428
    if (!NIL_P(opt)) {
429 429
	rb_get_kwargs(opt, keyword_ids, 0, 1, &kwfreeze);
430 430
	if (kwfreeze == Qfalse) return FALSE;
431
	if (kwfreeze != Qundef && kwfreeze != Qtrue) {
431
        if (kwfreeze == Qtrue) return TRUE;
432
	if (kwfreeze != Qundef) {
432 433
	    rb_raise(rb_eArgError, "unexpected value for freeze: %"PRIsVALUE,
433 434
		     rb_obj_class(kwfreeze));
434 435
	}
435 436
    }
436
    return TRUE;
437
    return -1; // neither true nor false
437 438
}
438 439

  
439 440
static VALUE
......
461 462
    init_copy(clone, obj);
462 463
    rb_funcall(clone, id_init_clone, 1, obj);
463 464

  
464
    if (kwfreeze) {
465
    if (kwfreeze == TRUE) {
466
        // true: always freeze
467
        RBASIC(clone)->flags |= FL_FREEZE;
468
    } else if (kwfreeze == FALSE) {
469
        // false: don't copy frozen flag = always unfreeze
470
    } else {
471
        // not set: copy frozen flag without changing it
465 472
	RBASIC(clone)->flags |= RBASIC(obj)->flags & FL_FREEZE;
466 473
    }
467 474

  
test/ruby/test_object.rb
59 59
    assert_equal(2, d.b)
60 60
    assert_equal(3, d.e)
61 61

  
62
    e = d.clone(freeze: true)
63
    assert_equal(true, e.frozen?)
64

  
62 65
    assert_equal 1, 1.clone
63 66
    assert_equal true, true.clone
64 67
    assert_equal nil, nil.clone