ext/mri/mri.c in looksee-1.0.3 vs ext/mri/mri.c in looksee-1.1.0

- old
+ new

@@ -1,12 +1,21 @@ #include "ruby.h" -#if RUBY_VERSION >= 193 +#if RUBY_VERSION >= 200 +# include "method.h" # include "internal.h" +#elif RUBY_VERSION >= 193 +# include "ruby/st.h" +# ifdef SA_EMPTY +# include "internal_falcon.h" +# define Looksee_method_table_foreach sa_foreach +# define Looksee_method_table_lookup sa_lookup +# else +# include "internal.h" +# endif # include "vm_core.h" # include "method.h" -# include "ruby/st.h" #elif RUBY_VERSION >= 192 # include "vm_core.h" # include "method.h" # include "ruby/st.h" #elif RUBY_VERSION >= 190 @@ -15,10 +24,15 @@ #else # include "node.h" # include "st.h" #endif +#ifndef Looksee_method_table_foreach +# define Looksee_method_table_foreach st_foreach +# define Looksee_method_table_lookup st_lookup +#endif + #if RUBY_VERSION < 187 # define RCLASS_IV_TBL(c) (RCLASS(c)->iv_tbl) # define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl) # define RCLASS_SUPER(c) (RCLASS(c)->super) #endif @@ -75,12 +89,14 @@ VALUE names; VISIBILITY_TYPE visibility; } add_method_if_matching_arg_t; static int add_method_if_matching(ID method_name, rb_method_entry_t *me, add_method_if_matching_arg_t *arg) { +# ifdef ID_ALLOCATOR if (method_name == ID_ALLOCATOR) return ST_CONTINUE; +# endif if (UNDEFINED_METHOD_ENTRY_P(me)) return ST_CONTINUE; if ((me->flag & NOEX_MASK) == arg->visibility) @@ -88,10 +104,16 @@ return ST_CONTINUE; } static int add_method_if_undefined(ID method_name, rb_method_entry_t *me, VALUE *names) { +# ifdef ID_ALLOCATOR + /* The allocator can be undefined with rb_undef_alloc_func, e.g. Struct. */ + if (method_name == ID_ALLOCATOR) + return ST_CONTINUE; +# endif + if (UNDEFINED_METHOD_ENTRY_P(me)) rb_ary_push(*names, ID2SYM(method_name)); return ST_CONTINUE; } @@ -109,13 +131,15 @@ VALUE names; VISIBILITY_TYPE visibility; } add_method_if_matching_arg_t; static int add_method_if_matching(ID method_name, NODE *body, add_method_if_matching_arg_t *arg) { +# ifdef ID_ALLOCATOR /* This entry is for the internal allocator function. */ if (method_name == ID_ALLOCATOR) return ST_CONTINUE; +# endif /* Module#undef_method: * * sets body->nd_body to NULL in ruby <= 1.8 * * sets body to NULL in ruby >= 1.9 */ @@ -126,10 +150,16 @@ rb_ary_push(arg->names, ID2SYM(method_name)); return ST_CONTINUE; } static int add_method_if_undefined(ID method_name, NODE *body, VALUE *names) { +# ifdef ID_ALLOCATOR + /* The allocator can be undefined with rb_undef_alloc_func, e.g. Struct. */ + if (method_name == ID_ALLOCATOR) + return ST_CONTINUE; +# endif + if (!body || !body->nd_body) rb_ary_push(*names, ID2SYM(method_name)); return ST_CONTINUE; } @@ -137,11 +167,12 @@ static VALUE internal_instance_methods(VALUE klass, VISIBILITY_TYPE visibility) { add_method_if_matching_arg_t arg; arg.names = rb_ary_new(); arg.visibility = visibility; - st_foreach(RCLASS_M_TBL(klass), add_method_if_matching, (st_data_t)&arg); + + Looksee_method_table_foreach(RCLASS_M_TBL(klass), add_method_if_matching, (st_data_t)&arg); return arg.names; } /* * Return the list of public instance methods (as Symbols) of the @@ -171,21 +202,21 @@ * Return the list of undefined instance methods (as Symbols) of the * given internal class. */ VALUE Looksee_internal_undefined_instance_methods(VALUE self, VALUE klass) { VALUE names = rb_ary_new(); - st_foreach(RCLASS_M_TBL(klass), add_method_if_undefined, (st_data_t)&names); + Looksee_method_table_foreach(RCLASS_M_TBL(klass), add_method_if_undefined, (st_data_t)&names); return names; } VALUE Looksee_singleton_class_p(VALUE self, VALUE object) { return BUILTIN_TYPE(object) == T_CLASS && FL_TEST(object, FL_SINGLETON) ? Qtrue : Qfalse; } VALUE Looksee_singleton_instance(VALUE self, VALUE singleton_class) { if (BUILTIN_TYPE(singleton_class) == T_CLASS && FL_TEST(singleton_class, FL_SINGLETON)) { VALUE object; - if (!st_lookup(RCLASS_IV_TBL(singleton_class), rb_intern("__attached__"), (st_data_t *)&object)) + if (!Looksee_method_table_lookup(RCLASS_IV_TBL(singleton_class), rb_intern("__attached__"), (st_data_t *)&object)) rb_raise(rb_eRuntimeError, "[looksee bug] can't find singleton object"); return object; } else { rb_raise(rb_eTypeError, "expected singleton class, got %s", rb_obj_classname(singleton_class)); }