aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenoit Germain <bnt period germain arrobase gmail period com>2017-06-13 12:06:17 +0200
committerBenoit Germain <bnt period germain arrobase gmail period com>2017-06-13 12:06:17 +0200
commit16a76921157fbb7b8e4363bb56744ea2f3ac1156 (patch)
treed2e0b1f2ec89f9e8bd0403362f286c98188af8ee /src
parent0371c1f79d0fae90f77eee4c911e54245bd3468c (diff)
downloadlanes-16a76921157fbb7b8e4363bb56744ea2f3ac1156.tar.gz
lanes-16a76921157fbb7b8e4363bb56744ea2f3ac1156.tar.bz2
lanes-16a76921157fbb7b8e4363bb56744ea2f3ac1156.zip
Accept non-string error messages
Diffstat (limited to 'src')
-rw-r--r--src/lanes.c73
1 files changed, 36 insertions, 37 deletions
diff --git a/src/lanes.c b/src/lanes.c
index 8410ca2..78fece8 100644
--- a/src/lanes.c
+++ b/src/lanes.c
@@ -297,7 +297,7 @@ static bool_t push_registry_table( lua_State* L, void* key, bool_t create)
297 STACK_GROW( L, 3); 297 STACK_GROW( L, 3);
298 STACK_CHECK( L); 298 STACK_CHECK( L);
299 lua_pushlightuserdata( L, key); // key 299 lua_pushlightuserdata( L, key); // key
300 lua_gettable( L, LUA_REGISTRYINDEX); // t? 300 lua_rawget( L, LUA_REGISTRYINDEX); // t?
301 301
302 if( lua_isnil( L, -1)) // nil? 302 if( lua_isnil( L, -1)) // nil?
303 { 303 {
@@ -1842,12 +1842,11 @@ done:
1842static int lane_error( lua_State* L) 1842static int lane_error( lua_State* L)
1843{ 1843{
1844 lua_Debug ar; 1844 lua_Debug ar;
1845 unsigned lev, n; 1845 int n;
1846 bool_t extended; 1846 bool_t extended;
1847 1847
1848 // [1]: error message (any type) 1848 // error message (any type)
1849 1849 assert( lua_gettop( L) == 1); // some_error
1850 assert( lua_gettop( L) == 1);
1851 1850
1852 // Don't do stack survey for cancelled lanes. 1851 // Don't do stack survey for cancelled lanes.
1853 // 1852 //
@@ -1856,10 +1855,11 @@ static int lane_error( lua_State* L)
1856 return 1; // just pass on 1855 return 1; // just pass on
1857 } 1856 }
1858 1857
1859 lua_pushlightuserdata( L, EXTENDED_STACK_TRACE_KEY); 1858 STACK_GROW( L, 3);
1860 lua_gettable( L, LUA_REGISTRYINDEX); 1859 lua_pushlightuserdata( L, EXTENDED_STACK_TRACE_KEY); // some_error estk
1860 lua_rawget( L, LUA_REGISTRYINDEX); // some_error basic|extended
1861 extended = lua_toboolean( L, -1); 1861 extended = lua_toboolean( L, -1);
1862 lua_pop( L, 1); 1862 lua_pop( L, 1); // some_error
1863 1863
1864 // Place stack trace at 'registry[lane_error]' for the 'lua_pcall()' 1864 // Place stack trace at 'registry[lane_error]' for the 'lua_pcall()'
1865 // caller to fetch. This bypasses the Lua 5.1 limitation of only one 1865 // caller to fetch. This bypasses the Lua 5.1 limitation of only one
@@ -1871,50 +1871,48 @@ static int lane_error( lua_State* L)
1871 // 1871 //
1872 // table of { "sourcefile.lua:<line>", ... } 1872 // table of { "sourcefile.lua:<line>", ... }
1873 // 1873 //
1874 STACK_GROW( L, 4); 1874 lua_newtable( L); // some_error {}
1875 lua_newtable( L);
1876 1875
1877 // Best to start from level 1, but in some cases it might be a C function 1876 // Best to start from level 1, but in some cases it might be a C function
1878 // and we don't get '.currentline' for that. It's okay - just keep level 1877 // and we don't get '.currentline' for that. It's okay - just keep level
1879 // and table index growing separate. --AKa 22-Jan-2009 1878 // and table index growing separate. --AKa 22-Jan-2009
1880 // 1879 //
1881 lev = 0; 1880 for( n = 1; lua_getstack( L, n, &ar); ++ n)
1882 n = 1;
1883 while( lua_getstack( L, ++ lev, &ar))
1884 { 1881 {
1885 lua_getinfo( L, extended ? "Sln" : "Sl", &ar); 1882 lua_getinfo( L, extended ? "Sln" : "Sl", &ar);
1886 if( extended) 1883 if( extended)
1887 { 1884 {
1888 lua_newtable( L); 1885 lua_newtable( L); // some_error {} {}
1889
1890 lua_pushstring( L, ar.source);
1891 lua_setfield( L, -2, "source");
1892 1886
1893 lua_pushinteger( L, ar.currentline); 1887 lua_pushstring( L, ar.source); // some_error {} {} source
1894 lua_setfield( L, -2, "currentline"); 1888 lua_setfield( L, -2, "source"); // some_error {} {}
1895 1889
1896 lua_pushstring( L, ar.name); 1890 lua_pushinteger( L, ar.currentline); // some_error {} {} currentline
1897 lua_setfield( L, -2, "name"); 1891 lua_setfield( L, -2, "currentline"); // some_error {} {}
1898 1892
1899 lua_pushstring( L, ar.namewhat); 1893 lua_pushstring( L, ar.name); // some_error {} {} name
1900 lua_setfield( L, -2, "namewhat"); 1894 lua_setfield( L, -2, "name"); // some_error {} {}
1901 1895
1902 lua_pushstring( L, ar.what); 1896 lua_pushstring( L, ar.namewhat); // some_error {} {} namewhat
1903 lua_setfield( L, -2, "what"); 1897 lua_setfield( L, -2, "namewhat"); // some_error {} {}
1904 1898
1905 lua_rawseti(L, -2, n ++); 1899 lua_pushstring( L, ar.what); // some_error {} {} what
1900 lua_setfield( L, -2, "what"); // some_error {} {}
1906 } 1901 }
1907 else if (ar.currentline > 0) 1902 else if( ar.currentline > 0)
1903 {
1904 lua_pushfstring( L, "%s:%d", ar.short_src, ar.currentline); // some_error {} "blah:blah"
1905 }
1906 else
1908 { 1907 {
1909 lua_pushinteger( L, n++ ); 1908 lua_pushfstring( L, "%s:?", ar.short_src); // some_error {} "blah"
1910 lua_pushfstring( L, "%s:%d", ar.short_src, ar.currentline );
1911 lua_settable( L, -3 );
1912 } 1909 }
1910 lua_rawseti( L, -2, (lua_Integer) n); // some_error {}
1913 } 1911 }
1914 1912
1915 lua_pushlightuserdata( L, STACK_TRACE_KEY); 1913 lua_pushlightuserdata( L, STACK_TRACE_KEY); // some_error {} stk
1916 lua_insert( L, -2); 1914 lua_insert( L, -2); // some_error stk {}
1917 lua_settable( L, LUA_REGISTRYINDEX); 1915 lua_rawset( L, LUA_REGISTRYINDEX); // some_error
1918 1916
1919 assert( lua_gettop( L) == 1); 1917 assert( lua_gettop( L) == 1);
1920 1918
@@ -1937,11 +1935,12 @@ static void push_stack_trace( lua_State* L, int rc_, int stk_base_)
1937 STACK_GROW( L, 1); 1935 STACK_GROW( L, 1);
1938 lua_pushlightuserdata( L, STACK_TRACE_KEY); // err STACK_TRACE_KEY 1936 lua_pushlightuserdata( L, STACK_TRACE_KEY); // err STACK_TRACE_KEY
1939 // yields nil if no stack was generated (in case of cancellation for example) 1937 // yields nil if no stack was generated (in case of cancellation for example)
1940 lua_gettable( L, LUA_REGISTRYINDEX); // err trace|nil 1938 lua_rawget( L, LUA_REGISTRYINDEX); // err trace|nil
1939 ASSERT_L( lua_gettop( L) == 1 + stk_base_);
1941 1940
1942 // For cancellation the error message is CANCEL_ERROR, and a stack trace isn't placed 1941 // For cancellation the error message is CANCEL_ERROR, and a stack trace isn't placed
1943 // For other errors, the message should be a string, and we should have a stack trace table 1942 // For other errors, the message can be whatever was thrown, and we should have a stack trace table
1944 ASSERT_L( (lua_istable( L, 1 + stk_base_) && lua_type( L, stk_base_) == LUA_TSTRING) || (lua_touserdata( L, stk_base_) == CANCEL_ERROR)); 1943 ASSERT_L( lua_type( L, 1 + stk_base_) == ((lua_touserdata( L, stk_base_) == CANCEL_ERROR) ? LUA_TNIL : LUA_TTABLE));
1945 // Just leaving the stack trace table on the stack is enough to get it through to the master. 1944 // Just leaving the stack trace table on the stack is enough to get it through to the master.
1946 break; 1945 break;
1947 } 1946 }
@@ -2085,7 +2084,7 @@ static THREAD_RETURN_T THREAD_CALLCONV lane_main( void* vs)
2085# endif // ERROR_FULL_STACK 2084# endif // ERROR_FULL_STACK
2086 2085
2087 // in case of error and if it exists, fetch stack trace from registry and push it 2086 // in case of error and if it exists, fetch stack trace from registry and push it
2088 push_stack_trace( L, rc, 1); 2087 push_stack_trace( L, rc, 1); // retvals|error [trace]
2089 2088
2090 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "Lane %p body: %s (%s)\n" INDENT_END, L, get_errcode_name( rc), (lua_touserdata( L, 1)==CANCEL_ERROR) ? "cancelled" : lua_typename( L, lua_type( L, 1)))); 2089 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "Lane %p body: %s (%s)\n" INDENT_END, L, get_errcode_name( rc), (lua_touserdata( L, 1)==CANCEL_ERROR) ? "cancelled" : lua_typename( L, lua_type( L, 1))));
2091 //STACK_DUMP(L); 2090 //STACK_DUMP(L);