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

* error.c (rb_syserr_new): new function to make SystemCallError

instance without errno.  [EXPERIMENTAL]
* error.c (rb_syserr_fail, rb_mod_syserr_fail): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29728 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2010-11-08 22:30:20 +00:00
parent b188d19ee0
commit b3c7867df7
3 changed files with 30 additions and 1 deletions

View file

@ -1,3 +1,10 @@
Tue Nov 9 07:30:15 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* error.c (rb_syserr_new): new function to make SystemCallError
instance without errno. [EXPERIMENTAL]
* error.c (rb_syserr_fail, rb_mod_syserr_fail): ditto.
Tue Nov 9 05:54:57 2010 Marc-Andre Lafortune <ruby-core@marc-andre.ca> Tue Nov 9 05:54:57 2010 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
* lib/*.rb: Remove unused variable warnings. * lib/*.rb: Remove unused variable warnings.

21
error.c
View file

@ -1532,17 +1532,28 @@ static VALUE
make_errno_exc(const char *mesg) make_errno_exc(const char *mesg)
{ {
int n = errno; int n = errno;
VALUE arg;
errno = 0; errno = 0;
if (n == 0) { if (n == 0) {
rb_bug("rb_sys_fail(%s) - errno == 0", mesg ? mesg : ""); rb_bug("rb_sys_fail(%s) - errno == 0", mesg ? mesg : "");
} }
return rb_syserr_new(n, mesg);
}
VALUE
rb_syserr_new(int n, const char *mesg)
{
VALUE arg;
arg = mesg ? rb_str_new2(mesg) : Qnil; arg = mesg ? rb_str_new2(mesg) : Qnil;
return rb_class_new_instance(1, &arg, get_syserr(n)); return rb_class_new_instance(1, &arg, get_syserr(n));
} }
void
rb_syserr_fail(int e, const char *mesg)
{
rb_exc_raise(rb_syserr_new(e, mesg));
}
void void
rb_sys_fail(const char *mesg) rb_sys_fail(const char *mesg)
{ {
@ -1557,6 +1568,14 @@ rb_mod_sys_fail(VALUE mod, const char *mesg)
rb_exc_raise(exc); rb_exc_raise(exc);
} }
void
rb_mod_syserr_fail(VALUE mod, int e, const char *mesg)
{
VALUE exc = rb_syserr_new(e, mesg);
rb_extend_object(exc, mod);
rb_exc_raise(exc);
}
void void
rb_sys_warning(const char *fmt, ...) rb_sys_warning(const char *fmt, ...)
{ {

View file

@ -1152,6 +1152,9 @@ NORETURN(void rb_mod_sys_fail(VALUE, const char*));
NORETURN(void rb_iter_break(void)); NORETURN(void rb_iter_break(void));
NORETURN(void rb_exit(int)); NORETURN(void rb_exit(int));
NORETURN(void rb_notimplement(void)); NORETURN(void rb_notimplement(void));
VALUE rb_syserr_new(int, const char *);
NORETURN(void rb_syserr_fail(int, const char*));
NORETURN(void rb_mod_syserr_fail(VALUE, int, const char*));
/* reports if `-W' specified */ /* reports if `-W' specified */
PRINTF_ARGS(void rb_warning(const char*, ...), 1, 2); PRINTF_ARGS(void rb_warning(const char*, ...), 1, 2);