summaryrefslogtreecommitdiff
path: root/class.c
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2020-12-22 05:27:47 +0900
committerKoichi Sasada <ko1@atdot.net>2020-12-22 06:09:30 +0900
commit520dcbd6009b07458d67309ae33a602d77062975 (patch)
tree13d96cb2df62c2d10cbe4316d77429e4b01d4294 /class.c
parentd0e4ccbefcdd6032d0ae70bc54c9a4fb55d92576 (diff)
reset cache before iterating
cee02d754d76563635c1db90d2ab6c01f8492470 resets pCMC and `me` will be a invalidated and continuing the invalidated `me`, it will break the data structure. This patch tris to clear all methods of specified class before manipulating the `me`s. [Issue #17417]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3964
Diffstat (limited to 'class.c')
-rw-r--r--class.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/class.c b/class.c
index 6d5cabcc6d..47f35b1f90 100644
--- a/class.c
+++ b/class.c
@@ -1105,12 +1105,11 @@ include_modules_at(const VALUE klass, VALUE c, VALUE module, int search_super)
static enum rb_id_table_iterator_result
move_refined_method(ID key, VALUE value, void *data)
{
- rb_method_entry_t *me = (rb_method_entry_t *) value;
- VALUE klass = (VALUE)data;
- struct rb_id_table *tbl = RCLASS_M_TBL(klass);
+ rb_method_entry_t *me = (rb_method_entry_t *)value;
if (me->def->type == VM_METHOD_TYPE_REFINED) {
- rb_clear_method_cache(klass, me->called_id);
+ VALUE klass = (VALUE)data;
+ struct rb_id_table *tbl = RCLASS_M_TBL(klass);
if (me->def->body.refined.orig_me) {
const rb_method_entry_t *orig_me = me->def->body.refined.orig_me, *new_me;
@@ -1130,6 +1129,19 @@ move_refined_method(ID key, VALUE value, void *data)
}
}
+static enum rb_id_table_iterator_result
+cache_clear_refined_method(ID key, VALUE value, void *data)
+{
+ rb_method_entry_t *me = (rb_method_entry_t *) value;
+
+ if (me->def->type == VM_METHOD_TYPE_REFINED) {
+ VALUE klass = (VALUE)data;
+ rb_clear_method_cache(klass, me->called_id);
+ }
+
+ return ID_TABLE_CONTINUE;
+}
+
static void
ensure_origin(VALUE klass)
{
@@ -1141,6 +1153,7 @@ ensure_origin(VALUE klass)
RCLASS_SET_ORIGIN(klass, origin);
RCLASS_M_TBL(origin) = RCLASS_M_TBL(klass);
RCLASS_M_TBL_INIT(klass);
+ rb_id_table_foreach(RCLASS_M_TBL(origin), cache_clear_refined_method, (void *)klass);
rb_id_table_foreach(RCLASS_M_TBL(origin), move_refined_method, (void *)klass);
}
}