From 430f5a1d61a1dae175f1e29840f7e7a91c1eaf1c Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 5 Dec 2007 07:18:52 +0000 Subject: * proc.c (rb_proc_s_new): call initialize. [ruby-core:13824] * proc.c (rb_proc_location): return file name and line number where the proc is defined. * thread.c (thread_s_new): call initialize. [ruby-core:13835] * thread.c (thread_initialize): split initialize method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14109 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- proc.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'proc.c') diff --git a/proc.c b/proc.c index 5f9e697f3e..d2bf571393 100644 --- a/proc.c +++ b/proc.c @@ -304,9 +304,12 @@ proc_new(VALUE klass, int is_lambda) */ static VALUE -rb_proc_s_new(VALUE klass) +rb_proc_s_new(int argc, VALUE *argv, VALUE klass) { - return proc_new(klass, Qfalse); + VALUE block = proc_new(klass, Qfalse); + + rb_obj_call_init(block, argc, argv); + return block; } /* @@ -471,6 +474,36 @@ rb_proc_arity(VALUE proc) return FIX2INT(proc_arity(proc)); } +static rb_iseq_t * +get_proc_iseq(VALUE self) +{ + rb_proc_t *proc; + rb_iseq_t *iseq; + + GetProcPtr(self, proc); + iseq = proc->block.iseq; + if (!RUBY_VM_NORMAL_ISEQ_P(iseq)) + return 0; + return iseq; +} + +VALUE +rb_proc_location(VALUE self) +{ + rb_iseq_t *iseq = get_proc_iseq(self); + VALUE loc[2]; + + if (!iseq) return Qnil; + loc[0] = iseq->filename; + if (iseq->insn_info_table) { + loc[1] = INT2FIX(iseq->insn_info_table[0].line_no); + } + else { + loc[1] = Qnil; + } + return rb_ary_new4(2, loc); +} + /* * call-seq: * prc == other_proc => true or false @@ -1438,7 +1471,7 @@ Init_Proc(void) /* Proc */ rb_cProc = rb_define_class("Proc", rb_cObject); rb_undef_alloc_func(rb_cProc); - rb_define_singleton_method(rb_cProc, "new", rb_proc_s_new, 0); + rb_define_singleton_method(rb_cProc, "new", rb_proc_s_new, -1); rb_define_method(rb_cProc, "call", proc_call, -1); rb_define_method(rb_cProc, "[]", proc_call, -1); rb_define_method(rb_cProc, "yield", proc_yield, -1); -- cgit v1.2.3