Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'jruby-9.1' into fix_method_inspect_4995
Browse files Browse the repository at this point in the history
headius committed Jan 22, 2018
2 parents 288fc1b + fc97cd8 commit 2936884
Showing 9 changed files with 17 additions and 54 deletions.
37 changes: 1 addition & 36 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -63,7 +63,6 @@
import org.jruby.parser.StaticScope;
import org.jruby.runtime.JavaSites;
import org.jruby.runtime.invokedynamic.InvokeDynamicSupport;
import org.jruby.runtime.opto.ConstantInvalidator;
import org.jruby.util.MRIRecursionGuard;
import org.jruby.util.io.EncodingUtils;
import org.objectweb.asm.util.TraceClassVisitor;
@@ -172,8 +171,6 @@
import java.lang.invoke.MethodHandle;
import java.lang.ref.WeakReference;
import java.net.BindException;
import java.net.PortUnreachableException;
import java.nio.channels.ClosedChannelException;
import java.nio.charset.Charset;
import java.security.SecureRandom;
import java.util.ArrayList;
@@ -198,8 +195,6 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.regex.Pattern;

import static java.lang.invoke.MethodHandles.explicitCastArguments;
@@ -4582,41 +4577,11 @@ public RubyString freezeAndDedupString(RubyString string) {
RubyString deduped;

if (dedupedRef == null || (deduped = dedupedRef.get()) == null) {
// Never use value as key
deduped = string.strDup(this);
deduped.setFrozen(true);

final WeakReference<RubyString> weakref = new WeakReference<>(deduped);

// try to insert new
dedupedRef = dedupMap.computeIfAbsent(string, new Function<RubyString, WeakReference<RubyString>>() {
@Override
public WeakReference<RubyString> apply(RubyString key) {
return weakref;
}
});
if (dedupedRef == null) return deduped;

// entry exists, return result if not vacated
RubyString unduped = dedupedRef.get();
if (unduped != null) return unduped;

// ref is there but vacated, try to replace it until we have a result
while (true) {
dedupedRef = dedupMap.computeIfPresent(string, new BiFunction<RubyString, WeakReference<RubyString>, WeakReference<RubyString>>() {
@Override
public WeakReference<RubyString> apply(RubyString key, WeakReference<RubyString> old) {
return old.get() == null ? weakref : old;
}
});

// return result if not vacated
unduped = dedupedRef.get();
if (unduped != null) return unduped;
}
dedupMap.put(string, new WeakReference<RubyString>(deduped));
} else if (deduped.getEncoding() != string.getEncoding()) {
// if encodings don't match, new string loses; can't dedup
// FIXME: This may never happen, if we are properly considering encoding in RubyString.hashCode
deduped = string.strDup(this);
deduped.setFrozen(true);
}
3 changes: 3 additions & 0 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -2607,6 +2607,9 @@ public RubyModule append_features(IRubyObject include) {
*/
@JRubyMethod(name = "extend_object", required = 1, visibility = PRIVATE)
public IRubyObject extend_object(IRubyObject obj) {
if (!isModule()) {
throw getRuntime().newTypeError(this, getRuntime().getModule());
}
obj.getSingletonClass().includeModule(this);
return obj;
}
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -5222,6 +5222,10 @@ private RubySymbol to_sym() {
RubySymbol specialCaseIntern = checkSpecialCasesIntern(value);
if (specialCaseIntern != null) return specialCaseIntern;

if (scanForCodeRange() == CR_BROKEN) {
throw getRuntime().newEncodingError("invalid symbol in encoding " + getEncoding() + " :" + inspect());
}

RubySymbol symbol = getRuntime().getSymbolTable().getSymbol(value);
if (symbol.getBytes() == value) shareLevel = SHARE_LEVEL_BYTELIST;
return symbol;
21 changes: 8 additions & 13 deletions core/src/main/java/org/jruby/RubySymbol.java
Original file line number Diff line number Diff line change
@@ -256,27 +256,22 @@ public IRubyObject inspect(ThreadContext context) {
}

final RubyString inspect(final Ruby runtime) {
ByteList result = new ByteList(symbolBytes.getRealSize() + 1);
result.setEncoding(symbolBytes.getEncoding());
result.append((byte)':');
result.append(symbolBytes);

// TODO: 1.9 rb_enc_symname_p
Encoding resenc = runtime.getDefaultInternalEncoding();
if (resenc == null) resenc = runtime.getDefaultExternalEncoding();

RubyString str = RubyString.newString(runtime, result);
RubyString str = RubyString.newString(runtime, symbolBytes);

if (isPrintable() && (resenc.equals(symbolBytes.getEncoding()) || str.isAsciiOnly()) && isSymbolName19(symbol)) {
return str;
if (!(isPrintable() && (resenc.equals(symbolBytes.getEncoding()) || str.isAsciiOnly()) && isSymbolName19(symbol))) {
str = str.inspect(runtime);
}

str = str.inspect(runtime);
ByteList bytes = str.getByteList();
bytes.set(0, ':');
bytes.set(1, '"');
ByteList result = new ByteList(str.getByteList().getRealSize() + 1);
result.setEncoding(str.getEncoding());
result.append((byte)':');
result.append(str.getBytes());

return str;
return RubyString.newString(runtime, result);
}

@Deprecated
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/lexer/yacc/RubyLexer.java
Original file line number Diff line number Diff line change
@@ -1883,6 +1883,7 @@ private int questionMark() throws IOException {
}

ByteList oneCharBL = new ByteList(1);
oneCharBL.setEncoding(getEncoding());
oneCharBL.append(c);
yaccValue = new StrNode(getPosition(), oneCharBL);
setState(EXPR_END);
1 change: 0 additions & 1 deletion test/mri/excludes/TestClass.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
exclude :test_cannot_reinitialize_class_with_initialize_copy, "broken subprocess logic in setup"
exclude :test_check_inheritable, "needs investigation"
exclude :test_extend_object, "needs investigation"
exclude :test_invalid_jump_from_class_definition, "needs investigation"
exclude :test_method_redefinition, "needs investigation"
exclude :test_module_function, "needs investigation"
1 change: 0 additions & 1 deletion test/mri/excludes/TestM17N.rb
Original file line number Diff line number Diff line change
@@ -2,4 +2,3 @@
exclude :test_nonascii_method_name, "lexer is not pulling mbc characters off the wire correctly"
exclude :test_split, "our impl has diverged and does not appear to handle encoded null char properly"
exclude :test_symbol, "management of differently-encoded symbols is not right"
exclude :test_symbol_op, "some symbols are created early and do not have UTF-8 encoding; management of differently-encoded symbols is not right"
1 change: 0 additions & 1 deletion test/mri/excludes/TestStringchar.rb

This file was deleted.

2 changes: 0 additions & 2 deletions test/mri/excludes/TestSymbol.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
exclude :test_ascii_incomat_inspect, "needs investigation"
exclude :test_inspect, "needs investigation"
exclude :test_to_proc_arg, "we have plans to do different caching here, see 69662ab8cd1616a2ee076488226a473648fc6267"
exclude :test_to_proc_binding, "needs investigation #4303"
exclude :test_to_proc_iseq, "needs investigation #4303"
exclude :test_symbol_encoding, "needs investigation"
exclude :test_symbol_fstr_leak, "assert_no_memory_leak fails due an unexpected nil"

0 comments on commit 2936884

Please sign in to comment.