develooper Front page | perl.cvs.parrot | Postings from December 2008

[svn:parrot] r33801 - in trunk/languages/lua: src/lib t

From:
fperrad
Date:
December 11, 2008 07:50
Subject:
[svn:parrot] r33801 - in trunk/languages/lua: src/lib t
Message ID:
20081211155004.28EABCB9AF@x12.develooper.com
Author: fperrad
Date: Thu Dec 11 07:50:02 2008
New Revision: 33801

Modified:
   trunk/languages/lua/src/lib/lfs.pir
   trunk/languages/lua/src/lib/luaaux.pir
   trunk/languages/lua/src/lib/luabasic.pir
   trunk/languages/lua/src/lib/luaio.pir
   trunk/languages/lua/t/basic.t
   trunk/languages/lua/t/lfs.t

Log:
[Lua] exception
- fix infinite loop in exception handler

Don't use die (even indirectly) in an handler, but rethrow the exception.

Modified: trunk/languages/lua/src/lib/lfs.pir
==============================================================================
--- trunk/languages/lua/src/lib/lfs.pir	(original)
+++ trunk/languages/lua/src/lib/lfs.pir	Thu Dec 11 07:50:02 2008
@@ -495,10 +495,12 @@
     .return (res)
   _handler:
     .local pmc e
-    .local string s
+    .local string msg
     .get_results (e)
-    s = e
-    lua_error("cannot open ", $S0, ": ", s)
+    msg = e
+    $S0 = lua_x_error("cannot open ", $S0, ": ", msg)
+    e = $S0
+    rethrow e
 .end
 
 .sub 'dir_aux' :anon :lex :outer(dir)

Modified: trunk/languages/lua/src/lib/luaaux.pir
==============================================================================
--- trunk/languages/lua/src/lib/luaaux.pir	(original)
+++ trunk/languages/lua/src/lib/luaaux.pir	Thu Dec 11 07:50:02 2008
@@ -27,15 +27,24 @@
 
 This function never returns.
 
+CAUTION: don't used it in an exception handler, but lua_x_argerror & rethrow.
+
 =cut
 
 .sub 'lua_argerror'
     .param int narg
     .param pmc extramsg :slurpy
+    $S0 = lua_x_argerror(narg, extramsg :flat)
+    lua_error($S0)
+.end
+
+.sub 'lua_x_argerror'
+    .param int narg
+    .param pmc extramsg :slurpy
     $S1 = narg
     new $P0, 'Lua'
     $S0 = $P0.'caller'()
-    lua_error("bad argument #", $S1, " to '", $S0, "' (", extramsg :flat, ")")
+    .tailcall lua_x_error("bad argument #", $S1, " to '", $S0, "' (", extramsg :flat, ")")
 .end
 
 
@@ -199,14 +208,21 @@
 
 This function never returns.
 
+CAUTION: don't used it in an exception handler, but lua_x_error & rethrow.
+
 =cut
 
 .sub 'lua_error'
     .param pmc message :slurpy
-    $S0 = join '', message
+    $S0 = lua_x_error(message :flat)
     die $S0
 .end
 
+.sub 'lua_x_error'
+    .param pmc message :slurpy
+    $S0 = join '', message
+    .return ($S0)
+.end
 
 =item C<lua_findtable (t, fname)>
 

Modified: trunk/languages/lua/src/lib/luabasic.pir
==============================================================================
--- trunk/languages/lua/src/lib/luabasic.pir	(original)
+++ trunk/languages/lua/src/lib/luabasic.pir	Thu Dec 11 07:50:02 2008
@@ -291,7 +291,11 @@
   L2:
     .return (f)
   _handler:
-    lua_argerror(1, "invalid level")
+    .local pmc e
+    .get_results (e)
+    $S0 = lua_x_argerror(1, "invalid level")
+    e = $S0
+    rethrow e
 .end
 
 =item C<getmetatable (object)>

Modified: trunk/languages/lua/src/lib/luaio.pir
==============================================================================
--- trunk/languages/lua/src/lib/luaio.pir	(original)
+++ trunk/languages/lua/src/lib/luaio.pir	Thu Dec 11 07:50:02 2008
@@ -388,7 +388,11 @@
     res = getiofile(IO_INPUT)
     .return (res)
   _handler:
-    lua_argerror(1, file)
+    .local pmc e
+    .get_results (e)
+    $S0 = lua_x_argerror(1, file)
+    e = $S0
+    rethrow e
 .end
 
 
@@ -429,7 +433,11 @@
     file = newfile(f)
     .tailcall aux_lines(file, 1)
   _handler:
-    lua_argerror(1, $S1)
+    .local pmc e
+    .get_results (e)
+    $S0 = lua_x_argerror(1, $S1)
+    e = $S0
+    rethrow e
 .end
 
 
@@ -531,7 +539,11 @@
     res = getiofile(IO_OUTPUT)
     .return (res)
   _handler:
-    lua_argerror(1, file)
+    .local pmc e
+    .get_results (e)
+    $S0 = lua_x_argerror(1, file)
+    e = $S0
+    rethrow e
 .end
 
 

Modified: trunk/languages/lua/t/basic.t
==============================================================================
--- trunk/languages/lua/t/basic.t	(original)
+++ trunk/languages/lua/t/basic.t	Thu Dec 11 07:50:02 2008
@@ -154,15 +154,11 @@
 /^[^:]+: [^:]+:\d+: bad argument #1 to 'getfenv' \(level must be non-negative\)\nstack traceback:\n/
 OUT
 
-SKIP: {
-skip("getfenv: infinite loop when too depth", 1);
-
 language_output_like( 'lua', <<'CODE', <<'OUT', 'function getfenv (too depth)' );
 print(getfenv(12))
 CODE
 /^[^:]+: [^:]+:\d+: bad argument #1 to 'getfenv' \(invalid level\)\nstack traceback:\n/
 OUT
-}
 
 language_output_is( 'lua', << 'CODE', << 'OUTPUT', 'function ipairs' );
 a = {"a","b","c"}
@@ -500,15 +496,11 @@
 /^[^:]+: [^:]+:\d+: bad argument #1 to 'setfenv' \(level must be non-negative\)\nstack traceback:\n/
 OUT
 
-SKIP: {
-skip("setfenv: infinite loop when too depth", 1);
-
 language_output_like( 'lua', <<'CODE', <<'OUT', 'function setfenv (too depth)' );
 print(setfenv(12, {}))
 CODE
 /^[^:]+: [^:]+:\d+: bad argument #1 to 'setfenv' \(invalid level\)\nstack traceback:\n/
 OUT
-}
 
 language_output_like( 'lua', <<'CODE', <<'OUT', 'function setfenv (bad arg)' );
 t = {}

Modified: trunk/languages/lua/t/lfs.t
==============================================================================
--- trunk/languages/lua/t/lfs.t	(original)
+++ trunk/languages/lua/t/lfs.t	Thu Dec 11 07:50:02 2008
@@ -111,16 +111,12 @@
 No such file or directory
 OUT
 
-SKIP: {
-skip("lfs.dir: infinite loop", 1);
-
 language_output_like( 'lua', <<'CODE', <<'OUT', 'function lfs.dir' );
 require "lfs"
 lfs.dir("xptoo")
 CODE
 /^[^:]+: [^:]+:\d+: cannot open xptoo: No such file or directory\nstack traceback:\n/
 OUT
-}
 
 mkdir '../xpto' unless -d '../xpto';
 



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About