From 79f87024ee9d0f264c0ab81d0a89e889ab9fde43 Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Sat, 12 Nov 2016 23:14:15 +0900 Subject: proc.c: assume rb_iseq_location_t::first_lineno is always available rb_iseq_location_t::first_lineno (typically referenced as iseq->body->location.first_lineno, where iseq is an rb_iseq_t *) can always be assumed to contain a Fixnum regardless of whether struct rb_iseq_constant_body::line_info_table (likewise, iseq->body->line_info_table) is NULL or non-NULL. This fixes TypeError on starting a new thread with an empty Proc with trace instructions disabled. The TypeError comes from thread_pthread.c, in native_set_thread_name(), where it expects the line number returned from rb_proc_location(). The number can be nil if the line_info_table is NULL. The check seems to be the remains from the days before the dedicated 'first_lineno' field was introduced. So remove it. This also modifies two other places, Proc#to_s and method redefinition code, in the same way. --- proc.c | 15 ++++----------- vm_method.c | 6 +++--- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/proc.c b/proc.c index d72e1a9254..1cc36a083c 100644 --- a/proc.c +++ b/proc.c @@ -1076,12 +1076,8 @@ iseq_location(const rb_iseq_t *iseq) if (!iseq) return Qnil; rb_iseq_check(iseq); loc[0] = iseq->body->location.path; - if (iseq->body->line_info_table) { - loc[1] = rb_iseq_first_lineno(iseq); - } - else { - loc[1] = Qnil; - } + loc[1] = iseq->body->location.first_lineno; + return rb_ary_new4(2, loc); } @@ -1234,12 +1230,9 @@ proc_to_s_(VALUE self, const rb_proc_t *proc) case block_type_iseq: { const rb_iseq_t *iseq = rb_iseq_check(block->as.captured.code.iseq); - int first_lineno = 0; - if (iseq->body->line_info_table) { - first_lineno = FIX2INT(rb_iseq_first_lineno(iseq)); - } str = rb_sprintf("#<%s:%p@%"PRIsVALUE":%d%s>", cname, (void *)self, - iseq->body->location.path, first_lineno, is_lambda); + iseq->body->location.path, + FIX2INT(iseq->body->location.first_lineno), is_lambda); } break; case block_type_symbol: diff --git a/vm_method.c b/vm_method.c index 33e90cf9f1..8aea9b54cc 100644 --- a/vm_method.c +++ b/vm_method.c @@ -563,9 +563,9 @@ rb_method_entry_make(VALUE klass, ID mid, VALUE defined_class, rb_method_visibil default: break; } - if (iseq && !NIL_P(iseq->body->location.path)) { - int line = iseq->body->line_info_table ? FIX2INT(rb_iseq_first_lineno(iseq)) : 0; - rb_compile_warning(RSTRING_PTR(iseq->body->location.path), line, + if (iseq) { + rb_compile_warning(RSTRING_PTR(iseq->body->location.path), + FIX2INT(iseq->body->location.first_lineno), "previous definition of %"PRIsVALUE" was here", rb_id2str(old_def->original_id)); } -- cgit v1.2.3