Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 69c0c2d3b275
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8c3a6691125d
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on May 22, 2018

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c5f8834 View commit details
  2. Copy the full SHA
    8c3a669 View commit details
Showing with 34 additions and 35 deletions.
  1. +16 −18 core/src/main/java/org/jruby/RubyKernel.java
  2. +18 −17 core/src/main/java/org/jruby/util/TypeConverter.java
34 changes: 16 additions & 18 deletions core/src/main/java/org/jruby/RubyKernel.java
Original file line number Diff line number Diff line change
@@ -433,9 +433,9 @@ static RubyFloat new_float(final Ruby runtime, RubyInteger num) {
public static IRubyObject new_hash(ThreadContext context, IRubyObject recv, IRubyObject arg) {
IRubyObject tmp;
Ruby runtime = context.runtime;
if (arg.isNil()) return RubyHash.newHash(runtime);
if (arg == context.nil) return RubyHash.newHash(runtime);
tmp = TypeConverter.checkHashType(context, sites(context).to_hash_checked, arg);
if (tmp.isNil()) {
if (tmp == context.nil) {
if (arg instanceof RubyArray && ((RubyArray) arg).isEmpty()) {
return RubyHash.newHash(runtime);
}
@@ -444,40 +444,38 @@ public static IRubyObject new_hash(ThreadContext context, IRubyObject recv, IRub
return tmp;
}

public static IRubyObject new_integer(ThreadContext context, IRubyObject recv, IRubyObject object) {
return new_integer19(context, recv, object);
}

@JRubyMethod(name = "Integer", module = true, visibility = PRIVATE)
public static IRubyObject new_integer19(ThreadContext context, IRubyObject recv, IRubyObject object) {
return newIntegerCommon(context, object, 0);
public static IRubyObject new_integer(ThreadContext context, IRubyObject recv, IRubyObject object) {
return TypeConverter.convertToInteger(context, object, 0);
}

@JRubyMethod(name = "Integer", module = true, visibility = PRIVATE)
public static IRubyObject new_integer19(ThreadContext context, IRubyObject recv, IRubyObject object, IRubyObject base) {
return newIntegerCommon(context, object, RubyNumeric.num2int(base));
}

private static IRubyObject newIntegerCommon(ThreadContext context, IRubyObject object, int bs) {
return TypeConverter.convertToInteger(context, object, bs);
public static IRubyObject new_integer(ThreadContext context, IRubyObject recv, IRubyObject object, IRubyObject base) {
return TypeConverter.convertToInteger(context, object, RubyNumeric.num2int(base));
}

public static IRubyObject new_string(ThreadContext context, IRubyObject recv, IRubyObject object) {
return new_string19(context, recv, object);
@Deprecated
public static IRubyObject new_integer19(ThreadContext context, IRubyObject recv, IRubyObject object) {
return new_integer(context, recv, object);
}

@JRubyMethod(name = "String", required = 1, module = true, visibility = PRIVATE)
public static IRubyObject new_string19(ThreadContext context, IRubyObject recv, IRubyObject object) {
public static IRubyObject new_string(ThreadContext context, IRubyObject recv, IRubyObject object) {
Ruby runtime = context.runtime;
KernelSites sites = sites(context);

IRubyObject tmp = TypeConverter.checkStringType(context, sites.to_str_checked, object, runtime.getString());
if (tmp.isNil()) {
if (tmp == context.nil) {
tmp = TypeConverter.convertToType(context, object, runtime.getString(), sites(context).to_s_checked);
}
return tmp;
}

@Deprecated
public static IRubyObject new_string19(ThreadContext context, IRubyObject recv, IRubyObject object) {
return new_string(context, recv, object);
}

// MRI: rb_f_p_internal
@JRubyMethod(rest = true, module = true, visibility = PRIVATE)
public static IRubyObject p(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
35 changes: 18 additions & 17 deletions core/src/main/java/org/jruby/util/TypeConverter.java
Original file line number Diff line number Diff line change
@@ -393,21 +393,22 @@ public static void checkType(ThreadContext context, IRubyObject x, final RubyMod

// rb_convert_to_integer
public static IRubyObject convertToInteger(ThreadContext context, IRubyObject val, int base) {
Ruby runtime = context.runtime;
final Ruby runtime = context.runtime;
IRubyObject tmp;

for (;;) {
if (val instanceof RubyFloat) {
if (base != 0) raiseIntegerBaseError(context);
return RubyNumeric.dbl2ival(context.runtime, ((RubyFloat) val).getValue());
} else if (val instanceof RubyInteger) {
if (base != 0) raiseIntegerBaseError(context);
return val;
} else if (val instanceof RubyString) {
return RubyNumeric.str2inum(context.runtime, (RubyString)val, base, true);
} else if (val instanceof RubyNil) {
if (base != 0) raiseIntegerBaseError(context);
throw context.runtime.newTypeError("can't convert nil into Integer");
switch (val.getMetaClass().getClassIndex()) {
case FLOAT:
if (base != 0) raiseIntegerBaseError(context);
return RubyNumeric.dbl2ival(context.runtime, ((RubyFloat) val).getValue());
case INTEGER:
if (base != 0) raiseIntegerBaseError(context);
return val;
case STRING:
return RubyNumeric.str2inum(context.runtime, (RubyString) val, base, true);
case NIL:
if (base != 0) raiseIntegerBaseError(context);
throw context.runtime.newTypeError("can't convert nil into Integer");
}

if (base != 0) {
@@ -419,22 +420,22 @@ public static IRubyObject convertToInteger(ThreadContext context, IRubyObject va
break;
}

tmp = TypeConverter.convertToType(context, val, runtime.getString(), "to_int", false);
return (tmp != context.nil) ? tmp : val.convertToInteger("to_i");
tmp = TypeConverter.convertToType(context, val, runtime.getInteger(), sites(context).to_int_checked, false);
return (tmp != context.nil) ? tmp : TypeConverter.convertToType(context, val, runtime.getInteger(), sites(context).to_i_checked);
}

// MRI: rb_Array
public static RubyArray rb_Array(ThreadContext context, IRubyObject val) {
IRubyObject tmp = checkArrayType(val); // to_ary

if (tmp.isNil()) {
if (tmp == context.nil) {
TypeConverterSites sites = sites(context);
tmp = convertToTypeWithCheck(context, val, context.runtime.getArray(), sites.to_a_checked);
if (tmp.isNil()) {
if (tmp == context.nil) {
return context.runtime.newArray(val);
}
}
return (RubyArray)tmp;
return (RubyArray) tmp;
}

// MRI: to_ary