diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-02-24 07:39:59 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-02-24 07:39:59 +0000 |
commit | 7d742d47cc2f0023c4aeffdec6a6296f6c69a10f (patch) | |
tree | 1fdb32b8e245856dc4cec984b562b6c24e695aa3 | |
parent | 9acf2091e14e49949aab6f38e1a41dd3d7d3077e (diff) |
* error.c: new functions to deal exceptions with string instances.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34787 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | error.c | 48 | ||||
-rw-r--r-- | include/ruby/ruby.h | 5 |
3 files changed, 56 insertions, 1 deletions
@@ -1,4 +1,6 @@ -Fri Feb 24 16:37:45 2012 Nobuyoshi Nakada <nobu@ruby-lang.org> +Fri Feb 24 16:39:57 2012 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * error.c: new functions to deal exceptions with string instances. * dir.c, file.c, io.c: use rb_sys_fail_path. @@ -1781,11 +1781,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)); } @@ -1796,12 +1816,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); @@ -1810,6 +1842,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); @@ -1818,6 +1858,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]; diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 898d2e251d..6909bf3d7a 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -1186,14 +1186,19 @@ PRINTF_ARGS(NORETURN(void rb_fatal(const char*, ...)), 1, 2); PRINTF_ARGS(NORETURN(void rb_bug(const char*, ...)), 1, 2); NORETURN(void rb_bug_errno(const char*, int)); NORETURN(void rb_sys_fail(const char*)); +NORETURN(void rb_sys_fail_str(VALUE)); NORETURN(void rb_mod_sys_fail(VALUE, const char*)); +NORETURN(void rb_mod_sys_fail_str(VALUE, VALUE)); NORETURN(void rb_iter_break(void)); NORETURN(void rb_iter_break_value(VALUE)); NORETURN(void rb_exit(int)); NORETURN(void rb_notimplement(void)); VALUE rb_syserr_new(int, const char *); +VALUE rb_syserr_new_str(int n, VALUE arg); NORETURN(void rb_syserr_fail(int, const char*)); +NORETURN(void rb_syserr_fail_str(int, VALUE)); NORETURN(void rb_mod_syserr_fail(VALUE, int, const char*)); +NORETURN(void rb_mod_syserr_fail_str(VALUE, int, VALUE)); /* reports if `-W' specified */ PRINTF_ARGS(void rb_warning(const char*, ...), 1, 2); |