ruby-changes:37446
From: nobu <ko1@a...>
Date: Fri, 6 Feb 2015 17:37:30 +0900 (JST)
Subject: [ruby-changes:37446] nobu:r49527 (trunk): error.c: rb_sys_enc_warning
nobu 2015-02-06 17:37:24 +0900 (Fri, 06 Feb 2015) New Revision: 49527 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49527 Log: error.c: rb_sys_enc_warning * error.c (rb_sys_enc_warning): new function to show warning and error message with the encoding. Modified files: trunk/error.c trunk/internal.h Index: error.c =================================================================== --- error.c (revision 49526) +++ error.c (revision 49527) @@ -231,6 +231,22 @@ rb_warn(const char *fmt, ...) https://github.com/ruby/ruby/blob/trunk/error.c#L231 rb_write_error_str(mesg); } +#if 0 +void +rb_enc_warn(rb_encoding *enc, const char *fmt, ...) +{ + VALUE mesg; + va_list args; + + if (NIL_P(ruby_verbose)) return; + + va_start(args, fmt); + mesg = warning_string(enc, fmt, args); + va_end(args); + rb_write_error_str(mesg); +} +#endif + /* rb_warning() reports only in verbose mode */ void rb_warning(const char *fmt, ...) @@ -246,6 +262,22 @@ rb_warning(const char *fmt, ...) https://github.com/ruby/ruby/blob/trunk/error.c#L262 rb_write_error_str(mesg); } +#if 0 +void +rb_enc_warning(rb_encoding *enc, const char *fmt, ...) +{ + VALUE mesg; + va_list args; + + if (!RTEST(ruby_verbose)) return; + + va_start(args, fmt); + mesg = warning_string(enc, fmt, args); + va_end(args); + rb_write_error_str(mesg); +} +#endif + /* * call-seq: * warn(msg, ...) -> nil @@ -2105,6 +2137,26 @@ rb_sys_warning(const char *fmt, ...) https://github.com/ruby/ruby/blob/trunk/error.c#L2137 va_end(args); rb_str_set_len(mesg, RSTRING_LEN(mesg)-1); rb_str_catf(mesg, ": %s\n", strerror(errno_save)); + rb_write_error_str(mesg); + errno = errno_save; +} + +void +rb_sys_enc_warning(rb_encoding *enc, const char *fmt, ...) +{ + VALUE mesg; + va_list args; + int errno_save; + + errno_save = errno; + + if (!RTEST(ruby_verbose)) return; + + va_start(args, fmt); + mesg = warning_string(enc, fmt, args); + va_end(args); + rb_str_set_len(mesg, RSTRING_LEN(mesg)-1); + rb_str_catf(mesg, ": %s\n", strerror(errno_save)); rb_write_error_str(mesg); errno = errno_save; } Index: internal.h =================================================================== --- internal.h (revision 49526) +++ internal.h (revision 49527) @@ -627,6 +627,9 @@ VALUE rb_check_backtrace(VALUE); https://github.com/ruby/ruby/blob/trunk/internal.h#L627 NORETURN(void rb_async_bug_errno(const char *,int)); const char *rb_builtin_type_name(int t); const char *rb_builtin_class_name(VALUE x); +PRINTF_ARGS(void rb_enc_warn(rb_encoding *enc, const char *fmt, ...), 2, 3); +PRINTF_ARGS(void rb_enc_warning(rb_encoding *enc, const char *fmt, ...), 2, 3); +PRINTF_ARGS(void rb_sys_enc_warning(rb_encoding *enc, const char *fmt, ...), 2, 3); /* eval.c */ VALUE rb_refinement_module_get_refined_class(VALUE module); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/