diff --git a/ChangeLog b/ChangeLog index de1c8443df..012f228309 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +Tue Nov 24 09:18:33 2009 Tanaka Akira + + * include/ruby/intern.h (rb_strerrno): declared. + + * template/known_errors.inc.tmpl: generate defined_error() and + undefined_error() instead of set_syserr. + + * error.c (Init_syserr): define defined_error() and undefined_error() + to follow the above change. + (rb_strerrno): defined. + + * thread_pthread.c: show error message and errno macro name with + rb_bug. + Mon Nov 23 16:06:53 2009 Nobuyoshi Nakada * thread_pthread.c (RUBY_STACK_MIN, RUBY_STACK_SPACE): delay for diff --git a/error.c b/error.c index 6297584ecd..aeacc4d130 100644 --- a/error.c +++ b/error.c @@ -1247,10 +1247,26 @@ rb_check_frozen(VALUE obj) if (OBJ_FROZEN(obj)) rb_error_frozen(rb_obj_classname(obj)); } -void Init_syserr(void) +void +Init_syserr(void) { rb_eNOERROR = set_syserr(0, "NOERROR"); +#define defined_error(name, num) set_syserr(num, name); +#define undefined_error(name) set_syserr(0, name); #include "known_errors.inc" +#undef defined_error +#undef undefined_error +} + +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 "NOERROR"; } static void diff --git a/include/ruby/intern.h b/include/ruby/intern.h index fd37ecab2a..87f5741425 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -200,6 +200,7 @@ 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); +char *rb_strerrno(int); /* eval.c */ int rb_sourceline(void); const char *rb_sourcefile(void); diff --git a/template/known_errors.inc.tmpl b/template/known_errors.inc.tmpl index c62114464f..deb54e44d7 100644 --- a/template/known_errors.inc.tmpl +++ b/template/known_errors.inc.tmpl @@ -7,8 +7,8 @@ % error_names = ARGF.read.split(/\s+/) % error_names.each do |name| #ifdef <%=name%> - set_syserr(<%=name%>, "<%=name%>"); + defined_error("<%=name%>", <%=name%>) #else - set_syserr(0, "<%=name%>"); + undefined_error("<%=name%>") #endif % end diff --git a/thread_pthread.c b/thread_pthread.c index 0d37a12130..3e5e94dd26 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -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: %d", r); + rb_bug("pthread_mutex_lock: %s (%s)", strerror(r), rb_strerrno(r)); } } @@ -43,7 +43,7 @@ native_mutex_unlock(pthread_mutex_t *lock) { int r; if ((r = pthread_mutex_unlock(lock)) != 0) { - rb_bug("native_mutex_unlock return non-zero: %d", r); + rb_bug("pthread_mutex_unlock: %s (%s)", strerror(r), rb_strerrno(r)); } } @@ -56,7 +56,7 @@ native_mutex_trylock(pthread_mutex_t *lock) return EBUSY; } else { - rb_bug("native_mutex_trylock return non-zero: %d", r); + rb_bug("pthread_mutex_trylock: %s (%s)", strerror(r), rb_strerrno(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("native_mutex_initialize return non-zero: %d", r); + rb_bug("pthread_mutex_init: %s (%s)", strerror(r), rb_strerrno(r)); } } @@ -78,7 +78,7 @@ native_mutex_destroy(pthread_mutex_t *lock) { int r = pthread_mutex_destroy(lock); if (r != 0) { - rb_bug("native_mutex_destroy return non-zero: %d", r); + rb_bug("pthread_mutex_destroy: %s (%s)", strerror(r), rb_strerrno(r)); } } @@ -87,7 +87,7 @@ native_cond_initialize(pthread_cond_t *cond) { int r = pthread_cond_init(cond, 0); if (r != 0) { - rb_bug("native_cond_initialize return non-zero: %d", r); + rb_bug("pthread_cond_init: %s (%s)", strerror(r), rb_strerrno(r)); } } @@ -96,7 +96,7 @@ native_cond_destroy(pthread_cond_t *cond) { int r = pthread_cond_destroy(cond); if (r != 0) { - rb_bug("native_cond_destroy return non-zero: %d", r); + rb_bug("pthread_cond_destroy: %s (%s)", strerror(r), rb_strerrno(r)); } } @@ -304,7 +304,7 @@ ruby_init_stack(volatile VALUE *addr } #define CHECK_ERR(expr) \ - {int err = (expr); if (err) {rb_bug("err: %d - %s", err, #expr);}} + {int err = (expr); if (err) {rb_bug("%s: %s (%s)", #expr, strerror(err), rb_strerrno(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: %d", r); + if (r) rb_bug("pthread_cond_wait: %s (%s)", strerror(r), rb_strerrno(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: %d", r); + if (r && r != ETIMEDOUT) rb_bug("pthread_cond_timedwait: %s (%s)", strerror(r), rb_strerrno(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: %d", err); + else rb_bug("thread_timer/timedwait: %s (%s)", strerror(err), rb_strerrno(err)); #if !defined(__CYGWIN__) && !defined(__SYMBIAN32__) if (signal_thread_list_anchor.next) {