Skip to content

Commit

Permalink
Merge branch '9.5-dev' into module_stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Jan 22, 2024
2 parents dba658c + 4f149b2 commit 1f132d1
Show file tree
Hide file tree
Showing 26 changed files with 238 additions and 119 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 @@ -5602,7 +5602,7 @@ public RubyClass getData() {
private final WarnCallback regexpWarnings = new WarnCallback() {
@Override
public void warn(String message) {
getWarnings().warning(message);
getWarnings().warn(message);
}
};

Expand Down
18 changes: 9 additions & 9 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ public IRubyObject initialize(ThreadContext context, Block block) {
unpack();
realLength = 0;
if (block.isGiven() && context.runtime.isVerbose()) {
context.runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used");
context.runtime.getWarnings().warn(ID.BLOCK_UNUSED, "given block not used");
}
return this;
}
Expand Down Expand Up @@ -2210,7 +2210,7 @@ private IRubyObject getDefaultSeparator(Ruby runtime) {
IRubyObject sep;
sep = runtime.getGlobalVariables().get("$,");
if (!sep.isNil()) {
runtime.getWarnings().warn("$, is set to non-nil value");
runtime.getWarnings().warnDeprecated("$, is set to non-nil value");
}
return sep;
}
Expand Down Expand Up @@ -2549,7 +2549,7 @@ public IRubyObject index(ThreadContext context, IRubyObject obj) {

@JRubyMethod(name = {"index", "find_index"})
public IRubyObject index(ThreadContext context, IRubyObject obj, Block unused) {
if (unused.isGiven()) context.runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used");
if (unused.isGiven()) context.runtime.getWarnings().warn(ID.BLOCK_UNUSED, "given block not used");
return index(context, obj);
}

Expand Down Expand Up @@ -2656,7 +2656,7 @@ public IRubyObject rindex(ThreadContext context, IRubyObject obj) {

@JRubyMethod
public IRubyObject rindex(ThreadContext context, IRubyObject obj, Block unused) {
if (unused.isGiven()) context.runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used");
if (unused.isGiven()) context.runtime.getWarnings().warn(ID.BLOCK_UNUSED, "given block not used");
return rindex(context, obj);
}

Expand Down Expand Up @@ -3521,7 +3521,7 @@ public IRubyObject count(ThreadContext context, Block block) {

@JRubyMethod(name = "count")
public IRubyObject count(ThreadContext context, IRubyObject obj, Block block) {
if (block.isGiven()) context.runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used");
if (block.isGiven()) context.runtime.getWarnings().warn(ID.BLOCK_UNUSED, "given block not used");

int n = 0;
for (int i = 0; i < realLength; i++) {
Expand Down Expand Up @@ -4929,7 +4929,7 @@ public IRubyObject all_pCommon(ThreadContext context, IRubyObject arg, Block blo
boolean patternGiven = arg != null;

if (block.isGiven() && patternGiven) {
context.runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used");
context.runtime.getWarnings().warn(ID.BLOCK_UNUSED, "given block not used");
}

if (!block.isGiven() || patternGiven) return all_pBlockless(context, arg);
Expand Down Expand Up @@ -4972,7 +4972,7 @@ public IRubyObject any_pCommon(ThreadContext context, IRubyObject arg, Block blo
boolean patternGiven = arg != null;

if (block.isGiven() && patternGiven) {
context.runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used");
context.runtime.getWarnings().warn(ID.BLOCK_UNUSED, "given block not used");
}

if (!block.isGiven() || patternGiven) return any_pBlockless(context, arg);
Expand Down Expand Up @@ -5014,7 +5014,7 @@ public IRubyObject none_pCommon(ThreadContext context, IRubyObject arg, Block bl
boolean patternGiven = arg != null;

if (block.isGiven() && patternGiven) {
context.runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used");
context.runtime.getWarnings().warn(ID.BLOCK_UNUSED, "given block not used");
}

if (!block.isGiven() || patternGiven) return none_pBlockless(context, arg);
Expand Down Expand Up @@ -5056,7 +5056,7 @@ public IRubyObject one_pCommon(ThreadContext context, IRubyObject arg, Block blo
boolean patternGiven = arg != null;

if (block.isGiven() && patternGiven) {
context.runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used");
context.runtime.getWarnings().warn(ID.BLOCK_UNUSED, "given block not used");
}

if (!block.isGiven() || patternGiven) return one_pBlockless(context, arg);
Expand Down
14 changes: 7 additions & 7 deletions core/src/main/java/org/jruby/RubyEnumerable.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public static IRubyObject count(ThreadContext context, IRubyObject self, final I
final Ruby runtime = context.runtime;
final SingleInt result = new SingleInt();

if (block.isGiven()) runtime.getWarnings().warning(ID.BLOCK_UNUSED , "given block not used");
if (block.isGiven()) runtime.getWarnings().warn(ID.BLOCK_UNUSED , "given block not used");

each(context, eachSite(context), self, new JavaInternalBlockBody(runtime, context, "Enumerable#count", Signature.ONE_REQUIRED) {
public IRubyObject yield(ThreadContext context1, IRubyObject[] args) {
Expand Down Expand Up @@ -690,7 +690,7 @@ public static IRubyObject find_index(ThreadContext context, IRubyObject self, fi
public static IRubyObject find_index(ThreadContext context, IRubyObject self, final IRubyObject cond, final Block block) {
final Ruby runtime = context.runtime;

if (block.isGiven()) runtime.getWarnings().warning(ID.BLOCK_UNUSED , "given block not used");
if (block.isGiven()) runtime.getWarnings().warn(ID.BLOCK_UNUSED , "given block not used");
if (self instanceof RubyArray) return ((RubyArray) self).find_index(context, cond);

return find_indexCommon(context, eachSite(context), self, cond);
Expand Down Expand Up @@ -1086,7 +1086,7 @@ public static IRubyObject inject(ThreadContext context, IRubyObject self, IRubyO
public static IRubyObject inject(ThreadContext context, IRubyObject self, IRubyObject init, IRubyObject method, final Block block) {
final Ruby runtime = context.runtime;

if (block.isGiven()) runtime.getWarnings().warning(ID.BLOCK_UNUSED , "given block not used");
if (block.isGiven()) runtime.getWarnings().warn(ID.BLOCK_UNUSED , "given block not used");

final String methodId = method.asJavaString();
final SingleObject<IRubyObject> result = new SingleObject<>(init);
Expand Down Expand Up @@ -1591,7 +1591,7 @@ public static IRubyObject none_pCommon(ThreadContext context, CallSite each, IRu
final boolean patternGiven = pattern != null;

if (block.isGiven() && patternGiven) {
context.runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used");
context.runtime.getWarnings().warn(ID.BLOCK_UNUSED, "given block not used");
}

try {
Expand Down Expand Up @@ -1646,7 +1646,7 @@ public static IRubyObject one_pCommon(ThreadContext context, CallSite each, IRub
final boolean patternGiven = pattern != null;

if (block.isGiven() && patternGiven) {
context.runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used");
context.runtime.getWarnings().warn(ID.BLOCK_UNUSED, "given block not used");
}

try {
Expand Down Expand Up @@ -1729,7 +1729,7 @@ public static IRubyObject all_pCommon(ThreadContext localContext, CallSite each,
final boolean patternGiven = pattern != null;

if (block.isGiven() && patternGiven) {
localContext.runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used");
localContext.runtime.getWarnings().warn(ID.BLOCK_UNUSED, "given block not used");
}

try {
Expand Down Expand Up @@ -1819,7 +1819,7 @@ public static IRubyObject any_pCommon(ThreadContext localContext, CallSite site,
final boolean patternGiven = pattern != null;

if (block.isGiven() && patternGiven) {
localContext.runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used");
localContext.runtime.getWarnings().warn(ID.BLOCK_UNUSED, "given block not used");
}

try {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyFileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static IRubyObject exist_p(IRubyObject recv, IRubyObject filename) {
return exist_p(recv.getRuntime().getCurrentContext(), recv, filename);
}

@JRubyMethod(name = {"exist?", "exists?"}, module = true)
@JRubyMethod(name = "exist?", module = true)
public static IRubyObject exist_p(ThreadContext context, IRubyObject recv, IRubyObject filename) {
// We get_path here to prevent doing it both existsOnClasspath and fileResource (Only call to_path once).
return RubyBoolean.newBoolean(context, exist(context, get_path(context, filename)));
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyGlobal.java
Original file line number Diff line number Diff line change
Expand Up @@ -829,13 +829,13 @@ public NonEffectiveGlobalVariable(Ruby runtime, String name, IRubyObject value)

@Override
public IRubyObject set(IRubyObject value) {
runtime.getWarnings().warn(ID.INEFFECTIVE_GLOBAL, "warning: variable " + name + " is no longer effective; ignored");
runtime.getWarnings().warnDeprecated(ID.INEFFECTIVE_GLOBAL, "warning: variable " + name + " is no longer effective; ignored");
return value;
}

@Override
public IRubyObject get() {
runtime.getWarnings().warn(ID.INEFFECTIVE_GLOBAL, "warning: variable " + name + " is no longer effective");
runtime.getWarnings().warnDeprecated(ID.INEFFECTIVE_GLOBAL, "warning: variable " + name + " is no longer effective");
return value;
}
}
Expand Down
106 changes: 56 additions & 50 deletions core/src/main/java/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -1819,15 +1819,18 @@ public static IRubyObject print(ThreadContext context, IRubyObject out, IRubyObj
int i;
IRubyObject line;
int argc = args.length;
IRubyObject outputFS = runtime.getGlobalVariables().get("$,");

/* if no argument given, print `$_' */
if (argc == 0) {
argc = 1;
line = context.getLastLine();
args = new IRubyObject[]{line};
}
if (argc > 1 && !outputFS.isNil()) {
runtime.getWarnings().warnDeprecated("$, is set to non-nil value");
}
for (i=0; i<argc; i++) {
IRubyObject outputFS = runtime.getGlobalVariables().get("$,");
if (!outputFS.isNil() && i>0) {
write(context, out, outputFS);
}
Expand Down Expand Up @@ -2403,7 +2406,7 @@ public IRubyObject close_on_exec_set(ThreadContext context, IRubyObject arg) {

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

Expand Down Expand Up @@ -2858,7 +2861,7 @@ private static void warnWrite(final Ruby runtime, IRubyObject maybeIO) {
} else {
sep = '#';
}
runtime.getWarnings().warning(klass.toString() + sep + "write is outdated interface which accepts just one argument");
runtime.getWarnings().warningDeprecated(klass.toString() + sep + "write is outdated interface which accepts just one argument");
}

@JRubyMethod
Expand Down Expand Up @@ -4439,66 +4442,38 @@ public static IRubyObject popen(ThreadContext context, IRubyObject recv, IRubyOb
}
}

@Deprecated
public static IRubyObject pipe19(ThreadContext context, IRubyObject recv) {
return pipe19(context, recv, IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);
public static IRubyObject pipe(ThreadContext context, IRubyObject recv) {
return pipe(context, recv, Block.NULL_BLOCK);
}

@Deprecated
public static IRubyObject pipe19(ThreadContext context, IRubyObject recv, IRubyObject modes) {
return pipe19(context, recv, new IRubyObject[] {modes}, Block.NULL_BLOCK);
@JRubyMethod(name = "pipe", meta = true)
public static IRubyObject pipe(ThreadContext context, IRubyObject klass, Block block) {
return pipe(context, klass, context.nil, context.nil, context.nil, block);
}

@Deprecated
public static IRubyObject pipe19(ThreadContext context, IRubyObject klass, IRubyObject[] argv, Block block) {
return pipe(context, klass, argv, block);
@JRubyMethod(name = "pipe", meta = true)
public static IRubyObject pipe(ThreadContext context, IRubyObject klass, IRubyObject arg0, Block block) {
IRubyObject opt = TypeConverter.checkHashType(context.runtime, arg0);

return pipe(context, klass, opt.isNil() ? arg0 : context.nil, context.nil, opt, block);
}

@JRubyMethod(name = "pipe", meta = true)
public static IRubyObject pipe(ThreadContext context, IRubyObject klass, IRubyObject arg0, IRubyObject arg1, Block block) {
IRubyObject opt = TypeConverter.checkHashType(context.runtime, arg1);

public static IRubyObject pipe(ThreadContext context, IRubyObject recv) {
return pipe(context, recv, IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);
return pipe(context, klass, arg0, !opt.isNil() ? context.nil : arg1, opt, block);
}

@JRubyMethod(name = "pipe", optional = 3, checkArity = false, meta = true)
public static IRubyObject pipe(ThreadContext context, IRubyObject klass, IRubyObject[] argv, Block block) {
int argc = Arity.checkArgumentCount(context, argv, 0, 3);

@JRubyMethod(name = "pipe", meta = true)
public static IRubyObject pipe(ThreadContext context, IRubyObject klass, IRubyObject v1, IRubyObject v2, IRubyObject opt, Block block) {
Ruby runtime = context.runtime;
int state;

RubyIO r, w;
// IRubyObject args[] = new IRubyObject[3]
IRubyObject v1, v2;
IRubyObject opt;
v1 = v2 = opt = context.nil;
OpenFile fptr, fptr2;
int[] fmode_p = {0};
IRubyObject ret;

switch (argc) {
case 3:
opt = argv[2].convertToHash();
argc--;
v2 = argv[1];
v1 = argv[0];
break;
case 2:
opt = TypeConverter.checkHashType(runtime, argv[1]);
if (!opt.isNil()) {
argc--;
} else {
v2 = argv[1];
}
v1 = argv[0];
break;
case 1:
opt = TypeConverter.checkHashType(runtime, argv[0]);
if (!opt.isNil()) {
argc--;
} else {
v1 = argv[0];
}
}

PosixShim posix = new PosixShim(runtime);
Channel[] fds = posix.pipe();
if (fds == null)
Expand All @@ -4513,7 +4488,7 @@ public static IRubyObject pipe(ThreadContext context, IRubyObject klass, IRubyOb
// close(pipes[1]);
// rb_jump_tag(state);
// }
r = new RubyIO(runtime, (RubyClass)klass);
r = new RubyIO(runtime, (RubyClass) klass);
r.initializeCommon(context, new ChannelFD(fds[0], runtime.getPosix(), runtime.getFilenoUtil()), runtime.newFixnum(OpenFlags.O_RDONLY), context.nil);
fptr = r.getOpenFileChecked();

Expand All @@ -4527,7 +4502,7 @@ public static IRubyObject pipe(ThreadContext context, IRubyObject klass, IRubyOb
// if (!NIL_P(r)) rb_io_close(r);
// rb_jump_tag(state);
// }
w = new RubyIO(runtime, (RubyClass)klass);
w = new RubyIO(runtime, (RubyClass) klass);
w.initializeCommon(context, new ChannelFD(fds[1], runtime.getPosix(), runtime.getFilenoUtil()), runtime.newFixnum(OpenFlags.O_WRONLY), context.nil);
fptr2 = w.getOpenFileChecked();
fptr2.setSync(true);
Expand Down Expand Up @@ -5750,6 +5725,37 @@ public IRubyObject sysread(ThreadContext context, IRubyObject[] args) {
return sysreadCommon(context, runtime, _length, _str);
}

@Deprecated
public static IRubyObject pipe19(ThreadContext context, IRubyObject recv) {
return pipe19(context, recv, IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);
}

@Deprecated
public static IRubyObject pipe19(ThreadContext context, IRubyObject recv, IRubyObject modes) {
return pipe19(context, recv, new IRubyObject[] {modes}, Block.NULL_BLOCK);
}

@Deprecated
public static IRubyObject pipe19(ThreadContext context, IRubyObject klass, IRubyObject[] argv, Block block) {
return pipe(context, klass, argv, block);
}

@Deprecated
public static IRubyObject pipe(ThreadContext context, IRubyObject klass, IRubyObject[] argv, Block block) {
switch (argv.length) {
case 0:
return pipe(context, klass, block);
case 1:
return pipe(context, klass, argv[0], block);
case 2:
return pipe(context, klass, argv[0], argv[1], block);
case 3:
return pipe(context, klass, argv[0], argv[1], argv[2], block);
default:
throw context.runtime.newArgumentError(argv.length, 0, 3);
}
}

protected OpenFile openFile;

/**
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyKernel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1933,7 +1933,7 @@ public static RubyFixnum spawn(ThreadContext context, IRubyObject recv, IRubyObj
return RubyProcess.spawn(context, recv, args);
}

@JRubyMethod(required = 1, optional = 9, checkArity = false, module = true, visibility = PRIVATE)
@JRubyMethod(required = 1, optional = 9, checkArity = false, module = true, notImplemented = true, visibility = PRIVATE)
public static IRubyObject syscall(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
throw context.runtime.newNotImplementedError("Kernel#syscall is not implemented in JRuby");
}
Expand Down
Loading

0 comments on commit 1f132d1

Please sign in to comment.