summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2023-06-02 14:25:19 -0400
committerAaron Patterson <aaron.patterson@gmail.com>2023-06-05 11:11:12 -0700
commit40f090f4339820d19da8ecdf81a981489c22eb57 (patch)
treeee8f90b5d49c2bb6cc44f135e3638fcd9599722e /internal
parent29ea3c5aaa9513fcd497781e7051c0f436725eb3 (diff)
Revert "Revert "Fix cvar caching when class is cloned""
This reverts commit 10621f7cb9a0c70e568f89cce47a02e878af6778. This was reverted because the gc integrity build started failing. We have figured out a fix so I'm reopening the PR. Original commit message: Fix cvar caching when class is cloned The class variable cache that was added in ruby#4544 changed the behavior of class variables on cloned classes. As reported when a class is cloned AND a class variable was set, and the class variable was read from the original class, reading a class variable from the cloned class would return the value from the original class. This was happening because the IC (inline cache) is stored on the ISEQ which is shared between the original and cloned class, therefore they share the cache too. To fix this we are now storing the `cref` in the cache so that we can check if it's equal to the current `cref`. If it's different we don't want to read from the cache. If it's the same we do. Cloned classes don't share the same cref with their original class. This will need to be backported to 3.1 in addition to 3.2 since the bug exists in both versions. We also added a marking function which was missing. Fixes [Bug #19379] Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/7900
Diffstat (limited to 'internal')
-rw-r--r--internal/class.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/internal/class.h b/internal/class.h
index b33c807e97..d76da84bd1 100644
--- a/internal/class.h
+++ b/internal/class.h
@@ -17,6 +17,9 @@
#include "ruby/intern.h" /* for rb_alloc_func_t */
#include "ruby/ruby.h" /* for struct RBasic */
#include "shape.h"
+#include "ruby_assert.h"
+#include "vm_core.h"
+#include "method.h" /* for rb_cref_t */
#ifdef RCLASS_SUPER
# undef RCLASS_SUPER
@@ -32,6 +35,7 @@ typedef struct rb_subclass_entry rb_subclass_entry_t;
struct rb_cvar_class_tbl_entry {
uint32_t index;
rb_serial_t global_cvar_state;
+ const rb_cref_t * cref;
VALUE class_value;
};