Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed Module#method_defined?

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@3041 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
commit 9e76215b12fa07752da2a75a4281e714110bdf6c 1 parent cf6cf2f
Laurent Sansonetti authored
Showing with 33 additions and 28 deletions.
  1. +14 −7 dispatcher.cpp
  2. +2 −2 vm.h
  3. +17 −19 vm_method.c
View
21 dispatcher.cpp
@@ -1784,9 +1784,15 @@ rb_vm_get_method(VALUE klass, VALUE obj, ID mid, int scope)
extern IMP basic_respond_to_imp; // vm_method.c
bool
-RoxorCore::respond_to(VALUE obj, SEL sel, bool priv, bool check_override)
+RoxorCore::respond_to(VALUE obj, VALUE klass, SEL sel, bool priv,
+ bool check_override)
{
- VALUE klass = CLASS_OF(obj);
+ if (klass == Qnil) {
+ klass = CLASS_OF(obj);
+ }
+ else {
+ assert(!check_override);
+ }
const bool overriden = check_override
? (class_getMethodImplementation((Class)klass, selRespondTo)
@@ -1844,21 +1850,22 @@ RoxorCore::respond_to(VALUE obj, SEL sel, bool priv, bool check_override)
}
static bool
-respond_to(VALUE obj, SEL sel, bool priv, bool check_override)
+respond_to(VALUE obj, VALUE klass, SEL sel, bool priv, bool check_override)
{
- return GET_CORE()->respond_to(obj, sel, priv, check_override);
+ return GET_CORE()->respond_to(obj, klass, sel, priv, check_override);
}
extern "C"
bool
rb_vm_respond_to(VALUE obj, SEL sel, bool priv)
{
- return respond_to(obj, sel, priv, true);
+ return respond_to(obj, Qnil, sel, priv, true);
}
extern "C"
bool
-rb_vm_respond_to2(VALUE obj, SEL sel, bool priv, bool check_override)
+rb_vm_respond_to2(VALUE obj, VALUE klass, SEL sel, bool priv,
+ bool check_override)
{
- return respond_to(obj, sel, priv, check_override);
+ return respond_to(obj, klass, sel, priv, check_override);
}
View
4 vm.h
@@ -302,7 +302,7 @@ void *rb_vm_get_call_cache(SEL sel);
VALUE rb_vm_yield(int argc, const VALUE *argv);
VALUE rb_vm_yield_under(VALUE klass, VALUE self, int argc, const VALUE *argv);
bool rb_vm_respond_to(VALUE obj, SEL sel, bool priv);
-bool rb_vm_respond_to2(VALUE obj, SEL sel, bool priv, bool check_override);
+bool rb_vm_respond_to2(VALUE obj, VALUE klass, SEL sel, bool priv, bool check_override);
VALUE rb_vm_method_missing(VALUE obj, int argc, const VALUE *argv);
void rb_vm_push_methods(VALUE ary, VALUE mod, bool include_objc_methods,
int (*filter) (VALUE, ID, VALUE));
@@ -800,7 +800,7 @@ class RoxorCore {
void invalidate_respond_to_cache(void) {
respond_to_cache.clear();
}
- bool respond_to(VALUE obj, SEL sel, bool priv, bool check_override);
+ bool respond_to(VALUE obj, VALUE klass, SEL sel, bool priv, bool check_override);
private:
bool register_bs_boxed(bs_element_type_t type, void *value);
View
36 vm_method.c
@@ -347,11 +347,25 @@ rb_mod_undef_method(VALUE mod, SEL sel, int argc, VALUE *argv)
* C.method_defined? "method4" #=> false
*/
+static bool
+rb_obj_respond_to2(VALUE obj, VALUE klass, ID id, bool priv, bool check_override)
+{
+ const char *id_name = rb_id2name(id);
+ SEL sel = sel_registerName(id_name);
+ if (!rb_vm_respond_to2(obj, klass, sel, priv, check_override)) {
+ char buf[100];
+ snprintf(buf, sizeof buf, "%s:", id_name);
+ sel = sel_registerName(buf);
+ return rb_vm_respond_to2(obj, klass, sel, priv, check_override);
+ }
+ return true;
+}
+
static VALUE
rb_mod_method_defined(VALUE mod, SEL sel, VALUE mid)
{
ID id = rb_to_id(mid);
- return rb_obj_respond_to(mod, id, true) ? Qtrue : Qfalse;
+ return rb_obj_respond_to2(Qnil, mod, id, true, false) ? Qtrue : Qfalse;
}
#define VISI_CHECK(x,f) (((x)&NOEX_MASK) == (f))
@@ -736,26 +750,10 @@ rb_mod_modfunc(VALUE module, SEL sel, int argc, VALUE *argv)
* optional second parameter evaluates to +true+.
*/
-//static NODE *basic_respond_to = 0;
-
-static bool
-rb_obj_respond_to2(VALUE obj, ID id, bool priv, bool check_override)
-{
- const char *id_name = rb_id2name(id);
- SEL sel = sel_registerName(id_name);
- if (!rb_vm_respond_to2(obj, sel, priv, check_override)) {
- char buf[100];
- snprintf(buf, sizeof buf, "%s:", id_name);
- sel = sel_registerName(buf);
- return rb_vm_respond_to2(obj, sel, priv, check_override);
- }
- return true;
-}
-
bool
rb_obj_respond_to(VALUE obj, ID id, bool priv)
{
- return rb_obj_respond_to2(obj, id, priv, true);
+ return rb_obj_respond_to2(obj, Qnil, id, priv, true);
}
bool
@@ -781,7 +779,7 @@ obj_respond_to(VALUE obj, SEL sel, int argc, VALUE *argv)
rb_scan_args(argc, argv, "11", &mid, &priv);
id = rb_to_id(mid);
- return rb_obj_respond_to2(obj, id, RTEST(priv), false) ? Qtrue : Qfalse;
+ return rb_obj_respond_to2(obj, Qnil, id, RTEST(priv), false) ? Qtrue : Qfalse;
}
IMP basic_respond_to_imp = NULL;
Please sign in to comment.
Something went wrong with that request. Please try again.