Project

General

Profile

Bug #15885 » 0001-Single-raise-tracepoint-event-when-exception-inside-.patch

deivid (David Rodríguez), 05/29/2019 10:28 AM

View differences:

eval_intern.h
294 294
NORETURN(void rb_print_undef_str(VALUE, VALUE));
295 295
NORETURN(void rb_print_inaccessible(VALUE, ID, rb_method_visibility_t));
296 296
NORETURN(void rb_vm_localjump_error(const char *,VALUE, int));
297
#if 0
298 297
NORETURN(void rb_vm_jump_tag_but_local_jump(int));
299
#endif
300 298

  
301 299
VALUE rb_vm_make_jump_tag_but_local_jump(int state, VALUE val);
302 300
rb_cref_t *rb_vm_cref(void);
load.c
568 568

  
569 569
NORETURN(static void load_failed(VALUE));
570 570

  
571
static int
571
static inline void
572 572
rb_load_internal0(rb_execution_context_t *ec, VALUE fname, int wrap)
573 573
{
574 574
    enum ruby_tag_type state;
......
621 621
    th->top_wrapper = wrapper;
622 622

  
623 623
    if (state) {
624
	/* usually state == TAG_RAISE only, except for
625
	 * rb_iseq_load_iseq case */
626
	VALUE exc = rb_vm_make_jump_tag_but_local_jump(state, Qundef);
627
	if (NIL_P(exc)) return state;
628
	th->ec->errinfo = exc;
629
	return TAG_RAISE;
624
        rb_vm_jump_tag_but_local_jump(state);
630 625
    }
631 626

  
632 627
    if (!NIL_P(th->ec->errinfo)) {
633
	/* exception during load */
634
	return TAG_RAISE;
628
        rb_exc_raise(th->ec->errinfo);
635 629
    }
636
    return state;
637 630
}
638 631

  
639 632
static void
640 633
rb_load_internal(VALUE fname, int wrap)
641 634
{
642 635
    rb_execution_context_t *ec = GET_EC();
643
    int state = rb_load_internal0(ec, fname, wrap);
644
    if (state) {
645
	if (state == TAG_RAISE) rb_exc_raise(ec->errinfo);
646
	EC_JUMP_TAG(ec, state);
647
    }
648
}
649

  
650
static VALUE
651
file_to_load(VALUE fname)
652
{
653
    VALUE tmp = rb_find_file(FilePathValue(fname));
654
    if (!tmp) load_failed(fname);
655
    return tmp;
636
    rb_load_internal0(ec, fname, wrap);
656 637
}
657 638

  
658 639
void
659 640
rb_load(VALUE fname, int wrap)
660 641
{
661
    rb_load_internal(file_to_load(fname), wrap);
642
    VALUE tmp = rb_find_file(FilePathValue(fname));
643
    if (!tmp) load_failed(fname);
644
    rb_load_internal(tmp, wrap);
662 645
}
663 646

  
664 647
void
665 648
rb_load_protect(VALUE fname, int wrap, int *pstate)
666 649
{
667 650
    enum ruby_tag_type state;
668
    volatile VALUE path = 0;
669 651

  
670 652
    EC_PUSH_TAG(GET_EC());
671 653
    if ((state = EC_EXEC_TAG()) == TAG_NONE) {
672
	path = file_to_load(fname);
654
        rb_load(fname, wrap);
673 655
    }
674 656
    EC_POP_TAG();
675 657

  
676
    if (state == TAG_NONE) state = rb_load_internal0(GET_EC(), path, wrap);
677 658
    if (state != TAG_NONE) *pstate = state;
678 659
}
679 660

  
......
1025 1006
	    else {
1026 1007
		switch (found) {
1027 1008
		  case 'r':
1028
		    state = rb_load_internal0(ec, path, 0);
1009
		    rb_load_internal(path, 0);
1029 1010
		    break;
1030 1011

  
1031 1012
		  case 's':
......
1034 1015
		    rb_ary_push(ruby_dln_librefs, LONG2NUM(handle));
1035 1016
		    break;
1036 1017
		}
1037
		if (!state) {
1038
		    rb_provide_feature(path);
1039
		    result = TAG_RETURN;
1040
		}
1018
                rb_provide_feature(path);
1019
                result = TAG_RETURN;
1041 1020
	    }
1042 1021
	}
1043 1022
    }
test/ruby/test_settracefunc.rb
1672 1672
    ary
1673 1673
  end
1674 1674

  
1675
  def test_single_raise_inside_load
1676
    events = []
1677
    tmpdir = Dir.mktmpdir
1678
    path = "#{tmpdir}/hola.rb"
1679
    File.open(path, "w") { |f| f.write("raise") }
1680
    TracePoint.new(:raise){|tp| next if !target_thread?; events << [tp.event]}.enable{
1681
      load path rescue nil
1682
    }
1683
    assert_equal [[:raise]], events
1684
  ensure
1685
    FileUtils.rmtree(tmpdir)
1686
  end
1687

  
1675 1688
  def f_raise
1676 1689
    raise
1677 1690
  rescue
vm.c
1488 1488
    return make_localjump_error(mesg, val, state);
1489 1489
}
1490 1490

  
1491
#if 0
1492 1491
void
1493 1492
rb_vm_jump_tag_but_local_jump(int state)
1494 1493
{
......
1496 1495
    if (!NIL_P(exc)) rb_exc_raise(exc);
1497 1496
    EC_JUMP_TAG(GET_EC(), state);
1498 1497
}
1499
#endif
1500 1498

  
1501 1499
static rb_control_frame_t *
1502 1500
next_not_local_frame(rb_control_frame_t *cfp)