Revision: 4493 http://trac.macosforge.org/projects/ruby/changeset/4493 Author: lsansonetti@apple.com Date: 2010-09-02 19:37:28 -0700 (Thu, 02 Sep 2010) Log Message: ----------- when a thread exists prematurely because of an exception, write a message on stderr once the thread object is being finalized only if #join was never called Modified Paths: -------------- MacRuby/trunk/thread.c MacRuby/trunk/vm.cpp MacRuby/trunk/vm.h Modified: MacRuby/trunk/thread.c =================================================================== --- MacRuby/trunk/thread.c 2010-09-03 01:59:54 UTC (rev 4492) +++ MacRuby/trunk/thread.c 2010-09-03 02:37:28 UTC (rev 4493) @@ -10,6 +10,7 @@ #include "ruby/macruby.h" #include "ruby/node.h" #include "vm.h" +#include "objc.h" VALUE rb_cThread; VALUE rb_cThGroup; @@ -47,6 +48,23 @@ return Data_Wrap_Struct(rb_cThread, NULL, NULL, t); } +static IMP +thread_finalize_imp_super = NULL; + +static void +thread_finalize_imp(void *rcv, SEL sel) +{ + rb_vm_thread_t *t = GetThreadPtr(rcv); + if (t->exception != Qnil && !t->joined_on_exception) { + fprintf(stderr, "*** Thread %p exited prematurely because of an uncaught exception:\n%s\n", + t->thread, + rb_str_cstr(rb_format_exception_message(t->exception))); + } + if (thread_finalize_imp_super != NULL) { + ((void(*)(void *, SEL))thread_finalize_imp_super)(rcv, sel); + } +} + static VALUE thread_initialize(VALUE thread, SEL sel, int argc, const VALUE *argv) { @@ -215,9 +233,9 @@ // If the thread was terminated because of an exception, we need to // propagate it. if (t->exception != Qnil) { + t->joined_on_exception = true; rb_exc_raise(t->exception); } - return self; } @@ -1568,6 +1586,9 @@ rb_cThread = rb_define_class("Thread", rb_cObject); rb_objc_define_method(*(VALUE *)rb_cThread, "alloc", thread_s_alloc, 0); + thread_finalize_imp_super = rb_objc_install_method2((Class)rb_cThread, + "finalize", (IMP)thread_finalize_imp); + rb_objc_define_method(*(VALUE *)rb_cThread, "start", thread_start, -1); rb_objc_define_method(*(VALUE *)rb_cThread, "fork", thread_start, -1); rb_objc_define_method(*(VALUE *)rb_cThread, "main", rb_thread_s_main, 0); Modified: MacRuby/trunk/vm.cpp =================================================================== --- MacRuby/trunk/vm.cpp 2010-09-03 01:59:54 UTC (rev 4492) +++ MacRuby/trunk/vm.cpp 2010-09-03 02:37:28 UTC (rev 4493) @@ -4543,6 +4543,7 @@ t->status = THREAD_ALIVE; t->in_cond_wait = false; t->abort_on_exception = false; + t->joined_on_exception = false; t->group = Qnil; // will be set right after t->mutexes = Qnil; Modified: MacRuby/trunk/vm.h =================================================================== --- MacRuby/trunk/vm.h 2010-09-03 01:59:54 UTC (rev 4492) +++ MacRuby/trunk/vm.h 2010-09-03 02:37:28 UTC (rev 4493) @@ -150,6 +150,7 @@ rb_vm_thread_status_t status; bool in_cond_wait; bool abort_on_exception; // per-local state, global one is in RoxorCore + bool joined_on_exception; VALUE locals; // a Hash object or Qnil VALUE exception; // killed-by exception or Qnil VALUE group; // always a ThreadGroup object
participants (1)
-
source_changes@macosforge.org