[#11073] segfault printing instruction sequence for iterator — <noreply@...>

Bugs item #10527, was opened at 2007-05-02 14:42

14 messages 2007/05/02
[#11142] Re: [ ruby-Bugs-10527 ] segfault printing instruction sequence for iterator — Nobuyoshi Nakada <nobu@...> 2007/05/10

Hi,

[#11188] Re: [ ruby-Bugs-10527 ] segfault printing instruction sequence for iterator — Paul Brannan <pbrannan@...> 2007/05/16

On Thu, May 10, 2007 at 04:51:18PM +0900, Nobuyoshi Nakada wrote:

[#11234] Planning to release 1.8.6 errata — Urabe Shyouhei <shyouhei@...>

Hi all.

17 messages 2007/05/25

Re: [ ruby-Bugs-11151 ] exception in at_exit --> 0 exit status

From: Nobuyoshi Nakada <nobu@...>
Date: 2007-05-27 06:17:34 UTC
List: ruby-core #11266
Hi,

At Sun, 27 May 2007 08:19:53 +0900,
Johan Holmberg wrote in [ruby-core:11263]:
> If an exception occurs in an at_exit block, the Ruby process
> still exits with a zero exit status. This seems
> wrong. Example code:
> 
>   $ ruby -e 'at_exit { raise "an error" }' ; echo $?
>   -e:1: an error (RuntimeError)
>           from -e:1
>   0
> 
> All Ruby version I have tested work this way:

I'm not sure if this is a bug or a feature.


Index: eval.c
===================================================================
--- eval.c	(revision 12393)
+++ eval.c	(working copy)
@@ -193,4 +193,7 @@ ruby_cleanup(int ex)
 	    ruby_default_signal(NUM2INT(sig));
 	}
+	else if (ex == 0) {
+	    ex = 1;
+	}
     }
 
@@ -226,8 +229,22 @@ ruby_exec(void)
 }
 
+#if EXIT_SUCCESS == 0 && EXIT_FAILURE == 1
+#define state_to_exitcode(ex) (ex)
+#else
+static int
+state_to_exitcode(int ex)
+{
+    switch (ex) {
+      case 0: return EXIT_SUCCESS;
+      case 1: return EXIT_FAILURE;
+    }
+    return ex;
+}
+#endif
+
 void
 ruby_stop(int ex)
 {
-    exit(ruby_cleanup(ex));
+    exit(state_to_exitcode(ruby_cleanup(ex)));
 }
 


-- 
Nobu Nakada

In This Thread