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
This commit is contained in:
nobu 2015-10-31 01:02:26 +00:00
parent 954224f3c5
commit 1546ffed49
8 changed files with 22 additions and 28 deletions

10
error.c
View File

@ -199,10 +199,10 @@ static VALUE
warning_string(rb_encoding *enc, const char *fmt, va_list args) warning_string(rb_encoding *enc, const char *fmt, va_list args)
{ {
VALUE str = rb_enc_str_new(0, 0, enc); 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)) { if (!NIL_P(file)) {
int line = rb_sourceline();
str = rb_str_append(str, file); str = rb_str_append(str, file);
if (line) rb_str_catf(str, ":%d", line); if (line) rb_str_catf(str, ":%d", line);
rb_str_cat2(str, ": "); rb_str_cat2(str, ": ");
@ -399,8 +399,7 @@ rb_bug(const char *fmt, ...)
int line = 0; int line = 0;
if (GET_THREAD()) { if (GET_THREAD()) {
file = rb_sourcefile(); file = rb_source_loc(&line);
line = rb_sourceline();
} }
report_bug(file, line, fmt, NULL); report_bug(file, line, fmt, NULL);
@ -415,8 +414,7 @@ rb_bug_context(const void *ctx, const char *fmt, ...)
int line = 0; int line = 0;
if (GET_THREAD()) { if (GET_THREAD()) {
file = rb_sourcefile(); file = rb_source_loc(&line);
line = rb_sourceline();
} }
report_bug(file, line, fmt, ctx); report_bug(file, line, fmt, ctx);

5
eval.c
View File

@ -476,7 +476,7 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause)
{ {
VALUE e; VALUE e;
const char *file = 0; const char *file = 0;
volatile int line = 0; int line;
int nocause = 0; int nocause = 0;
if (NIL_P(mesg)) { 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); exc_setup_cause(mesg, cause);
file = rb_sourcefile(); file = rb_source_loc(&line);
if (file) line = rb_sourceline();
if (file && !NIL_P(mesg)) { if (file && !NIL_P(mesg)) {
VALUE at; VALUE at;
if (sysstack_error_p(mesg)) { if (sysstack_error_p(mesg)) {

View File

@ -22,8 +22,8 @@ warn_printf(const char *fmt, ...)
static void static void
error_pos(void) error_pos(void)
{ {
VALUE sourcefile = rb_sourcefilename(); int sourceline;
int sourceline = rb_sourceline(); VALUE sourcefile = rb_source_location(&sourceline);
if (sourcefile) { if (sourcefile) {
ID caller_name; ID caller_name;
@ -105,8 +105,8 @@ error_print(void)
goto no_message; goto no_message;
} }
if (NIL_P(errat)) { if (NIL_P(errat)) {
const char *file = rb_sourcefile(); int line;
int line = rb_sourceline(); const char *file = rb_source_loc(&line);
if (!file) if (!file)
warn_printf("%d", line); warn_printf("%d", line);
else if (!line) else if (!line)

3
gc.c
View File

@ -1756,8 +1756,7 @@ newobj_init(VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3, int wb_prote
#endif #endif
#if GC_DEBUG #if GC_DEBUG
RANY(obj)->file = rb_sourcefile(); RANY(obj)->file = rb_source_loc(&RANY(obj)->line);
RANY(obj)->line = rb_sourceline();
assert(!SPECIAL_CONST_P(obj)); /* check alignment */ assert(!SPECIAL_CONST_P(obj)); /* check alignment */
#endif #endif

View File

@ -2636,9 +2636,8 @@ setup_const_entry(rb_const_entry_t *ce, VALUE klass, VALUE val,
rb_const_flag_t visibility) rb_const_flag_t visibility)
{ {
ce->flag = visibility; ce->flag = visibility;
ce->line = rb_sourceline();
RB_OBJ_WRITE(klass, &ce->value, val); 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 void

6
vm.c
View File

@ -203,16 +203,14 @@ ruby_th_dtrace_setup(rb_thread_t *th, VALUE klass, ID id,
type = BUILTIN_TYPE(klass); type = BUILTIN_TYPE(klass);
if (type == T_CLASS || type == T_ICLASS || type == T_MODULE) { if (type == T_CLASS || type == T_ICLASS || type == T_MODULE) {
VALUE name = rb_class_path_no_cache(klass); VALUE name = rb_class_path_no_cache(klass);
const char *classname; const char *classname, *filename;
const char *methodname = rb_id2name(id); const char *methodname = rb_id2name(id);
const char *filename = rb_sourcefile(); if (methodname && (filename = rb_source_loc(&args->line_no)) != 0) {
if (methodname && filename) {
if (NIL_P(name) || !(classname = StringValuePtr(name))) if (NIL_P(name) || !(classname = StringValuePtr(name)))
classname = "<unknown>"; classname = "<unknown>";
args->classname = classname; args->classname = classname;
args->methodname = methodname; args->methodname = methodname;
args->filename = filename; args->filename = filename;
args->line_no = rb_sourceline();
args->klass = klass; args->klass = klass;
args->name = name; args->name = name;
return TRUE; return TRUE;

View File

@ -1252,7 +1252,8 @@ rb_each(VALUE obj)
} }
static VALUE 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; int state;
VALUE result = Qundef; 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; volatile int mild_compile_error;
rb_cref_t *orig_cref; rb_cref_t *orig_cref;
VALUE crefval; VALUE crefval;
volatile VALUE file;
volatile int line;
if (file == 0) { file = filename ? filename : rb_source_location(&lineno);
file = rb_sourcefilename(); line = lineno;
line = rb_sourceline();
}
parse_in_eval = th->parse_in_eval; parse_in_eval = th->parse_in_eval;
mild_compile_error = th->mild_compile_error; mild_compile_error = th->mild_compile_error;

View File

@ -607,11 +607,11 @@ get_event_id(rb_event_flag_t event)
static void static void
call_trace_func(rb_event_flag_t event, VALUE proc, VALUE self, ID id, VALUE klass) 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 eventname = rb_str_new2(get_event_name(event));
VALUE filename = srcfile ? rb_str_new2(srcfile) : Qnil; VALUE filename = srcfile ? rb_str_new2(srcfile) : Qnil;
VALUE argv[6]; VALUE argv[6];
int line = rb_sourceline();
rb_thread_t *th = GET_THREAD(); rb_thread_t *th = GET_THREAD();
if (!klass) { if (!klass) {