chriscz / shedskin

Automatically exported from code.google.com/p/shedskin
0 stars 0 forks source link

sys.exit() does not allow strings #1

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. import sys
2. sys.exit("Program exits")

I'm testing this on Win XP. Shedskin 0.0.26 creates the .cpp and .hpp 
files, but will not make them. Changing the string in sys.exit() to an 
int, bypasses the problem.

Original issue reported on code.google.com by rune.str...@gmail.com on 16 Jan 2008 at 1:31

GoogleCodeExporter commented 9 years ago
thanks for mentioning. I think the diff below should fix this (I'll add it to 
SVN
later). note that it's still not possible to catch a SystemExit. 

--- ../shedskin-0.0.26-1/lib/sys.cpp    2008-01-16 21:13:59.000000000 +0100
+++ lib/sys.cpp 2008-01-17 15:08:31.000000000 +0100
@@ -32,9 +32,13 @@
     _stderr = new file(stderr); 
 }

-void exit(int code) {
-    std::exit(code);
-};
+void exit() {
+    std::exit(0);
+}; 
+
+template<> void exit(int x) {
+    std::exit(x);
+}

 } // module namespace

srepmub@akemi:~/shedskin$ diff -u ../shedskin-0.0.26-1/lib/sys.hpp lib/sys.hpp
--- ../shedskin-0.0.26-1/lib/sys.hpp    2008-01-16 21:13:59.000000000 +0100
+++ lib/sys.hpp 2008-01-17 15:08:12.000000000 +0100
@@ -14,7 +14,15 @@
 extern str *__name__, *copyright, *platform;
 extern int hexversion, maxint;
 extern file *_stdin, *_stdout, *_stderr;
-void exit(int code=0);
+
+void exit();
+template<class T> void exit(T x) {
+    if(x == 0)
+        std::exit(0);
+    print(_stderr, "%s\n", __str(x)); 
+    std::exit(1);
+}
+template<> void exit(int x);

 } // module namespace
 #endif

Original comment by mark.duf...@gmail.com on 17 Jan 2008 at 2:18

GoogleCodeExporter commented 9 years ago

Original comment by mark.duf...@gmail.com on 17 Jan 2008 at 2:20

GoogleCodeExporter commented 9 years ago
marking this as fixed.

Original comment by mark.duf...@gmail.com on 22 Jan 2008 at 8:02

GoogleCodeExporter commented 9 years ago
With python one can sys.exit(1) without anything being printed on 
stdout/stderr. How can one achieve this with shedskin? I miss a way to exit(1) 
without anything printing.

Original comment by rods...@gmail.com on 3 Jan 2012 at 10:53

GoogleCodeExporter commented 9 years ago
thanks for mentioning. this looks like a regression. I'm adding some tests for 
this now, and will hopefully fix the problem shortly..

Original comment by mark.duf...@gmail.com on 4 Jan 2012 at 7:51

GoogleCodeExporter commented 9 years ago
alright, fixed in GIT:

http://gitorious.org/shedskin/mainline/commit/b07c86912155e1d651c360ab6a859d1b4e
8db5e2

thanks again for mentioning! :-)

Original comment by mark.duf...@gmail.com on 4 Jan 2012 at 8:37