Permalink
Browse files

JRUBY-1057: Rubinius core/exception_spec failures

Small classpath tweakage for Eclipse users (for debugging)

git-svn-id: http://svn.codehaus.org/jruby/trunk/jruby@4915 961051c9-f516-0410-bf72-c9f7e237a7b7
  • Loading branch information...
1 parent 882fef6 commit 25297c74c3df6eef58b1e46bae1c2b93681554e3 @enebo enebo committed Nov 11, 2007
Showing with 99 additions and 1 deletion.
  1. +2 −0 .classpath
  2. +1 −1 src/org/jruby/Ruby.java
  3. +96 −0 src/org/jruby/RubySystemCallError.java
View
@@ -11,5 +11,7 @@
<classpathentry kind="lib" path="build_lib/asm-util-3.0.jar"/>
<classpathentry kind="lib" path="build_lib/asm-commons-3.0.jar"/>
<classpathentry kind="lib" path="build_lib/asm-3.0.jar"/>
+ <classpathentry kind="lib" path="build_lib/asm-tree-3.0.jar"/>
+ <classpathentry kind="lib" path="build_lib/asm-analysis-3.0.jar"/>
<classpathentry kind="output" path="build/classes/jruby"/>
</classpath>
View
@@ -1447,7 +1447,7 @@ private void initCoreClasses() {
}
if (profile.allowClass("NativeException")) NativeException.createClass(this, runtimeError);
if (profile.allowClass("SystemCallError")) {
- systemCallError = defineClass("SystemCallError", standardError, standardError.getAllocator());
+ systemCallError = RubySystemCallError.createSystemCallErrorClass(this, standardError);
}
if (profile.allowModule("Errno")) errnoModule = defineModule("Errno");
@@ -0,0 +1,96 @@
+package org.jruby;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.jruby.anno.JRubyMethod;
+import org.jruby.runtime.Block;
+import org.jruby.runtime.ObjectAllocator;
+import org.jruby.runtime.ObjectMarshal;
+import org.jruby.runtime.Visibility;
+import org.jruby.runtime.builtin.IRubyObject;
+import org.jruby.runtime.builtin.Variable;
+import org.jruby.runtime.component.VariableEntry;
+import org.jruby.runtime.marshal.MarshalStream;
+import org.jruby.runtime.marshal.UnmarshalStream;
+
+public class RubySystemCallError extends RubyException {
+ private IRubyObject errno;
+
+ protected RubySystemCallError(Ruby runtime, RubyClass rubyClass) {
+ this(runtime, rubyClass, null, 0);
+ }
+
+ public RubySystemCallError(Ruby runtime, RubyClass rubyClass, String message, int errno) {
+ super(runtime, rubyClass, message);
+
+ this.errno = runtime.newFixnum(errno);
+ }
+
+ private static ObjectAllocator SYSTEM_CALL_ERROR_ALLOCATOR = new ObjectAllocator() {
+ public IRubyObject allocate(Ruby runtime, RubyClass klass) {
+ RubyException instance = new RubySystemCallError(runtime, klass);
+
+ instance.setMetaClass(klass);
+
+ return instance;
+ }
+ };
+
+ private static final ObjectMarshal SYSTEM_CALL_ERROR_MARSHAL = new ObjectMarshal() {
+ public void marshalTo(Ruby runtime, Object obj, RubyClass type,
+ MarshalStream marshalStream) throws IOException {
+ RubySystemCallError exc = (RubySystemCallError) obj;
+
+ List<Variable<IRubyObject>> attrs = exc.getVariableList();
+ attrs.add(new VariableEntry<IRubyObject>(
+ "mesg", exc.message == null ? runtime.getNil() : exc.message));
+ attrs.add(new VariableEntry<IRubyObject>("errno", exc.errno));
+ attrs.add(new VariableEntry<IRubyObject>("bt", exc.getBacktrace()));
+ marshalStream.dumpVariables(attrs);
+ }
+
+ public Object unmarshalFrom(Ruby runtime, RubyClass type,
+ UnmarshalStream unmarshalStream) throws IOException {
+ RubySystemCallError exc = (RubySystemCallError) type.allocate();
+
+ unmarshalStream.registerLinkTarget(exc);
+ unmarshalStream.defaultVariablesUnmarshal(exc);
+
+ exc.message = exc.removeInternalVariable("mesg");
+ exc.errno = exc.removeInternalVariable("errno");
+ exc.set_backtrace(exc.removeInternalVariable("bt"));
+
+ return exc;
+ }
+ };
+
+ public static RubyClass createSystemCallErrorClass(Ruby runtime, RubyClass standardError) {
+ RubyClass exceptionClass = runtime.defineClass("SystemCallError", standardError, SYSTEM_CALL_ERROR_ALLOCATOR);
+
+ exceptionClass.setMarshal(SYSTEM_CALL_ERROR_MARSHAL);
+
+ runtime.callbackFactory(RubyClass.class);
+ exceptionClass.defineAnnotatedMethods(RubySystemCallError.class);
+
+ return exceptionClass;
+ }
+
+ @JRubyMethod(optional = 2, required=1, frame = true, visibility = Visibility.PRIVATE)
+ public IRubyObject initialize(IRubyObject[] args, Block block) {
+ if (args.length >= 1) message = args[0];
+ if (args.length == 2) {
+ errno = args[1].convertToInteger();
+ } else {
+ // FIXME: Get current errno value if one is set?
+ errno = getRuntime().getNil();
+ }
+
+ return this;
+ }
+
+ @JRubyMethod
+ public IRubyObject errno() {
+ return errno;
+ }
+}

0 comments on commit 25297c7

Please sign in to comment.