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 D3F5C324005 for ; Sun, 21 Sep 2008 03:59:02 +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 B05EB15E00 for ; Sun, 21 Sep 2008 03:57:57 +0900 (JST) Received: from localhost (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 39D7E142011 for ; Sun, 21 Sep 2008 03:57:58 +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 qoZoznVL5t3R for ; Sun, 21 Sep 2008 03:57:58 +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 15EA5142008 for ; Sun, 21 Sep 2008 03:57:58 +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 EE175952446 for ; Sun, 21 Sep 2008 03:57:56 +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 682DC3C21ED54; Sun, 21 Sep 2008 03:49:52 +0900 (JST) Received: from hs-out-0708.google.com (hs-out-0708.google.com [64.233.178.245]) by carbon.ruby-lang.org (Postfix) with ESMTP id D98323C21F130 for ; Sun, 21 Sep 2008 03:49:49 +0900 (JST) Received: by hs-out-0708.google.com with SMTP id j58so198480hsj.7 for ; Sat, 20 Sep 2008 11:57:46 -0700 (PDT) Received: by 10.100.41.4 with SMTP id o4mr1515518ano.7.1221937066291; Sat, 20 Sep 2008 11:57:46 -0700 (PDT) Received: by 10.100.12.13 with HTTP; Sat, 20 Sep 2008 11:57:46 -0700 (PDT) Delivered-To: ruby-core@ruby-lang.org Date: Sun, 21 Sep 2008 03:49:50 +0900 Posted: Sat, 20 Sep 2008 12:57:46 -0600 From: "Roger Pack" Reply-To: ruby-core@ruby-lang.org Subject: [ruby-core:18763] Re: [ANN] Ruby 1.9.1 feature freeze Sender: rogerpack2005@gmail.com To: ruby-core@ruby-lang.org Message-Id: <966599840809201157k293a6f04j67df3e164743c70a@mail.gmail.com> In-Reply-To: <20080908091118.9417CE0C5E@mail.bc9.jp> References: <966599840809040919v3b4868d7mbb5acce180a30b3d@mail.gmail.com> <20080908091118.9417CE0C5E@mail.bc9.jp> X-ML-Name: ruby-core X-Mail-Count: 18763 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= 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=-2.8 required=7.0 tests=ARIN,AWL,BAYES_00, CONTENT_TYPE_PRESENT,QENCPTR2 autolearn=disabled version=3.1.7-deb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender :to:subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references :x-google-sender-auth; bh=VN21q5IkhcOU6cCGomGHVOwfsqM/uNBnlMEgqjtrvo0=; b=OMbPDKBlWj/K1PjsTGqd2Z6AaOs6wo+0xMDw52ndTD6uvSVsHpnLsQTIyJyxNHPS8X TBXEUHEmmlCYmMxAj+6j6Kk8NoOyLfMyHtAX+qh0V1MJbyEzq6ZyIZY4CWQr3NsnkCFX DSaiIV6BykM6Z09cxXkdXJYSK3FDKp0Gx8MCo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references:x-google-sender-auth; b=d13jxsLgLRd8L3/SeZOJ7MPL95gtVLrbXdNLuyKBJe9BBixzBxJEMFsZM2E8hXcIym fjIuJGrGEtBA2cdDf+rFWm7CmDcL5w6UwkBhW4nQgzO8h3kvdsDtexXozRF2wB5KZwfV wvP1cdjtIKZbA3MbKeNzMh3mFgh4+1JIBCgpo= Content-Disposition: inline X-Google-Sender-Auth: 3f0998badfcaaa35 Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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: > I propose a new method, #location than those two new methods. ... > -- > Nobu Nakada Interestingly, there already was an rb_proc_location method in 1.9 [just no Proc#location nor Method#location nor Binding#location]. Anyway, here's Nobu Nakada's patch with the method name changed to source_location [should work against SVN head]. Note also the recent creation of Feature #578: add method to disassemble Proc objects Thanks for your help. I know I'm annoying with this :) -=R Index: proc.c =================================================================== --- proc.c (revision 19438) +++ proc.c (working copy) @@ -509,11 +509,11 @@ { rb_proc_t *proc; rb_block_t *blockptr = 0; + rb_iseq_t *iseq; GetProcPtr(procval, proc); + iseq = proc->block.iseq; + if (BUILTIN_TYPE(iseq) == T_NODE || iseq->arg_block != -1) { - if (BUILTIN_TYPE(proc->block.iseq) == T_NODE || - proc->block.iseq->arg_block != -1) { - if (rb_block_given_p()) { rb_proc_t *proc; VALUE procval; @@ -620,10 +620,9 @@ return iseq; } -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]; if (!iseq) return Qnil; @@ -639,6 +638,20 @@ /* * call-seq: + * prc.source_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_source_location(VALUE self) +{ + return iseq_location(get_proc_iseq(self)); +} + +/* + * call-seq: * prc == other_proc => true or false * * Return true if prc is the same object as @@ -1437,7 +1450,40 @@ return rb_mod_method_arity(CLASS_OF(obj), 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.source_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_source_location(VALUE method) +{ + return iseq_location(get_method_iseq(method)); +} + +/* * call-seq: * meth.to_s => string * meth.inspect => string @@ -1768,6 +1814,7 @@ rb_define_method(rb_cProc, "lambda?", proc_lambda_p, 0); rb_define_method(rb_cProc, "binding", proc_binding, 0); rb_define_method(rb_cProc, "curry", proc_curry, -1); + rb_define_method(rb_cProc, "source_location", rb_proc_source_location, 0); /* Exceptions */ rb_eLocalJumpError = rb_define_class("LocalJumpError", rb_eStandardError); @@ -1802,6 +1849,7 @@ rb_define_method(rb_cMethod, "name", method_name, 0); rb_define_method(rb_cMethod, "owner", method_owner, 0); rb_define_method(rb_cMethod, "unbind", method_unbind, 0); + rb_define_method(rb_cMethod, "source_location", rb_method_source_location, 0); rb_define_method(rb_mKernel, "method", rb_obj_method, 1); rb_define_method(rb_mKernel, "public_method", rb_obj_public_method, 1); @@ -1819,6 +1867,7 @@ rb_define_method(rb_cUnboundMethod, "name", method_name, 0); rb_define_method(rb_cUnboundMethod, "owner", method_owner, 0); rb_define_method(rb_cUnboundMethod, "bind", umethod_bind, 1); + rb_define_method(rb_cUnboundMethod, "source_location", rb_method_source_location, 0); /* Module#*_method */ rb_define_method(rb_cModule, "instance_method", rb_mod_instance_method, 1); Index: thread.c =================================================================== --- thread.c (revision 19438) +++ thread.c (working copy) @@ -528,10 +528,10 @@ } GetThreadPtr(thread, th); if (th->first_args) { - VALUE rb_proc_location(VALUE self); + VALUE rb_proc_source_location(VALUE self); VALUE proc = th->first_proc, line, loc; const char *file; - if (!proc || !RTEST(loc = rb_proc_location(proc))) { + if (!proc || !RTEST(loc = rb_proc_source_location(proc))) { rb_raise(rb_eThreadError, "already initialized thread"); } file = RSTRING_PTR(RARRAY_PTR(loc)[0]);