summaryrefslogtreecommitdiff
path: root/error.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-25 12:32:19 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-25 12:32:19 +0000
commit0f377c1c1038d3a56f1fa5508127b96fd1f43c6d (patch)
treeb69b749678f98d8040368f86f1b6f24accc678ed /error.c
parent5e808b6ba38dbd974b617e80e2cf054eaaca604f (diff)
merge revision(s) 34786,34787,34788,34789:
* dir.c, file.c, io.c: use rb_sys_fail_path. * error.c: new functions to deal exceptions with string instances. * dir.c, file.c, io.c (rb_sys_fail_path): use rb_sys_fail_str. * test/ruby/test_literal.rb (TestRubyLiteral#test_special_const): test for https://bugs.php.net/bug.php?id=61095 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@34814 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'error.c')
-rw-r--r--error.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/error.c b/error.c
index db9a46f72f..060b82c377 100644
--- a/error.c
+++ b/error.c
@@ -1633,11 +1633,31 @@ make_errno_exc(const char *mesg)
return rb_syserr_new(n, mesg);
}
+static VALUE
+make_errno_exc_str(VALUE mesg)
+{
+ int n = errno;
+
+ errno = 0;
+ if (!mesg) mesg = Qnil;
+ if (n == 0) {
+ const char *s = !NIL_P(mesg) ? RSTRING_PTR(mesg) : "";
+ rb_bug("rb_sys_fail_str(%s) - errno == 0", s);
+ }
+ return rb_syserr_new_str(n, mesg);
+}
+
VALUE
rb_syserr_new(int n, const char *mesg)
{
VALUE arg;
arg = mesg ? rb_str_new2(mesg) : Qnil;
+ return rb_syserr_new_str(n, arg);
+}
+
+VALUE
+rb_syserr_new_str(int n, VALUE arg)
+{
return rb_class_new_instance(1, &arg, get_syserr(n));
}
@@ -1648,12 +1668,24 @@ rb_syserr_fail(int e, const char *mesg)
}
void
+rb_syserr_fail_str(int e, VALUE mesg)
+{
+ rb_exc_raise(rb_syserr_new_str(e, mesg));
+}
+
+void
rb_sys_fail(const char *mesg)
{
rb_exc_raise(make_errno_exc(mesg));
}
void
+rb_sys_fail_str(VALUE mesg)
+{
+ rb_exc_raise(make_errno_exc_str(mesg));
+}
+
+void
rb_mod_sys_fail(VALUE mod, const char *mesg)
{
VALUE exc = make_errno_exc(mesg);
@@ -1662,6 +1694,14 @@ rb_mod_sys_fail(VALUE mod, const char *mesg)
}
void
+rb_mod_sys_fail_str(VALUE mod, VALUE mesg)
+{
+ VALUE exc = make_errno_exc_str(mesg);
+ rb_extend_object(exc, mod);
+ rb_exc_raise(exc);
+}
+
+void
rb_mod_syserr_fail(VALUE mod, int e, const char *mesg)
{
VALUE exc = rb_syserr_new(e, mesg);
@@ -1670,6 +1710,14 @@ rb_mod_syserr_fail(VALUE mod, int e, const char *mesg)
}
void
+rb_mod_syserr_fail_str(VALUE mod, int e, VALUE mesg)
+{
+ VALUE exc = rb_syserr_new_str(e, mesg);
+ rb_extend_object(exc, mod);
+ rb_exc_raise(exc);
+}
+
+void
rb_sys_warning(const char *fmt, ...)
{
char buf[BUFSIZ];