Project

General

Profile

Bug #16138 ยป ruby_2_5.patch

Patch for Ruby 2.5 - prajjwal (Prajjwal Singh), 09/04/2019 09:19 AM

View differences:

struct.c
517 517
static VALUE
518 518
rb_struct_s_def(int argc, VALUE *argv, VALUE klass)
519 519
{
520
    VALUE name, rest, keyword_init;
520
    VALUE name, rest, keyword_init = Qfalse;
521 521
    long i;
522 522
    VALUE st;
523 523
    st_table *tbl;
......
533 533
    }
534 534

  
535 535
    if (RB_TYPE_P(argv[argc-1], T_HASH)) {
536
	VALUE kwargs[1];
537 536
	static ID keyword_ids[1];
538 537

  
539 538
	if (!keyword_ids[0]) {
540 539
	    keyword_ids[0] = rb_intern("keyword_init");
541 540
	}
542
	rb_get_kwargs(argv[argc-1], keyword_ids, 0, 1, kwargs);
541

  
542
	rb_get_kwargs(argv[argc-1], keyword_ids, 0, 1, &keyword_init);
543
	if (keyword_init == Qundef) {
544
		keyword_init = Qfalse;
545
	}
546

  
543 547
	--argc;
544
	keyword_init = kwargs[0];
545
    }
546
    else {
547
	keyword_init = Qfalse;
548 548
    }
549 549

  
550 550
    rest = rb_ident_hash_new();
test/ruby/test_struct.rb
92 92
    assert_equal([:utime, :stime, :cutime, :cstime], Process.times.members)
93 93
  end
94 94

  
95
  def test_struct_new_with_empty_hash
96
    assert_equal({:a=>1}, Struct.new(:a, {}).new({:a=>1}).a)
97
  end
98

  
95 99
  def test_struct_new_with_keyword_init
96 100
    @Struct.new("KeywordInitTrue", :a, :b, keyword_init: true)
97 101
    @Struct.new("KeywordInitFalse", :a, :b, keyword_init: false)