Skip to content

Commit

Permalink
* revert r37993 to avoid SEGV in tests.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38022 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
shugo committed Nov 30, 2012
1 parent 696ebcd commit 9e44974
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 372 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Fri Nov 30 11:07:45 2012 Shugo Maeda <[email protected]>

* revert r37993 to avoid SEGV in tests.

Fri Nov 30 10:38:54 2012 Eric Hodel <[email protected]>

* lib/rdoc/ri/driver.rb: Relaxed matching for pages to be more
Expand Down
16 changes: 1 addition & 15 deletions class.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,13 +677,6 @@ rb_include_module(VALUE klass, VALUE module)
if (changed) rb_clear_cache();
}

static int
add_refined_method_entry_i(st_data_t key, st_data_t value, st_data_t data)
{
rb_add_refined_method_entry((VALUE) data, (ID) key);
return ST_CONTINUE;
}

static int
include_modules_at(VALUE klass, VALUE c, VALUE module)
{
Expand Down Expand Up @@ -714,13 +707,6 @@ include_modules_at(VALUE klass, VALUE c, VALUE module)
}
}
c = RCLASS_SUPER(c) = rb_include_class_new(module, RCLASS_SUPER(c));
if (FL_TEST(klass, RMODULE_IS_REFINEMENT)) {
VALUE refined_class =
rb_refinement_module_get_refined_class(klass);

st_foreach(RMODULE_M_TBL(module), add_refined_method_entry_i,
(st_data_t) refined_class);
}
if (RMODULE_M_TBL(module) && RMODULE_M_TBL(module)->num_entries)
changed = 1;
skip:
Expand Down Expand Up @@ -752,7 +738,7 @@ rb_prepend_module(VALUE klass, VALUE module)
RCLASS_SUPER(klass) = origin;
RCLASS_ORIGIN(klass) = origin;
RCLASS_M_TBL(origin) = RCLASS_M_TBL(klass);
RCLASS_M_TBL(klass) = st_init_numtable();
RCLASS_M_TBL(klass) = 0;
}
changed = include_modules_at(klass, klass, module);
if (changed < 0)
Expand Down
12 changes: 3 additions & 9 deletions eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -1187,14 +1187,6 @@ rb_mod_using(VALUE self, VALUE module)
return self;
}

VALUE rb_refinement_module_get_refined_class(VALUE module)
{
ID id_refined_class;

CONST_ID(id_refined_class, "__refined_class__");
return rb_attr_get(module, id_refined_class);
}

static VALUE
refinement_module_include(int argc, VALUE *argv, VALUE module)
{
Expand All @@ -1203,9 +1195,11 @@ refinement_module_include(int argc, VALUE *argv, VALUE module)
rb_control_frame_t *end_cfp = RUBY_VM_END_CONTROL_FRAME(th);
VALUE result = rb_mod_include(argc, argv, module);
NODE *cref;
ID id_refined_class;
VALUE klass, c;

klass = rb_refinement_module_get_refined_class(module);
CONST_ID(id_refined_class, "__refined_class__");
klass = rb_attr_get(module, id_refined_class);
while (RUBY_VM_VALID_CONTROL_FRAME_P(cfp, end_cfp)) {
if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq) &&
(cref = rb_vm_get_cref(cfp->iseq, cfp->ep)) &&
Expand Down
4 changes: 0 additions & 4 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2410,7 +2410,6 @@ mark_method_entry(rb_objspace_t *objspace, const rb_method_entry_t *me)
const rb_method_definition_t *def = me->def;

gc_mark(objspace, me->klass);
again:
if (!def) return;
switch (def->type) {
case VM_METHOD_TYPE_ISEQ:
Expand All @@ -2423,9 +2422,6 @@ mark_method_entry(rb_objspace_t *objspace, const rb_method_entry_t *me)
case VM_METHOD_TYPE_IVAR:
gc_mark(objspace, def->body.attr.location);
break;
case VM_METHOD_TYPE_REFINED:
def = def->body.orig_def;
goto again;
default:
break; /* ignore */
}
Expand Down
3 changes: 0 additions & 3 deletions internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ NORETURN(void rb_async_bug_errno(const char *,int));
const char *rb_builtin_type_name(int t);
const char *rb_builtin_class_name(VALUE x);

/* eval.c */
VALUE rb_refinement_module_get_refined_class(VALUE module);

/* eval_error.c */
void ruby_error_print(void);
VALUE rb_get_backtrace(VALUE info);
Expand Down
17 changes: 4 additions & 13 deletions method.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ typedef enum {
VM_METHOD_TYPE_NOTIMPLEMENTED,
VM_METHOD_TYPE_OPTIMIZED, /* Kernel#send, Proc#call, etc */
VM_METHOD_TYPE_MISSING, /* wrapper for method_missing(id) */
VM_METHOD_TYPE_CFUNC_FRAMELESS,
VM_METHOD_TYPE_REFINED,
VM_METHOD_TYPE_CFUNC_FRAMELESS
} rb_method_type_t;

struct rb_call_info_struct;
Expand Down Expand Up @@ -73,7 +72,6 @@ typedef struct rb_method_definition_struct {
OPTIMIZED_METHOD_TYPE_SEND,
OPTIMIZED_METHOD_TYPE_CALL
} optimize_type;
struct rb_method_definition_struct *orig_def;
} body;
int alias_count;
} rb_method_definition_t;
Expand All @@ -96,16 +94,9 @@ struct unlinked_method_entry_list_entry {
void rb_add_method_cfunc(VALUE klass, ID mid, VALUE (*func)(ANYARGS), int argc, rb_method_flag_t noex);
rb_method_entry_t *rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_flag_t noex);
rb_method_entry_t *rb_method_entry(VALUE klass, ID id, VALUE *define_class_ptr);
void rb_add_refined_method_entry(VALUE refined_class, ID mid);
rb_method_entry_t *rb_resolve_refined_method(VALUE refinements,
rb_method_entry_t *me,
rb_method_entry_t *me_buf,
VALUE *defined_class_ptr);
rb_method_entry_t *rb_method_entry_with_refinements(VALUE klass, ID id,
rb_method_entry_t *me_buf,
VALUE *defined_class_ptr);

rb_method_entry_t *rb_method_entry_get_without_cache(VALUE klass, ID id, VALUE *define_class_ptr);

rb_method_entry_t *rb_method_entry_get_with_refinements(VALUE refinements, VALUE klass, ID id, VALUE *define_class_ptr);
rb_method_entry_t *rb_method_entry_get_without_cache(VALUE klass, VALUE refinements, ID id, VALUE *define_class_ptr);
rb_method_entry_t *rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_flag_t noex);

int rb_method_entry_arity(const rb_method_entry_t *me);
Expand Down
5 changes: 3 additions & 2 deletions object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,7 @@ rb_obj_cmp(VALUE obj1, VALUE obj2)
static VALUE
rb_mod_to_s(VALUE klass)
{
ID id_defined_at;
ID id_refined_class, id_defined_at;
VALUE refined_class, defined_at;

if (FL_TEST(klass, FL_SINGLETON)) {
Expand All @@ -1357,7 +1357,8 @@ rb_mod_to_s(VALUE klass)

return s;
}
refined_class = rb_refinement_module_get_refined_class(klass);
CONST_ID(id_refined_class, "__refined_class__");
refined_class = rb_attr_get(klass, id_refined_class);
if (!NIL_P(refined_class)) {
VALUE s = rb_usascii_str_new2("#<refinement:");

Expand Down
4 changes: 1 addition & 3 deletions proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ mnew(VALUE klass, VALUE obj, ID id, VALUE mclass, int scope)
rb_method_flag_t flag = NOEX_UNDEF;

again:
me = rb_method_entry_with_refinements(klass, id, &meb, &defined_class);
me = rb_method_entry(klass, id, &defined_class);
if (UNDEFINED_METHOD_ENTRY_P(me)) {
ID rmiss = rb_intern("respond_to_missing?");
VALUE sym = ID2SYM(id);
Expand Down Expand Up @@ -1682,8 +1682,6 @@ rb_method_entry_arity(const rb_method_entry_t *me)
default:
break;
}
case VM_METHOD_TYPE_REFINED:
return -1;
}
}
rb_bug("rb_method_entry_arity: invalid method entry type (%d)", def->type);
Expand Down
28 changes: 1 addition & 27 deletions test/ruby/test_refinement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ def foo
end

def test_inline_method_cache
skip "can't implement efficiently with the current implementation of refinements"
c = InlineMethodCache::C.new
f = Proc.new { c.foo }
assert_equal("original", f.call)
Expand Down Expand Up @@ -821,31 +822,4 @@ def test_circular_using_is_not_allowed
end
end
end

module RedifineRefinedMethod
class C
def foo
"original"
end
end

module M
refine C do
def foo
"refined"
end
end
end

class C
def foo
"redefined"
end
end
end

def test_redefine_refined_method
c = RedifineRefinedMethod::C.new
assert_equal("refined", RedifineRefinedMethod::M.module_eval { c.foo })
end
end
49 changes: 14 additions & 35 deletions vm_eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,7 @@ vm_call0_body(rb_thread_t* th, rb_call_info_t *ci, const VALUE *argv)
case VM_METHOD_TYPE_BMETHOD:
return vm_call_bmethod_body(th, ci, argv);
case VM_METHOD_TYPE_ZSUPER:
case VM_METHOD_TYPE_REFINED:
{
if (ci->me->def->type == VM_METHOD_TYPE_REFINED &&
ci->me->def->body.orig_def) {
rb_method_entry_t orig_me;
orig_me = *ci->me;
orig_me.def = ci->me->def->body.orig_def;
ci->me = &orig_me;
goto again;
}

ci->defined_class = RCLASS_SUPER(ci->defined_class);

if (!ci->defined_class || !(ci->me = rb_method_entry(ci->defined_class, ci->mid, &ci->defined_class))) {
Expand Down Expand Up @@ -284,7 +274,8 @@ stack_check(void)
}

static inline rb_method_entry_t *
rb_search_method_entry(VALUE recv, ID mid, VALUE *defined_class_ptr);
rb_search_method_entry(VALUE refinements, VALUE recv, ID mid,
VALUE *defined_class_ptr);
static inline int rb_method_call_status(rb_thread_t *th, const rb_method_entry_t *me, call_type scope, VALUE self);
#define NOEX_OK NOEX_NOSUPER

Expand All @@ -304,11 +295,11 @@ static inline int rb_method_call_status(rb_thread_t *th, const rb_method_entry_t
*/
static inline VALUE
rb_call0(VALUE recv, ID mid, int argc, const VALUE *argv,
call_type scope, VALUE self)
call_type scope, VALUE self, VALUE refinements)
{
VALUE defined_class;
rb_method_entry_t *me =
rb_search_method_entry(recv, mid, &defined_class);
rb_search_method_entry(refinements, recv, mid, &defined_class);
rb_thread_t *th = GET_THREAD();
int call_status = rb_method_call_status(th, me, scope, self);

Expand Down Expand Up @@ -372,7 +363,7 @@ check_funcall(VALUE recv, ID mid, int argc, VALUE *argv)
}
}

me = rb_search_method_entry(recv, mid, &defined_class);
me = rb_search_method_entry(Qnil, recv, mid, &defined_class);
call_status = rb_method_call_status(th, me, CALL_FCALL, Qundef);
if (call_status != NOEX_OK) {
if (rb_method_basic_definition_p(klass, idMethodMissing)) {
Expand Down Expand Up @@ -437,7 +428,8 @@ rb_type_str(enum ruby_value_type type)
}

static inline rb_method_entry_t *
rb_search_method_entry(VALUE recv, ID mid, VALUE *defined_class_ptr)
rb_search_method_entry(VALUE refinements, VALUE recv, ID mid,
VALUE *defined_class_ptr)
{
VALUE klass = CLASS_OF(recv);

Expand Down Expand Up @@ -476,7 +468,8 @@ rb_search_method_entry(VALUE recv, ID mid, VALUE *defined_class_ptr)
rb_id2name(mid), type, (void *)recv, flags, klass);
}
}
return rb_method_entry(klass, mid, defined_class_ptr);
return rb_method_entry_get_with_refinements(refinements, klass, mid,
defined_class_ptr);
}

static inline int
Expand Down Expand Up @@ -540,7 +533,7 @@ rb_method_call_status(rb_thread_t *th, const rb_method_entry_t *me, call_type sc
static inline VALUE
rb_call(VALUE recv, ID mid, int argc, const VALUE *argv, call_type scope)
{
return rb_call0(recv, mid, argc, argv, scope, Qundef);
return rb_call0(recv, mid, argc, argv, scope, Qundef, Qnil);
}

NORETURN(static void raise_method_missing(rb_thread_t *th, int argc, const VALUE *argv,
Expand Down Expand Up @@ -793,24 +786,10 @@ rb_funcall_passing_block_with_refinements(VALUE recv, ID mid, int argc,
const VALUE *argv,
VALUE refinements)
{
VALUE defined_class;
rb_method_entry_t meb, *me =
rb_search_method_entry(recv, mid, &defined_class);
rb_thread_t *th;
int call_status;

if (me && me->def->type == VM_METHOD_TYPE_REFINED) {
me = rb_resolve_refined_method(refinements, me, &meb,
&defined_class);
}
PASS_PASSED_BLOCK_TH(GET_THREAD());
th = GET_THREAD();
call_status = rb_method_call_status(th, me, CALL_PUBLIC, Qundef);
if (call_status != NOEX_OK) {
return method_missing(recv, mid, argc, argv, call_status);
}
stack_check();
return vm_call0(th, recv, mid, argc, argv, me, defined_class);

return rb_call0(recv, mid, argc, argv, CALL_PUBLIC, Qundef,
refinements);
}

static VALUE
Expand All @@ -837,7 +816,7 @@ send_internal(int argc, const VALUE *argv, VALUE recv, call_type scope)
id = rb_to_id(vid);
}
PASS_PASSED_BLOCK_TH(th);
return rb_call0(recv, id, argc, argv, scope, self);
return rb_call0(recv, id, argc, argv, scope, self, Qnil);
}

/*
Expand Down
Loading

0 comments on commit 9e44974

Please sign in to comment.