зеркало из https://github.com/github/ruby.git
Define Thread#to_s (as Thread#inspect) and make alias `inspect` as `to_s`.
* thread.c: "Thread#to_s" is not defined without any reason. So this fix define "Thread#to_s" which returns a string with some thread information. Also this fix makes alias "inspect" which refers "to_s". This manner is same as other objects. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59560 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
93fd7e5639
Коммит
27535987be
11
thread.c
11
thread.c
|
@ -552,7 +552,7 @@ thread_cleanup_func(void *th_ptr, int atfork)
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE rb_threadptr_raise(rb_thread_t *, int, VALUE *);
|
static VALUE rb_threadptr_raise(rb_thread_t *, int, VALUE *);
|
||||||
static VALUE rb_thread_inspect(VALUE thread);
|
static VALUE rb_thread_to_s(VALUE thread);
|
||||||
|
|
||||||
void
|
void
|
||||||
ruby_thread_init_stack(rb_thread_t *th)
|
ruby_thread_init_stack(rb_thread_t *th)
|
||||||
|
@ -641,7 +641,7 @@ thread_start_func_2(rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_s
|
||||||
/* exit on main_thread */
|
/* exit on main_thread */
|
||||||
}
|
}
|
||||||
else if (th->report_on_exception) {
|
else if (th->report_on_exception) {
|
||||||
VALUE mesg = rb_thread_inspect(th->self);
|
VALUE mesg = rb_thread_to_s(th->self);
|
||||||
rb_str_cat_cstr(mesg, " terminated with exception:\n");
|
rb_str_cat_cstr(mesg, " terminated with exception:\n");
|
||||||
rb_write_error_str(mesg);
|
rb_write_error_str(mesg);
|
||||||
rb_threadptr_error_print(th, errinfo);
|
rb_threadptr_error_print(th, errinfo);
|
||||||
|
@ -2961,13 +2961,13 @@ rb_thread_setname(VALUE thread, VALUE name)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* thr.inspect -> string
|
* thr.to_s -> string
|
||||||
*
|
*
|
||||||
* Dump the name, id, and status of _thr_ to a string.
|
* Dump the name, id, and status of _thr_ to a string.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_thread_inspect(VALUE thread)
|
rb_thread_to_s(VALUE thread)
|
||||||
{
|
{
|
||||||
VALUE cname = rb_class_path(rb_obj_class(thread));
|
VALUE cname = rb_class_path(rb_obj_class(thread));
|
||||||
rb_thread_t *target_th = rb_thread_ptr(thread);
|
rb_thread_t *target_th = rb_thread_ptr(thread);
|
||||||
|
@ -4851,7 +4851,8 @@ Init_Thread(void)
|
||||||
|
|
||||||
rb_define_method(rb_cThread, "name", rb_thread_getname, 0);
|
rb_define_method(rb_cThread, "name", rb_thread_getname, 0);
|
||||||
rb_define_method(rb_cThread, "name=", rb_thread_setname, 1);
|
rb_define_method(rb_cThread, "name=", rb_thread_setname, 1);
|
||||||
rb_define_method(rb_cThread, "inspect", rb_thread_inspect, 0);
|
rb_define_method(rb_cThread, "to_s", rb_thread_to_s, 0);
|
||||||
|
rb_define_alias(rb_cThread, "inspect", "to_s");
|
||||||
|
|
||||||
rb_vm_register_special_exception(ruby_error_stream_closed, rb_eIOError,
|
rb_vm_register_special_exception(ruby_error_stream_closed, rb_eIOError,
|
||||||
"stream closed in another thread");
|
"stream closed in another thread");
|
||||||
|
|
Загрузка…
Ссылка в новой задаче