aboutsummaryrefslogtreecommitdiffstats
path: root/object.c
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2023-12-24 21:26:37 -0500
committerPeter Zhu <peter@peterzhu.ca>2023-12-24 22:13:49 -0500
commitb4efa4b7005efee484e61fbc6af9c652fee36db2 (patch)
tree5c1556521231d47f2531417a9fc61451c2464bc5 /object.c
parent1b5f3dd6a1a5d054e3fd5af10b5dc2f49e1046fc (diff)
downloadruby-b4efa4b7005efee484e61fbc6af9c652fee36db2.tar.gz
Don't copy RUBY_FL_PROMOTED flag in rb_obj_setup
RUBY_FL_PROMOTED is used by the garbage collector to track when an object becomes promoted to the old generation. rb_obj_setup must not copy that flag over because then it may become out-of-sync with the age of the object. This fixes a bug in Method#clone where the cloned Method object may get RUBY_FL_PROMOTED incorrectly set.
Diffstat (limited to 'object.c')
-rw-r--r--object.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/object.c b/object.c
index 81d1ed6f6f..cde1d7b1d6 100644
--- a/object.c
+++ b/object.c
@@ -119,7 +119,8 @@ rb_obj_reveal(VALUE obj, VALUE klass)
VALUE
rb_obj_setup(VALUE obj, VALUE klass, VALUE type)
{
- RBASIC(obj)->flags = type;
+ VALUE ignored_flags = RUBY_FL_PROMOTED;
+ RBASIC(obj)->flags = (type & ~ignored_flags) | (RBASIC(obj)->flags & ignored_flags);
RBASIC_SET_CLASS(obj, klass);
return obj;
}