Skip to content

Instantly share code, notes, and snippets.

@headius
Last active November 12, 2021 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save headius/32ecf9c7b669e48e34e99958fa8a8d0d to your computer and use it in GitHub Desktop.
Save headius/32ecf9c7b669e48e34e99958fa8a8d0d to your computer and use it in GitHub Desktop.
diff --git a/core/src/main/java/org/jruby/RubyBasicObject.java b/core/src/main/java/org/jruby/RubyBasicObject.java
index d9a5ccd1c6..45bd08da83 100644
--- a/core/src/main/java/org/jruby/RubyBasicObject.java
+++ b/core/src/main/java/org/jruby/RubyBasicObject.java
@@ -837,7 +837,7 @@ public class RubyBasicObject implements Cloneable, IRubyObject, Serializable, Co
IRubyObject dup = metaClass.getRealClass().allocate();
- initCopy(metaClass.runtime.getCurrentContext(), dup, this, false);
+ initCopy(metaClass.runtime.getCurrentContext(), dup, this, null, false);
return dup;
}
@@ -847,7 +847,7 @@ public class RubyBasicObject implements Cloneable, IRubyObject, Serializable, Co
* Initializes a copy with variable and special instance variable
* information, and then call the initialize_copy Ruby method.
*/
- private static IRubyObject initCopy(ThreadContext context, IRubyObject clone, IRubyObject original, boolean doClone) {
+ private static IRubyObject initCopy(ThreadContext context, IRubyObject clone, IRubyObject original, IRubyObject kwargs, boolean doClone) {
assert !clone.isFrozen() : "frozen object (" + clone.getMetaClass().getName() + ") allocated";
original.copySpecialInstanceVariables(clone);
@@ -860,9 +860,15 @@ public class RubyBasicObject implements Cloneable, IRubyObject, Serializable, Co
}
/* FIXME: finalizer should be dupped here */
- return doClone ?
- sites(context).initialize_clone.call(context, clone, clone, original) :
- sites(context).initialize_dup.call(context, clone, clone, original);
+ if (kwargs == null) {
+ return doClone ?
+ sites(context).initialize_clone.call(context, clone, clone, original) :
+ sites(context).initialize_dup.call(context, clone, clone, original);
+ } else {
+ return doClone ?
+ sites(context).initialize_clone.call(context, clone, clone, original, kwargs) :
+ sites(context).initialize_dup.call(context, clone, clone, original, kwargs);
+ }
}
protected static boolean OBJ_INIT_COPY(IRubyObject obj, IRubyObject orig) {
@@ -904,7 +910,7 @@ public class RubyBasicObject implements Cloneable, IRubyObject, Serializable, Co
@Override
public IRubyObject rbClone() {
- return rbCloneInternal(metaClass.runtime.getCurrentContext(), true);
+ return rbCloneInternal(metaClass.runtime.getCurrentContext(), null, true);
}
public IRubyObject rbClone(ThreadContext context, IRubyObject maybeOpts) {
@@ -923,10 +929,10 @@ public class RubyBasicObject implements Cloneable, IRubyObject, Serializable, Co
}
}
- return rbCloneInternal(context, kwfreeze);
+ return rbCloneInternal(context, opts, kwfreeze);
}
- private RubyBasicObject rbCloneInternal(ThreadContext context, boolean freeze) {
+ private RubyBasicObject rbCloneInternal(ThreadContext context, IRubyObject kwargs, boolean freeze) {
if (isSpecialObject()) {
final Ruby runtime = context.runtime;
@@ -939,9 +945,9 @@ public class RubyBasicObject implements Cloneable, IRubyObject, Serializable, Co
RubyBasicObject clone = (RubyBasicObject) metaClass.getRealClass().allocate();
clone.setMetaClass(getSingletonClassCloneAndAttach(clone));
- initCopy(context, clone, this, true);
+ initCopy(context, clone, this, kwargs, true);
- if (freeze && isFrozen()) clone.setFrozen(true);
+ if (freeze) clone.setFrozen(true);
return clone;
}
diff --git a/core/src/main/ruby/jruby/kernel/kernel.rb b/core/src/main/ruby/jruby/kernel/kernel.rb
index 748381a1f1..e87941b370 100644
--- a/core/src/main/ruby/jruby/kernel/kernel.rb
+++ b/core/src/main/ruby/jruby/kernel/kernel.rb
@@ -5,12 +5,12 @@ module Kernel
end
# Replaces Java version for better caching
- def initialize_dup(original)
- initialize_copy(original)
+ def initialize_dup(...)
+ initialize_copy(...)
end
# Replaces Java version for better caching
- def initialize_clone(original)
- initialize_copy(original)
+ def initialize_clone(...)
+ initialize_copy(...)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment