ruby-changes:41865
From: nobu <ko1@a...>
Date: Thu, 25 Feb 2016 21:35:42 +0900 (JST)
Subject: [ruby-changes:41865] nobu:r53939 (trunk): eval_error.c: remove warn_printf
nobu 2016-02-25 21:36:24 +0900 (Thu, 25 Feb 2016) New Revision: 53939 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53939 Log: eval_error.c: remove warn_printf * eval_error.c (warn_printf): remove. * eval_error.c (error_pos_str): return error position string, split from error_pos. Modified files: trunk/eval.c trunk/eval_error.c Index: eval_error.c =================================================================== --- eval_error.c (revision 53938) +++ eval_error.c (revision 53939) @@ -3,42 +3,42 @@ https://github.com/ruby/ruby/blob/trunk/eval_error.c#L3 * included by eval.c */ -static void -warn_printf(const char *fmt, ...) -{ - VALUE str; - va_list args; - - va_init_list(args, fmt); - str = rb_vsprintf(fmt, args); - va_end(args); - rb_write_error_str(str); -} - #define warn_print(x) rb_write_error(x) #define warn_print2(x,l) rb_write_error2((x),(l)) #define warn_print_str(x) rb_write_error_str(x) +static VALUE error_pos_str(void); + static void error_pos(void) { + VALUE str = error_pos_str(); + if (!NIL_P(str)) { + warn_print_str(str); + } +} + +static VALUE +error_pos_str(void) +{ int sourceline; VALUE sourcefile = rb_source_location(&sourceline); if (sourcefile) { ID caller_name; if (sourceline == 0) { - warn_printf("%"PRIsVALUE": ", sourcefile); + return rb_sprintf("%"PRIsVALUE": ", sourcefile); } else if ((caller_name = rb_frame_callee()) != 0) { - warn_printf("%"PRIsVALUE":%d:in `%"PRIsVALUE"': ", - sourcefile, sourceline, - rb_id2str(caller_name)); + return rb_sprintf("%"PRIsVALUE":%d:in `%"PRIsVALUE"': ", + sourcefile, sourceline, + rb_id2str(caller_name)); } else { - warn_printf("%"PRIsVALUE":%d: ", sourcefile, sourceline); + return rb_sprintf("%"PRIsVALUE":%d: ", sourcefile, sourceline); } } + return Qnil; } static VALUE @@ -173,11 +173,11 @@ error_print(void) https://github.com/ruby/ruby/blob/trunk/eval_error.c#L173 for (i = 1; i < len; i++) { VALUE line = RARRAY_AREF(errat, i); if (RB_TYPE_P(line, T_STRING)) { - warn_printf("\tfrom %"PRIsVALUE"\n", line); + warn_print_str(rb_sprintf("\tfrom %"PRIsVALUE"\n", line)); } if (skip && i == TRACE_HEAD && len > TRACE_MAX) { - warn_printf("\t ... %ld levels...\n", - len - TRACE_HEAD - TRACE_TAIL); + warn_print_str(rb_sprintf("\t ... %ld levels...\n", + len - TRACE_HEAD - TRACE_TAIL)); i = len - TRACE_TAIL; } } Index: eval.c =================================================================== --- eval.c (revision 53938) +++ eval.c (revision 53939) @@ -534,17 +534,18 @@ setup_exception(rb_thread_t *th, int tag https://github.com/ruby/ruby/blob/trunk/eval.c#L534 e = rb_obj_as_string(mesg); th->errinfo = mesg; if (file && line) { - warn_printf("Exception `%"PRIsVALUE"' at %s:%d - %"PRIsVALUE"\n", - rb_obj_class(mesg), file, line, e); + e = rb_sprintf("Exception `%"PRIsVALUE"' at %s:%d - %"PRIsVALUE"\n", + rb_obj_class(mesg), file, line, e); } else if (file) { - warn_printf("Exception `%"PRIsVALUE"' at %s - %"PRIsVALUE"\n", - rb_obj_class(mesg), file, e); + e = rb_sprintf("Exception `%"PRIsVALUE"' at %s - %"PRIsVALUE"\n", + rb_obj_class(mesg), file, e); } else { - warn_printf("Exception `%"PRIsVALUE"' - %"PRIsVALUE"\n", - rb_obj_class(mesg), e); + e = rb_sprintf("Exception `%"PRIsVALUE"' - %"PRIsVALUE"\n", + rb_obj_class(mesg), e); } + warn_print_str(e); } TH_POP_TAG(); if (status == TAG_FATAL && th->errinfo == exception_error) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/