FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge · MSNexploder/jruby@f97bf30 · GitHub

forked from jruby/jruby

Commit f97bf30

Browse files
committed
Merge
2 parents f377d1c + 86f0346 commit f97bf30

40 files changed

Lines changed: 545 additions & 464 deletions

‎core/src/main/java/org/jruby/RubyArray.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3178,9 +3178,11 @@ public IRubyObject sort_bang19(ThreadContext context, Block block) {
31783178
}
31793179

31803180
private IRubyObject sortInternal(final ThreadContext context, boolean honorOverride) {
3181+
Ruby runtime = context.runtime;
3182+
31813183
// One check per specialized fast-path to make the check invariant.
3182-
final boolean fixnumBypass = !honorOverride || context.runtime.newFixnum(0).isBuiltin("<=>");
3183-
final boolean stringBypass = !honorOverride || context.runtime.newString("").isBuiltin("<=>");
3184+
final boolean fixnumBypass = !honorOverride || runtime.getFixnum().isMethodBuiltin("<=>");
3185+
final boolean stringBypass = !honorOverride || runtime.getString().isMethodBuiltin("<=>");
31843186

31853187
try {
31863188
Qsort.sort(values, begin, begin + realLength, new Comparator() {

‎core/src/main/java/org/jruby/RubyBasicObject.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,9 +1501,7 @@ public ClassIndex getNativeClassIndex() {
15011501
* @return true if so
15021502
*/
15031503
public boolean isBuiltin(String methodName) {
1504-
DynamicMethod method = getMetaClass().searchMethodInner(methodName);
1505-
1506-
return method != null && method.isBuiltin();
1504+
return getMetaClass().isMethodBuiltin(methodName);
15071505
}
15081506

15091507
@JRubyMethod(name = "singleton_method_added", module = true, visibility = PRIVATE)

‎core/src/main/java/org/jruby/RubyFile.java‎

Lines changed: 29 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838
import jnr.constants.platform.OpenFlags;
3939
import jnr.posix.POSIX;
4040
import org.jcodings.Encoding;
41-
import org.jruby.util.io.ModeFlags;
42-
import org.jruby.util.io.OpenFile;
43-
import org.jruby.util.io.ChannelDescriptor;
4441
import java.io.File;
4542
import java.io.FileDescriptor;
4643
import java.io.FileNotFoundException;
@@ -77,22 +74,25 @@
7774
import org.jruby.util.ByteList;
7875
import org.jruby.util.FileResource;
7976
import org.jruby.util.JRubyFile;
77+
import org.jruby.util.ResourceException;
8078
import org.jruby.util.TypeConverter;
81-
import org.jruby.util.io.DirectoryAsFileException;
82-
import org.jruby.util.io.PermissionDeniedException;
83-
import org.jruby.util.io.Stream;
84-
import org.jruby.util.io.ChannelStream;
85-
import org.jruby.util.io.IOOptions;
79+
import org.jruby.util.encoding.Transcoder;
8680
import org.jruby.util.io.BadDescriptorException;
81+
import org.jruby.util.io.ChannelDescriptor;
82+
import org.jruby.util.io.ChannelStream;
83+
import org.jruby.util.io.DirectoryAsFileException;
84+
import org.jruby.util.io.EncodingUtils;
8785
import org.jruby.util.io.FileExistsException;
86+
import org.jruby.util.io.IOEncodable;
87+
import org.jruby.util.io.IOOptions;
8888
import org.jruby.util.io.InvalidValueException;
89+
import org.jruby.util.io.ModeFlags;
90+
import org.jruby.util.io.OpenFile;
8991
import org.jruby.util.io.PipeException;
92+
import org.jruby.util.io.Stream;
9093
import org.jruby.exceptions.RaiseException;
9194
import org.jruby.runtime.Helpers;
9295
import org.jruby.runtime.encoding.EncodingService;
93-
import org.jruby.util.encoding.Transcoder;
94-
import org.jruby.util.io.EncodingUtils;
95-
import org.jruby.util.io.IOEncodable;
9696

9797
/**
9898
* Ruby File class equivalent in java.
@@ -1317,23 +1317,16 @@ private ChannelDescriptor sysopen(String path, ModeFlags modes, int perm) {
13171317
// TODO: check if too many open files, GC and try again
13181318

13191319
return descriptor;
1320-
} catch (PermissionDeniedException pde) {
1321-
// PDException can be thrown only when creating the file and
1322-
// permission is denied. See JavaDoc of PermissionDeniedException.
1323-
throw getRuntime().newErrnoEACCESError(path);
1324-
} catch (FileNotFoundException fnfe) {
1325-
// FNFException can be thrown in both cases, when the file
1326-
// is not found, or when permission is denied.
1327-
if (Ruby.isSecurityRestricted() || new File(path).exists()) {
1328-
throw getRuntime().newErrnoEACCESError(path);
1329-
}
1330-
throw getRuntime().newErrnoENOENTError(path);
1331-
} catch (DirectoryAsFileException dafe) {
1332-
throw getRuntime().newErrnoEISDirError();
1333-
} catch (FileExistsException fee) {
1334-
throw getRuntime().newErrnoEEXISTError(path);
1335-
} catch (IOException ioe) {
1336-
throw getRuntime().newIOErrorFromException(ioe);
1320+
} catch (ResourceException resourceException) {
1321+
throw resourceException.newRaiseException(getRuntime());
1322+
} catch (FileNotFoundException ignored) {
1323+
throw new IllegalStateException("For compile compatibility only");
1324+
} catch (DirectoryAsFileException ignored) {
1325+
throw new IllegalStateException("For compile compatibility only");
1326+
} catch (FileExistsException ignored) {
1327+
throw new IllegalStateException("For compile compatibility only");
1328+
} catch (IOException ignored) {
1329+
throw new IllegalStateException("For compile compatibility only");
13371330
}
13381331
}
13391332

@@ -1343,34 +1336,18 @@ private Stream fopen(String path, ModeFlags flags) {
13431336
getRuntime(),
13441337
path,
13451338
flags);
1339+
} catch (InvalidValueException ex) {
1340+
throw getRuntime().newErrnoEINVALError();
1341+
} catch (PipeException ex) {
1342+
throw new IllegalStateException("For compile compatibility only");
13461343
} catch (BadDescriptorException e) {
1347-
throw getRuntime().newErrnoEBADFError();
1348-
} catch (PermissionDeniedException pde) {
1349-
// PDException can be thrown only when creating the file and
1350-
// permission is denied. See JavaDoc of PermissionDeniedException.
1351-
throw getRuntime().newErrnoEACCESError(path);
1344+
throw new IllegalStateException("For compile compatibility only");
13521345
} catch (FileNotFoundException ex) {
1353-
// FNFException can be thrown in both cases, when the file
1354-
// is not found, or when permission is denied.
1355-
// FIXME: yes, this is indeed gross.
1356-
String message = ex.getMessage();
1357-
1358-
if (message.contains(/*P*/"ermission denied") ||
1359-
message.contains(/*A*/"ccess is denied")) {
1360-
throw getRuntime().newErrnoEACCESError(path);
1361-
}
1362-
1363-
throw getRuntime().newErrnoENOENTError(path);
1364-
} catch (DirectoryAsFileException ex) {
1365-
throw getRuntime().newErrnoEISDirError();
1346+
throw new IllegalStateException("For compile compatibility only");
13661347
} catch (FileExistsException ex) {
1367-
throw getRuntime().newErrnoEEXISTError(path);
1348+
throw new IllegalStateException("For compile compatibility only");
13681349
} catch (IOException ex) {
1369-
throw getRuntime().newIOErrorFromException(ex);
1370-
} catch (InvalidValueException ex) {
1371-
throw getRuntime().newErrnoEINVALError();
1372-
} catch (PipeException ex) {
1373-
throw getRuntime().newErrnoEPIPEError();
1350+
throw new IllegalStateException("For compile compatibility only");
13741351
} catch (SecurityException ex) {
13751352
throw getRuntime().newErrnoEACCESError(path);
13761353
}

‎core/src/main/java/org/jruby/RubyIO.java‎

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@
3636
package org.jruby;
3737

3838
import org.jruby.runtime.Helpers;
39+
import org.jruby.util.ResourceException;
3940
import org.jruby.util.StringSupport;
41+
import org.jruby.util.io.DirectoryAsFileException;
4042
import org.jruby.util.io.EncodingUtils;
43+
import org.jruby.util.io.FileExistsException;
4144
import org.jruby.util.io.ModeFlags;
4245
import org.jruby.util.io.SelectBlob;
4346
import jnr.constants.platform.Fcntl;
@@ -88,8 +91,6 @@
8891
import org.jruby.util.io.ChannelStream;
8992
import org.jruby.util.io.InvalidValueException;
9093
import org.jruby.util.io.PipeException;
91-
import org.jruby.util.io.FileExistsException;
92-
import org.jruby.util.io.DirectoryAsFileException;
9394
import org.jruby.util.io.STDIO;
9495
import org.jruby.util.io.OpenFile;
9596
import org.jruby.util.io.ChannelDescriptor;
@@ -342,11 +343,7 @@ protected void reopenPath(Ruby runtime, IRubyObject[] args) {
342343
openFile.setPath(path);
343344

344345
if (openFile.getMainStream() == null) {
345-
try {
346-
openFile.setMainStream(ChannelStream.fopen(runtime, path, modes.getModeFlags()));
347-
} catch (FileExistsException fee) {
348-
throw runtime.newErrnoEEXISTError(path);
349-
}
346+
openFile.setMainStream(ChannelStream.fopen(runtime, path, modes.getModeFlags()));
350347

351348
if (openFile.getPipeStream() != null) {
352349
openFile.getPipeStream().fclose();
@@ -360,14 +357,16 @@ protected void reopenPath(Ruby runtime, IRubyObject[] args) {
360357
// TODO: pipe handler to be reopened with path and "w" mode
361358
}
362359
}
360+
} catch (InvalidValueException e) {
361+
throw runtime.newErrnoEINVALError();
363362
} catch (PipeException pe) {
364-
throw runtime.newErrnoEPIPEError();
363+
throw new IllegalStateException("For compile compatibility only");
365364
} catch (IOException ex) {
366-
throw runtime.newIOErrorFromException(ex);
365+
throw new IllegalStateException("For compile compatibility only");
367366
} catch (BadDescriptorException ex) {
368-
throw runtime.newErrnoEBADFError();
369-
} catch (InvalidValueException e) {
370-
throw runtime.newErrnoEINVALError();
367+
throw new IllegalStateException("For compile compatibility only");
368+
} catch (FileExistsException fee) {
369+
throw new IllegalStateException("For compile compatibility only");
371370
}
372371
}
373372

@@ -1179,16 +1178,19 @@ private static IRubyObject sysopenCommon(IRubyObject recv, IRubyObject[] args, B
11791178
runtime.getJRubyClassLoader());
11801179
// always a new fileno, so ok to use internal only
11811180
fileno = descriptor.getFileno();
1181+
} catch (ResourceException resourceException) {
1182+
throw resourceException.newRaiseException(runtime);
1183+
} catch (FileNotFoundException ignored) {
1184+
throw new IllegalStateException("For compile compatibility only");
1185+
} catch (DirectoryAsFileException ignored) {
1186+
throw new IllegalStateException("For compile compatibility only");
1187+
} catch (FileExistsException ignored) {
1188+
throw new IllegalStateException("For compile compatibility only");
1189+
} catch (IOException ignored) {
1190+
throw new IllegalStateException("For compile compatibility only");
11821191
}
1183-
catch (FileNotFoundException fnfe) {
1184-
throw runtime.newErrnoENOENTError(path);
1185-
} catch (DirectoryAsFileException dafe) {
1186-
throw runtime.newErrnoEISDirError(path);
1187-
} catch (FileExistsException fee) {
1188-
throw runtime.newErrnoEEXISTError(path);
1189-
} catch (IOException ioe) {
1190-
throw runtime.newIOErrorFromException(ioe);
1191-
}
1192+
1193+
11921194
return runtime.newFixnum(fileno);
11931195
}
11941196

‎core/src/main/java/org/jruby/RubyModule.java‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3869,6 +3869,19 @@ private static void visitMethods(NodeVisitor visitor, RubyModule mod) {
38693869
}
38703870
}
38713871

3872+
/**
3873+
* Return true if the given method is defined on this class and is a builtin
3874+
* (defined in Java at boot).
3875+
*
3876+
* @param methodName
3877+
* @return
3878+
*/
3879+
public boolean isMethodBuiltin(String methodName) {
3880+
DynamicMethod method = searchMethodInner(methodName);
3881+
3882+
return method != null && method.isBuiltin();
3883+
}
3884+
38723885
@Deprecated
38733886
public void checkMethodBound(ThreadContext context, IRubyObject[] args, Visibility visibility) {
38743887
}

‎core/src/main/java/org/jruby/ext/bigdecimal/RubyBigDecimal.java‎

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
import org.jruby.RubyObject;
5151
import org.jruby.RubyRational;
5252
import org.jruby.RubyString;
53-
53+
import org.jruby.RubySymbol;
5454
import org.jruby.anno.JRubyClass;
5555
import org.jruby.anno.JRubyConstant;
5656
import org.jruby.anno.JRubyMethod;
@@ -360,25 +360,16 @@ public static IRubyObject mode(ThreadContext context, IRubyObject recv, IRubyObj
360360
return newExceptionMode;
361361
}
362362

363-
long _ROUND_MODE = ((RubyFixnum)clazz.getConstant("ROUND_MODE")).getLongValue();
364-
if (longMode == _ROUND_MODE) {
365-
if (value.isNil()) return c.searchInternalModuleVariable("vpRoundingMode");
366-
if (!(value instanceof RubyFixnum)) {
367-
throw context.runtime.newTypeError("wrong argument type " + mode.getMetaClass() + " (expected Fixnum)");
368-
}
369-
370-
RubyFixnum roundingMode = (RubyFixnum)value;
371-
if (roundingMode == clazz.getConstant("ROUND_UP") ||
372-
roundingMode == clazz.getConstant("ROUND_DOWN") ||
373-
roundingMode == clazz.getConstant("ROUND_FLOOR") ||
374-
roundingMode == clazz.getConstant("ROUND_CEILING") ||
375-
roundingMode == clazz.getConstant("ROUND_HALF_UP") ||
376-
roundingMode == clazz.getConstant("ROUND_HALF_DOWN") ||
377-
roundingMode == clazz.getConstant("ROUND_HALF_EVEN")) {
378-
c.setInternalModuleVariable("vpRoundingMode", roundingMode);
379-
} else {
380-
throw context.runtime.newTypeError("invalid rounding mode");
363+
long ROUND_MODE = ((RubyFixnum)clazz.getConstant("ROUND_MODE")).getLongValue();
364+
if (longMode == ROUND_MODE) {
365+
if (value.isNil()) {
366+
return c.searchInternalModuleVariable("vpRoundingMode");
381367
}
368+
369+
RoundingMode javaRoundingMode = javaRoundingModeFromRubyRoundingMode(context.runtime, value);
370+
RubyFixnum roundingMode = context.runtime.newFixnum(javaRoundingMode.ordinal());
371+
c.setInternalModuleVariable("vpRoundingMode", roundingMode);
372+
382373
return c.searchInternalModuleVariable("vpRoundingMode");
383374
}
384375
throw context.runtime.newTypeError("first argument for BigDecimal#mode invalid");
@@ -1113,20 +1104,20 @@ public IRubyObject exponent() {
11131104
public IRubyObject finite_p() {
11141105
return getRuntime().newBoolean(!isNaN() && !isInfinity());
11151106
}
1116-
1107+
11171108
private void floorNaNInfinityCheck(Ruby runtime) {
11181109
if (isNaN() || isInfinity()) {
11191110
throw runtime.newFloatDomainError("Computation results to '" + to_s(NULL_ARRAY).asJavaString() + "'");
11201111
}
11211112
}
11221113

1123-
private IRubyObject floorInternal(ThreadContext context, int n) {
1114+
private RubyBigDecimal floorInternal(ThreadContext context, int n) {
11241115
return value.scale() > n ? new RubyBigDecimal(context.runtime, value.setScale(n, RoundingMode.FLOOR)) : this;
11251116
}
11261117

11271118
@JRubyMethod public IRubyObject floor(ThreadContext context) {
11281119
floorNaNInfinityCheck(context.runtime);
1129-
return floorInternal(context, 0);
1120+
return floorInternal(context, 0).to_int();
11301121
}
11311122

11321123
@JRubyMethod public IRubyObject floor(ThreadContext context, IRubyObject arg) {
@@ -1180,23 +1171,49 @@ public IRubyObject precs(ThreadContext context) {
11801171

11811172
@JRubyMethod
11821173
public IRubyObject round(ThreadContext context) {
1183-
return new RubyBigDecimal(context.runtime, value.setScale(0, getRoundingMode(context.runtime)));
1174+
return new RubyBigDecimal(context.runtime, value.setScale(0, getRoundingMode(context.runtime))).to_int();
11841175
}
11851176

11861177
@JRubyMethod
11871178
public IRubyObject round(ThreadContext context, IRubyObject scale) {
1188-
return new RubyBigDecimal(context.runtime, value.setScale(num2int(scale), getRoundingMode(context.runtime)));
1179+
return new RubyBigDecimal(context.runtime, value.setScale(num2int(scale), getRoundingMode(context.runtime))).to_int();
11891180
}
11901181

11911182
@JRubyMethod
11921183
public IRubyObject round(ThreadContext context, IRubyObject scale, IRubyObject mode) {
11931184
return new RubyBigDecimal(context.runtime,
1194-
value.setScale(num2int(scale), javaRoundingModeFromRubyRoundingMode(mode)));
1185+
value.setScale(num2int(scale), javaRoundingModeFromRubyRoundingMode(context.runtime, mode)));
11951186
}
11961187

11971188
//this relies on the Ruby rounding enumerations == Java ones, which they (currently) all are
1198-
private RoundingMode javaRoundingModeFromRubyRoundingMode(IRubyObject arg) {
1199-
return RoundingMode.valueOf(num2int(arg));
1189+
private static RoundingMode javaRoundingModeFromRubyRoundingMode(Ruby runtime, IRubyObject arg) {
1190+
if (arg instanceof RubySymbol) {
1191+
RubySymbol roundingModeSymbol = (RubySymbol) arg;
1192+
String roundingModeString = roundingModeSymbol.asJavaString();
1193+
if (roundingModeString.equals("up")) {
1194+
return RoundingMode.UP;
1195+
} else if (roundingModeString.equals("down") || roundingModeString.equals("truncate")) {
1196+
return RoundingMode.DOWN;
1197+
} else if (roundingModeString.equals("half_up") || roundingModeString.equals("default")) {
1198+
return RoundingMode.HALF_UP;
1199+
} else if (roundingModeString.equals("half_down")) {
1200+
return RoundingMode.HALF_DOWN;
1201+
} else if (roundingModeString.equals("half_even") || roundingModeString.equals("banker")) {
1202+
return RoundingMode.HALF_EVEN;
1203+
} else if (roundingModeString.equals("ceiling") || roundingModeString.equals("ceil")) {
1204+
return RoundingMode.CEILING;
1205+
} else if (roundingModeString.equals("floor")) {
1206+
return RoundingMode.FLOOR;
1207+
} else {
1208+
throw runtime.newArgumentError("invalid rounding mode");
1209+
}
1210+
} else {
1211+
try {
1212+
return RoundingMode.valueOf(num2int(arg));
1213+
} catch (IllegalArgumentException iae) {
1214+
throw runtime.newArgumentError("invalid rounding mode");
1215+
}
1216+
}
12001217
}
12011218

12021219
@JRubyMethod

‎core/src/main/java/org/jruby/java/proxies/JavaProxy.java‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,14 @@ public IRubyObject initialize_copy(IRubyObject original) {
181181

182182
private static Class<?> getJavaClass(ThreadContext context, RubyModule module) {
183183
try {
184-
IRubyObject jClass = Helpers.invoke(context, module, "java_class");
184+
IRubyObject jClass = Helpers.invoke(context, module, "java_class");
185185

186-
187-
return !(jClass instanceof JavaClass) ? null : ((JavaClass) jClass).javaClass();
188-
} catch (Exception e) { return null; }
186+
return !(jClass instanceof JavaClass) ? null : ((JavaClass) jClass).javaClass();
187+
} catch (Exception e) {
188+
// clear $! since our "java_class" invoke above may have failed and set it
189+
context.setErrorInfo(context.nil);
190+
return null;
191+
}
189192
}
190193

191194
/**

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL