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 31b7c07
Show file tree
Hide file tree
Showing 77 changed files with 264 additions and 264 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
8 changes: 4 additions & 4 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ public IRubyObject insert19(IRubyObject arg1, IRubyObject arg2) {
return insert(arg1, arg2);
}

@JRubyMethod(name = "insert", required = 1, rest = true)
@JRubyMethod(name = "insert", required = 1, rest = true, checkArity = false)
public IRubyObject insert(IRubyObject[] args) {
final Ruby runtime = metaClass.runtime;

Expand Down Expand Up @@ -2687,7 +2687,7 @@ public IRubyObject indexes(IRubyObject[] args) {
/** rb_ary_indexes
*
*/
@JRubyMethod(name = {"indexes", "indices"}, required = 1, rest = true)
@JRubyMethod(name = {"indexes", "indices"}, required = 1, rest = true, checkArity = false)
public IRubyObject indexes(ThreadContext context, IRubyObject[] args) {
int argc = Arity.checkArgumentCount(context, args, 1, -1);

Expand Down Expand Up @@ -3126,7 +3126,7 @@ public IRubyObject delete_if(ThreadContext context, Block block) {
/** rb_ary_zip
*
*/
@JRubyMethod(optional = 1, rest = true)
@JRubyMethod(optional = 1, rest = true, checkArity = false)
public IRubyObject zip(ThreadContext context, IRubyObject[] args, Block block) {
final Ruby runtime = context.runtime;
RubyClass array = runtime.getArray();
Expand Down Expand Up @@ -5487,7 +5487,7 @@ public IRubyObject dig(ThreadContext context, IRubyObject arg0, IRubyObject arg1
return RubyObject.dig2(context, val, arg1, arg2);
}

@JRubyMethod(name = "dig", required = 1, rest = true)
@JRubyMethod(name = "dig", required = 1, rest = true, checkArity = false)
public IRubyObject dig(ThreadContext context, IRubyObject[] args) {
int argc = Arity.checkArgumentCount(context, args, 1, -1);

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -1678,7 +1678,7 @@ public IRubyObject send(ThreadContext context, IRubyObject arg0, IRubyObject arg

return getMetaClass().finvokeWithRefinements(context, this, staticScope, name, arg1, arg2, block);
}
@JRubyMethod(name = "__send__", required = 1, rest = true, omit = true, keywords = true)
@JRubyMethod(name = "__send__", required = 1, rest = true, checkArity = false, omit = true, keywords = true)
public IRubyObject send(ThreadContext context, IRubyObject[] args, Block block) {
int argc = Arity.checkArgumentCount(context, args, 1, -1);
int callInfo = context.callInfo;
Expand Down Expand Up @@ -2594,7 +2594,7 @@ public IRubyObject instance_eval19(ThreadContext context, IRubyObject arg0, IRub
* k = Klass.new
* k.instance_exec(5) {|x| {@literal @}secret+x } #=> 104
*/
@JRubyMethod(name = "instance_exec", optional = 3, rest = true, keywords = true,
@JRubyMethod(name = "instance_exec", rest = true, keywords = true,
reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE},
writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE})
public IRubyObject instance_exec(ThreadContext context, IRubyObject[] args, Block block) {
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
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyException.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public RubyException(Ruby runtime, RubyClass rubyClass, String message) {
this.setMessage(message == null ? runtime.getNil() : runtime.newString(message));
}

@JRubyMethod(name = "exception", optional = 1, rest = true, meta = true)
@JRubyMethod(name = "exception", rest = true, meta = true)
public static IRubyObject exception(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
return ((RubyClass) recv).newInstance(context, args, block);
}
Expand Down 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
Loading

0 comments on commit 31b7c07

Please sign in to comment.