Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into truffle-head
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Sep 26, 2016
2 parents 8842dec + 8821718 commit 574fd07
Show file tree
Hide file tree
Showing 122 changed files with 1,909 additions and 1,214 deletions.
8 changes: 6 additions & 2 deletions core/src/main/java/org/jruby/Ruby.java
Expand Up @@ -1609,8 +1609,10 @@ private void initExceptions() {
ioError = defineClassIfAllowed("IOError", standardError);
scriptError = defineClassIfAllowed("ScriptError", exceptionClass);
rangeError = defineClassIfAllowed("RangeError", standardError);
signalException = defineClassIfAllowed("SignalException", exceptionClass);

if (profile.allowClass("SignalException")) {
signalException = RubySignalException.createSignalExceptionClass(this, exceptionClass);
}
if (profile.allowClass("NameError")) {
nameError = RubyNameError.createNameErrorClass(this, standardError);
nameErrorMessage = RubyNameError.createNameErrorMessageClass(this, nameError);
Expand All @@ -1632,7 +1634,9 @@ private void initExceptions() {
}

fatal = defineClassIfAllowed("Fatal", exceptionClass);
interrupt = defineClassIfAllowed("Interrupt", signalException);
if (profile.allowClass("Interrupt")) {
interrupt = RubyInterrupt.createInterruptClass(this, signalException);
}
typeError = defineClassIfAllowed("TypeError", standardError);
argumentError = defineClassIfAllowed("ArgumentError", standardError);
if (profile.allowClass("UncaughtThrowError")) {
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/org/jruby/RubyFile.java
Expand Up @@ -298,6 +298,12 @@ protected IRubyObject rbIoClose(Ruby runtime) {

@JRubyMethod(required = 1)
public IRubyObject flock(ThreadContext context, IRubyObject operation) {

// Solaris uses a ruby-ffi version defined in jruby/kernel/file.rb, so re-dispatch
if (org.jruby.platform.Platform.IS_SOLARIS) {
return callMethod(context, "flock", operation);
}

Ruby runtime = context.runtime;
OpenFile fptr;
// int[] op = {0,0};
Expand Down
78 changes: 78 additions & 0 deletions core/src/main/java/org/jruby/RubyInterrupt.java
@@ -0,0 +1,78 @@
/***** BEGIN LICENSE BLOCK *****
* Version: EPL 1.0/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Eclipse Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.eclipse.org/legal/epl-v10.html
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the EPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the EPL, the GPL or the LGPL.
***** END LICENSE BLOCK *****/

package org.jruby;

import static jnr.constants.platform.Signal.SIGINT;

import org.jruby.anno.JRubyMethod;
import org.jruby.anno.JRubyClass;
import org.jruby.runtime.Block;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Arity;
import org.jruby.runtime.builtin.IRubyObject;
import static org.jruby.runtime.Visibility.PRIVATE;
import org.jruby.util.ArraySupport;

@JRubyClass(name="Interrupt", parent="SignalException")
public class RubyInterrupt extends RubySignalException {
private static final ObjectAllocator INTERRUPT_ALLOCATOR = new ObjectAllocator() {
@Override
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
return new RubyInterrupt(runtime, klass);
}
};

static RubyClass createInterruptClass(Ruby runtime, RubyClass signalExceptionClass) {
RubyClass interruptClass = runtime.defineClass("Interrupt", signalExceptionClass, INTERRUPT_ALLOCATOR);
interruptClass.defineAnnotatedMethods(RubyInterrupt.class);
return interruptClass;
}

protected RubyInterrupt(Ruby runtime, RubyClass exceptionClass) {
super(runtime, exceptionClass);
}

@JRubyMethod(optional = 1, visibility = PRIVATE)
@Override
public IRubyObject initialize(ThreadContext context, IRubyObject[] args, Block block) {
final Ruby runtime = context.runtime;

Arity.checkArgumentCount(runtime, args, 0, 1);

IRubyObject signo = runtime.newFixnum(SIGINT);

if (args.length > 0) {
args = ArraySupport.newCopy(signo, args);
} else {
args = new IRubyObject[]{signo, runtime.newString("Interrupt")};
}

super.initialize(args, block);
return this;
}
}
28 changes: 23 additions & 5 deletions core/src/main/java/org/jruby/RubySignal.java
Expand Up @@ -74,9 +74,9 @@ public static Map<String, Integer> list() {
Map<String, Integer> signals = new HashMap<String, Integer>();

for (Signal s : Signal.values()) {
if (!s.description().startsWith("SIG"))
if (!s.description().startsWith(SIGNAME_PREFIX))
continue;
if (!RUBY_18_SIGNALS.contains(s.description().substring(3)))
if (!RUBY_18_SIGNALS.contains(signmWithoutPrefix(s.description())))
continue;

// replace CLD with CHLD value
Expand All @@ -88,7 +88,7 @@ public static Map<String, Integer> list() {
if (signo >= 20000)
continue;

signals.put(s.description().substring("SIG".length()), signo);
signals.put(signmWithoutPrefix(s.description()), signo);
}

return signals;
Expand Down Expand Up @@ -143,12 +143,28 @@ public static IRubyObject signame(ThreadContext context, final IRubyObject recv,
public static String signo2signm(long no) {
for (Signal s : Signal.values()) {
if (s.intValue() == no) {
return s.name().substring(3);
return signmWithoutPrefix(s.name());
}
}
return null;
}


// MRI: signm2signo
public static long signm2signo(String nm) {
for (Signal s : Signal.values()) {
if (signmWithoutPrefix(s.name()).equals(nm)) return s.longValue();
}
return 0;
}

public static String signmWithPrefix(String nm) {
return (nm.startsWith(SIGNAME_PREFIX)) ? nm : SIGNAME_PREFIX + nm;
}

public static String signmWithoutPrefix(String nm) {
return (nm.startsWith(SIGNAME_PREFIX)) ? nm.substring(SIGNAME_PREFIX.length()) : nm;
}

private static final Set<String> RUBY_18_SIGNALS;
static {
RUBY_18_SIGNALS = new HashSet<String>();
Expand Down Expand Up @@ -201,4 +217,6 @@ public static String signo2signm(long no) {
RUBY_18_SIGNALS.add(name);
}
}

private static final String SIGNAME_PREFIX = "SIG";
}// RubySignal
127 changes: 127 additions & 0 deletions core/src/main/java/org/jruby/RubySignalException.java
@@ -0,0 +1,127 @@
/***** BEGIN LICENSE BLOCK *****
* Version: EPL 1.0/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Eclipse Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.eclipse.org/legal/epl-v10.html
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the EPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the EPL, the GPL or the LGPL.
***** END LICENSE BLOCK *****/

package org.jruby;

import static jnr.constants.platform.Signal.NSIG;

import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.Arity;
import org.jruby.runtime.Block;
import org.jruby.runtime.ThreadContext;
import static org.jruby.runtime.Visibility.PRIVATE;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.RubyBasicObject;
import org.jruby.RubySignal;
import org.jruby.util.TypeConverter;

@JRubyClass(name="SignalException", parent="Exception")
public class RubySignalException extends RubyException {
private static final ObjectAllocator SIGNAL_EXCEPTION_ALLOCATOR = new ObjectAllocator() {
@Override
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
return new RubySignalException(runtime, klass);
}
};

protected RubySignalException(Ruby runtime, RubyClass exceptionClass) {
super(runtime, exceptionClass);
}

static RubyClass createSignalExceptionClass(Ruby runtime, RubyClass exceptionClass) {
RubyClass signalExceptionClass = runtime.defineClass("SignalException", exceptionClass, SIGNAL_EXCEPTION_ALLOCATOR);
signalExceptionClass.defineAnnotatedMethods(RubySignalException.class);

return signalExceptionClass;
}

@JRubyMethod(optional = 2, visibility = PRIVATE)
public IRubyObject initialize(ThreadContext context, IRubyObject[] args, Block block) {
final Ruby runtime = context.runtime;
int argnum = 1;
IRubyObject sig = context.nil;
long _signo;
int argc = args.length;

if (argc > 0) {
sig = TypeConverter.checkIntegerType(runtime, args[0], "to_int");

if (sig.isNil()) {
sig = args[0];
} else {
argnum = 2;
}
}

Arity.checkArgumentCount(runtime, args, 1, argnum);

if (argnum == 2) {
_signo = sig.convertToInteger().getLongValue();
if (_signo < 0 || _signo > NSIG.longValue()) {
throw runtime.newArgumentError("invalid signal number (" + _signo + ")");
}

if (argc > 1) {
sig = args[1];
} else {
sig = runtime.newString(RubySignal.signmWithPrefix(RubySignal.signo2signm(_signo)));
}
} else {
String signm = sig.toString();
_signo = RubySignal.signm2signo(RubySignal.signmWithoutPrefix(signm));

if (_signo == 0) {
throw runtime.newArgumentError("unsupported name " + sig);
}

sig = runtime.newString(RubySignal.signmWithPrefix(signm));
}

super.initialize(new IRubyObject[]{sig}, block);
this.signo = runtime.newFixnum(_signo);

return this;
}

@JRubyMethod
public IRubyObject signo(ThreadContext context) {
assert signo != null;

if (signo == RubyBasicObject.UNDEF) return context.nil;

return signo;
}

@JRubyMethod(name = {"message","signm"})
@Override
public IRubyObject message(ThreadContext context) {
return super.message(context);
}

private IRubyObject signo;
}
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/RubyThread.java
Expand Up @@ -213,6 +213,7 @@ protected RubyThread(Ruby runtime, RubyClass type) {
super(runtime, type);

finalResult = errorInfo = runtime.getNil();
threadName = runtime.getNil();
}

public RubyThread(Ruby runtime, RubyClass klass, Runnable runnable) {
Expand Down

0 comments on commit 574fd07

Please sign in to comment.