summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-04-15 00:06:13 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-04-15 00:06:13 +0000
commit57fb2199059cb55b632d093c2e64c8a3c60acfbb (patch)
treee35e0fb134907d12cee224d3750f4cc00c7b7634
parentb860144680e3af51f7fc0d7185185a92c4fa6aca (diff)
* reduce UNREACHABLE.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35333 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--bignum.c42
-rw-r--r--class.c11
-rw-r--r--dir.c8
-rw-r--r--encoding.c11
-rw-r--r--ext/pty/pty.c1
-rw-r--r--file.c29
-rw-r--r--io.c20
-rw-r--r--marshal.c15
-rw-r--r--numeric.c12
-rw-r--r--ruby.c4
-rw-r--r--win32/win32.c8
11 files changed, 62 insertions, 99 deletions
diff --git a/bignum.c b/bignum.c
index 9d09098f29f..3551f4fb6a7 100644
--- a/bignum.c
+++ b/bignum.c
@@ -2976,33 +2976,31 @@ big_fdiv(VALUE x, VALUE y)
switch (TYPE(y)) {
case T_FIXNUM:
y = rb_int2big(FIX2LONG(y));
- case T_BIGNUM: {
+ case T_BIGNUM:
bigtrunc(y);
l = RBIGNUM_LEN(y) - 1;
ey = l * BITSPERDIG;
ey += bdigbitsize(BDIGITS(y)[l]);
ey -= DBL_BIGDIG * BITSPERDIG;
if (ey) y = big_shift(y, ey);
- bignum:
- bigdivrem(x, y, &z, 0);
- l = ex - ey;
-#if SIZEOF_LONG > SIZEOF_INT
- {
- /* Visual C++ can't be here */
- if (l > INT_MAX) return DBL2NUM(INFINITY);
- if (l < INT_MIN) return DBL2NUM(0.0);
- }
-#endif
- return DBL2NUM(ldexp(big2dbl(z), (int)l));
- }
+ break;
case T_FLOAT:
y = dbl2big(ldexp(frexp(RFLOAT_VALUE(y), &i), DBL_MANT_DIG));
ey = i - DBL_MANT_DIG;
- goto bignum;
+ break;
+ default:
+ rb_bug("big_fdiv");
}
- rb_bug("big_fdiv");
-
- UNREACHABLE;
+ bigdivrem(x, y, &z, 0);
+ l = ex - ey;
+#if SIZEOF_LONG > SIZEOF_INT
+ {
+ /* Visual C++ can't be here */
+ if (l > INT_MAX) return DBL2NUM(INFINITY);
+ if (l < INT_MIN) return DBL2NUM(0.0);
+ }
+#endif
+ return DBL2NUM(ldexp(big2dbl(z), (int)l));
}
/*
@@ -3665,17 +3663,13 @@ static VALUE
rb_big_coerce(VALUE x, VALUE y)
{
if (FIXNUM_P(y)) {
- return rb_assoc_new(rb_int2big(FIX2LONG(y)), x);
- }
- else if (RB_TYPE_P(y, T_BIGNUM)) {
- return rb_assoc_new(y, x);
+ y = rb_int2big(FIX2LONG(y));
}
- else {
+ else if (!RB_TYPE_P(y, T_BIGNUM)) {
rb_raise(rb_eTypeError, "can't coerce %s to Bignum",
rb_obj_classname(y));
}
-
- UNREACHABLE;
+ return rb_assoc_new(y, x);
}
/*
diff --git a/class.c b/class.c
index 8dc2f2eb5c9..00f508e1b47 100644
--- a/class.c
+++ b/class.c
@@ -1649,15 +1649,12 @@ rb_scan_args(int argc, const VALUE *argv, const char *fmt, ...)
}
va_end(vargs);
- if (argi < argc)
- goto argc_error;
+ if (argi < argc) {
+ argc_error:
+ rb_error_arity(argc, n_mand, f_var ? UNLIMITED_ARGUMENTS : n_mand + n_opt);
+ }
return argc;
-
- argc_error:
- rb_error_arity(argc, n_mand, f_var ? UNLIMITED_ARGUMENTS : n_mand + n_opt);
-
- UNREACHABLE;
}
/*!
diff --git a/dir.c b/dir.c
index e2304a69f4b..8476c0e1d30 100644
--- a/dir.c
+++ b/dir.c
@@ -584,14 +584,10 @@ dir_read(VALUE dir)
if (READDIR(dirp->dir, dirp->enc, &STRUCT_DIRENT(entry), dp)) {
return rb_external_str_new_with_enc(dp->d_name, NAMLEN(dp), dirp->enc);
}
- else if (errno == 0) { /* end of stream */
- return Qnil;
- }
else {
- rb_sys_fail(0);
+ if (errno != 0) rb_sys_fail(0);
+ return Qnil; /* end of stream */
}
-
- UNREACHABLE;
}
/*
diff --git a/encoding.c b/encoding.c
index f2506b3412f..41f217063b6 100644
--- a/encoding.c
+++ b/encoding.c
@@ -922,14 +922,11 @@ rb_enc_codepoint_len(const char *p, const char *e, int *len_p, rb_encoding *enc)
if (e <= p)
rb_raise(rb_eArgError, "empty string");
r = rb_enc_precise_mbclen(p, e, enc);
- if (MBCLEN_CHARFOUND_P(r)) {
- if (len_p) *len_p = MBCLEN_CHARFOUND_LEN(r);
- return rb_enc_mbc_to_codepoint(p, e, enc);
- }
- else
+ if (!MBCLEN_CHARFOUND_P(r)) {
rb_raise(rb_eArgError, "invalid byte sequence in %s", rb_enc_name(enc));
-
- UNREACHABLE;
+ }
+ if (len_p) *len_p = MBCLEN_CHARFOUND_LEN(r);
+ return rb_enc_mbc_to_codepoint(p, e, enc);
}
#undef rb_enc_codepoint
diff --git a/ext/pty/pty.c b/ext/pty/pty.c
index de5cbf79e29..126e33c8a61 100644
--- a/ext/pty/pty.c
+++ b/ext/pty/pty.c
@@ -630,6 +630,7 @@ pty_getpty(int argc, VALUE *argv, VALUE self)
return res;
}
+NORETURN(static void raise_from_check(pid_t pid, int status));
static void
raise_from_check(pid_t pid, int status)
{
diff --git a/file.c b/file.c
index 1c31086d26d..59de83c5fd1 100644
--- a/file.c
+++ b/file.c
@@ -4182,13 +4182,8 @@ test_check(int n, int argc, VALUE *argv)
n+=1;
rb_check_arity(argc, n, n);
for (i=1; i<n; i++) {
- switch (TYPE(argv[i])) {
- case T_STRING:
- default:
+ if (!RB_TYPE_P(argv[i], T_FILE)) {
FilePathValue(argv[i]);
- break;
- case T_FILE:
- break;
}
}
}
@@ -4260,7 +4255,16 @@ rb_f_test(int argc, VALUE *argv)
if (argc == 0) rb_check_arity(argc, 2, 3);
cmd = NUM2CHR(argv[0]);
- if (cmd == 0) goto unknown;
+ if (cmd == 0) {
+ unknown:
+ /* unknown command */
+ if (ISPRINT(cmd)) {
+ rb_raise(rb_eArgError, "unknown command '%s%c'", cmd == '\'' || cmd == '\\' ? "\\" : "", cmd);
+ }
+ else {
+ rb_raise(rb_eArgError, "unknown command \"\\x%02X\"", cmd);
+ }
+ }
if (strchr("bcdefgGkloOprRsSuwWxXz", cmd)) {
CHECK(1);
switch (cmd) {
@@ -4379,16 +4383,7 @@ rb_f_test(int argc, VALUE *argv)
return Qfalse;
}
}
- unknown:
- /* unknown command */
- if (ISPRINT(cmd)) {
- rb_raise(rb_eArgError, "unknown command '%s%c'", cmd == '\'' || cmd == '\\' ? "\\" : "", cmd);
- }
- else {
- rb_raise(rb_eArgError, "unknown command \"\\x%02X\"", cmd);
- }
-
- UNREACHABLE;
+ goto unknown;
}
diff --git a/io.c b/io.c
index bf7db693c92..599ae0aa651 100644
--- a/io.c
+++ b/io.c
@@ -2336,10 +2336,7 @@ io_readpartial(int argc, VALUE *argv, VALUE io)
ret = io_getpartial(argc, argv, io, 0);
if (NIL_P(ret))
rb_eof_error();
- else
- return ret;
-
- UNREACHABLE;
+ return ret;
}
/*
@@ -2399,10 +2396,7 @@ io_read_nonblock(int argc, VALUE *argv, VALUE io)
ret = io_getpartial(argc, argv, io, 1);
if (NIL_P(ret))
rb_eof_error();
- else
- return ret;
-
- UNREACHABLE;
+ return ret;
}
/*
@@ -4437,6 +4431,8 @@ rb_io_fmode_modestr(int fmode)
return MODE_BTMODE("a", "ab", "at");
}
switch (fmode & FMODE_READWRITE) {
+ default:
+ rb_raise(rb_eArgError, "invalid access fmode 0x%x", fmode);
case FMODE_READABLE:
return MODE_BTMODE("r", "rb", "rt");
case FMODE_WRITABLE:
@@ -4447,9 +4443,6 @@ rb_io_fmode_modestr(int fmode)
}
return MODE_BTMODE("r+", "rb+", "rt+");
}
- rb_raise(rb_eArgError, "invalid access fmode 0x%x", fmode);
-
- UNREACHABLE;
}
static int
@@ -4607,6 +4600,8 @@ rb_io_oflags_modestr(int oflags)
}
}
switch (oflags & (O_RDONLY|O_WRONLY|O_RDWR)) {
+ default:
+ rb_raise(rb_eArgError, "invalid access oflags 0x%x", oflags);
case O_RDONLY:
return MODE_BINARY("r", "rb");
case O_WRONLY:
@@ -4614,9 +4609,6 @@ rb_io_oflags_modestr(int oflags)
case O_RDWR:
return MODE_BINARY("r+", "rb+");
}
- rb_raise(rb_eArgError, "invalid access oflags 0x%x", oflags);
-
- UNREACHABLE;
}
/*
diff --git a/marshal.c b/marshal.c
index 362cfa544d7..e05b9f5c769 100644
--- a/marshal.c
+++ b/marshal.c
@@ -1143,12 +1143,10 @@ r_symlink(struct load_arg *arg)
st_data_t id;
long num = r_long(arg);
- if (st_lookup(arg->symbols, num, &id)) {
- return (ID)id;
+ if (!st_lookup(arg->symbols, num, &id)) {
+ rb_raise(rb_eArgError, "bad symbol");
}
- rb_raise(rb_eArgError, "bad symbol");
-
- UNREACHABLE;
+ return (ID)id;
}
static ID
@@ -1181,6 +1179,8 @@ r_symbol(struct load_arg *arg)
again:
switch ((type = r_byte(arg))) {
+ default:
+ rb_raise(rb_eArgError, "dump format error for symbol(0x%x)", type);
case TYPE_IVAR:
ivar = 1;
goto again;
@@ -1191,12 +1191,7 @@ r_symbol(struct load_arg *arg)
rb_raise(rb_eArgError, "dump format error (symlink with encoding)");
}
return r_symlink(arg);
- default:
- rb_raise(rb_eArgError, "dump format error for symbol(0x%x)", type);
- break;
}
-
- UNREACHABLE;
}
static VALUE
diff --git a/numeric.c b/numeric.c
index 03abf6db8f3..8d2500abfbf 100644
--- a/numeric.c
+++ b/numeric.c
@@ -2109,11 +2109,11 @@ rb_num2ll(VALUE val)
break;
default:
- val = rb_to_int(val);
- return NUM2LL(val);
+ break;
}
- UNREACHABLE;
+ val = rb_to_int(val);
+ return NUM2LL(val);
}
unsigned LONG_LONG
@@ -2153,11 +2153,11 @@ rb_num2ull(VALUE val)
break;
default:
- val = rb_to_int(val);
- return NUM2ULL(val);
+ break;
}
- UNREACHABLE;
+ val = rb_to_int(val);
+ return NUM2ULL(val);
}
#endif /* HAVE_LONG_LONG */
diff --git a/ruby.c b/ruby.c
index 31385e43106..93779a76e29 100644
--- a/ruby.c
+++ b/ruby.c
@@ -1756,9 +1756,9 @@ opt_W_getter(ID id, void *data)
return INT2FIX(1);
case Qtrue:
return INT2FIX(2);
+ default:
+ return Qnil;
}
-
- UNREACHABLE;
}
void
diff --git a/win32/win32.c b/win32/win32.c
index 5437cb6c38e..84c929d371b 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -1071,17 +1071,13 @@ child_result(struct ChildRecord *child, int mode)
return -1;
}
- switch (mode) {
- case P_NOWAIT:
- return child->pid;
- case P_OVERLAY:
+ if (mode == P_OVERLAY) {
WaitForSingleObject(child->hProcess, INFINITE);
GetExitCodeProcess(child->hProcess, &exitcode);
CloseChildHandle(child);
_exit(exitcode);
- default:
- UNREACHABLE;
}
+ return child->pid;
}
/* License: Ruby's */