aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-10-11 12:42:50 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-10-11 12:42:50 +0000
commitcc2334bd7bdeae8e91397576020d397a3d04af5f (patch)
tree93fcdac5b5aa7c4d11a6e011a89275cd2103ffac
parenta3cb2093ef475648c1845b70122639e9f69e85e7 (diff)
downloadruby-cc2334bd7bdeae8e91397576020d397a3d04af5f.tar.gz
* eval.c (rb_obj_respond_to): check if obj responds to the given
method with the given visibility. [ruby-dev:27408] * eval.c (rb_respond_to): conform to Object#respond_to?. [ruby-dev:27411] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--eval.c26
-rw-r--r--intern.h1
-rw-r--r--parse.y11
4 files changed, 23 insertions, 23 deletions
diff --git a/ChangeLog b/ChangeLog
index 5f1cc20636..9ec0b37945 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,4 @@
-Tue Oct 11 21:30:11 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Tue Oct 11 21:41:58 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (RUBY_FUNC_ATTRIBUTE): check prefixed attribute form
first. [ruby-dev:27398]
@@ -9,10 +9,10 @@ Tue Oct 11 21:30:11 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* util.h (qsort): removed the definition incompatible to ANSI.
fixed: [ruby-core:06147]
-Mon Oct 10 00:09:54 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+ * eval.c (rb_obj_respond_to): check if obj responds to the given
+ method with the given visibility. [ruby-dev:27408]
- * parse.y (ripper_initialize): rollback obj_respond_to().
- fixed: [ruby-dev:27406]
+ * eval.c (rb_respond_to): conform to Object#respond_to?. [ruby-dev:27411]
Sat Oct 8 19:49:42 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
diff --git a/eval.c b/eval.c
index d04180f11c..fdf0de938e 100644
--- a/eval.c
+++ b/eval.c
@@ -4011,19 +4011,27 @@ module_setup(VALUE module, NODE *n)
static NODE *basic_respond_to = 0;
int
-rb_respond_to(VALUE obj, ID id)
+rb_obj_respond_to(VALUE obj, ID id, int priv)
{
VALUE klass = CLASS_OF(obj);
- if (rb_method_node(klass, respond_to) == basic_respond_to &&
- rb_method_boundp(klass, id, 0)) {
- return Qtrue;
+
+ if (rb_method_node(klass, respond_to) == basic_respond_to) {
+ return rb_method_boundp(klass, id, !priv);
}
- else{
- return rb_funcall(obj, respond_to, 1, ID2SYM(id));
+ else {
+ VALUE args[2];
+ int n = 0;
+ args[n++] = ID2SYM(id);
+ if (priv) args[n++] = Qtrue;
+ return rb_funcall2(obj, respond_to, n, args);
}
- return Qfalse;
}
+int
+rb_respond_to(VALUE obj, ID id)
+{
+ return rb_obj_respond_to(obj, id, Qfalse);
+}
/*
* call-seq:
@@ -4035,7 +4043,7 @@ rb_respond_to(VALUE obj, ID id)
*/
static VALUE
-rb_obj_respond_to(int argc, VALUE *argv, VALUE obj)
+obj_respond_to(int argc, VALUE *argv, VALUE obj)
{
VALUE mid, priv;
ID id;
@@ -7553,7 +7561,7 @@ Init_eval(void)
rb_define_global_function("method_missing", rb_method_missing, -1);
rb_define_global_function("loop", rb_f_loop, 0);
- rb_define_method(rb_mKernel, "respond_to?", rb_obj_respond_to, -1);
+ rb_define_method(rb_mKernel, "respond_to?", obj_respond_to, -1);
respond_to = rb_intern("respond_to?");
basic_respond_to = rb_method_node(rb_cObject, respond_to);
rb_global_variable((VALUE*)&basic_respond_to);
diff --git a/intern.h b/intern.h
index db233fb290..4cd58b31d3 100644
--- a/intern.h
+++ b/intern.h
@@ -221,6 +221,7 @@ void rb_dvar_asgn(ID, VALUE);
void rb_dvar_push(ID, VALUE);
VALUE *rb_svar(int);
VALUE rb_eval_cmd(VALUE, VALUE, int);
+int rb_obj_respond_to(VALUE, ID, int);
int rb_respond_to(VALUE, ID);
void rb_interrupt(void);
VALUE rb_apply(VALUE, ID, VALUE);
diff --git a/parse.y b/parse.y
index f254817d22..86dcfc7cc8 100644
--- a/parse.y
+++ b/parse.y
@@ -8953,15 +8953,6 @@ ripper_s_allocate(VALUE klass)
return self;
}
-static int
-obj_respond_to(VALUE obj, VALUE mid)
-{
- VALUE st;
-
- st = rb_funcall(obj, rb_intern("respond_to?"), 2, mid, Qfalse);
- return RTEST(st);
-}
-
#define ripper_initialized_p(r) ((r)->parser_lex_input != 0)
/*
@@ -8982,7 +8973,7 @@ ripper_initialize(int argc, VALUE *argv, VALUE self)
Data_Get_Struct(self, struct parser_params, parser);
rb_scan_args(argc, argv, "12", &src, &fname, &lineno);
- if (obj_respond_to(src, ID2SYM(ripper_id_gets))) {
+ if (rb_obj_respond_to(src, ripper_id_gets, 0)) {
parser->parser_lex_gets = ripper_lex_get_generic;
}
else {