* include/ruby/ruby.h (rb_bug_errno): declared.

* include/ruby/intern.h (rb_strerrno): declaration removed.

* error.c (rb_strerrno): make it static.  return NULL for unknown
  errors.
  (rb_bug_errno): defined.

* thread_pthread.c: use rb_bug_errno.

* signal.c (ruby_signal): use rb_bug_errno.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25904 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2009-11-24 11:03:51 +00:00
Родитель f6fbdf261e
Коммит ff9d908832
6 изменённых файлов: 52 добавлений и 25 удалений

Просмотреть файл

@ -1,3 +1,17 @@
Tue Nov 24 20:01:49 2009 Tanaka Akira <akr@fsij.org>
* include/ruby/ruby.h (rb_bug_errno): declared.
* include/ruby/intern.h (rb_strerrno): declaration removed.
* error.c (rb_strerrno): make it static. return NULL for unknown
errors.
(rb_bug_errno): defined.
* thread_pthread.c: use rb_bug_errno.
* signal.c (ruby_signal): use rb_bug_errno.
Tue Nov 24 10:17:38 2009 NARUSE, Yui <naruse@ruby-lang.org>
* file.c (file_path_convert): fix fs_encoding is not assign.

37
error.c
Просмотреть файл

@ -24,6 +24,17 @@
extern const char ruby_description[];
static const char *
rb_strerrno(int err)
{
#define defined_error(name, num) if (err == num) return name;
#define undefined_error(name)
#include "known_errors.inc"
#undef defined_error
#undef undefined_error
return NULL;
}
static int
err_position_0(char *buf, long len, const char *file, int line)
{
@ -235,6 +246,20 @@ rb_bug(const char *fmt, ...)
abort();
}
void
rb_bug_errno(const char *mesg, int errno_arg)
{
if (errno_arg == 0)
rb_bug("%s: errno == 0 (NOERROR)", mesg);
else {
const char *errno_str = rb_strerrno(errno_arg);
if (errno_str)
rb_bug("%s: %s (%s)", mesg, strerror(errno_arg), errno_str);
else
rb_bug("%s: %s (%d)", mesg, strerror(errno_arg), errno_arg);
}
}
void
rb_compile_bug(const char *file, int line, const char *fmt, ...)
{
@ -1258,18 +1283,6 @@ Init_syserr(void)
#undef undefined_error
}
const char *
rb_strerrno(int err)
{
if (err == 0) return "NOERROR";
#define defined_error(name, num) if (err == num) return name;
#define undefined_error(name)
#include "known_errors.inc"
#undef defined_error
#undef undefined_error
return "UNKNOWNERROR";
}
static void
err_append(const char *s)
{

Просмотреть файл

@ -200,7 +200,6 @@ PRINTF_ARGS(void rb_compile_error_append(const char*, ...), 1, 2);
NORETURN(void rb_load_fail(const char*));
NORETURN(void rb_error_frozen(const char*));
void rb_check_frozen(VALUE);
const char *rb_strerrno(int);
/* eval.c */
int rb_sourceline(void);
const char *rb_sourcefile(void);

Просмотреть файл

@ -1100,6 +1100,7 @@ VALUE *rb_ruby_debug_ptr(void);
PRINTF_ARGS(NORETURN(void rb_raise(VALUE, const char*, ...)), 2, 3);
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_mod_sys_fail(VALUE, const char*));
NORETURN(void rb_iter_break(void));

Просмотреть файл

@ -487,7 +487,7 @@ ruby_signal(int signum, sighandler_t handler)
#endif
if (sigaction(signum, &sigact, &old) < 0) {
if (errno != 0 && errno != EINVAL) {
rb_bug("sigaction error.\n");
rb_bug_errno("sigaction", errno);
}
}
return old.sa_handler;

Просмотреть файл

@ -34,7 +34,7 @@ native_mutex_lock(pthread_mutex_t *lock)
{
int r;
if ((r = pthread_mutex_lock(lock)) != 0) {
rb_bug("pthread_mutex_lock: %s (%s)", strerror(r), rb_strerrno(r));
rb_bug_errno("pthread_mutex_lock", r);
}
}
@ -43,7 +43,7 @@ native_mutex_unlock(pthread_mutex_t *lock)
{
int r;
if ((r = pthread_mutex_unlock(lock)) != 0) {
rb_bug("pthread_mutex_unlock: %s (%s)", strerror(r), rb_strerrno(r));
rb_bug_errno("pthread_mutex_unlock", r);
}
}
@ -56,7 +56,7 @@ native_mutex_trylock(pthread_mutex_t *lock)
return EBUSY;
}
else {
rb_bug("pthread_mutex_trylock: %s (%s)", strerror(r), rb_strerrno(r));
rb_bug_errno("pthread_mutex_trylock", r);
}
}
return 0;
@ -67,7 +67,7 @@ native_mutex_initialize(pthread_mutex_t *lock)
{
int r = pthread_mutex_init(lock, 0);
if (r != 0) {
rb_bug("pthread_mutex_init: %s (%s)", strerror(r), rb_strerrno(r));
rb_bug_errno("pthread_mutex_init", r);
}
}
@ -78,7 +78,7 @@ native_mutex_destroy(pthread_mutex_t *lock)
{
int r = pthread_mutex_destroy(lock);
if (r != 0) {
rb_bug("pthread_mutex_destroy: %s (%s)", strerror(r), rb_strerrno(r));
rb_bug_errno("pthread_mutex_destroy", r);
}
}
@ -87,7 +87,7 @@ native_cond_initialize(pthread_cond_t *cond)
{
int r = pthread_cond_init(cond, 0);
if (r != 0) {
rb_bug("pthread_cond_init: %s (%s)", strerror(r), rb_strerrno(r));
rb_bug_errno("pthread_cond_init", r);
}
}
@ -96,7 +96,7 @@ native_cond_destroy(pthread_cond_t *cond)
{
int r = pthread_cond_destroy(cond);
if (r != 0) {
rb_bug("pthread_cond_destroy: %s (%s)", strerror(r), rb_strerrno(r));
rb_bug_errno("pthread_cond_destroy", r);
}
}
@ -304,7 +304,7 @@ ruby_init_stack(volatile VALUE *addr
}
#define CHECK_ERR(expr) \
{int err = (expr); if (err) {rb_bug("%s: %s (%s)", #expr, strerror(err), rb_strerrno(err));}}
{int err = (expr); if (err) {rb_bug_errno(#expr, err);}}
static int
native_thread_init_stack(rb_thread_t *th)
@ -621,7 +621,7 @@ native_sleep(rb_thread_t *th, struct timeval *tv)
thread_debug("native_sleep: pthread_cond_wait start\n");
r = pthread_cond_wait(&th->native_thread_data.sleep_cond,
&th->interrupt_lock);
if (r) rb_bug("pthread_cond_wait: %s (%s)", strerror(r), rb_strerrno(r));
if (r) rb_bug_errno("pthread_cond_wait", r);
thread_debug("native_sleep: pthread_cond_wait end\n");
}
else {
@ -630,7 +630,7 @@ native_sleep(rb_thread_t *th, struct timeval *tv)
(unsigned long)ts.tv_sec, ts.tv_nsec);
r = pthread_cond_timedwait(&th->native_thread_data.sleep_cond,
&th->interrupt_lock, &ts);
if (r && r != ETIMEDOUT) rb_bug("pthread_cond_timedwait: %s (%s)", strerror(r), rb_strerrno(r));
if (r && r != ETIMEDOUT) rb_bug_errno("pthread_cond_timedwait", r);
thread_debug("native_sleep: pthread_cond_timedwait end (%d)\n", r);
}
@ -763,7 +763,7 @@ thread_timer(void *dummy)
else if (err == 0 || err == EINTR) {
if (rb_signal_buff_size() == 0) break;
}
else rb_bug("thread_timer/timedwait: %s (%s)", strerror(err), rb_strerrno(err));
else rb_bug_errno("thread_timer/timedwait", err);
#if !defined(__CYGWIN__) && !defined(__SYMBIAN32__)
if (signal_thread_list_anchor.next) {