ruby-changes:22738
From: nobu <ko1@a...>
Date: Fri, 24 Feb 2012 16:40:10 +0900 (JST)
Subject: [ruby-changes:22738] nobu:r34787 (trunk): * error.c: new functions to deal exceptions with string instances.
nobu 2012-02-24 16:39:59 +0900 (Fri, 24 Feb 2012) New Revision: 34787 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34787 Log: * error.c: new functions to deal exceptions with string instances. Modified files: trunk/ChangeLog trunk/error.c trunk/include/ruby/ruby.h Index: include/ruby/ruby.h =================================================================== --- include/ruby/ruby.h (revision 34786) +++ include/ruby/ruby.h (revision 34787) @@ -1186,14 +1186,19 @@ 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); Index: ChangeLog =================================================================== --- ChangeLog (revision 34786) +++ ChangeLog (revision 34787) @@ -1,5 +1,7 @@ -Fri Feb 24 16:37:45 2012 Nobuyoshi Nakada <nobu@r...> +Fri Feb 24 16:39:57 2012 Nobuyoshi Nakada <nobu@r...> + * error.c: new functions to deal exceptions with string instances. + * dir.c, file.c, io.c: use rb_sys_fail_path. Fri Feb 24 15:49:07 2012 Nobuyoshi Nakada <nobu@r...> Index: error.c =================================================================== --- error.c (revision 34786) +++ error.c (revision 34787) @@ -1781,11 +1781,31 @@ 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 @@ } 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 @@ } 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 @@ } 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]; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/