Skip to content

Commit

Permalink
Opt-out all core methods from auto arity check
Browse files Browse the repository at this point in the history
These were all moved to manual arity-checking in jruby#7751,
but that led to breakage when third-party extensions had varargs
paths that did not check arity manually (see jruby#7851).
Instead we restore the default to auto arity-check with this flag
provided for opting out (jruby#7680).
  • Loading branch information
headius committed Jul 17, 2023
1 parent cd3059d commit 5ddad7a
Show file tree
Hide file tree
Showing 68 changed files with 215 additions and 215 deletions.
24 changes: 12 additions & 12 deletions core/src/main/java/org/jruby/RubyArgsFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ private static boolean isGenericInput(Ruby runtime, ArgsFileData data) {
/** Read a line.
*
*/
@JRubyMethod(name = "gets", optional = 1, writes = LASTLINE)
@JRubyMethod(name = "gets", optional = 1, checkArity = false, writes = LASTLINE)
public static IRubyObject gets(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
Arity.checkArgumentCount(context, args, 0, 1);

Expand All @@ -415,7 +415,7 @@ public static IRubyObject gets(ThreadContext context, IRubyObject recv, IRubyObj
/** Read a line.
*
*/
@JRubyMethod(name = "readline", optional = 1, writes = LASTLINE)
@JRubyMethod(name = "readline", optional = 1, checkArity = false, writes = LASTLINE)
public static IRubyObject readline(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
IRubyObject line = gets(context, recv, args);

Expand All @@ -424,7 +424,7 @@ public static IRubyObject readline(ThreadContext context, IRubyObject recv, IRub
return line;
}

@JRubyMethod(optional = 1)
@JRubyMethod(optional = 1, checkArity = false)
public static IRubyObject readlines(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
Arity.checkArgumentCount(context, args, 0, 1);

Expand All @@ -443,7 +443,7 @@ public static IRubyObject readlines(ThreadContext context, IRubyObject recv, IRu
return ary;
}

@JRubyMethod(optional = 1)
@JRubyMethod(optional = 1, checkArity = false)
public static IRubyObject to_a(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
Arity.checkArgumentCount(context, args, 0, 1);

Expand Down Expand Up @@ -478,7 +478,7 @@ public static IRubyObject each_byte(final ThreadContext context, IRubyObject rec
return block.isGiven() ? each_byte(context, recv, block) : enumeratorize(context.runtime, recv, "each_byte");
}

@JRubyMethod(optional = 1)
@JRubyMethod(optional = 1, checkArity = false)
public static IRubyObject bytes(final ThreadContext context, IRubyObject recv, IRubyObject[] args, final Block block) {
Arity.checkArgumentCount(context, args, 0, 1);
return block.isGiven() ? each_byte(context, recv, block) : enumeratorize(context.runtime, recv, "bytes");
Expand Down Expand Up @@ -555,7 +555,7 @@ public static IRubyObject codepoints(ThreadContext context, IRubyObject recv, Bl
/** Invoke a block for each line.
*
*/
@JRubyMethod(name = "each_line", optional = 1)
@JRubyMethod(name = "each_line", optional = 1, checkArity = false)
public static IRubyObject each_line(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
if (!block.isGiven()) return enumeratorize(context.runtime, recv, "each_line", args);

Expand All @@ -581,7 +581,7 @@ public static IRubyObject each_line(ThreadContext context, IRubyObject recv, IRu
}

@Deprecated // TODO "warning: ARGF#lines is deprecated; use #each_line instead"
@JRubyMethod(optional = 1)
@JRubyMethod(optional = 1, checkArity = false)
public static IRubyObject lines(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
if (!block.isGiven()) return RubyEnumerator.enumeratorize(context.runtime, recv, "each_line");
return each_line(context, recv, args, block);
Expand All @@ -592,7 +592,7 @@ public static IRubyObject each_line19(final ThreadContext context, IRubyObject r
return each_line(context, recv, args, block);
}

@JRubyMethod(name = "each", optional = 1)
@JRubyMethod(name = "each", optional = 1, checkArity = false)
public static IRubyObject each(final ThreadContext context, IRubyObject recv, IRubyObject[] args, final Block block) {
return block.isGiven() ? each_line(context, recv, args, block) : enumeratorize(context.runtime, recv, "each", args);
}
Expand Down Expand Up @@ -737,7 +737,7 @@ public static IRubyObject set_pos(ThreadContext context, IRubyObject recv, IRuby
return getCurrentDataFile(context, "no stream to set position").pos_set(context, offset);
}

@JRubyMethod(name = "seek", required = 1, optional = 1)
@JRubyMethod(name = "seek", required = 1, optional = 1, checkArity = false)
public static IRubyObject seek(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
Arity.checkArgumentCount(context, args, 1, 2);

Expand Down Expand Up @@ -774,14 +774,14 @@ public static IRubyObject getbyte(ThreadContext context, IRubyObject recv) {
}
}

@JRubyMethod(required = 1, optional = 2)
@JRubyMethod(required = 1, optional = 2, checkArity = false)
public static IRubyObject read_nonblock(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
Arity.checkArgumentCount(context, args, 1, 3);

return getPartial(context, recv, args, true);
}

@JRubyMethod(required = 1, optional = 1)
@JRubyMethod(required = 1, optional = 1, checkArity = false)
public static IRubyObject readpartial(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
Arity.checkArgumentCount(context, args, 1, 2);

Expand Down Expand Up @@ -860,7 +860,7 @@ public static IRubyObject getc(ThreadContext context, IRubyObject recv) {
}
}

@JRubyMethod(name = "read", optional = 2)
@JRubyMethod(name = "read", optional = 2, checkArity = false)
public static IRubyObject read(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
int argc = Arity.checkArgumentCount(context, args, 0, 2);

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyBinding.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public IRubyObject initialize_copy(IRubyObject other) {
}

// c: bind_eval
@JRubyMethod(name = "eval", required = 1, optional = 2)
@JRubyMethod(name = "eval", required = 1, optional = 2, checkArity = false)
public IRubyObject eval(ThreadContext context, IRubyObject[] args) {
int argc = Arity.checkArgumentCount(context, args, 1, 3);

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyComplex.java
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ private static IRubyObject f_complex_polar(ThreadContext context, RubyClass claz
/** nucomp_s_polar
*
*/
@JRubyMethod(name = "polar", meta = true, required = 1, optional = 1)
@JRubyMethod(name = "polar", meta = true, required = 1, optional = 1, checkArity = false)
public static IRubyObject polar(ThreadContext context, IRubyObject clazz, IRubyObject... args) {
int argc = Arity.checkArgumentCount(context, args, 1, 2);

Expand Down Expand Up @@ -1177,7 +1177,7 @@ public IRubyObject to_r(ThreadContext context) {
/** nucomp_rationalize
*
*/
@JRubyMethod(name = "rationalize", optional = 1)
@JRubyMethod(name = "rationalize", optional = 1, checkArity = false)
public IRubyObject rationalize(ThreadContext context, IRubyObject[] args) {
if (k_inexact_p(image) || !f_zero_p(context, image)) {
throw context.runtime.newRangeError("can't convert " + f_to_s(context, this).convertToString() + " into Rational");
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/org/jruby/RubyConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public RubyConverter(Ruby runtime) {
super(runtime, runtime.getConverter());
}

@JRubyMethod(visibility = PRIVATE, required = 1, optional = 2)
@JRubyMethod(visibility = PRIVATE, required = 1, optional = 2, checkArity = false)
public IRubyObject initialize(ThreadContext context, IRubyObject[] args) {
int argc = Arity.checkArgumentCount(context, args, 1, 3);

Expand Down Expand Up @@ -221,7 +221,7 @@ public IRubyObject destination_encoding(ThreadContext context) {
}

// econv_primitive_convert
@JRubyMethod(required = 2, optional = 4)
@JRubyMethod(required = 2, optional = 4, checkArity = false)
public IRubyObject primitive_convert(ThreadContext context, IRubyObject[] args) {
int argc = Arity.checkArgumentCount(context, args, 2, 6);

Expand Down Expand Up @@ -524,7 +524,7 @@ public IRubyObject primitive_errinfo(ThreadContext context) {
return ary;
}

@JRubyMethod(meta = true, required = 2, optional = 1)
@JRubyMethod(meta = true, required = 2, optional = 1, checkArity = false)
public static IRubyObject search_convpath(ThreadContext context, IRubyObject self, IRubyObject[] argv) {
final Ruby runtime = context.runtime;
final IRubyObject nil = context.nil;
Expand Down Expand Up @@ -596,7 +596,7 @@ public IRubyObject insert_output(ThreadContext context, IRubyObject string) {
}

// econv_putback
@JRubyMethod(optional = 1)
@JRubyMethod(optional = 1, checkArity = false)
public IRubyObject putback(ThreadContext context, IRubyObject[] argv)
{
int argc = Arity.checkArgumentCount(context, argv, 0, 1);
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/RubyDir.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ private static ByteList globArgumentAsByteList(ThreadContext context, IRubyObjec
* with each filename is passed to the block in turn. In this case, Nil is
* returned.
*/
@JRubyMethod(required = 1, optional = 2, meta = true)
@JRubyMethod(required = 1, optional = 2, checkArity = false, meta = true)
public static IRubyObject glob(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
Arity.checkArgumentCount(context, args, 1, 3);

Expand Down Expand Up @@ -434,7 +434,7 @@ private static void checkDirIsTwoSlashesOnWindows(Ruby runtime, String path) {
}

/** Changes the current directory to <code>path</code> */
@JRubyMethod(optional = 1, meta = true)
@JRubyMethod(optional = 1, checkArity = false, meta = true)
public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
int argc = Arity.checkArgumentCount(context, args, 0, 1);
Ruby runtime = context.runtime;
Expand Down Expand Up @@ -652,7 +652,7 @@ public static IRubyObject home(ThreadContext context, IRubyObject recv, IRubyObj
* <code>mode</code> parameter is provided only to support existing Ruby
* code, and is ignored.
*/
@JRubyMethod(name = "mkdir", required = 1, optional = 1, meta = true)
@JRubyMethod(name = "mkdir", required = 1, optional = 1, checkArity = false, meta = true)
public static IRubyObject mkdir(ThreadContext context, IRubyObject recv, IRubyObject... args) {
Arity.checkArgumentCount(context, args, 1, 2);
Ruby runtime = context.runtime;
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyEnumerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public static IRubyObject enumeratorize(Ruby runtime, RubyClass type, IRubyObjec

// used internally to create lazy without block (from Enumerator/Enumerable)
// and used internally to create enum from Enumerator::Lazy#eager
@JRubyMethod(name = "__from", meta = true, required = 2, optional = 2, visibility = PRIVATE, keywords = true)
@JRubyMethod(name = "__from", meta = true, required = 2, optional = 2, checkArity = false, visibility = PRIVATE, keywords = true)
public static IRubyObject __from(ThreadContext context, IRubyObject klass, IRubyObject[] args) {
int argc = Arity.checkArgumentCount(context, args, 2, 4);

Expand Down Expand Up @@ -570,7 +570,7 @@ private static JavaSites.FiberSites sites(ThreadContext context) {
/** MRI: enumerator_s_produce
*
*/
@JRubyMethod(meta = true, optional = 1)
@JRubyMethod(meta = true, optional = 1, checkArity = false)
public static IRubyObject produce(ThreadContext context, IRubyObject recv, IRubyObject[] args, final Block block) {
int argc = Arity.checkArgumentCount(context, args, 0, 1);

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyException.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public IRubyObject backtrace_locations(ThreadContext context) {
return backtrace.backtraceLocations = backtrace.generateBacktraceLocations(context);
}

@JRubyMethod(optional = 1)
@JRubyMethod(optional = 1, checkArity = false)
public RubyException exception(IRubyObject[] args) {
switch (args.length) {
case 0 :
Expand Down
14 changes: 7 additions & 7 deletions core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public IRubyObject flock(ThreadContext context, IRubyObject operation) {
}

// rb_file_initialize
@JRubyMethod(name = "initialize", required = 1, optional = 3, visibility = PRIVATE)
@JRubyMethod(name = "initialize", required = 1, optional = 3, checkArity = false, visibility = PRIVATE)
public IRubyObject initialize(ThreadContext context, IRubyObject[] args, Block block) {
int argc = Arity.checkArgumentCount(context, args, 1, 4);

Expand Down Expand Up @@ -682,7 +682,7 @@ public static IRubyObject chown(ThreadContext context, IRubyObject recv, IRubyOb
return runtime.newFixnum(count);
}

@JRubyMethod(required = 1, optional = 1, meta = true)
@JRubyMethod(required = 1, optional = 1, checkArity = false, meta = true)
public static IRubyObject dirname(ThreadContext context, IRubyObject recv, IRubyObject [] args) {
int argc = Arity.checkArgumentCount(context, args, 1, 2);

Expand Down Expand Up @@ -897,7 +897,7 @@ public static IRubyObject extname(ThreadContext context, IRubyObject recv, IRuby
* @param args
* @return Resulting absolute path as a String
*/
@JRubyMethod(name = "expand_path", required = 1, optional = 1, meta = true)
@JRubyMethod(name = "expand_path", required = 1, optional = 1, checkArity = false, meta = true)
public static IRubyObject expand_path(ThreadContext context, IRubyObject recv, IRubyObject... args) {
Arity.checkArgumentCount(context, args, 1, 2);

Expand Down Expand Up @@ -929,7 +929,7 @@ public static IRubyObject expand_path19(ThreadContext context, IRubyObject recv,
* @param args
* @return
*/
@JRubyMethod(required = 1, optional = 1, meta = true)
@JRubyMethod(required = 1, optional = 1, checkArity = false, meta = true)
public static IRubyObject absolute_path(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
Arity.checkArgumentCount(context, args, 1, 2);

Expand All @@ -944,7 +944,7 @@ public static IRubyObject absolute_path_p(ThreadContext context, IRubyObject rec
return context.runtime.newBoolean(isJRubyAbsolutePath(file.asJavaString()));
}

@JRubyMethod(required = 1, optional = 1, meta = true)
@JRubyMethod(required = 1, optional = 1, checkArity = false, meta = true)
public static IRubyObject realdirpath(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
Arity.checkArgumentCount(context, args, 1, 2);

Expand Down Expand Up @@ -993,7 +993,7 @@ public static IRubyObject realpath(ThreadContext context, IRubyObject recv, IRub
* [set]: Matches a single char in a set (re: [...]).
*
*/
@JRubyMethod(name = {"fnmatch", "fnmatch?"}, required = 2, optional = 1, meta = true)
@JRubyMethod(name = {"fnmatch", "fnmatch?"}, required = 2, optional = 1, checkArity = false, meta = true)
public static IRubyObject fnmatch(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
int argc = Arity.checkArgumentCount(context, args, 2, 3);

Expand Down Expand Up @@ -1261,7 +1261,7 @@ public static IRubyObject truncate19(ThreadContext context, IRubyObject recv, IR
return truncateCommon(context, recv, path, arg2);
}

@JRubyMethod(meta = true, optional = 1)
@JRubyMethod(meta = true, optional = 1, checkArity = false)
public static IRubyObject umask(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
int argc = Arity.checkArgumentCount(context, args, 0, 1);

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyFloat.java
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ public IRubyObject to_r(ThreadContext context) {
/** float_rationalize
*
*/
@JRubyMethod(name = "rationalize", optional = 1)
@JRubyMethod(name = "rationalize", optional = 1, checkArity = false)
public IRubyObject rationalize(ThreadContext context, IRubyObject[] args) {
Arity.checkArgumentCount(context, args, 0, 1);

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyGC.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ public static RubyModule createGCModule(Ruby runtime) {
return result;
}

@JRubyMethod(module = true, visibility = PRIVATE, optional = 1)
@JRubyMethod(module = true, visibility = PRIVATE, optional = 1, checkArity = false)
public static IRubyObject start(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
Arity.checkArgumentCount(context, args, 0, 1);

return context.nil;
}

@JRubyMethod(optional = 1)
@JRubyMethod(optional = 1, checkArity = false)
public static IRubyObject garbage_collect(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
Arity.checkArgumentCount(context, args, 0, 1);
return context.nil;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public RubyGenerator(Ruby runtime, RubyClass klass) {
}

// generator_initialize
@JRubyMethod(visibility = Visibility.PRIVATE, optional = 1)
@JRubyMethod(visibility = Visibility.PRIVATE, optional = 1, checkArity = false)
public IRubyObject initialize(ThreadContext context, IRubyObject[] args, Block block) {
int argc = Arity.checkArgumentCount(context, args, 0, 1);

Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/RubyHash.java
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ public <T> boolean allSymbols() {
/** rb_hash_initialize
*
*/
@JRubyMethod(optional = 1, visibility = PRIVATE)
@JRubyMethod(optional = 1, checkArity = false, visibility = PRIVATE)
public IRubyObject initialize(IRubyObject[] args, final Block block) {
modify();

Expand Down Expand Up @@ -1651,7 +1651,7 @@ public IRubyObject each_key(final ThreadContext context, final Block block) {
return block.isGiven() ? each_keyCommon(context, block) : enumeratorizeWithSize(context, this, "each_key", RubyHash::size);
}

@JRubyMethod(name = "transform_keys", optional = 1, rest = true)
@JRubyMethod(name = "transform_keys", optional = 1, checkArity = false, rest = true)
public IRubyObject transform_keys(final ThreadContext context, IRubyObject[] args, final Block block) {
if (args.length == 0 && !block.isGiven()) {
return enumeratorizeWithSize(context, this, "transform_keys", RubyHash::size);
Expand Down Expand Up @@ -2316,7 +2316,7 @@ public IRubyObject rbClone(ThreadContext context) {
return rbClone(context, context.nil);
}

@JRubyMethod(name = "any?", optional = 1)
@JRubyMethod(name = "any?", optional = 1, checkArity = false)
public IRubyObject any_p(ThreadContext context, IRubyObject[] args, Block block) {
int argc = Arity.checkArgumentCount(context, args, 0, 1);

Expand Down
Loading

0 comments on commit 5ddad7a

Please sign in to comment.