summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-20 08:11:40 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-20 08:11:40 +0000
commita712ced7cbef41910bef32af362af22348826646 (patch)
tree125b55e9ced0155fd3ad1cd0bd2dd76ce1a1b4fd
parente24e1979cb38d809e09effecef9d1efb20a06442 (diff)
merge revision(s) 49479,49483,49526,49527:
remove duplication in warning * dir.c (sys_warning_1): remove duplication in the message. * error.c (rb_mod_sys_fail_str): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@49657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--dir.c2
-rw-r--r--error.c76
-rw-r--r--internal.h3
-rw-r--r--version.h2
4 files changed, 71 insertions, 12 deletions
diff --git a/dir.c b/dir.c
index e3d83533d5..4ca681dfb4 100644
--- a/dir.c
+++ b/dir.c
@@ -1084,7 +1084,7 @@ dir_s_rmdir(VALUE obj, VALUE dir)
static VALUE
sys_warning_1(VALUE mesg)
{
- rb_sys_warning("%s:%s", strerror(errno), (const char *)mesg);
+ rb_sys_warning("%s", (const char *)mesg);
return Qnil;
}
diff --git a/error.c b/error.c
index 0e8e17b195..b92d886832 100644
--- a/error.c
+++ b/error.c
@@ -198,10 +198,10 @@ rb_compile_warning(const char *file, int line, const char *fmt, ...)
va_end(args);
}
-static void
-warn_print(const char *fmt, va_list args)
+static VALUE
+warning_string(rb_encoding *enc, const char *fmt, va_list args)
{
- VALUE str = rb_str_new(0, 0);
+ VALUE str = rb_enc_str_new(0, 0, enc);
VALUE file = rb_sourcefilename();
if (!NIL_P(file)) {
@@ -214,33 +214,69 @@ warn_print(const char *fmt, va_list args)
rb_str_cat2(str, "warning: ");
rb_str_vcatf(str, fmt, args);
rb_str_cat2(str, "\n");
- rb_write_error_str(str);
+ return str;
}
void
rb_warn(const char *fmt, ...)
{
+ VALUE mesg;
va_list args;
if (NIL_P(ruby_verbose)) return;
va_start(args, fmt);
- warn_print(fmt, args);
+ mesg = warning_string(0, fmt, args);
va_end(args);
+ 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, ...)
{
+ VALUE mesg;
+ va_list args;
+
+ if (!RTEST(ruby_verbose)) return;
+
+ va_start(args, fmt);
+ mesg = warning_string(0, fmt, args);
+ va_end(args);
+ 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);
- warn_print(fmt, args);
+ mesg = warning_string(enc, fmt, args);
va_end(args);
+ rb_write_error_str(mesg);
}
+#endif
/*
* call-seq:
@@ -2088,7 +2124,7 @@ rb_mod_syserr_fail_str(VALUE mod, int e, VALUE mesg)
void
rb_sys_warning(const char *fmt, ...)
{
- char buf[BUFSIZ];
+ VALUE mesg;
va_list args;
int errno_save;
@@ -2096,12 +2132,32 @@ rb_sys_warning(const char *fmt, ...)
if (!RTEST(ruby_verbose)) return;
- snprintf(buf, BUFSIZ, "warning: %s", fmt);
- snprintf(buf+strlen(buf), BUFSIZ-strlen(buf), ": %s", strerror(errno_save));
+ va_start(args, fmt);
+ mesg = warning_string(0, 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;
+}
+
+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);
- warn_print(buf, args);
+ 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;
}
diff --git a/internal.h b/internal.h
index 9ed083fff1..186e6f884b 100644
--- a/internal.h
+++ b/internal.h
@@ -627,6 +627,9 @@ VALUE rb_check_backtrace(VALUE);
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);
diff --git a/version.h b/version.h
index ce29e8dcdc..03f0ca67d9 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.2.0"
#define RUBY_RELEASE_DATE "2015-02-20"
-#define RUBY_PATCHLEVEL 65
+#define RUBY_PATCHLEVEL 66
#define RUBY_RELEASE_YEAR 2015
#define RUBY_RELEASE_MONTH 2