Skip to content

Commit ff30385

Browse files
committed
Merge pull request jruby#8962 from headius/polyglot_upgrade
Upgrade polyglot and remove openssl lib hack
2 parents f5b5cdd + bb57885 commit ff30385

9 files changed

Lines changed: 119 additions & 77 deletions

File tree

.mvn/extensions.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<extension>
44
<groupId>io.takari.polyglot</groupId>
55
<artifactId>polyglot-ruby</artifactId>
6-
<version>0.5.0</version>
6+
<version>0.8.1</version>
77
</extension>
88
</extensions>

core/src/main/java/org/jruby/RubyContinuation.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
package org.jruby;
3030

3131
import org.jruby.anno.JRubyClass;
32+
import org.jruby.api.Error;
3233
import org.jruby.exceptions.CatchThrow;
3334
import org.jruby.runtime.Block;
3435
import org.jruby.runtime.ClassIndex;
@@ -91,9 +92,7 @@ public Continuation getContinuation() {
9192
@Deprecated
9293
public IRubyObject call(ThreadContext context, IRubyObject[] args) {
9394
if (disabled) {
94-
RubyKernel.raise(context, context.runtime.getThreadError(),
95-
new IRubyObject[]{newString(context, "continuations can not be called from outside their scope")},
96-
Block.NULL_BLOCK);
95+
throw Error.typeError(context, "continuations can not be called from outside their scope");
9796
}
9897
continuation.args = args;
9998
throw continuation;

core/src/main/java/org/jruby/RubyKernel.java

Lines changed: 92 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,28 @@ public static IRubyObject sprintf(ThreadContext context, IRubyObject recv, IRuby
10291029
public static IRubyObject sprintf(IRubyObject recv, IRubyObject[] args) {
10301030
return sprintf(((RubyBasicObject) recv).getCurrentContext(), recv, args);
10311031
}
1032+
1033+
@JRubyMethod(name = {"raise", "fail"}, module = true, visibility = PRIVATE, omit = true)
1034+
public static IRubyObject raise(ThreadContext context, IRubyObject recv) {
1035+
IRubyObject errorInfo = context.getErrorInfo();
1036+
maybeRaiseJavaException(context, errorInfo);
1037+
1038+
RaiseException raise;
1039+
IRubyObject lastException = errorInfo;
1040+
if (lastException.isNil()) {
1041+
raise = RaiseException.from(context.runtime, runtimeErrorClass(context), "");
1042+
} else {
1043+
// non RubyException value is allowed to be assigned as $!.
1044+
raise = ((RubyException) lastException).toThrowable();
1045+
}
1046+
1047+
var exception = raise.getException();
1048+
if (context.runtime.isDebug()) printExceptionSummary(context, exception);
1049+
1050+
throw raise;
1051+
}
1052+
1053+
@JRubyMethod(name = {"raise", "fail"}, module = true, visibility = PRIVATE, omit = true)
10321054
public static IRubyObject raise(ThreadContext context, IRubyObject self, IRubyObject arg0) {
10331055
// semi extract_raise_opts :
10341056
if (arg0 instanceof RubyHash opt && !opt.isEmpty() &&
@@ -1040,46 +1062,71 @@ public static IRubyObject raise(ThreadContext context, IRubyObject self, IRubyOb
10401062

10411063
maybeRaiseJavaException(context, arg0);
10421064

1043-
RaiseException raise = arg0 instanceof RubyString ?
1044-
((RubyException) context.runtime.getRuntimeError().newInstance(context, arg0)).toThrowable() :
1045-
convertToException(context, arg0, null).toThrowable();
1065+
raiseCommon(context, arg0, null, null, 1, true, cause);
10461066

1047-
var exception = raise.getException();
1067+
return null; // not reached
1068+
}
10481069

1049-
if (context.runtime.isDebug()) printExceptionSummary(context, exception);
1050-
if (exception.getCause() == null && cause != exception) exception.setCause(cause);
1070+
@JRubyMethod(name = {"raise", "fail"}, module = true, visibility = PRIVATE, omit = true)
1071+
public static IRubyObject raise(ThreadContext context, IRubyObject recv, IRubyObject arg0, IRubyObject arg1) {
1072+
boolean forceCause = false;
10511073

1052-
throw raise;
1074+
// semi extract_raise_opts :
1075+
IRubyObject cause = null;
1076+
IRubyObject last = arg1;
1077+
int argc = 2;
1078+
cause = getCauseOption(context, last, cause);
1079+
1080+
if (cause != null) {
1081+
forceCause = true;
1082+
argc--;
1083+
} else {
1084+
cause = context.getErrorInfo(); // returns nil for no error-info
1085+
}
1086+
1087+
maybeRaiseJavaException(context, arg0);
1088+
1089+
raiseCommon(context, arg0, arg1, null, argc, forceCause, cause);
1090+
1091+
return null; // not reached
10531092
}
10541093

1055-
@JRubyMethod(name = {"raise", "fail"}, optional = 3, checkArity = false, module = true, visibility = PRIVATE, omit = true)
1056-
public static IRubyObject raise(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
1057-
int argc = Arity.checkArgumentCount(context, args, 0, 3);
1094+
@JRubyMethod(name = {"raise", "fail"}, module = true, visibility = PRIVATE, omit = true)
1095+
public static IRubyObject raise(ThreadContext context, IRubyObject recv, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
10581096
boolean forceCause = false;
10591097

10601098
// semi extract_raise_opts :
10611099
IRubyObject cause = null;
1062-
if (argc > 0) {
1063-
IRubyObject last = args[argc - 1];
1064-
if (last instanceof RubyHash opt) {
1065-
RubySymbol key;
1066-
if (!opt.isEmpty() && (opt.has_key_p(context, key = asSymbol(context, "cause")) == context.tru)) {
1067-
cause = opt.delete(context, key, Block.NULL_BLOCK);
1068-
forceCause = true;
1069-
if (opt.isEmpty() && --argc == 0) { // more opts will be passed along
1070-
throw argumentError(context, "only cause is given with no arguments");
1071-
}
1072-
}
1073-
}
1074-
}
1100+
IRubyObject last = arg2;
1101+
int argc = 3;
1102+
cause = getCauseOption(context, last, cause);
10751103

1076-
if ( argc > 0 ) { // for argc == 0 we will be raising $!
1077-
// NOTE: getErrorInfo needs to happen before new RaiseException(...)
1078-
if ( cause == null ) cause = context.getErrorInfo(); // returns nil for no error-info
1104+
if (cause != null) {
1105+
forceCause = true;
1106+
argc--;
1107+
} else {
1108+
cause = context.getErrorInfo(); // returns nil for no error-info
10791109
}
10801110

1081-
maybeRaiseJavaException(context, args, argc);
1111+
raiseCommon(context, arg0, arg1, arg2, argc, forceCause, cause);
1112+
1113+
return null; // not reached
1114+
}
10821115

1116+
private static IRubyObject getCauseOption(ThreadContext context, IRubyObject last, IRubyObject cause) {
1117+
if (last instanceof RubyHash opt) {
1118+
RubySymbol key;
1119+
if (!opt.isEmpty() && (opt.has_key_p(context, key = asSymbol(context, "cause")) == context.tru)) {
1120+
cause = opt.delete(context, key, Block.NULL_BLOCK);
1121+
if (opt.isEmpty()) { // more opts will be passed along
1122+
throw argumentError(context, "only cause is given with no arguments");
1123+
}
1124+
}
1125+
}
1126+
return cause;
1127+
}
1128+
1129+
private static void raiseCommon(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, int argc, boolean forceCause, IRubyObject cause) {
10831130
RaiseException raise;
10841131
switch (argc) {
10851132
case 0:
@@ -1092,18 +1139,18 @@ public static IRubyObject raise(ThreadContext context, IRubyObject recv, IRubyOb
10921139
}
10931140
break;
10941141
case 1:
1095-
if (args[0] instanceof RubyString) {
1096-
raise = ((RubyException) runtimeErrorClass(context).newInstance(context, args, block)).toThrowable();
1142+
if (arg0 instanceof RubyString) {
1143+
raise = ((RubyException) runtimeErrorClass(context).newInstance(context, arg0)).toThrowable();
10971144
} else {
1098-
raise = convertToException(context, args[0], null).toThrowable();
1145+
raise = convertToException(context, arg0, null).toThrowable();
10991146
}
11001147
break;
11011148
case 2:
1102-
raise = convertToException(context, args[0], args[1]).toThrowable();
1149+
raise = convertToException(context, arg0, arg1).toThrowable();
11031150
break;
11041151
default:
1105-
RubyException exception = convertToException(context, args[0], args[1]);
1106-
exception.setBacktrace(context, args[2]);
1152+
RubyException exception = convertToException(context, arg0, arg1);
1153+
exception.setBacktrace(context, arg2);
11071154
raise = exception.toThrowable();
11081155
break;
11091156
}
@@ -1115,19 +1162,19 @@ public static IRubyObject raise(ThreadContext context, IRubyObject recv, IRubyOb
11151162
throw raise;
11161163
}
11171164

1118-
private static void maybeRaiseJavaException(ThreadContext context, final IRubyObject[] args, final int argc) {
1119-
// Check for a Java exception
1120-
IRubyObject maybeException = null;
1121-
switch (argc) {
1122-
case 0:
1123-
maybeException = globalVariables(context).get("$!");
1124-
break;
1125-
case 1:
1126-
if (args.length == 1) maybeException = args[0];
1127-
break;
1128-
}
1165+
public static IRubyObject raise(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
1166+
return switch (args.length) {
1167+
case 0 -> raise(context, recv);
1168+
case 1 -> raise(context, recv, args[0]);
1169+
case 2 -> raise(context, recv, args[0], args[1]);
1170+
case 3 -> raise(context, recv, args[0], args[1], args[2]);
1171+
default -> throw argumentError(context, args, 0, 3);
1172+
};
1173+
}
11291174

1130-
maybeRaiseJavaException(context, maybeException);
1175+
@Deprecated(since = "10.0.3.0")
1176+
public static IRubyObject raise(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block unused) {
1177+
return raise(context, recv, args);
11311178
}
11321179

11331180
private static void maybeRaiseJavaException(ThreadContext context, final IRubyObject arg) {

core/src/main/java/org/jruby/RubyThread.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,11 @@ private void executeInterrupts(ThreadContext context, boolean blockingTiming) {
300300
if (getStatus() == Status.SLEEP) exitSleep();
301301

302302
// if it's a Ruby exception, force the cause through
303-
IRubyObject[] args = err instanceof RubyException exc ?
304-
Helpers.arrayOf(err, RubyHash.newKwargs(runtime, "cause", exc.cause(context))) :
305-
Helpers.arrayOf(err);
306-
RubyKernel.raise(context, this, args, Block.NULL_BLOCK);
303+
if (err instanceof RubyException exc) {
304+
RubyKernel.raise(context, this, err, RubyHash.newKwargs(runtime, "cause", exc.cause(context)));
305+
} else {
306+
RubyKernel.raise(context, this, err);
307+
}
307308
}
308309
}
309310

core/src/main/java/org/jruby/api/Error.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ public static ArgumentError argumentError(ThreadContext context, int length, int
6060
return (ArgumentError) context.runtime.newArgumentError(length, min, max);
6161
}
6262

63+
/**
64+
* Return an instance of ArgumentError for the given argument list, min, and max.
65+
*
66+
* @param context the current thread context
67+
* @param args the argument array
68+
* @param min the minimum length required
69+
* @param max the maximum length required
70+
* @return the created exception
71+
*/
72+
public static ArgumentError argumentError(ThreadContext context, IRubyObject[] args, int min, int max) {
73+
return (ArgumentError) context.runtime.newArgumentError(args.length, min, max);
74+
}
75+
6376
public static RaiseException floatDomainError(ThreadContext context, String message){
6477
return context.runtime.newRaiseException(context.runtime.getFloatDomainError(), message);
6578
}

core/src/main/java/org/jruby/ext/timeout/Timeout.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,9 @@ private static IRubyObject raiseTimeoutErrorIfMatches(ThreadContext context,
223223
return RubyKernel.raise( // throws
224224
context,
225225
kernelModule(context),
226-
new IRubyObject[] {
227-
getTimeoutError(context, timeout), // Timeout::Error
228-
rubyException.callMethod(context, "message"),
229-
rubyException.callMethod(context, "backtrace")
230-
},
231-
Block.NULL_BLOCK);
226+
getTimeoutError(context, timeout), // Timeout::Error
227+
rubyException.callMethod(context, "message"),
228+
rubyException.callMethod(context, "backtrace"));
232229
}
233230
return null;
234231
}

core/src/main/java/org/jruby/ir/instructions/ThrowExceptionInstr.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public Object interpret(ThreadContext context, StaticScope currScope, DynamicSco
4848
Object excObj = getException().retrieve(context, self, currScope, currDynScope, temp);
4949

5050
if (excObj instanceof IRubyObject exc) {
51-
RubyKernel.raise(context, kernelModule(context), new IRubyObject[] {exc}, Block.NULL_BLOCK);
51+
RubyKernel.raise(context, kernelModule(context), exc);
5252
} else if (excObj instanceof Throwable exc) { // java exception -- avoid having to add 'throws' clause everywhere!
5353
Helpers.throwException(exc);
5454
}

lib/pom.rb

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -227,21 +227,6 @@ def log(message=nil)
227227

228228
FileUtils.mkdir_p( default_specs )
229229

230-
# have an empty openssl.rb so we do not run in trouble with not having
231-
# jopenssl which is part of the default gems
232-
lib_dir = File.join( target, 'lib' )
233-
openssl = File.join( lib_dir, 'openssl.rb' )
234-
FileUtils.mkdir_p( lib_dir )
235-
FileUtils.touch( openssl )
236-
$LOAD_PATH.unshift lib_dir
237-
238-
# since the bouncy castle .jars are version-ed (e.g. bcprov-jdk15on-1.47)
239-
# make sure we cleanup before adding the ones from the jruby-openssl.gem:
240-
Dir.glob( File.join( lib_dir, "bc{prov,pkix}*.jar" ) ).each do |f|
241-
# use this instead of FileUtils.rm_f - issue #1698
242-
File.delete( f ) if File.exists?( f )
243-
end
244-
245230
# now we can require the rubygems staff
246231
require 'rubygems/installer'
247232
require 'rubygems/package'

lib/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,7 @@ DO NOT MODIFY - GENERATED CODE
14441444
<plugin>
14451445
<groupId>io.takari.polyglot</groupId>
14461446
<artifactId>polyglot-maven-plugin</artifactId>
1447-
<version>0.5.0</version>
1447+
<version>0.8.1</version>
14481448
<executions>
14491449
<execution>
14501450
<id>install_gems</id>
@@ -1484,7 +1484,7 @@ DO NOT MODIFY - GENERATED CODE
14841484
<dependency>
14851485
<groupId>io.takari.polyglot</groupId>
14861486
<artifactId>polyglot-ruby</artifactId>
1487-
<version>0.5.0</version>
1487+
<version>0.8.1</version>
14881488
</dependency>
14891489
</dependencies>
14901490
<inherited>false</inherited>

0 commit comments

Comments
 (0)