From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id B0E5D1F03AF for ; Mon, 8 Sep 2008 18:12:12 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id BAF5915F0B for ; Mon, 8 Sep 2008 18:11:27 +0900 (JST) Received: from localhost (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id A19CD14201B for ; Mon, 8 Sep 2008 18:11:31 +0900 (JST) X-Virus-Scanned: amavisd-new at funfun.nagaokaut.ac.jp Received: from funfun.nagaokaut.ac.jp ([127.0.0.1]) by localhost (funfun.nagaokaut.ac.jp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id T-Y9WyYGumY3 for ; Mon, 8 Sep 2008 18:11:31 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 7EAC014200A for ; Mon, 8 Sep 2008 18:11:31 +0900 (JST) Received: from carbon.ruby-lang.org (carbon.ruby-lang.org [221.186.184.68]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id ECAF3952461 for ; Mon, 8 Sep 2008 18:11:27 +0900 (JST) Received: from beryllium.ruby-lang.org (beryllium.ruby-lang.org [127.0.0.1]) by carbon.ruby-lang.org (Postfix) with ESMTP id 2E2703C22944B; Mon, 8 Sep 2008 18:05:13 +0900 (JST) Received: from mta21.asp.home.ne.jp (mta21.asp.home.ne.jp [203.165.10.229]) by carbon.ruby-lang.org (Postfix) with ESMTP id 286993C229418 for ; Mon, 8 Sep 2008 18:05:05 +0900 (JST) Received: by mta21.asp.home.ne.jp (8.14.1/v8081100) with ESMTP id m889BJ69029375 for ; Mon, 8 Sep 2008 18:11:19 +0900 (JST) Received: from mail.bc9.jp (www.bc9.jp [202.89.240.19]) by mxo32.asp.home.ne.jp (8.14.1/v8081100) with ESMTP id m889BI5a020857 for ; Mon, 8 Sep 2008 18:11:18 +0900 (JST) Received: from sharui.kanuma.tochigi (202-127-187-186.users.bc9.ne.jp [202.127.187.186]) by mail.bc9.jp (Postfix) with ESMTP id 9417CE0C5E for ; Mon, 8 Sep 2008 18:11:18 +0900 (JST) Delivered-To: ruby-core@ruby-lang.org Date: Mon, 8 Sep 2008 18:05:05 +0900 Posted: Mon, 08 Sep 2008 18:11:18 +0900 From: Nobuyoshi Nakada Reply-To: ruby-core@ruby-lang.org Subject: [ruby-core:18490] Re: [ANN] Ruby 1.9.1 feature freeze To: ruby-core@ruby-lang.org Message-Id: <20080908091118.9417CE0C5E@mail.bc9.jp> In-Reply-To: References: <966599840809040919v3b4868d7mbb5acce180a30b3d@mail.gmail.com> X-ML-Name: ruby-core X-Mail-Count: 18490 X-MLServer: fml [fml 4.0.3 release (20011202/4.0.3)]; post only (only members can post) X-ML-Info: If you have a question, send e-mail with the body "help" (without quotes) to the address ruby-core-ctl@ruby-lang.org; help= User-Agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL/10.7 Emacs/22.2 (i486-pc-linux-gnu) MULE/5.0 (SAKAKI) X-Spam-Checker-Version: SpamAssassin 3.1.7-deb (2006-10-05) on carbon.ruby-lang.org X-Spam-Level: X-Spam-Status: No, score=-4.9 required=7.0 tests=AWL,BAYES_00,CN_202_127, CONTENT_TYPE_PRESENT,FORGED_RCVD_HELO autolearn=disabled version=3.1.7-deb Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-Id: ruby-core.ruby-lang.org List-Software: fml [fml 4.0.3 release (20011202/4.0.3)] List-Post: List-Owner: List-Help: List-Unsubscribe: Hi, At Sun, 7 Sep 2008 04:53:43 +0900, Yukihiro Matsumoto wrote in [ruby-core:18471]: > This is a proposal to add __file__ and __line__ methods to Method and > Proc objects. Issues are: > > * the method names. I don't think proposed names that are > surrounded by underscores are appropriate. > * non-Ruby defined methods/procs. the patch raises TypeError, but > is it really appropriate? Should they return nil for such cases? > * use-case. the proposal comes with use-case sourceref.rb, but any > other use case? I propose a new method, #location than those two new methods. Index: proc.c =================================================================== --- proc.c (revision 19215) +++ proc.c (working copy) @@ -510,9 +510,9 @@ proc_call(int argc, VALUE *argv, VALUE p rb_proc_t *proc; rb_block_t *blockptr = 0; + rb_iseq_t *iseq; GetProcPtr(procval, proc); - if (BUILTIN_TYPE(proc->block.iseq) == T_NODE || - proc->block.iseq->arg_block != -1) { - + iseq = proc->block.iseq; + if (BUILTIN_TYPE(iseq) == T_NODE || iseq->arg_block != -1) { if (rb_block_given_p()) { rb_proc_t *proc; @@ -621,8 +621,7 @@ get_proc_iseq(VALUE self) } -VALUE -rb_proc_location(VALUE self) +static VALUE +iseq_location(rb_iseq_t *iseq) { - rb_iseq_t *iseq = get_proc_iseq(self); VALUE loc[2]; @@ -640,4 +639,18 @@ rb_proc_location(VALUE self) /* * call-seq: + * prc.location => [String, Fixnum] + * + * returns the ruby source filename and line number containing this proc + * or nil if this proc was not defined in ruby (i.e. native) + */ + +VALUE +rb_proc_location(VALUE self) +{ + return iseq_location(get_proc_iseq(self)); +} + +/* + * call-seq: * prc == other_proc => true or false * @@ -1438,4 +1451,37 @@ rb_obj_method_arity(VALUE obj, ID id) } +static rb_iseq_t * +get_method_iseq(VALUE method) +{ + struct METHOD *data; + NODE *body; + rb_iseq_t *iseq; + + Data_Get_Struct(method, struct METHOD, data); + body = data->body; + switch (nd_type(body)) { + case RUBY_VM_METHOD_NODE: + GetISeqPtr((VALUE)body->nd_body, iseq); + if (RUBY_VM_NORMAL_ISEQ_P(iseq)) break; + default: + return 0; + } + return iseq; +} + +/* + * call-seq: + * meth.location => [String, Fixnum] + * + * returns the ruby source filename and line number containing this method + * or nil if this method was not defined in ruby (i.e. native) + */ + +VALUE +rb_method_location(VALUE method) +{ + return iseq_location(get_method_iseq(method)); +} + /* * call-seq: @@ -1769,4 +1815,5 @@ Init_Proc(void) rb_define_method(rb_cProc, "binding", proc_binding, 0); rb_define_method(rb_cProc, "curry", proc_curry, -1); + rb_define_method(rb_cProc, "location", rb_proc_location, 0); /* Exceptions */ @@ -1803,4 +1850,5 @@ Init_Proc(void) rb_define_method(rb_cMethod, "owner", method_owner, 0); rb_define_method(rb_cMethod, "unbind", method_unbind, 0); + rb_define_method(rb_cMethod, "location", rb_method_location, 0); rb_define_method(rb_mKernel, "method", rb_obj_method, 1); rb_define_method(rb_mKernel, "public_method", rb_obj_public_method, 1); @@ -1820,4 +1868,5 @@ Init_Proc(void) rb_define_method(rb_cUnboundMethod, "owner", method_owner, 0); rb_define_method(rb_cUnboundMethod, "bind", umethod_bind, 1); + rb_define_method(rb_cUnboundMethod, "location", rb_method_location, 0); /* Module#*_method */ -- Nobu Nakada