summaryrefslogtreecommitdiff
path: root/error.c
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-20 15:20:15 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-20 15:20:15 +0000
commitb20e9ebe5aea57b6f49b0d100f26967165feafca (patch)
tree604bbde5e9b5bef206661cd31e7b5b3891ded57e /error.c
parent83b2ba3cfa9d2a3b881b6bc2fcc62072cc923d8b (diff)
merge revision(s) 58146,58150,58156: [Backport #13276]
error.c: refactor warning messages * error.c (with_warning_string): extract building warning message string from variadic arguments. * error.c (syserr_warning): write warning message with the system error message. error.c: warning functions * error.c: define warning functions in all combinations of * no errno, system errno, argument * without/with encoding * enabled/disabled by default dir.c: err at glob failure * dir.c (glob_helper): raise a SystemCallError exception when opendir() failed, except for ENOENT, ENOTDIR, and EACCES. this behavior predates 1.0; the comments in glob.c claimed that glob() returned -1 on error but actualy the pointer to a global variable, then dir_glob() did check only -1 as the comments, and ignored actual errors. [ruby-core:80226] [Bug #13276] dir.c: ruby_glob_funcs_t git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@61367 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'error.c')
-rw-r--r--error.c174
1 files changed, 112 insertions, 62 deletions
diff --git a/error.c b/error.c
index efcf278793..b890be13a8 100644
--- a/error.c
+++ b/error.c
@@ -217,62 +217,52 @@ warning_string(rb_encoding *enc, const char *fmt, va_list args)
fmt, args);
}
+#define with_warning_string(mesg, enc, fmt) \
+ VALUE mesg; \
+ va_list args; va_start(args, fmt); \
+ mesg = warning_string(enc, fmt, args); \
+ va_end(args);
+
void
rb_warn(const char *fmt, ...)
{
- VALUE mesg;
- va_list args;
-
- if (NIL_P(ruby_verbose)) return;
-
- va_start(args, fmt);
- mesg = warning_string(0, fmt, args);
- va_end(args);
- rb_write_warning_str(mesg);
+ if (!NIL_P(ruby_verbose)) {
+ with_warning_string(mesg, 0, fmt) {
+ rb_write_warning_str(mesg);
+ }
+ }
}
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_warning_str(mesg);
+ if (!NIL_P(ruby_verbose)) {
+ with_warning_string(mesg, enc, fmt) {
+ rb_write_warning_str(mesg);
+ }
+ }
}
/* 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_warning_str(mesg);
+ if (RTEST(ruby_verbose)) {
+ with_warning_string(mesg, 0, fmt) {
+ rb_write_warning_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_warning_str(mesg);
+ if (RTEST(ruby_verbose)) {
+ with_warning_string(mesg, enc, fmt) {
+ rb_write_warning_str(mesg);
+ }
+ }
}
#endif
@@ -2394,44 +2384,104 @@ rb_mod_syserr_fail_str(VALUE mod, int e, VALUE mesg)
rb_exc_raise(exc);
}
+static void
+syserr_warning(VALUE mesg, int err)
+{
+ rb_str_set_len(mesg, RSTRING_LEN(mesg)-1);
+ rb_str_catf(mesg, ": %s\n", strerror(err));
+ rb_write_warning_str(mesg);
+}
+
+#if 0
void
-rb_sys_warning(const char *fmt, ...)
+rb_sys_warn(const char *fmt, ...)
{
- VALUE mesg;
- va_list args;
- int errno_save;
+ if (!NIL_P(ruby_verbose)) {
+ int errno_save = errno;
+ with_warning_string(mesg, 0, fmt) {
+ syserr_warning(mesg, errno_save);
+ }
+ errno = errno_save;
+ }
+}
- errno_save = errno;
+void
+rb_syserr_warn(int err, const char *fmt, ...)
+{
+ if (!NIL_P(ruby_verbose)) {
+ with_warning_string(mesg, 0, fmt) {
+ syserr_warning(mesg, err);
+ }
+ }
+}
- if (!RTEST(ruby_verbose)) return;
+void
+rb_sys_enc_warn(rb_encoding *enc, const char *fmt, ...)
+{
+ if (!NIL_P(ruby_verbose)) {
+ int errno_save = errno;
+ with_warning_string(mesg, enc, fmt) {
+ syserr_warning(mesg, errno_save);
+ }
+ errno = 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_warning_str(mesg);
- errno = errno_save;
+void
+rb_syserr_enc_warn(int err, rb_encoding *enc, const char *fmt, ...)
+{
+ if (!NIL_P(ruby_verbose)) {
+ with_warning_string(mesg, enc, fmt) {
+ syserr_warning(mesg, err);
+ }
+ }
}
+#endif
void
-rb_sys_enc_warning(rb_encoding *enc, const char *fmt, ...)
+rb_sys_warning(const char *fmt, ...)
{
- VALUE mesg;
- va_list args;
- int errno_save;
+ if (RTEST(ruby_verbose)) {
+ int errno_save = errno;
+ with_warning_string(mesg, 0, fmt) {
+ syserr_warning(mesg, errno_save);
+ }
+ errno = errno_save;
+ }
+}
- errno_save = errno;
+#if 0
+void
+rb_syserr_warning(int err, const char *fmt, ...)
+{
+ if (RTEST(ruby_verbose)) {
+ with_warning_string(mesg, 0, fmt) {
+ syserr_warning(mesg, err);
+ }
+ }
+}
+#endif
- if (!RTEST(ruby_verbose)) return;
+void
+rb_sys_enc_warning(rb_encoding *enc, const char *fmt, ...)
+{
+ if (RTEST(ruby_verbose)) {
+ int errno_save = errno;
+ with_warning_string(mesg, enc, fmt) {
+ syserr_warning(mesg, errno_save);
+ }
+ errno = errno_save;
+ }
+}
- 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_warning_str(mesg);
- errno = errno_save;
+void
+rb_syserr_enc_warning(int err, rb_encoding *enc, const char *fmt, ...)
+{
+ if (RTEST(ruby_verbose)) {
+ with_warning_string(mesg, enc, fmt) {
+ syserr_warning(mesg, err);
+ }
+ }
}
void