diff options
| author | NARUSE, Yui <nurse@users.noreply.github.com> | 2024-03-21 10:45:01 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-21 01:45:01 +0000 |
| commit | a63e979853783601a60228b45741f8b3776e5507 (patch) | |
| tree | 8396278af85906d600486360bfb7e466aaef6161 /object.c | |
| parent | a406c516685f1950269c4e43d13cc748f0bfbc06 (diff) | |
merge revision(s) d19d683a354530a27b4cbb049223f8dc70c75849,de1a586ecc2ee7f465f0c0a69291054136a3a819: [Backport #20250] (#10308)
rb_obj_setup: do not copy RUBY_FL_SEEN_OBJ_ID
[Bug #20250]
We're seting up a new instance, so it never had an associated
object_id.
proc.c: get rid of `CLONESETUP`
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
[Bug #20253]
All the way down to Ruby 1.9, `Proc`, `Method`, `UnboundMethod`
and `Binding` always had their own specific clone and dup routine.
This caused various discrepancies with how other objects behave
on `dup` and `clone. [Bug #20250], [Bug #20253].
This commit get rid of `CLONESETUP` and use the the same codepath
as all other types, so ensure consistency.
NB: It's still not accepting the `freeze` keyword argument on `clone`.
Co-Authored-By: Étienne Barrié <etienne.barrie@gmail.com>
Diffstat (limited to 'object.c')
| -rw-r--r-- | object.c | 32 |
1 files changed, 21 insertions, 11 deletions
@@ -119,7 +119,7 @@ rb_obj_reveal(VALUE obj, VALUE klass) VALUE rb_obj_setup(VALUE obj, VALUE klass, VALUE type) { - VALUE ignored_flags = RUBY_FL_PROMOTED; + VALUE ignored_flags = RUBY_FL_PROMOTED | RUBY_FL_SEEN_OBJ_ID; RBASIC(obj)->flags = (type & ~ignored_flags) | (RBASIC(obj)->flags & ignored_flags); RBASIC_SET_CLASS(obj, klass); return obj; @@ -453,15 +453,12 @@ immutable_obj_clone(VALUE obj, VALUE kwfreeze) return obj; } -static VALUE -mutable_obj_clone(VALUE obj, VALUE kwfreeze) +VALUE +rb_obj_clone_setup(VALUE obj, VALUE clone, VALUE kwfreeze) { - VALUE clone, singleton; VALUE argv[2]; - clone = rb_obj_alloc(rb_obj_class(obj)); - - singleton = rb_singleton_class_clone_and_attach(obj, clone); + VALUE singleton = rb_singleton_class_clone_and_attach(obj, clone); RBASIC_SET_CLASS(clone, singleton); if (FL_TEST(singleton, FL_SINGLETON)) { rb_singleton_class_attached(singleton, clone); @@ -528,6 +525,13 @@ mutable_obj_clone(VALUE obj, VALUE kwfreeze) return clone; } +static VALUE +mutable_obj_clone(VALUE obj, VALUE kwfreeze) +{ + VALUE clone = rb_obj_alloc(rb_obj_class(obj)); + return rb_obj_clone_setup(obj, clone, kwfreeze); +} + VALUE rb_obj_clone(VALUE obj) { @@ -535,6 +539,15 @@ rb_obj_clone(VALUE obj) return mutable_obj_clone(obj, Qnil); } +VALUE +rb_obj_dup_setup(VALUE obj, VALUE dup) +{ + init_copy(dup, obj); + rb_funcall(dup, id_init_dup, 1, obj); + + return dup; +} + /* * call-seq: * obj.dup -> an_object @@ -583,10 +596,7 @@ rb_obj_dup(VALUE obj) return obj; } dup = rb_obj_alloc(rb_obj_class(obj)); - init_copy(dup, obj); - rb_funcall(dup, id_init_dup, 1, obj); - - return dup; + return rb_obj_dup_setup(obj, dup); } /* |
