Skip to content

Commit

Permalink
Merge branch 'master' into ruby-2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Mar 27, 2018
2 parents e13b58c + 25df05d commit e87f729
Show file tree
Hide file tree
Showing 73 changed files with 752 additions and 170 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
Expand Up @@ -5278,7 +5278,7 @@ private void setNetworkStack() {
deprecatedNetworkStackProperty();
}

@SuppressWarnings("deprecated")
@SuppressWarnings("deprecation")
private void deprecatedNetworkStackProperty() {
if (Options.PREFER_IPV4.load()) {
LOG.warn("Warning: not setting network stack system property because socket subsystem may already be booted."
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/java/org/jruby/RubyInteger.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,17 +337,16 @@ public IRubyObject succ(ThreadContext context) {
}

static final ByteList[] SINGLE_CHAR_BYTELISTS;
@Deprecated
public static final ByteList[] SINGLE_CHAR_BYTELISTS19;
static {
SINGLE_CHAR_BYTELISTS = new ByteList[256];
for (int i = 0; i < 256; i++) {
ByteList bytes = new ByteList(new byte[] { (byte) i }, false);
SINGLE_CHAR_BYTELISTS[i] = bytes;
bytes.setEncoding(i < 0x80 ? USASCIIEncoding.INSTANCE : ASCIIEncoding.INSTANCE);
}
SINGLE_CHAR_BYTELISTS19 = SINGLE_CHAR_BYTELISTS;
}
@Deprecated
public static final ByteList[] SINGLE_CHAR_BYTELISTS19 = SINGLE_CHAR_BYTELISTS;

static ByteList singleCharByteList(final byte index) {
return SINGLE_CHAR_BYTELISTS[index & 0xFF];
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
import org.jruby.anno.JRubyMethod;
import org.jruby.anno.JRubyClass;
import org.jruby.internal.runtime.methods.AliasMethod;
import org.jruby.internal.runtime.methods.DelegatingDynamicMethod;
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.internal.runtime.methods.IRMethodArgs;
import org.jruby.internal.runtime.methods.ProcMethod;
import org.jruby.internal.runtime.methods.WrapperMethod;
import org.jruby.runtime.ArgumentDescriptor;
import org.jruby.runtime.Block;
import org.jruby.runtime.ClassIndex;
Expand Down Expand Up @@ -259,7 +259,7 @@ public IRubyObject inspect() {
RubyModule definedClass;
RubyModule mklass = originModule;

if (method instanceof AliasMethod || method instanceof WrapperMethod) {
if (method instanceof AliasMethod || method instanceof DelegatingDynamicMethod) {
definedClass = method.getRealMethod().getDefinedClass();
}
else {
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.internal.runtime.methods.JavaMethod;
import org.jruby.internal.runtime.methods.NativeCallMethod;
import org.jruby.internal.runtime.methods.PartialDelegatingMethod;
import org.jruby.internal.runtime.methods.ProcMethod;
import org.jruby.internal.runtime.methods.SynchronizedDynamicMethod;
import org.jruby.internal.runtime.methods.UndefinedMethod;
import org.jruby.internal.runtime.methods.WrapperMethod;
import org.jruby.ir.IRClosure;
import org.jruby.ir.IRMethod;
import org.jruby.ir.runtime.IRRuntimeHelpers;
Expand All @@ -105,7 +105,6 @@
import org.jruby.runtime.ivars.MethodData;
import org.jruby.runtime.marshal.MarshalStream;
import org.jruby.runtime.marshal.UnmarshalStream;
import org.jruby.runtime.opto.ConstantInvalidator;
import org.jruby.runtime.opto.Invalidator;
import org.jruby.runtime.opto.OptoFactory;
import org.jruby.runtime.profile.MethodEnhancer;
Expand Down Expand Up @@ -1851,7 +1850,7 @@ public void exportMethod(String name, Visibility visibility) {
if (this == method.getImplementationClass()) {
method.setVisibility(visibility);
} else {
DynamicMethod newMethod = new WrapperMethod(this, method, visibility);
DynamicMethod newMethod = new PartialDelegatingMethod(this, method, visibility);

methodLocation.addMethod(name, newMethod);
}
Expand Down
85 changes: 85 additions & 0 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
Expand Up @@ -5358,6 +5358,91 @@ public IRubyObject size(IRubyObject[] args) {
};
}

private static ByteList GRAPHEME_CLUSTER_PATTERN = new ByteList(new byte[] {(byte)'\\', (byte)'X'});

private SizeFn eachGraphemeClusterSizeFn() {
final RubyString self = this;
return new SizeFn() {
@Override
public IRubyObject size(IRubyObject[] args) {
Ruby runtime = self.getRuntime();
ByteList value = self.getByteList();
Encoding enc = value.getEncoding();
if (!enc.isUnicode() || isSingleByteOptimizable(self, enc)) return self.length();

Regex reg = RubyRegexp.getRegexpFromCache(runtime, GRAPHEME_CLUSTER_PATTERN, enc, RegexpOptions.NULL_OPTIONS);
int beg = value.getBegin();
int end = beg + value.getRealSize();
Matcher matcher = reg.matcher(value.getUnsafeBytes(), beg, end);
int count = 0;

while (beg < end) {
int len = matcher.match(beg, end, Option.DEFAULT);
if (len <= 0) break;
count++;
beg += len;
}
return RubyFixnum.newFixnum(runtime, count);
}
};
}

private IRubyObject enumerateGraphemeClusters(ThreadContext context, String name, Block block, boolean wantarray) {
RubyString str = this;
RubyArray ary = null;
Ruby runtime = context.getRuntime();
Encoding enc = value.getEncoding();
if (!enc.isUnicode() || isSingleByteOptimizable(str, enc)) return enumerateChars(context, name, block, wantarray);

if (block.isGiven()) {
if (wantarray) {
// this code should be live in 3.0
if (false) {
runtime.getWarnings().warn("given block not used");
ary = RubyArray.newArray(runtime);
} else {
runtime.getWarnings().warning("passing a block to String#grapheme_clusters is deprecated");
wantarray = false;
}
}
} else {
if (wantarray)
ary = RubyArray.newBlankArray(runtime, str.size());
else
return enumeratorizeWithSize(context, str, name, eachGraphemeClusterSizeFn());
}

Regex reg = RubyRegexp.getRegexpFromCache(runtime, GRAPHEME_CLUSTER_PATTERN, enc, RegexpOptions.NULL_OPTIONS);

int beg = value.getBegin();
int end = beg + value.getRealSize();
byte[]bytes = value.getUnsafeBytes();
Matcher matcher = reg.matcher(bytes, beg, end);

while (beg < end) {
int len = matcher.match(beg, end, Option.DEFAULT);
if (len <= 0) break;
RubyString result = newStringShared(runtime, bytes, beg, len, enc);
if (wantarray)
ary.push(result);
else
block.yield(context, result);
beg += len;
}

return wantarray ? ary : str;
}

@JRubyMethod
public IRubyObject grapheme_clusters(ThreadContext context, Block block) {
return enumerateGraphemeClusters(context, "grapheme_clusters", block, true);
}

@JRubyMethod
public IRubyObject each_grapheme_cluster(ThreadContext context, Block block) {
return enumerateGraphemeClusters(context, "each_grapheme_cluster", block, false);
}

/** rb_str_intern
*
*/
Expand Down
26 changes: 10 additions & 16 deletions core/src/main/java/org/jruby/RubyTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -1589,20 +1589,15 @@ private static RubyTime createTime(ThreadContext context, RubyClass klass, IRuby
RubyTime time = new RubyTime(runtime, klass, dt);
// Ignores usec if 8 args (for compatibility with parse-date) or if not supplied.
if (args.length != 8 && args[6] != context.nil) {
boolean fractionalUSecGiven = args[6] instanceof RubyFloat || args[6] instanceof RubyRational;

if (fractionalUSecGiven) {
if (args[6] instanceof RubyRational) {
RubyRational usecRat = (RubyRational) args[6];
RubyRational nsecRat = (RubyRational) usecRat.op_mul(context, runtime.newFixnum(1000));
double tmpNanos = nsecRat.getDoubleValue(context);
time.dt = dt.withMillis((long) (dt.getMillis() + (tmpNanos / 1000000)));
nanos = (long) tmpNanos % 1000000;
} else {
double micros = RubyNumeric.num2dbl(args[6]);
time.dt = dt.withMillis(dt.getMillis() + (long) (micros / 1000));
nanos = (long) Math.rint((micros * 1000) % 1000000);
}
if (args[6] instanceof RubyRational) {
RubyRational nsec = (RubyRational) ((RubyRational) args[6]).op_mul(context, runtime.newFixnum(1000));
long tmpNanos = (long) nsec.getDoubleValue(context);
time.dt = dt.withMillis(dt.getMillis() + (tmpNanos / 1_000_000));
nanos = tmpNanos % 1_000_000;
} else if (args[6] instanceof RubyFloat) {
double micros = ((RubyFloat) args[6]).getDoubleValue();
time.dt = dt.withMillis(dt.getMillis() + (long) (micros / 1000));
nanos = (long) Math.rint((micros * 1000) % 1_000_000);
} else {
int usec = i_args4 % 1000;
int msec = i_args4 / 1000;
Expand All @@ -1616,8 +1611,7 @@ private static RubyTime createTime(ThreadContext context, RubyClass klass, IRuby
}
}

if (nanos != 0)
time.setNSec(nanos);
if (nanos != 0) time.setNSec(nanos);

time.callInit(IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);
time.setIsTzRelative(setTzRelative);
Expand Down
12 changes: 6 additions & 6 deletions core/src/main/java/org/jruby/TopSelfFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static IRubyObject createTopSelf(final Ruby runtime, final boolean wrappe

final RubyClass singletonClass = topSelf.getSingletonClass();

singletonClass.addMethod("to_s", new JavaMethod.JavaMethodZero(singletonClass, Visibility.PUBLIC) {
singletonClass.addMethod("to_s", new JavaMethod.JavaMethodZero(singletonClass, Visibility.PUBLIC, "to_s") {
@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name) {
return runtime.newString("main");
Expand All @@ -70,29 +70,29 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz

// The following three methods must be defined fast, since they expect to modify the current frame
// (i.e. they expect no frame will be allocated for them). JRUBY-1185.
singletonClass.addMethod("include", new JavaMethod.JavaMethodN(singletonClass, Visibility.PRIVATE) {
singletonClass.addMethod("include", new JavaMethod.JavaMethodN(singletonClass, Visibility.PRIVATE, "include") {
@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
return context.runtime.getObject().include(args);
}
});

singletonClass.addMethod("public", new JavaMethod.JavaMethodN(singletonClass, Visibility.PRIVATE) {
singletonClass.addMethod("public", new JavaMethod.JavaMethodN(singletonClass, Visibility.PRIVATE, "public") {
@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
return context.runtime.getObject().rbPublic(context, args);
}
});

singletonClass.addMethod("private", new JavaMethod.JavaMethodN(singletonClass, Visibility.PRIVATE) {
singletonClass.addMethod("private", new JavaMethod.JavaMethodN(singletonClass, Visibility.PRIVATE, "private") {
@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
return context.runtime.getObject().rbPrivate(context, args);
}
});

final RubyClass klass = wrapper ? singletonClass : runtime.getObject();
singletonClass.addMethod("define_method", new JavaMethod.JavaMethodOneOrTwoBlock(singletonClass, Visibility.PRIVATE) {
singletonClass.addMethod("define_method", new JavaMethod.JavaMethodOneOrTwoBlock(singletonClass, Visibility.PRIVATE, "define_method") {
@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, Block block) {
if (klass == singletonClass) warnWrapper(context);
Expand All @@ -106,7 +106,7 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
}
});

singletonClass.addMethod("using", new JavaMethod.JavaMethodN(singletonClass, Visibility.PRIVATE) {
singletonClass.addMethod("using", new JavaMethod.JavaMethodN(singletonClass, Visibility.PRIVATE, "using") {
@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
Arity.checkArgumentCount(context.runtime, args, 1, 1);
Expand Down
7 changes: 6 additions & 1 deletion core/src/main/java/org/jruby/anno/IndyBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,12 @@ public void processMethodDeclarationMulti(List<ExecutableElement> methods) {
}
buffer.append(')');

Handle handle = new Handle(isStatic ? H_INVOKESTATIC : H_INVOKEVIRTUAL, qualifiedName.toString().replace('.', '/'), method.getSimpleName().toString(), Method.getMethod(buffer.toString()).getDescriptor());
Handle handle = new Handle(
isStatic ? H_INVOKESTATIC : H_INVOKEVIRTUAL,
qualifiedName.toString().replace('.', '/'),
method.getSimpleName().toString(),
Method.getMethod(buffer.toString()).getDescriptor(),
false);

int handleOffset = calculateHandleOffset(method.getParameters().size(), anno.required(), anno.optional(), anno.rest(), isStatic, hasContext, hasBlock);

Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/org/jruby/ext/coverage/CoverageData.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ private boolean hasCodeBeenPartiallyCovered(int[] lines) {
public synchronized Map<String, int[]> prepareCoverage(String filename, int[] lines) {
assert lines != null;

if (filename == null) {
// null filename from certain evals, Ruby.executeScript, etc (jruby/jruby#5111)
// we opt to ignore scripts with no filename, since coverage means nothing
return coverage;
}

Map<String, int[]> coverage = this.coverage;

if (coverage != null) {
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/org/jruby/ext/date/RubyDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public IRubyObject initialize_copy(IRubyObject original) {
/**
* @deprecated internal Date.new!
*/
@JRubyMethod(name = "new!", meta = true)
@JRubyMethod(name = "new!", meta = true, visibility = Visibility.PRIVATE)
public static RubyDate new_(ThreadContext context, IRubyObject self) {
if (self == getDateTime(context.runtime)) {
return new RubyDateTime(context.runtime, 0, CHRONO_ITALY_UTC);
Expand All @@ -304,7 +304,7 @@ public static RubyDate new_(ThreadContext context, IRubyObject self) {
/**
* @deprecated internal Date.new!
*/
@JRubyMethod(name = "new!", meta = true)
@JRubyMethod(name = "new!", meta = true, visibility = Visibility.PRIVATE)
public static RubyDate new_(ThreadContext context, IRubyObject self, IRubyObject ajd) {
if (ajd instanceof JavaProxy) { // backwards - compatibility with JRuby's date.rb
if (self == getDateTime(context.runtime)) {
Expand All @@ -321,7 +321,7 @@ public static RubyDate new_(ThreadContext context, IRubyObject self, IRubyObject
/**
* @deprecated internal Date.new!
*/
@JRubyMethod(name = "new!", meta = true)
@JRubyMethod(name = "new!", meta = true, visibility = Visibility.PRIVATE)
public static RubyDate new_(ThreadContext context, IRubyObject self, IRubyObject ajd, IRubyObject of) {
if (self == getDateTime(context.runtime)) {
return new RubyDateTime(context.runtime, (RubyClass) self).initialize(context, ajd, of);
Expand All @@ -332,7 +332,7 @@ public static RubyDate new_(ThreadContext context, IRubyObject self, IRubyObject
/**
* @deprecated internal Date.new!
*/
@JRubyMethod(name = "new!", meta = true)
@JRubyMethod(name = "new!", meta = true, visibility = Visibility.PRIVATE)
public static RubyDate new_(ThreadContext context, IRubyObject self, IRubyObject ajd, IRubyObject of, IRubyObject sg) {
if (self == getDateTime(context.runtime)) {
return new RubyDateTime(context.runtime, (RubyClass) self).initialize(context, ajd, of, sg);
Expand Down
9 changes: 9 additions & 0 deletions core/src/main/java/org/jruby/ext/socket/RubyUDPSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.net.SocketAddress;
import java.net.SocketException;
import java.net.MulticastSocket;
import java.net.SocketOption;
import java.net.StandardProtocolFamily;
import java.net.UnknownHostException;
import java.net.DatagramPacket;
Expand All @@ -49,6 +50,7 @@
import java.nio.channels.Channel;
import java.nio.channels.DatagramChannel;
import java.nio.channels.NotYetConnectedException;
import java.nio.channels.UnsupportedAddressTypeException;

import jnr.constants.platform.AddressFamily;
import jnr.netdb.Service;
Expand Down Expand Up @@ -124,6 +126,7 @@ public IRubyObject initialize(ThreadContext context, ProtocolFamily family) {
Ruby runtime = context.runtime;

try {
this.family = family;
DatagramChannel channel = DatagramChannel.open(family);
initSocket(newChannelFD(runtime, channel));
} catch (ConnectException e) {
Expand Down Expand Up @@ -189,6 +192,11 @@ else if (host instanceof RubyFixnum) {

return RubyFixnum.zero(runtime);
}
catch (UnsupportedAddressTypeException e) {
// This may not be the appropriate message for all such exceptions
ProtocolFamily family = this.family == null ? StandardProtocolFamily.INET : this.family;
throw SocketUtils.sockerr(runtime, "bind: unsupported address " + host.inspect() + " for protocol family " + family);
}
catch (UnknownHostException e) {
throw SocketUtils.sockerr(runtime, "bind: name or service not known");
}
Expand Down Expand Up @@ -634,6 +642,7 @@ private static IRubyObject doReceiveMulticast(RubyBasicSocket socket, final Ruby
}

private volatile Class<? extends InetAddress> explicitFamily;
private volatile ProtocolFamily family;

@Deprecated
public IRubyObject bind(IRubyObject host, IRubyObject port) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public Arity getArity() {
/**
* Get the "real" method contained within this method. This simply returns
* self except in cases where a method is wrapped to give it a new
* name or new implementation class (AliasMethod, WrapperMethod, ...).
* name or new implementation class (AliasMethod, PartialDelegatingMethod, ...).
*
* @return The "real" method associated with this one
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ public DynamicMethod getAnnotatedMethod(RubyModule implementationClass, JavaMeth
}
}

@SuppressWarnings("deprecation")
public JavaMethod constructJavaMethod(RubyModule implementationClass, JavaMethodDescriptor desc, String name, Class c) throws InstantiationException, IllegalAccessException, java.lang.reflect.InvocationTargetException, NoSuchMethodException {
// In order to support older versions of generated JavaMethod invokers, we check for the Version
// annotation to be present and > 0. If absent, we use a thread local to allow the deprecated constructor
Expand Down
Loading

0 comments on commit e87f729

Please sign in to comment.