From: Nobuyoshi Nakada <nobu@ruby-lang.org>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:18490] Re: [ANN] Ruby 1.9.1 feature freeze
Date: Mon, 8 Sep 2008 18:05:05 +0900 [thread overview]
Message-ID: <20080908091118.9417CE0C5E@mail.bc9.jp> (raw)
In-Reply-To: <E1Kc3wb-000509-MS@x61.netlab.jp>
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.
\f
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 */
\f
--
Nobu Nakada
next prev parent reply other threads:[~2008-09-08 9:12 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <966599840809022308q2d6f4370l1de6340c9f1fee8a@mail.gmail.com>
2008-09-04 16:13 ` [ruby-core:18452] [ANN] Ruby 1.9.1 feature freeze Roger Pack
2008-09-04 17:34 ` [ruby-core:18455] " hemant
2008-09-06 18:38 ` [ruby-core:18469] " Charles Oliver Nutter
2008-09-06 19:53 ` [ruby-core:18471] " Yukihiro Matsumoto
2008-09-06 21:23 ` [ruby-core:18474] " Wilson Bilkovich
2008-09-08 4:02 ` [ruby-core:18487] " Roger Pack
2008-09-08 9:05 ` Nobuyoshi Nakada [this message]
2008-09-08 9:36 ` [ruby-core:18491] " Yukihiro Matsumoto
2008-09-08 11:22 ` [ruby-core:18493] " Trans
2008-09-09 8:30 ` [ruby-core:18519] " Yukihiro Matsumoto
2008-09-09 23:39 ` [ruby-core:18528] " Trans
2008-09-08 14:41 ` [ruby-core:18496] " Wilson Bilkovich
[not found] ` <966599840809080824t69da9db3saec127e89bb6069@mail.gmail.com>
2008-09-08 15:20 ` [ruby-core:18497] " Roger Pack
2008-09-08 18:26 ` [ruby-core:18501] " Wilson Bilkovich
2008-09-09 1:40 ` [ruby-core:18509] " Charles Oliver Nutter
[not found] ` <966599840809091113k4c738de3kcfdb74bd747ac1d4@mail.gmail.com>
2008-09-09 18:21 ` [ruby-core:18521] " Roger Pack
2008-09-10 17:01 ` [ruby-core:18546] " Paul Brannan
2008-09-16 20:10 ` [ruby-core:18636] " Roger Pack
2008-09-08 15:24 ` [ruby-core:18498] " Robert Klemme
2008-09-08 19:27 ` [ruby-core:18502] " Joel VanderWerf
2008-09-20 18:49 ` [ruby-core:18763] " Roger Pack
2008-09-25 1:18 ` [ruby-core:18875] " Nobuyoshi Nakada
[not found] ` <966599840809251625t77060aedq4248037a6c95cc84@mail.gmail.com>
2008-09-26 4:17 ` [ruby-core:18970] " Roger Pack
2008-09-26 14:09 ` [ruby-core:18978] " Nobuyoshi Nakada
2008-09-26 16:19 ` [ruby-core:18981] " Roger Pack
2008-09-26 18:25 ` [ruby-core:18984] " Nobuyoshi Nakada
2008-12-19 21:55 ` [ruby-core:20708] " Roger Pack
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080908091118.9417CE0C5E@mail.bc9.jp \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).