Skip to content

Commit f8ac719

Browse files
committedJan 29, 2018
Merge branch 'jruby-9.1'
2 parents 61205a6 + 577d13a commit f8ac719

39 files changed

+144
-246
lines changed
 

‎core/pom.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@
4646
jar 'com.github.jnr:jnr-enxio:0.16', :exclusions => ['com.github.jnr:jnr-ffi']
4747
jar 'com.github.jnr:jnr-x86asm:1.0.2', :exclusions => ['com.github.jnr:jnr-ffi']
4848
jar 'com.github.jnr:jnr-unixsocket:0.17', :exclusions => ['com.github.jnr:jnr-ffi']
49-
jar 'com.github.jnr:jnr-posix:3.0.43', :exclusions => ['com.github.jnr:jnr-ffi']
49+
jar 'com.github.jnr:jnr-posix:3.0.44', :exclusions => ['com.github.jnr:jnr-ffi']
5050
jar 'com.github.jnr:jnr-constants:0.9.9', :exclusions => ['com.github.jnr:jnr-ffi']
5151
jar 'com.github.jnr:jnr-ffi:2.1.7'
5252
jar 'com.github.jnr:jffi:${jffi.version}'
5353
jar 'com.github.jnr:jffi:${jffi.version}:native'
5454

55-
jar 'org.jruby.joni:joni:2.1.13'
55+
jar 'org.jruby.joni:joni:2.1.14'
5656
jar 'org.jruby.extras:bytelist:1.0.15'
57-
jar 'org.jruby.jcodings:jcodings:1.0.26'
57+
jar 'org.jruby.jcodings:jcodings:1.0.27'
5858
jar 'org.jruby:dirgra:0.3'
5959

6060
jar 'com.headius:invokebinder:1.11'

‎core/pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ DO NOT MODIFIY - GENERATED CODE
135135
<dependency>
136136
<groupId>com.github.jnr</groupId>
137137
<artifactId>jnr-posix</artifactId>
138-
<version>3.0.43</version>
138+
<version>3.0.44</version>
139139
<exclusions>
140140
<exclusion>
141141
<artifactId>jnr-ffi</artifactId>
@@ -173,7 +173,7 @@ DO NOT MODIFIY - GENERATED CODE
173173
<dependency>
174174
<groupId>org.jruby.joni</groupId>
175175
<artifactId>joni</artifactId>
176-
<version>2.1.13</version>
176+
<version>2.1.14</version>
177177
</dependency>
178178
<dependency>
179179
<groupId>org.jruby.extras</groupId>
@@ -183,7 +183,7 @@ DO NOT MODIFIY - GENERATED CODE
183183
<dependency>
184184
<groupId>org.jruby.jcodings</groupId>
185185
<artifactId>jcodings</artifactId>
186-
<version>1.0.26</version>
186+
<version>1.0.27</version>
187187
</dependency>
188188
<dependency>
189189
<groupId>org.jruby</groupId>

‎core/src/main/java/org/jruby/RubyEncoding.java

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import org.jruby.runtime.encoding.EncodingService;
5252
import org.jruby.runtime.opto.OptoFactory;
5353
import org.jruby.util.ByteList;
54-
import org.jruby.util.CodeRangeable;
5554
import org.jruby.util.StringSupport;
5655
import org.jruby.util.io.EncodingUtils;
5756
import org.jruby.util.unsafe.UnsafeHolder;

‎core/src/main/java/org/jruby/RubyHash.java

+24-11
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,6 @@ protected final void checkIterating() {
515515
throw getRuntime().newRuntimeError("can't add a new key into hash during iteration");
516516
}
517517
}
518-
// ------------------------------
519-
public static long collisions = 0;
520518

521519
// put implementation
522520

@@ -525,26 +523,32 @@ private final void internalPut(final IRubyObject key, final IRubyObject value) {
525523
}
526524

527525
private final void internalPutSmall(final IRubyObject key, final IRubyObject value) {
528-
internalPutSmall(key, value, true);
526+
internalPutNoResize(key, value, true);
529527
}
530528

531529
protected void internalPut(final IRubyObject key, final IRubyObject value, final boolean checkForExisting) {
532530
checkResize();
533531

534-
internalPutSmall(key, value, checkForExisting);
532+
internalPutNoResize(key, value, checkForExisting);
535533
}
536534

537-
protected void internalPutSmall(final IRubyObject key, final IRubyObject value, final boolean checkForExisting) {
535+
protected final IRubyObject internalJavaPut(final IRubyObject key, final IRubyObject value) {
536+
checkResize();
537+
538+
return internalPutNoResize(key, value, true);
539+
}
540+
541+
protected IRubyObject internalPutNoResize(final IRubyObject key, final IRubyObject value, final boolean checkForExisting) {
538542
final int hash = hashValue(key);
539543
final int i = bucketIndex(hash, table.length);
540544

541-
// if (table[i] != null) collisions++;
542-
543545
if (checkForExisting) {
544546
for (RubyHashEntry entry = table[i]; entry != null; entry = entry.next) {
545547
if (internalKeyExist(entry, hash, key)) {
548+
IRubyObject existing = entry.value;
546549
entry.value = value;
547-
return;
550+
551+
return existing;
548552
}
549553
}
550554
}
@@ -553,6 +557,9 @@ protected void internalPutSmall(final IRubyObject key, final IRubyObject value,
553557

554558
table[i] = new RubyHashEntry(hash, key, value, table[i], head);
555559
size++;
560+
561+
// no existing entry
562+
return null;
556563
}
557564

558565
// get implementation
@@ -1040,7 +1047,7 @@ protected void op_asetSmallForString(Ruby runtime, RubyString key, IRubyObject v
10401047
} else {
10411048
checkIterating();
10421049
if (!key.isFrozen()) key = (RubyString)key.dupFrozen();
1043-
internalPutSmall(key, value, false);
1050+
internalPutNoResize(key, value, false);
10441051
}
10451052
}
10461053

@@ -2159,8 +2166,9 @@ public Object get(Object key) {
21592166

21602167
@Override
21612168
public Object put(Object key, Object value) {
2162-
internalPut(JavaUtil.convertJavaToUsableRubyObject(getRuntime(), key), JavaUtil.convertJavaToUsableRubyObject(getRuntime(), value));
2163-
return value;
2169+
Ruby runtime = getRuntime();
2170+
IRubyObject existing = internalJavaPut(JavaUtil.convertJavaToUsableRubyObject(runtime, key), JavaUtil.convertJavaToUsableRubyObject(runtime, value));
2171+
return existing == null ? null : existing.toJava(Object.class);
21642172
}
21652173

21662174
@Override
@@ -2600,4 +2608,9 @@ public IRubyObject default_value_get(ThreadContext context, IRubyObject[] args)
26002608
throw context.runtime.newArgumentError(args.length, 1);
26012609
}
26022610
}
2611+
2612+
@Deprecated
2613+
protected void internalPutSmall(final IRubyObject key, final IRubyObject value, final boolean checkForExisting) {
2614+
internalPutNoResize(key, value, checkForExisting);
2615+
}
26032616
}

‎core/src/main/java/org/jruby/RubyIO.java

+20-13
Original file line numberDiff line numberDiff line change
@@ -2204,8 +2204,8 @@ public IRubyObject close_on_exec_set(ThreadContext context, IRubyObject arg) {
22042204
int fd = -1;
22052205

22062206
if (fptr == null || (fd = fptr.fd().realFileno) == -1
2207-
|| !posix.isNative()) {
2208-
runtime.getWarnings().warning("close_on_exec is not implemented for this stream type: " + fptr.fd().ch.getClass().getSimpleName());
2207+
|| !posix.isNative() || Platform.IS_WINDOWS ) {
2208+
runtime.getWarnings().warning("close_on_exec is not implemented on this platform for this stream type: " + fptr.fd().ch.getClass().getSimpleName());
22092209
return context.nil;
22102210
}
22112211

@@ -2408,12 +2408,12 @@ public void setBlocking(boolean blocking) {
24082408

24092409
@JRubyMethod(name = "fcntl")
24102410
public IRubyObject fcntl(ThreadContext context, IRubyObject cmd) {
2411-
return ctl(context.runtime, cmd, null);
2411+
return ctl(context, cmd, null);
24122412
}
24132413

24142414
@JRubyMethod(name = "fcntl")
24152415
public IRubyObject fcntl(ThreadContext context, IRubyObject cmd, IRubyObject arg) {
2416-
return ctl(context.runtime, cmd, arg);
2416+
return ctl(context, cmd, arg);
24172417
}
24182418

24192419
@JRubyMethod(name = "ioctl", required = 1, optional = 1)
@@ -2427,10 +2427,11 @@ public IRubyObject ioctl(ThreadContext context, IRubyObject[] args) {
24272427
arg = context.runtime.getNil();
24282428
}
24292429

2430-
return ctl(context.runtime, cmd, arg);
2430+
return ctl(context, cmd, arg);
24312431
}
24322432

2433-
private IRubyObject ctl(Ruby runtime, IRubyObject cmd, IRubyObject arg) {
2433+
private IRubyObject ctl(ThreadContext context, IRubyObject cmd, IRubyObject arg) {
2434+
Ruby runtime = context.runtime;
24342435
long realCmd = cmd.convertToInteger().getLongValue();
24352436
long nArg = 0;
24362437

@@ -2463,25 +2464,31 @@ private IRubyObject ctl(Ruby runtime, IRubyObject cmd, IRubyObject arg) {
24632464
// for mode changes which should persist across fork() boundaries. Since JVM has no fork
24642465
// this is not a problem for us.
24652466
if (realCmd == FcntlLibrary.FD_CLOEXEC) {
2466-
close_on_exec_set(runtime.getCurrentContext(), runtime.getTrue());
2467+
close_on_exec_set(context, runtime.getTrue());
24672468
} else if (realCmd == Fcntl.F_SETFD.intValue()) {
24682469
if (arg != null && (nArg & FcntlLibrary.FD_CLOEXEC) == FcntlLibrary.FD_CLOEXEC) {
2469-
close_on_exec_set(runtime.getCurrentContext(), arg);
2470+
close_on_exec_set(context, arg);
24702471
} else {
24712472
throw runtime.newNotImplementedError("F_SETFD only supports FD_CLOEXEC");
24722473
}
24732474
} else if (realCmd == Fcntl.F_GETFD.intValue()) {
2474-
return runtime.newFixnum(close_on_exec_p(runtime.getCurrentContext()).isTrue() ? FD_CLOEXEC : 0);
2475+
return runtime.newFixnum(close_on_exec_p(context).isTrue() ? FD_CLOEXEC : 0);
24752476
} else if (realCmd == Fcntl.F_SETFL.intValue()) {
24762477
if ((nArg & OpenFlags.O_NONBLOCK.intValue()) != 0) {
2477-
boolean block = (nArg & ModeFlags.NONBLOCK) != ModeFlags.NONBLOCK;
2478+
fptr.setBlocking(runtime, true);
2479+
} else {
2480+
fptr.setBlocking(runtime, false);
2481+
}
24782482

2479-
fptr.setBlocking(runtime, block);
2483+
if ((nArg & OpenFlags.O_CLOEXEC.intValue()) != 0) {
2484+
close_on_exec_set(context, context.tru);
24802485
} else {
2481-
throw runtime.newNotImplementedError("F_SETFL only supports O_NONBLOCK");
2486+
close_on_exec_set(context, context.fals);
24822487
}
24832488
} else if (realCmd == Fcntl.F_GETFL.intValue()) {
2484-
return fptr.isBlocking() ? RubyFixnum.zero(runtime) : RubyFixnum.newFixnum(runtime, ModeFlags.NONBLOCK);
2489+
return runtime.newFixnum(
2490+
(fptr.isBlocking() ? 0 : OpenFlags.O_NONBLOCK.intValue()) |
2491+
(close_on_exec_p(context).isTrue() ? FD_CLOEXEC : 0));
24852492
} else {
24862493
throw runtime.newNotImplementedError("JRuby only supports F_SETFL and F_GETFL with NONBLOCK for fcntl/ioctl");
24872494
}

‎core/src/main/java/org/jruby/RubyModule.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -1212,11 +1212,6 @@ public final void addMethodAtBootTimeOnly(String name, DynamicMethod method) {
12121212
method.setImplementationClass(methodLocation);
12131213
}
12141214

1215-
// if method does not have a name already, set it
1216-
if (method.getName() == null) {
1217-
method.setName(name);
1218-
}
1219-
12201215
methodLocation.getMethodsForWrite().put(name, method);
12211216

12221217
getRuntime().addProfiledMethod(name, method);
@@ -2064,7 +2059,7 @@ private DynamicMethod createProcMethod(String name, Visibility visibility, RubyP
20642059
// a method definition.
20652060
block.getBody().getStaticScope().makeArgumentScope();
20662061

2067-
return new ProcMethod(this, proc, visibility);
2062+
return new ProcMethod(this, proc, visibility, name);
20682063
}
20692064

20702065
public IRubyObject name() {

‎core/src/main/java/org/jruby/RubyNumeric.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.jruby.ast.util.ArgsUtil;
4040
import org.jruby.common.RubyWarnings;
4141
import org.jruby.exceptions.RaiseException;
42-
import org.jruby.internal.runtime.methods.DynamicMethod;
4342
import org.jruby.javasupport.JavaUtil;
4443
import org.jruby.runtime.Block;
4544
import org.jruby.runtime.CallSite;
@@ -50,7 +49,6 @@
5049
import org.jruby.runtime.ThreadContext;
5150
import org.jruby.runtime.Visibility;
5251
import org.jruby.runtime.builtin.IRubyObject;
53-
import org.jruby.runtime.callsite.CachingCallSite;
5452
import org.jruby.util.ByteList;
5553
import org.jruby.util.ConvertBytes;
5654
import org.jruby.util.ConvertDouble;
@@ -62,7 +60,11 @@
6260

6361
import static org.jruby.RubyEnumerator.SizeFn;
6462
import static org.jruby.RubyEnumerator.enumeratorizeWithSize;
65-
import static org.jruby.util.Numeric.*;
63+
import static org.jruby.util.Numeric.f_abs;
64+
import static org.jruby.util.Numeric.f_arg;
65+
import static org.jruby.util.Numeric.f_mul;
66+
import static org.jruby.util.Numeric.f_negative_p;
67+
import static org.jruby.util.Numeric.f_to_r;
6668

6769
/**
6870
* Base class for all numerical types in ruby.
@@ -1236,21 +1238,21 @@ protected final IRubyObject op_num_equal(ThreadContext context, IRubyObject othe
12361238
return numFuncall(context, other, sites(context).op_equals, this);
12371239
}
12381240

1239-
/** num_numerator
1241+
/** numeric_numerator
12401242
*
12411243
*/
12421244
@JRubyMethod(name = "numerator")
12431245
public IRubyObject numerator(ThreadContext context) {
1244-
IRubyObject rational = RubyRational.newRationalConvert(context, this);
1246+
IRubyObject rational = f_to_r(context, this);
12451247
return sites(context).numerator.call(context, rational, rational);
12461248
}
12471249

1248-
/** num_denominator
1250+
/** numeric_denominator
12491251
*
12501252
*/
12511253
@JRubyMethod(name = "denominator")
12521254
public IRubyObject denominator(ThreadContext context) {
1253-
IRubyObject rational = RubyRational.newRationalConvert(context, this);
1255+
IRubyObject rational = f_to_r(context, this);
12541256
return sites(context).denominator.call(context, rational, rational);
12551257
}
12561258

‎core/src/main/java/org/jruby/RubyStruct.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,9 @@ public static RubyClass newInstance(IRubyObject recv, IRubyObject[] args, Block
227227
final String memberName = args[i].asJavaString();
228228
// if we are storing a name as well, index is one too high for values
229229
final int index = (name == null && !nilName) ? i : i - 1;
230-
newStruct.addMethod(memberName, new Accessor(newStruct, index));
231-
newStruct.addMethod(memberName + '=', new Mutator(newStruct, index));
230+
newStruct.addMethod(memberName, new Accessor(newStruct, memberName, index));
231+
String nameAsgn = memberName + '=';
232+
newStruct.addMethod(nameAsgn, new Mutator(newStruct, nameAsgn, index));
232233
}
233234

234235
if (block.isGiven()) {
@@ -770,8 +771,8 @@ public IRubyObject initialize_copy(IRubyObject arg) {
770771
private static class Accessor extends DynamicMethod {
771772
private final int index;
772773

773-
public Accessor(RubyClass newStruct, int index) {
774-
super(newStruct, Visibility.PUBLIC);
774+
public Accessor(RubyClass newStruct, String name, int index) {
775+
super(newStruct, Visibility.PUBLIC, name);
775776
this.index = index;
776777
}
777778

@@ -788,15 +789,15 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
788789

789790
@Override
790791
public DynamicMethod dup() {
791-
return new Accessor((RubyClass) getImplementationClass(), index);
792+
return new Accessor((RubyClass) getImplementationClass(), name, index);
792793
}
793794
}
794795

795796
private static class Mutator extends DynamicMethod {
796797
private final int index;
797798

798-
public Mutator(RubyClass newStruct, int index) {
799-
super(newStruct, Visibility.PUBLIC);
799+
public Mutator(RubyClass newStruct, String name, int index) {
800+
super(newStruct, Visibility.PUBLIC, name);
800801
this.index = index;
801802
}
802803

@@ -813,7 +814,7 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
813814

814815
@Override
815816
public DynamicMethod dup() {
816-
return new Accessor((RubyClass) getImplementationClass(), index);
817+
return new Mutator((RubyClass) getImplementationClass(), name, index);
817818
}
818819
}
819820

‎core/src/main/java/org/jruby/ext/ffi/AbstractInvoker.java

-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ protected AbstractInvoker(Ruby runtime, RubyClass klass, int arity, MemoryIO io)
8080
public IRubyObject attach(ThreadContext context, IRubyObject obj, IRubyObject methodName) {
8181

8282
DynamicMethod m = createDynamicMethod(obj.getSingletonClass());
83-
m.setName(methodName.asJavaString());
8483
obj.getSingletonClass().addMethod(methodName.asJavaString(), m);
8584
if (obj instanceof RubyModule) {
8685
((RubyModule) obj).addMethod(methodName.asJavaString(), m);

‎core/src/main/java/org/jruby/ext/ffi/Pointer.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public boolean isKindOf(IRubyObject obj, RubyModule type) {
4242
Pointer nullPointer = new Pointer(runtime, pointerClass, new NullMemoryIO(runtime));
4343
pointerClass.setConstant("NULL", nullPointer);
4444

45-
runtime.getNilClass().addMethod("to_ptr", new NilToPointerMethod(runtime.getNilClass(), nullPointer));
45+
runtime.getNilClass().addMethod("to_ptr", new NilToPointerMethod(runtime.getNilClass(), nullPointer, "to_ptr"));
4646

4747
return pointerClass;
4848
}
@@ -197,8 +197,8 @@ private static final class NilToPointerMethod extends DynamicMethod {
197197
private static final Arity ARITY = Arity.NO_ARGUMENTS;
198198
private final Pointer nullPointer;
199199

200-
private NilToPointerMethod(RubyModule implementationClass, Pointer nullPointer) {
201-
super(implementationClass, Visibility.PUBLIC);
200+
private NilToPointerMethod(RubyModule implementationClass, Pointer nullPointer, String name) {
201+
super(implementationClass, Visibility.PUBLIC, name);
202202
this.nullPointer = nullPointer;
203203
}
204204

‎core/src/main/java/org/jruby/ext/ffi/jffi/DefaultMethod.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ public class DefaultMethod extends DynamicMethod implements CacheableMethod {
2323
protected final Arity arity;
2424
protected final Function function;
2525

26-
2726
public DefaultMethod(RubyModule implementationClass, Function function,
2827
Signature signature, NativeInvoker defaultInvoker) {
29-
super(implementationClass, Visibility.PUBLIC);
28+
super(implementationClass, Visibility.PUBLIC, defaultInvoker.getName());
3029
this.arity = Arity.fixed(signature.getParameterCount());
3130
this.function = function;
3231
this.defaultInvoker = defaultInvoker;
@@ -83,7 +82,6 @@ private synchronized NativeInvoker tryCompilation() {
8382

8483
NativeInvoker invoker = getJITHandle().compile(getImplementationClass(), function, signature, getName());
8584
if (invoker != null) {
86-
invoker.setName(getName());
8785
compiledInvoker = invoker;
8886
getImplementationClass().invalidateCacheDescendants();
8987
return compiledInvoker;

0 commit comments

Comments
 (0)
Please sign in to comment.