mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* method.h: introduce the folliwing field and macros.
* rb_method_definition_t::complemented_count to count shared method entries because of complemented method entries and separate from alias_count. Shared `def' only by complemented method entries should not prevent method re-definition warning. * METHOD_ENTRY_COMPLEMENTED(me) to represent complemented method entry. * METHOD_ENTRY_COMPLEMENTED_SET(me) to check it as complemented me. * vm_insnhelper.c (aliased_callable_method_entry): should also check me->def->complemented_count. * vm_method.c (method_definition_addref_complement): add to count complemented method entries number. * vm_method.c (rb_method_definition_release): release `def' iff alias_count == 0 and complemented_count == 0. * test/ruby/test_module.rb: add a test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52636 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e2f0af5740
commit
3f7c0e9fd5
5 changed files with 71 additions and 12 deletions
25
ChangeLog
25
ChangeLog
|
@ -1,3 +1,28 @@
|
||||||
|
Wed Nov 18 17:08:18 2015 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
|
* method.h: introduce the folliwing field and macros.
|
||||||
|
|
||||||
|
* rb_method_definition_t::complemented_count to count shared method
|
||||||
|
entries because of complemented method entries and separate from
|
||||||
|
alias_count.
|
||||||
|
|
||||||
|
Shared `def' only by complemented method entries should not prevent
|
||||||
|
method re-definition warning.
|
||||||
|
|
||||||
|
* METHOD_ENTRY_COMPLEMENTED(me) to represent complemented method entry.
|
||||||
|
* METHOD_ENTRY_COMPLEMENTED_SET(me) to check it as complemented me.
|
||||||
|
|
||||||
|
* vm_insnhelper.c (aliased_callable_method_entry): should also
|
||||||
|
check me->def->complemented_count.
|
||||||
|
|
||||||
|
* vm_method.c (method_definition_addref_complement): add to count
|
||||||
|
complemented method entries number.
|
||||||
|
|
||||||
|
* vm_method.c (rb_method_definition_release): release `def' iff
|
||||||
|
alias_count == 0 and complemented_count == 0.
|
||||||
|
|
||||||
|
* test/ruby/test_module.rb: add a test.
|
||||||
|
|
||||||
Wed Nov 18 17:06:19 2015 Koichi Sasada <ko1@atdot.net>
|
Wed Nov 18 17:06:19 2015 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* gc.c (rb_raw_obj_info): fix trivial issues.
|
* gc.c (rb_raw_obj_info): fix trivial issues.
|
||||||
|
|
7
method.h
7
method.h
|
@ -65,6 +65,8 @@ typedef struct rb_callable_method_entry_struct { /* same fields with rb_method_e
|
||||||
|
|
||||||
#define METHOD_ENTRY_VISI(me) (rb_method_visibility_t)(((me)->flags & (IMEMO_FL_USER0 | IMEMO_FL_USER1)) >> (IMEMO_FL_USHIFT+0))
|
#define METHOD_ENTRY_VISI(me) (rb_method_visibility_t)(((me)->flags & (IMEMO_FL_USER0 | IMEMO_FL_USER1)) >> (IMEMO_FL_USHIFT+0))
|
||||||
#define METHOD_ENTRY_BASIC(me) (int) (((me)->flags & (IMEMO_FL_USER2 )) >> (IMEMO_FL_USHIFT+2))
|
#define METHOD_ENTRY_BASIC(me) (int) (((me)->flags & (IMEMO_FL_USER2 )) >> (IMEMO_FL_USHIFT+2))
|
||||||
|
#define METHOD_ENTRY_COMPLEMENTED(me) ((me)->flags & IMEMO_FL_USER3)
|
||||||
|
#define METHOD_ENTRY_COMPLEMENTED_SET(me) ((me)->flags = (me)->flags | IMEMO_FL_USER3)
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
METHOD_ENTRY_VISI_SET(rb_method_entry_t *me, rb_method_visibility_t visi)
|
METHOD_ENTRY_VISI_SET(rb_method_entry_t *me, rb_method_visibility_t visi)
|
||||||
|
@ -143,8 +145,9 @@ typedef struct rb_method_refined_struct {
|
||||||
} rb_method_refined_t;
|
} rb_method_refined_t;
|
||||||
|
|
||||||
typedef struct rb_method_definition_struct {
|
typedef struct rb_method_definition_struct {
|
||||||
rb_method_type_t type; /* method type */
|
rb_method_type_t type : 8; /* method type */
|
||||||
int alias_count;
|
int alias_count : 28;
|
||||||
|
int complemented_count: 28;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
rb_method_iseq_t iseq;
|
rb_method_iseq_t iseq;
|
||||||
|
|
|
@ -1280,6 +1280,20 @@ class TestModule < Test::Unit::TestCase
|
||||||
undef foo
|
undef foo
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
stderr = EnvUtil.verbose_warning do
|
||||||
|
Module.new do
|
||||||
|
def foo; end
|
||||||
|
mod = self
|
||||||
|
c = Class.new do
|
||||||
|
include mod
|
||||||
|
end
|
||||||
|
c.new.foo
|
||||||
|
def foo; end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert_match(/: warning: method redefined; discarding old foo/, stderr)
|
||||||
|
assert_match(/: warning: previous definition of foo/, stderr)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_protected_singleton_method
|
def test_protected_singleton_method
|
||||||
|
|
|
@ -1990,7 +1990,7 @@ aliased_callable_method_entry(const rb_callable_method_entry_t *me)
|
||||||
VM_ASSERT(RB_TYPE_P(orig_me->owner, T_MODULE));
|
VM_ASSERT(RB_TYPE_P(orig_me->owner, T_MODULE));
|
||||||
cme = rb_method_entry_complement_defined_class(orig_me, defined_class);
|
cme = rb_method_entry_complement_defined_class(orig_me, defined_class);
|
||||||
|
|
||||||
if (me->def->alias_count == 0) {
|
if (me->def->alias_count + me->def->complemented_count == 0) {
|
||||||
RB_OBJ_WRITE(me, &me->def->body.alias.original_me, cme);
|
RB_OBJ_WRITE(me, &me->def->body.alias.original_me, cme);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
35
vm_method.c
35
vm_method.c
|
@ -135,19 +135,24 @@ rb_add_method_cfunc(VALUE klass, ID mid, VALUE (*func)(ANYARGS), int argc, rb_me
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
rb_method_definition_release(rb_method_definition_t *def)
|
rb_method_definition_release(rb_method_definition_t *def, int complemented)
|
||||||
{
|
{
|
||||||
if (def != NULL) {
|
if (def != NULL) {
|
||||||
const int count = def->alias_count;
|
const int alias_count = def->alias_count;
|
||||||
VM_ASSERT(count >= 0);
|
const int complemented_count = def->complemented_count;
|
||||||
|
VM_ASSERT(alias_count >= 0);
|
||||||
|
VM_ASSERT(complemented_count >= 0);
|
||||||
|
|
||||||
if (count == 0) {
|
if (alias_count + complemented_count == 0) {
|
||||||
if (METHOD_DEBUG) fprintf(stderr, "-%p-%s:%d\n", def, rb_id2name(def->original_id), count);
|
if (METHOD_DEBUG) fprintf(stderr, "-%p-%s:%d,%d (remove)\n", def, rb_id2name(def->original_id), alias_count, complemented_count);
|
||||||
xfree(def);
|
xfree(def);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (METHOD_DEBUG) fprintf(stderr, "-%p-%s:%d->%d\n", def, rb_id2name(def->original_id), count, count-1);
|
if (complemented) def->complemented_count--;
|
||||||
def->alias_count--;
|
else if (def->alias_count > 0) def->alias_count--;
|
||||||
|
|
||||||
|
if (METHOD_DEBUG) fprintf(stderr, "-%p-%s:%d->%d,%d->%d (dec)\n", def, rb_id2name(def->original_id),
|
||||||
|
alias_count, def->alias_count, complemented_count, def->complemented_count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,7 +160,7 @@ rb_method_definition_release(rb_method_definition_t *def)
|
||||||
void
|
void
|
||||||
rb_free_method_entry(const rb_method_entry_t *me)
|
rb_free_method_entry(const rb_method_entry_t *me)
|
||||||
{
|
{
|
||||||
rb_method_definition_release(me->def);
|
rb_method_definition_release(me->def, METHOD_ENTRY_COMPLEMENTED(me));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline rb_method_entry_t *search_method(VALUE klass, ID id, VALUE *defined_class_ptr);
|
static inline rb_method_entry_t *search_method(VALUE klass, ID id, VALUE *defined_class_ptr);
|
||||||
|
@ -342,6 +347,14 @@ method_definition_addref(rb_method_definition_t *def)
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static rb_method_definition_t *
|
||||||
|
method_definition_addref_complement(rb_method_definition_t *def)
|
||||||
|
{
|
||||||
|
def->complemented_count++;
|
||||||
|
if (METHOD_DEBUG) fprintf(stderr, "+%p-%s:%d\n", def, rb_id2name(def->original_id), def->alias_count);
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
|
||||||
static rb_method_entry_t *
|
static rb_method_entry_t *
|
||||||
rb_method_entry_alloc(ID called_id, VALUE owner, VALUE defined_class, const rb_method_definition_t *def)
|
rb_method_entry_alloc(ID called_id, VALUE owner, VALUE defined_class, const rb_method_definition_t *def)
|
||||||
{
|
{
|
||||||
|
@ -385,8 +398,12 @@ const rb_callable_method_entry_t *
|
||||||
rb_method_entry_complement_defined_class(const rb_method_entry_t *src_me, VALUE defined_class)
|
rb_method_entry_complement_defined_class(const rb_method_entry_t *src_me, VALUE defined_class)
|
||||||
{
|
{
|
||||||
rb_method_entry_t *me = rb_method_entry_alloc(src_me->called_id, src_me->owner, defined_class,
|
rb_method_entry_t *me = rb_method_entry_alloc(src_me->called_id, src_me->owner, defined_class,
|
||||||
method_definition_addref(src_me->def));
|
method_definition_addref_complement(src_me->def));
|
||||||
METHOD_ENTRY_FLAGS_COPY(me, src_me);
|
METHOD_ENTRY_FLAGS_COPY(me, src_me);
|
||||||
|
METHOD_ENTRY_COMPLEMENTED_SET(me);
|
||||||
|
|
||||||
|
VM_ASSERT(RB_TYPE_P(me->owner, T_MODULE));
|
||||||
|
|
||||||
return (rb_callable_method_entry_t *)me;
|
return (rb_callable_method_entry_t *)me;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue