From 1546ffed499aa40e905485b00293fbb530d7ebd1 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 31 Oct 2015 01:02:26 +0000 Subject: use rb_source_loc and rb_source_location * error.c, eval.c, eval_error.c, gc.c, variable.c, vm.c, vm_eval.c, vm_trace.c: use rb_source_loc/rb_source_location instead of combination of rb_sourcefile/rb_sourcefilename and rb_sourceline. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52398 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- error.c | 10 ++++------ eval.c | 5 ++--- eval_error.c | 8 ++++---- gc.c | 3 +-- variable.c | 3 +-- vm.c | 6 ++---- vm_eval.c | 11 ++++++----- vm_trace.c | 4 ++-- 8 files changed, 22 insertions(+), 28 deletions(-) diff --git a/error.c b/error.c index 1db0e74a09..3dbdb5240f 100644 --- a/error.c +++ b/error.c @@ -199,10 +199,10 @@ static VALUE warning_string(rb_encoding *enc, const char *fmt, va_list args) { VALUE str = rb_enc_str_new(0, 0, enc); - VALUE file = rb_sourcefilename(); + int line; + VALUE file = rb_source_location(&line); if (!NIL_P(file)) { - int line = rb_sourceline(); str = rb_str_append(str, file); if (line) rb_str_catf(str, ":%d", line); rb_str_cat2(str, ": "); @@ -399,8 +399,7 @@ rb_bug(const char *fmt, ...) int line = 0; if (GET_THREAD()) { - file = rb_sourcefile(); - line = rb_sourceline(); + file = rb_source_loc(&line); } report_bug(file, line, fmt, NULL); @@ -415,8 +414,7 @@ rb_bug_context(const void *ctx, const char *fmt, ...) int line = 0; if (GET_THREAD()) { - file = rb_sourcefile(); - line = rb_sourceline(); + file = rb_source_loc(&line); } report_bug(file, line, fmt, ctx); diff --git a/eval.c b/eval.c index f598525261..e7f95deadb 100644 --- a/eval.c +++ b/eval.c @@ -476,7 +476,7 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause) { VALUE e; const char *file = 0; - volatile int line = 0; + int line; int nocause = 0; if (NIL_P(mesg)) { @@ -493,8 +493,7 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause) } exc_setup_cause(mesg, cause); - file = rb_sourcefile(); - if (file) line = rb_sourceline(); + file = rb_source_loc(&line); if (file && !NIL_P(mesg)) { VALUE at; if (sysstack_error_p(mesg)) { diff --git a/eval_error.c b/eval_error.c index 82a69033b6..395b9b0196 100644 --- a/eval_error.c +++ b/eval_error.c @@ -22,8 +22,8 @@ warn_printf(const char *fmt, ...) static void error_pos(void) { - VALUE sourcefile = rb_sourcefilename(); - int sourceline = rb_sourceline(); + int sourceline; + VALUE sourcefile = rb_source_location(&sourceline); if (sourcefile) { ID caller_name; @@ -105,8 +105,8 @@ error_print(void) goto no_message; } if (NIL_P(errat)) { - const char *file = rb_sourcefile(); - int line = rb_sourceline(); + int line; + const char *file = rb_source_loc(&line); if (!file) warn_printf("%d", line); else if (!line) diff --git a/gc.c b/gc.c index e57d616f62..fcfd53da49 100644 --- a/gc.c +++ b/gc.c @@ -1756,8 +1756,7 @@ newobj_init(VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3, int wb_prote #endif #if GC_DEBUG - RANY(obj)->file = rb_sourcefile(); - RANY(obj)->line = rb_sourceline(); + RANY(obj)->file = rb_source_loc(&RANY(obj)->line); assert(!SPECIAL_CONST_P(obj)); /* check alignment */ #endif diff --git a/variable.c b/variable.c index 49853b64e9..048ddde069 100644 --- a/variable.c +++ b/variable.c @@ -2636,9 +2636,8 @@ setup_const_entry(rb_const_entry_t *ce, VALUE klass, VALUE val, rb_const_flag_t visibility) { ce->flag = visibility; - ce->line = rb_sourceline(); RB_OBJ_WRITE(klass, &ce->value, val); - RB_OBJ_WRITE(klass, &ce->file, rb_sourcefilename()); + RB_OBJ_WRITE(klass, &ce->file, rb_source_location(&ce->line)); } void diff --git a/vm.c b/vm.c index d79d38a8d9..1e2b4dc1c4 100644 --- a/vm.c +++ b/vm.c @@ -203,16 +203,14 @@ ruby_th_dtrace_setup(rb_thread_t *th, VALUE klass, ID id, type = BUILTIN_TYPE(klass); if (type == T_CLASS || type == T_ICLASS || type == T_MODULE) { VALUE name = rb_class_path_no_cache(klass); - const char *classname; + const char *classname, *filename; const char *methodname = rb_id2name(id); - const char *filename = rb_sourcefile(); - if (methodname && filename) { + if (methodname && (filename = rb_source_loc(&args->line_no)) != 0) { if (NIL_P(name) || !(classname = StringValuePtr(name))) classname = ""; args->classname = classname; args->methodname = methodname; args->filename = filename; - args->line_no = rb_sourceline(); args->klass = klass; args->name = name; return TRUE; diff --git a/vm_eval.c b/vm_eval.c index ffb3a6b8f6..4634b981f3 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -1252,7 +1252,8 @@ rb_each(VALUE obj) } static VALUE -eval_string_with_cref(VALUE self, VALUE src, VALUE scope, rb_cref_t *const cref_arg, volatile VALUE file, volatile int line) +eval_string_with_cref(VALUE self, VALUE src, VALUE scope, rb_cref_t *const cref_arg, + VALUE filename, int lineno) { int state; VALUE result = Qundef; @@ -1264,11 +1265,11 @@ eval_string_with_cref(VALUE self, VALUE src, VALUE scope, rb_cref_t *const cref_ volatile int mild_compile_error; rb_cref_t *orig_cref; VALUE crefval; + volatile VALUE file; + volatile int line; - if (file == 0) { - file = rb_sourcefilename(); - line = rb_sourceline(); - } + file = filename ? filename : rb_source_location(&lineno); + line = lineno; parse_in_eval = th->parse_in_eval; mild_compile_error = th->mild_compile_error; diff --git a/vm_trace.c b/vm_trace.c index 1ce11f9548..bf318b1960 100644 --- a/vm_trace.c +++ b/vm_trace.c @@ -607,11 +607,11 @@ get_event_id(rb_event_flag_t event) static void call_trace_func(rb_event_flag_t event, VALUE proc, VALUE self, ID id, VALUE klass) { - const char *srcfile = rb_sourcefile(); + int line; + const char *srcfile = rb_source_loc(&line); VALUE eventname = rb_str_new2(get_event_name(event)); VALUE filename = srcfile ? rb_str_new2(srcfile) : Qnil; VALUE argv[6]; - int line = rb_sourceline(); rb_thread_t *th = GET_THREAD(); if (!klass) { -- cgit v1.2.3