diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-11-18 08:15:51 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-11-18 08:15:51 +0000 |
commit | 3f7c0e9fd567fcfbcc8d2ac3ab8499cb321b3073 (patch) | |
tree | 659cc9ee4ffe825840cf55fb7db713e3fd48ca41 /vm_method.c | |
parent | e2f0af57407859b1d094e6885c27dabff345c190 (diff) |
* 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
Diffstat (limited to 'vm_method.c')
-rw-r--r-- | vm_method.c | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/vm_method.c b/vm_method.c index c88167434b..685e31fa7c 100644 --- a/vm_method.c +++ b/vm_method.c @@ -135,19 +135,24 @@ rb_add_method_cfunc(VALUE klass, ID mid, VALUE (*func)(ANYARGS), int argc, rb_me } 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) { - const int count = def->alias_count; - VM_ASSERT(count >= 0); + const int alias_count = def->alias_count; + const int complemented_count = def->complemented_count; + VM_ASSERT(alias_count >= 0); + VM_ASSERT(complemented_count >= 0); - if (count == 0) { - if (METHOD_DEBUG) fprintf(stderr, "-%p-%s:%d\n", def, rb_id2name(def->original_id), count); + if (alias_count + complemented_count == 0) { + if (METHOD_DEBUG) fprintf(stderr, "-%p-%s:%d,%d (remove)\n", def, rb_id2name(def->original_id), alias_count, complemented_count); xfree(def); } else { - if (METHOD_DEBUG) fprintf(stderr, "-%p-%s:%d->%d\n", def, rb_id2name(def->original_id), count, count-1); - def->alias_count--; + if (complemented) def->complemented_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 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); @@ -342,6 +347,14 @@ method_definition_addref(rb_method_definition_t *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 * 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_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_COMPLEMENTED_SET(me); + + VM_ASSERT(RB_TYPE_P(me->owner, T_MODULE)); + return (rb_callable_method_entry_t *)me; } |