Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/jruby-9.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Feb 6, 2024
2 parents 3eaaa51 + 4e67d1b commit 15afb12
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 19 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -2664,9 +2664,9 @@ private IRubyObject ctl(ThreadContext context, IRubyObject cmd, IRubyObject arg)
return runtime.newFixnum(close_on_exec_p(context).isTrue() ? FD_CLOEXEC : 0);
} else if (realCmd == Fcntl.F_SETFL.intValue()) {
if ((nArg & OpenFlags.O_NONBLOCK.intValue()) != 0) {
fptr.setBlocking(runtime, true);
} else {
fptr.setBlocking(runtime, false);
} else {
fptr.setBlocking(runtime, true);
}

if ((nArg & OpenFlags.O_CLOEXEC.intValue()) != 0) {
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/runtime/Helpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.lang.reflect.Array;

import java.net.PortUnreachableException;
import java.net.SocketException;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.NonReadableChannelException;
import java.nio.channels.NonWritableChannelException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ private static Class generateInternal(final ClassDefiningClassLoader cdcl, final
final String baseName = p(DynamicScope.class);

JiteClass jiteClass = new JiteClass(clsPath, baseName, new String[0]) {{
setSourceFile(clsPath + ".java");

// parent class constructor
defineMethod("<init>", ACC_PUBLIC, sig(void.class, StaticScope.class, DynamicScope.class), new CodeBlock() {{
aload(0);
Expand Down Expand Up @@ -238,38 +240,56 @@ private static Class generateInternal(final ClassDefiningClassLoader cdcl, final
iload(3);
pushInt(1);
isub();

line(6);
invokevirtual(baseName, "setValueVoid", sig(void.class, IRubyObject.class, int.class, int.class));
voidreturn();
}});

// optional overrides
defineMethod("getValueDepthZero", ACC_PUBLIC, sig(IRubyObject.class, int.class), new CodeBlock() {{
line(6);
line(7);

if (size > 0) genGetSwitch(clsPath, newFields, this, 1);

line(1);
line(8);

invokestatic(clsPath, "sizeError", sig(RuntimeException.class));
athrow();
}});

defineMethod("setValueDepthZeroVoid", ACC_PUBLIC, sig(void.class, IRubyObject.class, int.class), new CodeBlock() {{
line(6);
line(9);

if (size > 0) genPutSwitch(clsPath, newFields, this, 2);

line(1);
line(10);

invokestatic(clsPath, "sizeError", sig(RuntimeException.class));
athrow();
}});

// utilities

defineMethod("sizeError", ACC_PRIVATE | ACC_STATIC, sig(RuntimeException.class), new CodeBlock() {{
line(11);
newobj(p(RuntimeException.class));
dup();
ldc(clsName + " only supports scopes with " + size + " variables");

line(12);
invokespecial(p(RuntimeException.class), "<init>", sig(void.class, String.class));
areturn();
}});

// specialized getters and setters

for (int i = 0; i < SPECIALIZED_GETS.size(); i++) {
final int offset = i;

defineMethod(SPECIALIZED_GETS.get(offset), ACC_PUBLIC, sig(IRubyObject.class), new CodeBlock() {{
line(6);
// line numbers for specialized getters are 100 + offset
line(100 + offset);

if (size <= offset) {
invokestatic(clsPath, "sizeError", sig(RuntimeException.class));
Expand All @@ -286,7 +306,8 @@ private static Class generateInternal(final ClassDefiningClassLoader cdcl, final
final int offset = i;

defineMethod(SPECIALIZED_GETS_OR_NIL.get(offset), ACC_PUBLIC, sig(IRubyObject.class, IRubyObject.class), new CodeBlock() {{
line(6);
// line numbers for specialized get-or-nils are 200 + offset
line(200 + offset);

if (size <= offset) {
invokestatic(clsPath, "sizeError", sig(RuntimeException.class));
Expand Down Expand Up @@ -317,7 +338,8 @@ private static Class generateInternal(final ClassDefiningClassLoader cdcl, final
final int offset = i;

defineMethod(SPECIALIZED_SETS.get(offset), ACC_PUBLIC, sig(void.class, IRubyObject.class), new CodeBlock() {{
line(6);
// line numbers for specialized setters are 300 + offset
line(300 + offset);

if (size <= offset) {
invokestatic(clsPath, "sizeError", sig(RuntimeException.class));
Expand All @@ -332,18 +354,10 @@ private static Class generateInternal(final ClassDefiningClassLoader cdcl, final
}

// fields

for (String prop : newFields) {
defineField(prop, ACC_PUBLIC, ci(IRubyObject.class), null);
}

// utilities
defineMethod("sizeError", ACC_PRIVATE | ACC_STATIC, sig(RuntimeException.class), new CodeBlock() {{
newobj(p(RuntimeException.class));
dup();
ldc(clsName + " only supports scopes with " + size + " variables");
invokespecial(p(RuntimeException.class), "<init>", sig(void.class, String.class));
areturn();
}});
}};

return defineClass(cdcl, jiteClass);
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/util/ConvertBytes.java
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ private void squeezeZeroes() {
break;
}
} else {
us += 0;
us = 0;
}
beg++;
}
Expand Down
12 changes: 12 additions & 0 deletions spec/ruby/core/string/to_i_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
"1_2_3asdf".to_i.should == 123
end

it "ignores multiple non-consecutive underscoes when the first digit is 0" do
(2..16).each do |base|
"0_0_010".to_i(base).should == base;
end
end

it "bails out at the first double underscore if the first digit is 0" do
(2..16).each do |base|
"010__1".to_i(base).should == base;
end
end

it "ignores leading whitespaces" do
[ " 123", " 123", "\r\n\r\n123", "\t\t123",
"\r\n\t\n123", " \t\n\r\t 123"].each do |str|
Expand Down

0 comments on commit 15afb12

Please sign in to comment.