1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
nobu 2012-02-24 07:39:59 +00:00
parent 9acf2091e1
commit 7d742d47cc
3 changed files with 56 additions and 1 deletions

View file

@ -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.

48
error.c
View file

@ -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));
}
@ -1795,12 +1815,24 @@ rb_syserr_fail(int e, const char *mesg)
rb_exc_raise(rb_syserr_new(e, 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)
{
@ -1809,6 +1841,14 @@ rb_mod_sys_fail(VALUE mod, const char *mesg)
rb_exc_raise(exc);
}
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)
{
@ -1817,6 +1857,14 @@ rb_mod_syserr_fail(VALUE mod, int e, const char *mesg)
rb_exc_raise(exc);
}
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, ...)
{

View file

@ -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);