aboutsummaryrefslogtreecommitdiff
path: root/src/lanes.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lanes.cpp')
-rw-r--r--src/lanes.cpp107
1 files changed, 54 insertions, 53 deletions
diff --git a/src/lanes.cpp b/src/lanes.cpp
index 38dd92c..6123766 100644
--- a/src/lanes.cpp
+++ b/src/lanes.cpp
@@ -113,7 +113,7 @@ THE SOFTWARE.
113// intern the debug name in the specified lua state so that the pointer remains valid when the lane's state is closed 113// intern the debug name in the specified lua state so that the pointer remains valid when the lane's state is closed
114static void securize_debug_threadname( lua_State* L, Lane* s) 114static void securize_debug_threadname( lua_State* L, Lane* s)
115{ 115{
116 STACK_CHECK( L, 0); 116 STACK_CHECK_START_REL(L, 0);
117 STACK_GROW( L, 3); 117 STACK_GROW( L, 3);
118 lua_getiuservalue( L, 1, 1); 118 lua_getiuservalue( L, 1, 1);
119 lua_newtable( L); 119 lua_newtable( L);
@@ -122,7 +122,7 @@ static void securize_debug_threadname( lua_State* L, Lane* s)
122 s->debug_name = lua_tostring( L, -1); 122 s->debug_name = lua_tostring( L, -1);
123 lua_rawset( L, -3); 123 lua_rawset( L, -3);
124 lua_pop( L, 1); 124 lua_pop( L, 1);
125 STACK_END( L, 0); 125 STACK_CHECK( L, 0);
126} 126}
127 127
128#if ERROR_FULL_STACK 128#if ERROR_FULL_STACK
@@ -155,12 +155,13 @@ struct s_Linda;
155static bool push_registry_table( lua_State* L, UniqueKey key, bool create) 155static bool push_registry_table( lua_State* L, UniqueKey key, bool create)
156{ 156{
157 STACK_GROW( L, 3); 157 STACK_GROW( L, 3);
158 STACK_CHECK( L, 0); 158 STACK_CHECK_START_REL(L, 0);
159 159
160 key.query_registry(L); // ? 160 key.query_registry(L); // ?
161 if( lua_isnil( L, -1)) // nil? 161 if( lua_isnil( L, -1)) // nil?
162 { 162 {
163 lua_pop( L, 1); // 163 lua_pop( L, 1); //
164 STACK_CHECK(L, 0);
164 165
165 if( !create) 166 if( !create)
166 { 167 {
@@ -170,7 +171,7 @@ static bool push_registry_table( lua_State* L, UniqueKey key, bool create)
170 lua_newtable( L); // t 171 lua_newtable( L); // t
171 key.set_registry(L, [](lua_State* L) { lua_pushvalue(L, -2); }); 172 key.set_registry(L, [](lua_State* L) { lua_pushvalue(L, -2); });
172 } 173 }
173 STACK_END( L, 1); 174 STACK_CHECK( L, 1);
174 return true; // table pushed 175 return true; // table pushed
175} 176}
176 177
@@ -675,11 +676,8 @@ done:
675 676
676static int lane_error( lua_State* L) 677static int lane_error( lua_State* L)
677{ 678{
678 lua_Debug ar;
679 int n;
680
681 // error message (any type) 679 // error message (any type)
682 STACK_CHECK_ABS( L, 1); // some_error 680 STACK_CHECK_START_ABS(L, 1); // some_error
683 681
684 // Don't do stack survey for cancelled lanes. 682 // Don't do stack survey for cancelled lanes.
685 // 683 //
@@ -692,6 +690,7 @@ static int lane_error( lua_State* L)
692 EXTENDED_STACKTRACE_REGKEY.query_registry(L); // some_error basic|extended 690 EXTENDED_STACKTRACE_REGKEY.query_registry(L); // some_error basic|extended
693 bool const extended{ lua_toboolean(L, -1) ? true : false}; 691 bool const extended{ lua_toboolean(L, -1) ? true : false};
694 lua_pop( L, 1); // some_error 692 lua_pop( L, 1); // some_error
693 STACK_CHECK(L, 1);
695 694
696 // Place stack trace at 'registry[STACKTRACE_REGKEY]' for the 'lua_pcall()' 695 // Place stack trace at 'registry[STACKTRACE_REGKEY]' for the 'lua_pcall()'
697 // caller to fetch. This bypasses the Lua 5.1 limitation of only one 696 // caller to fetch. This bypasses the Lua 5.1 limitation of only one
@@ -709,7 +708,8 @@ static int lane_error( lua_State* L)
709 // and we don't get '.currentline' for that. It's okay - just keep level 708 // and we don't get '.currentline' for that. It's okay - just keep level
710 // and table index growing separate. --AKa 22-Jan-2009 709 // and table index growing separate. --AKa 22-Jan-2009
711 // 710 //
712 for( n = 1; lua_getstack( L, n, &ar); ++ n) 711 lua_Debug ar;
712 for (int n = 1; lua_getstack(L, n, &ar); ++n)
713 { 713 {
714 lua_getinfo( L, extended ? "Sln" : "Sl", &ar); 714 lua_getinfo( L, extended ? "Sln" : "Sl", &ar);
715 if( extended) 715 if( extended)
@@ -745,8 +745,8 @@ static int lane_error( lua_State* L)
745 // store the stack trace table in the registry 745 // store the stack trace table in the registry
746 STACKTRACE_REGKEY.set_registry(L, [](lua_State* L) { lua_insert(L, -2); }); // some_error 746 STACKTRACE_REGKEY.set_registry(L, [](lua_State* L) { lua_insert(L, -2); }); // some_error
747 747
748 STACK_END( L, 1); 748 STACK_CHECK(L, 1);
749 return 1; // the untouched error value 749 return 1; // the untouched error value
750} 750}
751#endif // ERROR_FULL_STACK 751#endif // ERROR_FULL_STACK
752 752
@@ -761,12 +761,12 @@ static void push_stack_trace( lua_State* L, int rc_, int stk_base_)
761 case LUA_ERRRUN: // cancellation or a runtime error 761 case LUA_ERRRUN: // cancellation or a runtime error
762#if ERROR_FULL_STACK // when ERROR_FULL_STACK, we installed a handler 762#if ERROR_FULL_STACK // when ERROR_FULL_STACK, we installed a handler
763 { 763 {
764 STACK_CHECK( L, 0); 764 STACK_CHECK_START_REL(L, 0);
765 // fetch the call stack table from the registry where the handler stored it 765 // fetch the call stack table from the registry where the handler stored it
766 STACK_GROW( L, 1); 766 STACK_GROW( L, 1);
767 // yields nil if no stack was generated (in case of cancellation for example) 767 // yields nil if no stack was generated (in case of cancellation for example)
768 STACKTRACE_REGKEY.query_registry(L); // err trace|nil 768 STACKTRACE_REGKEY.query_registry(L); // err trace|nil
769 STACK_END( L, 1); 769 STACK_CHECK( L, 1);
770 770
771 // For cancellation the error message is CANCEL_ERROR, and a stack trace isn't placed 771 // For cancellation the error message is CANCEL_ERROR, and a stack trace isn't placed
772 // For other errors, the message can be whatever was thrown, and we should have a stack trace table 772 // For other errors, the message can be whatever was thrown, and we should have a stack trace table
@@ -793,16 +793,16 @@ LUAG_FUNC( set_debug_threadname)
793 Lane* s = (Lane*) lua_touserdata( L, lua_upvalueindex( 1)); 793 Lane* s = (Lane*) lua_touserdata( L, lua_upvalueindex( 1));
794 luaL_checktype( L, -1, LUA_TSTRING); // "name" 794 luaL_checktype( L, -1, LUA_TSTRING); // "name"
795 lua_settop( L, 1); 795 lua_settop( L, 1);
796 STACK_CHECK_ABS( L, 1); 796 STACK_CHECK_START_ABS( L, 1);
797 // store a hidden reference in the registry to make sure the string is kept around even if a lane decides to manually change the "decoda_name" global... 797 // store a hidden reference in the registry to make sure the string is kept around even if a lane decides to manually change the "decoda_name" global...
798 hidden_regkey.set_registry(L, [](lua_State* L) { lua_pushvalue(L, -2); }); 798 hidden_regkey.set_registry(L, [](lua_State* L) { lua_pushvalue(L, -2); });
799 STACK_MID( L, 1); 799 STACK_CHECK( L, 1);
800 s->debug_name = lua_tostring( L, -1); 800 s->debug_name = lua_tostring( L, -1);
801 // keep a direct pointer on the string 801 // keep a direct pointer on the string
802 THREAD_SETNAME( s->debug_name); 802 THREAD_SETNAME( s->debug_name);
803 // to see VM name in Decoda debugger Virtual Machine window 803 // to see VM name in Decoda debugger Virtual Machine window
804 lua_setglobal( L, "decoda_name"); // 804 lua_setglobal( L, "decoda_name"); //
805 STACK_END( L, 0); 805 STACK_CHECK( L, 0);
806 return 0; 806 return 0;
807} 807}
808 808
@@ -990,7 +990,7 @@ LUAG_FUNC( require)
990 char const* name = lua_tostring( L, 1); 990 char const* name = lua_tostring( L, 1);
991 int const nargs = lua_gettop( L); 991 int const nargs = lua_gettop( L);
992 DEBUGSPEW_CODE( Universe* U = universe_get( L)); 992 DEBUGSPEW_CODE( Universe* U = universe_get( L));
993 STACK_CHECK( L, 0); 993 STACK_CHECK_START_REL(L, 0);
994 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lanes.require %s BEGIN\n" INDENT_END, name)); 994 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lanes.require %s BEGIN\n" INDENT_END, name));
995 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); 995 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth);
996 lua_pushvalue( L, lua_upvalueindex(1)); // "name" require 996 lua_pushvalue( L, lua_upvalueindex(1)); // "name" require
@@ -999,7 +999,7 @@ LUAG_FUNC( require)
999 populate_func_lookup_table( L, -1, name); 999 populate_func_lookup_table( L, -1, name);
1000 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lanes.require %s END\n" INDENT_END, name)); 1000 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lanes.require %s END\n" INDENT_END, name));
1001 DEBUGSPEW_CODE( -- U->debugspew_indent_depth); 1001 DEBUGSPEW_CODE( -- U->debugspew_indent_depth);
1002 STACK_END( L, 0); 1002 STACK_CHECK( L, 0);
1003 return 1; 1003 return 1;
1004} 1004}
1005 1005
@@ -1015,13 +1015,13 @@ LUAG_FUNC( register)
1015 lua_settop( L, 2); 1015 lua_settop( L, 2);
1016 luaL_argcheck( L, (mod_type == LUA_TTABLE) || (mod_type == LUA_TFUNCTION), 2, "unexpected module type"); 1016 luaL_argcheck( L, (mod_type == LUA_TTABLE) || (mod_type == LUA_TFUNCTION), 2, "unexpected module type");
1017 DEBUGSPEW_CODE( Universe* U = universe_get( L)); 1017 DEBUGSPEW_CODE( Universe* U = universe_get( L));
1018 STACK_CHECK( L, 0); // "name" mod_table 1018 STACK_CHECK_START_REL(L, 0); // "name" mod_table
1019 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lanes.register %s BEGIN\n" INDENT_END, name)); 1019 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lanes.register %s BEGIN\n" INDENT_END, name));
1020 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth); 1020 DEBUGSPEW_CODE( ++ U->debugspew_indent_depth);
1021 populate_func_lookup_table( L, -1, name); 1021 populate_func_lookup_table( L, -1, name);
1022 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lanes.register %s END\n" INDENT_END, name)); 1022 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lanes.register %s END\n" INDENT_END, name));
1023 DEBUGSPEW_CODE( -- U->debugspew_indent_depth); 1023 DEBUGSPEW_CODE( -- U->debugspew_indent_depth);
1024 STACK_END( L, 0); 1024 STACK_CHECK( L, 0);
1025 return 0; 1025 return 0;
1026} 1026}
1027 1027
@@ -1075,10 +1075,10 @@ LUAG_FUNC( lane_new)
1075 L2 = luaG_newstate( U, L, libs_str); // L // L2 1075 L2 = luaG_newstate( U, L, libs_str); // L // L2
1076 1076
1077 STACK_GROW( L2, nargs + 3); // 1077 STACK_GROW( L2, nargs + 3); //
1078 STACK_CHECK( L2, 0); 1078 STACK_CHECK_START_REL(L2, 0);
1079 1079
1080 STACK_GROW( L, 3); // func libs priority globals package required gc_cb [... args ...] 1080 STACK_GROW( L, 3); // func libs priority globals package required gc_cb [... args ...]
1081 STACK_CHECK( L, 0); 1081 STACK_CHECK_START_REL(L, 0);
1082 1082
1083 // give a default "Lua" name to the thread to see VM name in Decoda debugger 1083 // give a default "Lua" name to the thread to see VM name in Decoda debugger
1084 lua_pushfstring( L2, "Lane #%p", L2); // "..." 1084 lua_pushfstring( L2, "Lane #%p", L2); // "..."
@@ -1146,8 +1146,8 @@ LUAG_FUNC( lane_new)
1146 } // func libs priority globals package required gc_cb [... args ...] 1146 } // func libs priority globals package required gc_cb [... args ...]
1147 DEBUGSPEW_CODE( -- U->debugspew_indent_depth); 1147 DEBUGSPEW_CODE( -- U->debugspew_indent_depth);
1148 } 1148 }
1149 STACK_MID( L, 0); 1149 STACK_CHECK( L, 0);
1150 STACK_MID( L2, 0); // 1150 STACK_CHECK( L2, 0); //
1151 1151
1152 // Appending the specified globals to the global environment 1152 // Appending the specified globals to the global environment
1153 // *after* stdlibs have been loaded and modules required, in case we transfer references to native functions they exposed... 1153 // *after* stdlibs have been loaded and modules required, in case we transfer references to native functions they exposed...
@@ -1175,8 +1175,8 @@ LUAG_FUNC( lane_new)
1175 1175
1176 DEBUGSPEW_CODE( -- U->debugspew_indent_depth); 1176 DEBUGSPEW_CODE( -- U->debugspew_indent_depth);
1177 } 1177 }
1178 STACK_MID( L, 0); 1178 STACK_CHECK( L, 0);
1179 STACK_MID( L2, 0); 1179 STACK_CHECK( L2, 0);
1180 1180
1181 // Lane main function 1181 // Lane main function
1182 if( lua_type( L, 1) == LUA_TFUNCTION) 1182 if( lua_type( L, 1) == LUA_TFUNCTION)
@@ -1200,8 +1200,8 @@ LUAG_FUNC( lane_new)
1200 return luaL_error( L, "error when parsing lane function code"); 1200 return luaL_error( L, "error when parsing lane function code");
1201 } 1201 }
1202 } 1202 }
1203 STACK_MID( L, 0); 1203 STACK_CHECK( L, 0);
1204 STACK_MID( L2, 1); 1204 STACK_CHECK( L2, 1);
1205 ASSERT_L( lua_isfunction( L2, 1)); 1205 ASSERT_L( lua_isfunction( L2, 1));
1206 1206
1207 // revive arguments 1207 // revive arguments
@@ -1217,10 +1217,10 @@ LUAG_FUNC( lane_new)
1217 return luaL_error( L, "tried to copy unsupported types"); 1217 return luaL_error( L, "tried to copy unsupported types");
1218 } 1218 }
1219 } 1219 }
1220 STACK_END( L, -nargs); 1220 STACK_CHECK( L, -nargs);
1221 ASSERT_L( lua_gettop( L) == FIXED_ARGS); 1221 ASSERT_L( lua_gettop( L) == FIXED_ARGS);
1222 STACK_CHECK( L, 0); 1222 STACK_CHECK_RESET_REL(L, 0);
1223 STACK_MID( L2, 1 + nargs); 1223 STACK_CHECK( L2, 1 + nargs);
1224 1224
1225 // 's' is allocated from heap, not Lua, since its life span may surpass the handle's (if free running thread) 1225 // 's' is allocated from heap, not Lua, since its life span may surpass the handle's (if free running thread)
1226 // 1226 //
@@ -1260,7 +1260,7 @@ LUAG_FUNC( lane_new)
1260 // 1260 //
1261 lua_pushvalue( L, lua_upvalueindex( 1)); // func libs priority globals package required gc_cb lane mt 1261 lua_pushvalue( L, lua_upvalueindex( 1)); // func libs priority globals package required gc_cb lane mt
1262 lua_setmetatable( L, -2); // func libs priority globals package required gc_cb lane 1262 lua_setmetatable( L, -2); // func libs priority globals package required gc_cb lane
1263 STACK_MID( L, 1); 1263 STACK_CHECK( L, 1);
1264 1264
1265 // Create uservalue for the userdata 1265 // Create uservalue for the userdata
1266 // (this is where lane body return values will be stored when the handle is indexed by a numeric key) 1266 // (this is where lane body return values will be stored when the handle is indexed by a numeric key)
@@ -1279,8 +1279,8 @@ LUAG_FUNC( lane_new)
1279 // Store 's' in the lane's registry, for 'cancel_test()' (we do cancel tests at pending send/receive). 1279 // Store 's' in the lane's registry, for 'cancel_test()' (we do cancel tests at pending send/receive).
1280 CANCEL_TEST_KEY.set_registry(L2, [s](lua_State* L) { lua_pushlightuserdata(L, s); }); // func [... args ...] 1280 CANCEL_TEST_KEY.set_registry(L2, [s](lua_State* L) { lua_pushlightuserdata(L, s); }); // func [... args ...]
1281 1281
1282 STACK_END( L, 1); 1282 STACK_CHECK( L, 1);
1283 STACK_END( L2, 1 + nargs); 1283 STACK_CHECK( L2, 1 + nargs);
1284 1284
1285 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lane_new: launching thread\n" INDENT_END)); 1285 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lane_new: launching thread\n" INDENT_END));
1286 THREAD_CREATE( &s->thread, lane_main, s, priority); 1286 THREAD_CREATE( &s->thread, lane_main, s, priority);
@@ -1436,7 +1436,7 @@ LUAG_FUNC( thread_join)
1436 return 2; 1436 return 2;
1437 } 1437 }
1438 1438
1439 STACK_CHECK( L, 0); 1439 STACK_CHECK_START_REL(L, 0);
1440 // Thread is DONE/ERROR_ST/CANCELLED; all ours now 1440 // Thread is DONE/ERROR_ST/CANCELLED; all ours now
1441 1441
1442 if (s->mstatus == ThreadStatus::Killed) // OS thread was killed if thread_cancel was forced 1442 if (s->mstatus == ThreadStatus::Killed) // OS thread was killed if thread_cancel was forced
@@ -1492,7 +1492,7 @@ LUAG_FUNC( thread_join)
1492 lua_close( L2); 1492 lua_close( L2);
1493 } 1493 }
1494 s->L = 0; 1494 s->L = 0;
1495 STACK_END( L, ret); 1495 STACK_CHECK( L, ret);
1496 return ret; 1496 return ret;
1497} 1497}
1498 1498
@@ -1723,7 +1723,7 @@ LUAG_FUNC( wakeup_conv )
1723 // .yday (day of the year) 1723 // .yday (day of the year)
1724 // .isdst (daylight saving on/off) 1724 // .isdst (daylight saving on/off)
1725 1725
1726 STACK_CHECK( L, 0); 1726 STACK_CHECK_START_REL(L, 0);
1727 lua_getfield( L, 1, "year" ); year= (int)lua_tointeger(L,-1); lua_pop(L,1); 1727 lua_getfield( L, 1, "year" ); year= (int)lua_tointeger(L,-1); lua_pop(L,1);
1728 lua_getfield( L, 1, "month" ); month= (int)lua_tointeger(L,-1); lua_pop(L,1); 1728 lua_getfield( L, 1, "month" ); month= (int)lua_tointeger(L,-1); lua_pop(L,1);
1729 lua_getfield( L, 1, "day" ); day= (int)lua_tointeger(L,-1); lua_pop(L,1); 1729 lua_getfield( L, 1, "day" ); day= (int)lua_tointeger(L,-1); lua_pop(L,1);
@@ -1737,7 +1737,7 @@ LUAG_FUNC( wakeup_conv )
1737 lua_getfield( L, 1, "isdst" ); 1737 lua_getfield( L, 1, "isdst" );
1738 isdst= lua_isboolean(L,-1) ? lua_toboolean(L,-1) : -1; 1738 isdst= lua_isboolean(L,-1) ? lua_toboolean(L,-1) : -1;
1739 lua_pop(L,1); 1739 lua_pop(L,1);
1740 STACK_END( L, 0); 1740 STACK_CHECK( L, 0);
1741 1741
1742 t.tm_year= year-1900; 1742 t.tm_year= year-1900;
1743 t.tm_mon= month-1; // 0..11 1743 t.tm_mon= month-1; // 0..11
@@ -1863,7 +1863,7 @@ LUAG_FUNC( configure)
1863#endif // THREADAPI == THREADAPI_PTHREAD 1863#endif // THREADAPI == THREADAPI_PTHREAD
1864 1864
1865 STACK_GROW( L, 4); 1865 STACK_GROW( L, 4);
1866 STACK_CHECK_ABS( L, 1); // settings 1866 STACK_CHECK_START_ABS( L, 1); // settings
1867 1867
1868 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%p: lanes.configure() BEGIN\n" INDENT_END, L)); 1868 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%p: lanes.configure() BEGIN\n" INDENT_END, L));
1869 DEBUGSPEW_CODE( if( U) ++ U->debugspew_indent_depth); 1869 DEBUGSPEW_CODE( if( U) ++ U->debugspew_indent_depth);
@@ -1900,13 +1900,13 @@ LUAG_FUNC( configure)
1900 initialize_allocator_function( U, L); 1900 initialize_allocator_function( U, L);
1901 initialize_on_state_create( U, L); 1901 initialize_on_state_create( U, L);
1902 init_keepers( U, L); 1902 init_keepers( U, L);
1903 STACK_MID( L, 1); 1903 STACK_CHECK( L, 1);
1904 1904
1905 // Initialize 'timer_deep'; a common Linda object shared by all states 1905 // Initialize 'timer_deep'; a common Linda object shared by all states
1906 lua_pushcfunction( L, LG_linda); // settings lanes.linda 1906 lua_pushcfunction( L, LG_linda); // settings lanes.linda
1907 lua_pushliteral( L, "lanes-timer"); // settings lanes.linda "lanes-timer" 1907 lua_pushliteral( L, "lanes-timer"); // settings lanes.linda "lanes-timer"
1908 lua_call( L, 1, 1); // settings linda 1908 lua_call( L, 1, 1); // settings linda
1909 STACK_MID( L, 2); 1909 STACK_CHECK( L, 2);
1910 1910
1911 // Proxy userdata contents is only a 'DEEP_PRELUDE*' pointer 1911 // Proxy userdata contents is only a 'DEEP_PRELUDE*' pointer
1912 U->timer_deep = *(DeepPrelude**) lua_touserdata( L, -1); 1912 U->timer_deep = *(DeepPrelude**) lua_touserdata( L, -1);
@@ -1914,7 +1914,7 @@ LUAG_FUNC( configure)
1914 ++ U->timer_deep->refcount; 1914 ++ U->timer_deep->refcount;
1915 lua_pop( L, 1); // settings 1915 lua_pop( L, 1); // settings
1916 } 1916 }
1917 STACK_MID( L, 1); 1917 STACK_CHECK( L, 1);
1918 1918
1919 // Serialize calls to 'require' from now on, also in the primary state 1919 // Serialize calls to 'require' from now on, also in the primary state
1920 serialize_require( DEBUGSPEW_PARAM_COMMA( U) L); 1920 serialize_require( DEBUGSPEW_PARAM_COMMA( U) L);
@@ -1934,7 +1934,7 @@ LUAG_FUNC( configure)
1934 lua_setfield( L, -2, "threads"); // settings M 1934 lua_setfield( L, -2, "threads"); // settings M
1935 } 1935 }
1936#endif // HAVE_LANE_TRACKING() 1936#endif // HAVE_LANE_TRACKING()
1937 STACK_MID( L, 2); 1937 STACK_CHECK( L, 2);
1938 1938
1939 { 1939 {
1940 char const* errmsg; 1940 char const* errmsg;
@@ -1945,7 +1945,7 @@ LUAG_FUNC( configure)
1945 } 1945 }
1946 lua_setfield( L, -2, "timer_gateway"); // settings M 1946 lua_setfield( L, -2, "timer_gateway"); // settings M
1947 } 1947 }
1948 STACK_MID( L, 2); 1948 STACK_CHECK( L, 2);
1949 1949
1950 // prepare the metatable for threads 1950 // prepare the metatable for threads
1951 // contains keys: { __gc, __index, cached_error, cached_tostring, cancel, join, get_debug_threadname } 1951 // contains keys: { __gc, __index, cached_error, cached_tostring, cancel, join, get_debug_threadname }
@@ -1992,16 +1992,16 @@ LUAG_FUNC( configure)
1992 CANCEL_ERROR.push(L); // settings M CANCEL_ERROR 1992 CANCEL_ERROR.push(L); // settings M CANCEL_ERROR
1993 lua_setfield( L, -2, "cancel_error"); // settings M 1993 lua_setfield( L, -2, "cancel_error"); // settings M
1994 1994
1995 STACK_MID( L, 2); // reference stack contains only the function argument 'settings' 1995 STACK_CHECK( L, 2); // reference stack contains only the function argument 'settings'
1996 // we'll need this every time we transfer some C function from/to this state 1996 // we'll need this every time we transfer some C function from/to this state
1997 LOOKUP_REGKEY.set_registry(L, [](lua_State* L) { lua_newtable(L); }); // settings M 1997 LOOKUP_REGKEY.set_registry(L, [](lua_State* L) { lua_newtable(L); }); // settings M
1998 STACK_MID( L, 2); 1998 STACK_CHECK( L, 2);
1999 1999
2000 // register all native functions found in that module in the transferable functions database 2000 // register all native functions found in that module in the transferable functions database
2001 // we process it before _G because we don't want to find the module when scanning _G (this would generate longer names) 2001 // we process it before _G because we don't want to find the module when scanning _G (this would generate longer names)
2002 // for example in package.loaded["lanes.core"].* 2002 // for example in package.loaded["lanes.core"].*
2003 populate_func_lookup_table( L, -1, name); 2003 populate_func_lookup_table( L, -1, name);
2004 STACK_MID( L, 2); 2004 STACK_CHECK( L, 2);
2005 2005
2006 // record all existing C/JIT-fast functions 2006 // record all existing C/JIT-fast functions
2007 // Lua 5.2 no longer has LUA_GLOBALSINDEX: we must push globals table on the stack 2007 // Lua 5.2 no longer has LUA_GLOBALSINDEX: we must push globals table on the stack
@@ -2018,7 +2018,7 @@ LUAG_FUNC( configure)
2018 2018
2019 // set _R[CONFIG_REGKEY] = settings 2019 // set _R[CONFIG_REGKEY] = settings
2020 CONFIG_REGKEY.set_registry(L, [](lua_State* L) { lua_pushvalue(L, -2); }); 2020 CONFIG_REGKEY.set_registry(L, [](lua_State* L) { lua_pushvalue(L, -2); });
2021 STACK_END( L, 1); 2021 STACK_CHECK( L, 1);
2022 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%p: lanes.configure() END\n" INDENT_END, L)); 2022 DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "%p: lanes.configure() END\n" INDENT_END, L));
2023 DEBUGSPEW_CODE( -- U->debugspew_indent_depth); 2023 DEBUGSPEW_CODE( -- U->debugspew_indent_depth);
2024 // Return the settings table 2024 // Return the settings table
@@ -2085,7 +2085,7 @@ LANES_API int luaopen_lanes_core( lua_State* L)
2085#endif // defined PLATFORM_WIN32 && !defined NDEBUG 2085#endif // defined PLATFORM_WIN32 && !defined NDEBUG
2086 2086
2087 STACK_GROW( L, 4); 2087 STACK_GROW( L, 4);
2088 STACK_CHECK( L, 0); 2088 STACK_CHECK_START_REL(L, 0);
2089 2089
2090 // Prevent PUC-Lua/LuaJIT mismatch. Hopefully this works for MoonJIT too 2090 // Prevent PUC-Lua/LuaJIT mismatch. Hopefully this works for MoonJIT too
2091 lua_getglobal( L, "jit"); // {jit?} 2091 lua_getglobal( L, "jit"); // {jit?}
@@ -2097,6 +2097,7 @@ LANES_API int luaopen_lanes_core( lua_State* L)
2097 return luaL_error( L, "Lanes is built for LuaJIT, don't run from PUC-Lua"); 2097 return luaL_error( L, "Lanes is built for LuaJIT, don't run from PUC-Lua");
2098#endif 2098#endif
2099 lua_pop( L, 1); // 2099 lua_pop( L, 1); //
2100 STACK_CHECK(L, 0);
2100 2101
2101 // Create main module interface table 2102 // Create main module interface table
2102 // we only have 1 closure, which must be called to configure Lanes 2103 // we only have 1 closure, which must be called to configure Lanes
@@ -2118,7 +2119,7 @@ LANES_API int luaopen_lanes_core( lua_State* L)
2118 lua_setfield( L, -2, "configure"); // M 2119 lua_setfield( L, -2, "configure"); // M
2119 } 2120 }
2120 2121
2121 STACK_END( L, 1); 2122 STACK_CHECK( L, 1);
2122 return 1; 2123 return 1;
2123} 2124}
2124 2125
@@ -2135,12 +2136,12 @@ static int default_luaopen_lanes( lua_State* L)
2135// call this instead of luaopen_lanes_core() when embedding Lua and Lanes in a custom application 2136// call this instead of luaopen_lanes_core() when embedding Lua and Lanes in a custom application
2136LANES_API void luaopen_lanes_embedded( lua_State* L, lua_CFunction _luaopen_lanes) 2137LANES_API void luaopen_lanes_embedded( lua_State* L, lua_CFunction _luaopen_lanes)
2137{ 2138{
2138 STACK_CHECK( L, 0); 2139 STACK_CHECK_START_REL(L, 0);
2139 // pre-require lanes.core so that when lanes.lua calls require "lanes.core" it finds it is already loaded 2140 // pre-require lanes.core so that when lanes.lua calls require "lanes.core" it finds it is already loaded
2140 luaL_requiref( L, "lanes.core", luaopen_lanes_core, 0); // ... lanes.core 2141 luaL_requiref( L, "lanes.core", luaopen_lanes_core, 0); // ... lanes.core
2141 lua_pop( L, 1); // ... 2142 lua_pop( L, 1); // ...
2142 STACK_MID( L, 0); 2143 STACK_CHECK( L, 0);
2143 // call user-provided function that runs the chunk "lanes.lua" from wherever they stored it 2144 // call user-provided function that runs the chunk "lanes.lua" from wherever they stored it
2144 luaL_requiref( L, "lanes", _luaopen_lanes ? _luaopen_lanes : default_luaopen_lanes, 0); // ... lanes 2145 luaL_requiref( L, "lanes", _luaopen_lanes ? _luaopen_lanes : default_luaopen_lanes, 0); // ... lanes
2145 STACK_END( L, 1); 2146 STACK_CHECK( L, 1);
2146} 2147}