aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cancel.cpp2
-rw-r--r--src/compat.cpp2
-rw-r--r--src/deep.cpp12
-rw-r--r--src/keeper.cpp10
-rw-r--r--src/lanes.cpp34
-rw-r--r--src/linda.cpp28
-rw-r--r--src/macros_and_utils.h24
-rw-r--r--src/tools.cpp56
-rw-r--r--src/universe.cpp4
-rw-r--r--src/universe.h2
10 files changed, 90 insertions, 84 deletions
diff --git a/src/cancel.cpp b/src/cancel.cpp
index fe1f3e6..a7dc0ec 100644
--- a/src/cancel.cpp
+++ b/src/cancel.cpp
@@ -264,7 +264,7 @@ LUAG_FUNC(thread_cancel)
264 switch (thread_cancel(lane, op, hook_count, wait_timeout, wake_lane)) 264 switch (thread_cancel(lane, op, hook_count, wait_timeout, wake_lane))
265 { 265 {
266 default: // should never happen unless we added a case and forgot to handle it 266 default: // should never happen unless we added a case and forgot to handle it
267 ASSERT_L(false); 267 LUA_ASSERT(L, false);
268 break; 268 break;
269 269
270 case CancelResult::Timeout: 270 case CancelResult::Timeout:
diff --git a/src/compat.cpp b/src/compat.cpp
index 9f652a7..712aa23 100644
--- a/src/compat.cpp
+++ b/src/compat.cpp
@@ -55,7 +55,7 @@ void luaL_requiref(lua_State *L, const char *modname, lua_CFunction openf, int g
55 55
56void* lua_newuserdatauv( lua_State* L, size_t sz, int nuvalue) 56void* lua_newuserdatauv( lua_State* L, size_t sz, int nuvalue)
57{ 57{
58 ASSERT_L( nuvalue <= 1); 58 LUA_ASSERT(L, nuvalue <= 1);
59 return lua_newuserdata(L, sz); 59 return lua_newuserdata(L, sz);
60} 60}
61 61
diff --git a/src/deep.cpp b/src/deep.cpp
index 3e1d90a..e4d090f 100644
--- a/src/deep.cpp
+++ b/src/deep.cpp
@@ -212,7 +212,7 @@ char const* DeepFactory::PushDeepProxy(Dest L, DeepPrelude* prelude, int nuv_, L
212 212
213 // a new full userdata, fitted with the specified number of uservalue slots (always 1 for Lua < 5.4) 213 // a new full userdata, fitted with the specified number of uservalue slots (always 1 for Lua < 5.4)
214 DeepPrelude** const proxy{ lua_newuserdatauv<DeepPrelude*>(L, nuv_) }; // DPC proxy 214 DeepPrelude** const proxy{ lua_newuserdatauv<DeepPrelude*>(L, nuv_) }; // DPC proxy
215 ASSERT_L(proxy); 215 LUA_ASSERT(L, proxy);
216 *proxy = prelude; 216 *proxy = prelude;
217 prelude->m_refcount.fetch_add(1, std::memory_order_relaxed); // one more proxy pointing to this deep data 217 prelude->m_refcount.fetch_add(1, std::memory_order_relaxed); // one more proxy pointing to this deep data
218 218
@@ -312,8 +312,8 @@ char const* DeepFactory::PushDeepProxy(Dest L, DeepPrelude* prelude, int nuv_, L
312 } 312 }
313 } 313 }
314 STACK_CHECK(L, 2); // DPC proxy metatable 314 STACK_CHECK(L, 2); // DPC proxy metatable
315 ASSERT_L(lua_type_as_enum(L, -2) == LuaType::USERDATA); 315 LUA_ASSERT(L, lua_type_as_enum(L, -2) == LuaType::USERDATA);
316 ASSERT_L(lua_istable( L, -1)); 316 LUA_ASSERT(L, lua_istable( L, -1));
317 lua_setmetatable( L, -2); // DPC proxy 317 lua_setmetatable( L, -2); // DPC proxy
318 318
319 // If we're here, we obviously had to create a new proxy, so cache it. 319 // If we're here, we obviously had to create a new proxy, so cache it.
@@ -321,7 +321,7 @@ char const* DeepFactory::PushDeepProxy(Dest L, DeepPrelude* prelude, int nuv_, L
321 lua_pushvalue( L, -2); // DPC proxy deep proxy 321 lua_pushvalue( L, -2); // DPC proxy deep proxy
322 lua_rawset( L, -4); // DPC proxy 322 lua_rawset( L, -4); // DPC proxy
323 lua_remove( L, -2); // proxy 323 lua_remove( L, -2); // proxy
324 ASSERT_L(lua_type_as_enum(L, -1) == LuaType::USERDATA); 324 LUA_ASSERT(L, lua_type_as_enum(L, -1) == LuaType::USERDATA);
325 STACK_CHECK(L, 0); 325 STACK_CHECK(L, 0);
326 return nullptr; 326 return nullptr;
327} 327}
@@ -361,8 +361,8 @@ int DeepFactory::pushDeepUserdata(Dest L, int nuv_) const
361 return luaL_error( L, "Bad Deep Factory: DEEP_VERSION is incorrect, rebuild your implementation with the latest deep implementation"); 361 return luaL_error( L, "Bad Deep Factory: DEEP_VERSION is incorrect, rebuild your implementation with the latest deep implementation");
362 } 362 }
363 363
364 ASSERT_L(prelude->m_refcount.load(std::memory_order_relaxed) == 0); // 'DeepFactory::PushDeepProxy' will lift it to 1 364 LUA_ASSERT(L, prelude->m_refcount.load(std::memory_order_relaxed) == 0); // 'DeepFactory::PushDeepProxy' will lift it to 1
365 ASSERT_L(&prelude->m_factory == this); 365 LUA_ASSERT(L, &prelude->m_factory == this);
366 366
367 if (lua_gettop( L) - oldtop != 0) 367 if (lua_gettop( L) - oldtop != 0)
368 { 368 {
diff --git a/src/keeper.cpp b/src/keeper.cpp
index 0875b87..48f0166 100644
--- a/src/keeper.cpp
+++ b/src/keeper.cpp
@@ -64,7 +64,7 @@ class keeper_fifo
64 [[nodiscard]] static void* operator new([[maybe_unused]] size_t size_, lua_State* L) noexcept { return lua_newuserdatauv<keeper_fifo>(L, 1); } 64 [[nodiscard]] static void* operator new([[maybe_unused]] size_t size_, lua_State* L) noexcept { return lua_newuserdatauv<keeper_fifo>(L, 1); }
65 // always embedded somewhere else or "in-place constructed" as a full userdata 65 // always embedded somewhere else or "in-place constructed" as a full userdata
66 // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception 66 // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception
67 static void operator delete([[maybe_unused]] void* p_, lua_State* L) { ASSERT_L(!"should never be called") }; 67 static void operator delete([[maybe_unused]] void* p_, lua_State* L_) { LUA_ASSERT(L_, !"should never be called"); }
68 68
69 [[nodiscard]] static keeper_fifo* getPtr(lua_State* L, int idx_) 69 [[nodiscard]] static keeper_fifo* getPtr(lua_State* L, int idx_)
70 { 70 {
@@ -146,7 +146,7 @@ static void fifo_peek(lua_State* L, keeper_fifo* fifo_, int count_)
146// out: remove the fifo from the stack, push as many items as required on the stack (function assumes they exist in sufficient number) 146// out: remove the fifo from the stack, push as many items as required on the stack (function assumes they exist in sufficient number)
147static void fifo_pop( lua_State* L, keeper_fifo* fifo_, int count_) 147static void fifo_pop( lua_State* L, keeper_fifo* fifo_, int count_)
148{ 148{
149 ASSERT_L(lua_istable(L, -1)); 149 LUA_ASSERT(L, lua_istable(L, -1));
150 int const fifo_idx{ lua_gettop(L) }; // ... fifotbl 150 int const fifo_idx{ lua_gettop(L) }; // ... fifotbl
151 // each iteration pushes a value on the stack! 151 // each iteration pushes a value on the stack!
152 STACK_GROW(L, count_ + 2); 152 STACK_GROW(L, count_ + 2);
@@ -582,7 +582,7 @@ int keepercall_count(lua_State* L)
582 } // all keys are exhausted // out fifos 582 } // all keys are exhausted // out fifos
583 lua_pop(L, 1); // out 583 lua_pop(L, 1); // out
584 } 584 }
585 ASSERT_L(lua_gettop(L) == 1); 585 LUA_ASSERT(L, lua_gettop(L) == 1);
586 return 1; 586 return 1;
587} 587}
588 588
@@ -651,7 +651,7 @@ void close_keepers(Universe* U)
651 */ 651 */
652void init_keepers(Universe* U, lua_State* L) 652void init_keepers(Universe* U, lua_State* L)
653{ 653{
654 ASSERT_L(lua_gettop(L) == 1 && lua_istable(L, 1)); 654 LUA_ASSERT(L, lua_gettop(L) == 1 && lua_istable(L, 1));
655 STACK_CHECK_START_REL(L, 0); // L K 655 STACK_CHECK_START_REL(L, 0); // L K
656 lua_getfield(L, 1, "nb_keepers"); // settings nb_keepers 656 lua_getfield(L, 1, "nb_keepers"); // settings nb_keepers
657 int const nb_keepers{ static_cast<int>(lua_tointeger(L, -1)) }; 657 int const nb_keepers{ static_cast<int>(lua_tointeger(L, -1)) };
@@ -838,7 +838,7 @@ KeeperCallResult keeper_call(Universe* U, lua_State* K, keeper_api_t func_, lua_
838 int const args{ starting_index ? (lua_gettop(L) - starting_index + 1) : 0 }; 838 int const args{ starting_index ? (lua_gettop(L) - starting_index + 1) : 0 };
839 int const top_K{ lua_gettop(K) }; 839 int const top_K{ lua_gettop(K) };
840 // if we didn't do anything wrong, the keeper stack should be clean 840 // if we didn't do anything wrong, the keeper stack should be clean
841 ASSERT_L(lua_gettop(K) == 0); 841 LUA_ASSERT(L, lua_gettop(K) == 0);
842 842
843 STACK_GROW(K, 2); 843 STACK_GROW(K, 2);
844 PUSH_KEEPER_FUNC(K, func_); // func_ 844 PUSH_KEEPER_FUNC(K, func_); // func_
diff --git a/src/lanes.cpp b/src/lanes.cpp
index 6b3a9a1..1f938d4 100644
--- a/src/lanes.cpp
+++ b/src/lanes.cpp
@@ -317,7 +317,7 @@ static void push_stack_trace(lua_State* L, int rc_, int stk_base_)
317 317
318 // For cancellation the error message is CANCEL_ERROR, and a stack trace isn't placed 318 // For cancellation the error message is CANCEL_ERROR, and a stack trace isn't placed
319 // For other errors, the message can be whatever was thrown, and we should have a stack trace table 319 // For other errors, the message can be whatever was thrown, and we should have a stack trace table
320 ASSERT_L(lua_type(L, 1 + stk_base_) == (CANCEL_ERROR.equals(L, stk_base_) ? LUA_TNIL : LUA_TTABLE)); 320 LUA_ASSERT(L, lua_type(L, 1 + stk_base_) == (CANCEL_ERROR.equals(L, stk_base_) ? LUA_TNIL : LUA_TTABLE));
321 // Just leaving the stack trace table on the stack is enough to get it through to the master. 321 // Just leaving the stack trace table on the stack is enough to get it through to the master.
322 break; 322 break;
323 } 323 }
@@ -327,7 +327,7 @@ static void push_stack_trace(lua_State* L, int rc_, int stk_base_)
327 case LUA_ERRERR: // error while running the error handler (if any, for example an out-of-memory condition) 327 case LUA_ERRERR: // error while running the error handler (if any, for example an out-of-memory condition)
328 default: 328 default:
329 // we should have a single value which is either a string (the error message) or CANCEL_ERROR 329 // we should have a single value which is either a string (the error message) or CANCEL_ERROR
330 ASSERT_L((lua_gettop(L) == stk_base_) && ((lua_type(L, stk_base_) == LUA_TSTRING) || CANCEL_ERROR.equals(L, stk_base_))); 330 LUA_ASSERT(L, (lua_gettop(L) == stk_base_) && ((lua_type(L, stk_base_) == LUA_TSTRING) || CANCEL_ERROR.equals(L, stk_base_)));
331 break; 331 break;
332 } 332 }
333} 333}
@@ -367,10 +367,10 @@ static void push_stack_trace(lua_State* L, int rc_, int stk_base_)
367 int args = 0; 367 int args = 0;
368 lua_pushinteger(L, n); // ... finalizers lane_error n 368 lua_pushinteger(L, n); // ... finalizers lane_error n
369 lua_rawget(L, finalizers_index); // ... finalizers lane_error finalizer 369 lua_rawget(L, finalizers_index); // ... finalizers lane_error finalizer
370 ASSERT_L(lua_isfunction(L, -1)); 370 LUA_ASSERT(L, lua_isfunction(L, -1));
371 if (lua_rc_ != LUA_OK) // we have an error message and an optional stack trace at the bottom of the stack 371 if (lua_rc_ != LUA_OK) // we have an error message and an optional stack trace at the bottom of the stack
372 { 372 {
373 ASSERT_L( finalizers_index == 2 || finalizers_index == 3); 373 LUA_ASSERT(L, finalizers_index == 2 || finalizers_index == 3);
374 //char const* err_msg = lua_tostring(L, 1); 374 //char const* err_msg = lua_tostring(L, 1);
375 lua_pushvalue(L, 1); // ... finalizers lane_error finalizer err_msg 375 lua_pushvalue(L, 1); // ... finalizers lane_error finalizer err_msg
376 // note we don't always have a stack trace for example when CANCEL_ERROR, or when we got an error that doesn't call our handler, such as LUA_ERRMEM 376 // note we don't always have a stack trace for example when CANCEL_ERROR, or when we got an error that doesn't call our handler, such as LUA_ERRMEM
@@ -564,7 +564,7 @@ static void selfdestruct_add(Lane* lane_)
564 if (U->timer_deep != nullptr) // test ins case some early internal error prevented Lanes from creating the deep timer 564 if (U->timer_deep != nullptr) // test ins case some early internal error prevented Lanes from creating the deep timer
565 { 565 {
566 [[maybe_unused]] int const prev_ref_count{ U->timer_deep->m_refcount.fetch_sub(1, std::memory_order_relaxed) }; 566 [[maybe_unused]] int const prev_ref_count{ U->timer_deep->m_refcount.fetch_sub(1, std::memory_order_relaxed) };
567 ASSERT_L(prev_ref_count == 1); // this should be the last reference 567 LUA_ASSERT(L, prev_ref_count == 1); // this should be the last reference
568 DeepFactory::DeleteDeepObject(L, U->timer_deep); 568 DeepFactory::DeleteDeepObject(L, U->timer_deep);
569 U->timer_deep = nullptr; 569 U->timer_deep = nullptr;
570 } 570 }
@@ -987,7 +987,7 @@ LUAG_FUNC(lane_new)
987 static constexpr int FIXED_ARGS{ 7 }; 987 static constexpr int FIXED_ARGS{ 7 };
988 int const nargs{ lua_gettop(L) - FIXED_ARGS }; 988 int const nargs{ lua_gettop(L) - FIXED_ARGS };
989 Universe* const U{ universe_get(L) }; 989 Universe* const U{ universe_get(L) };
990 ASSERT_L( nargs >= 0); 990 LUA_ASSERT(L, nargs >= 0);
991 991
992 // public Lanes API accepts a generic range -3/+3 992 // public Lanes API accepts a generic range -3/+3
993 // that will be remapped into the platform-specific scheduler priority scheme 993 // that will be remapped into the platform-specific scheduler priority scheme
@@ -1104,7 +1104,7 @@ LUAG_FUNC(lane_new)
1104 // give a default "Lua" name to the thread to see VM name in Decoda debugger 1104 // give a default "Lua" name to the thread to see VM name in Decoda debugger
1105 lua_pushfstring( L2, "Lane #%p", L2); // "..." 1105 lua_pushfstring( L2, "Lane #%p", L2); // "..."
1106 lua_setglobal( L2, "decoda_name"); // 1106 lua_setglobal( L2, "decoda_name"); //
1107 ASSERT_L( lua_gettop( L2) == 0); 1107 LUA_ASSERT(L, lua_gettop( L2) == 0);
1108 1108
1109 // package 1109 // package
1110 if (package_idx != 0) 1110 if (package_idx != 0)
@@ -1113,7 +1113,7 @@ LUAG_FUNC(lane_new)
1113 // when copying with mode LookupMode::LaneBody, should raise an error in case of problem, not leave it one the stack 1113 // when copying with mode LookupMode::LaneBody, should raise an error in case of problem, not leave it one the stack
1114 InterCopyContext c{ U, Dest{ L2 }, Source{ L }, {}, SourceIndex{ package_idx }, {}, {}, {} }; 1114 InterCopyContext c{ U, Dest{ L2 }, Source{ L }, {}, SourceIndex{ package_idx }, {}, {}, {} };
1115 [[maybe_unused]] InterCopyResult const ret{ c.inter_copy_package() }; 1115 [[maybe_unused]] InterCopyResult const ret{ c.inter_copy_package() };
1116 ASSERT_L(ret == InterCopyResult::Success); // either all went well, or we should not even get here 1116 LUA_ASSERT(L, ret == InterCopyResult::Success); // either all went well, or we should not even get here
1117 } 1117 }
1118 1118
1119 // modules to require in the target lane *before* the function is transfered! 1119 // modules to require in the target lane *before* the function is transfered!
@@ -1228,7 +1228,7 @@ LUAG_FUNC(lane_new)
1228 } 1228 }
1229 STACK_CHECK(L, 0); 1229 STACK_CHECK(L, 0);
1230 STACK_CHECK(L2, 1); 1230 STACK_CHECK(L2, 1);
1231 ASSERT_L(lua_isfunction(L2, 1)); 1231 LUA_ASSERT(L, lua_isfunction(L2, 1));
1232 1232
1233 // revive arguments 1233 // revive arguments
1234 if (nargs > 0) 1234 if (nargs > 0)
@@ -1243,7 +1243,7 @@ LUAG_FUNC(lane_new)
1243 } 1243 }
1244 } 1244 }
1245 STACK_CHECK(L, -nargs); 1245 STACK_CHECK(L, -nargs);
1246 ASSERT_L(lua_gettop( L) == FIXED_ARGS); 1246 LUA_ASSERT(L, lua_gettop( L) == FIXED_ARGS);
1247 1247
1248 // Store 'lane' in the lane's registry, for 'cancel_test()' (we do cancel tests at pending send/receive). 1248 // Store 'lane' in the lane's registry, for 'cancel_test()' (we do cancel tests at pending send/receive).
1249 LANE_POINTER_REGKEY.setValue(L2, [lane](lua_State* L) { lua_pushlightuserdata(L, lane); }); // func [... args ...] 1249 LANE_POINTER_REGKEY.setValue(L2, [lane](lua_State* L) { lua_pushlightuserdata(L, lane); }); // func [... args ...]
@@ -1355,7 +1355,7 @@ LUAG_FUNC(lane_new)
1355void push_thread_status(lua_State* L, Lane* lane_) 1355void push_thread_status(lua_State* L, Lane* lane_)
1356{ 1356{
1357 char const* const str{ thread_status_string(lane_) }; 1357 char const* const str{ thread_status_string(lane_) };
1358 ASSERT_L(str); 1358 LUA_ASSERT(L, str);
1359 1359
1360 lua_pushstring(L, str); 1360 lua_pushstring(L, str);
1361} 1361}
@@ -1430,7 +1430,7 @@ LUAG_FUNC(thread_join)
1430 1430
1431 default: 1431 default:
1432 DEBUGSPEW_CODE(fprintf(stderr, "Status: %d\n", lane->m_status)); 1432 DEBUGSPEW_CODE(fprintf(stderr, "Status: %d\n", lane->m_status));
1433 ASSERT_L(false); 1433 LUA_ASSERT(L, false);
1434 ret = 0; 1434 ret = 0;
1435 } 1435 }
1436 lua_close(L2); 1436 lua_close(L2);
@@ -1454,7 +1454,7 @@ LUAG_FUNC(thread_index)
1454 static constexpr int KEY{ 2 }; 1454 static constexpr int KEY{ 2 };
1455 static constexpr int USR{ 3 }; 1455 static constexpr int USR{ 3 };
1456 Lane* const lane{ ToLane(L, UD) }; 1456 Lane* const lane{ ToLane(L, UD) };
1457 ASSERT_L(lua_gettop(L) == 2); 1457 LUA_ASSERT(L, lua_gettop(L) == 2);
1458 1458
1459 STACK_GROW(L, 8); // up to 8 positions are needed in case of error propagation 1459 STACK_GROW(L, 8); // up to 8 positions are needed in case of error propagation
1460 1460
@@ -1515,7 +1515,7 @@ LUAG_FUNC(thread_index)
1515 // me[-2] could carry the stack table, but even 1515 // me[-2] could carry the stack table, but even
1516 // me[-1] is rather unnecessary (and undocumented); 1516 // me[-1] is rather unnecessary (and undocumented);
1517 // use ':join()' instead. --AKa 22-Jan-2009 1517 // use ':join()' instead. --AKa 22-Jan-2009
1518 ASSERT_L(lua_isnil(L, 4) && !lua_isnil(L, 5) && lua_istable(L, 6)); 1518 LUA_ASSERT(L, lua_isnil(L, 4) && !lua_isnil(L, 5) && lua_istable(L, 6));
1519 // store errstring at key -1 1519 // store errstring at key -1
1520 lua_pushnumber(L, -1); 1520 lua_pushnumber(L, -1);
1521 lua_pushvalue(L, 5); 1521 lua_pushvalue(L, 5);
@@ -1741,7 +1741,7 @@ LUAG_FUNC(configure)
1741 Universe* U = universe_get(L); 1741 Universe* U = universe_get(L);
1742 bool const from_master_state{ U == nullptr }; 1742 bool const from_master_state{ U == nullptr };
1743 char const* name = luaL_checkstring(L, lua_upvalueindex(1)); 1743 char const* name = luaL_checkstring(L, lua_upvalueindex(1));
1744 ASSERT_L(lua_type(L, 1) == LUA_TTABLE); 1744 LUA_ASSERT(L, lua_type(L, 1) == LUA_TTABLE);
1745 1745
1746 STACK_GROW(L, 4); 1746 STACK_GROW(L, 4);
1747 STACK_CHECK_START_ABS(L, 1); // settings 1747 STACK_CHECK_START_ABS(L, 1); // settings
@@ -1832,10 +1832,10 @@ LUAG_FUNC(configure)
1832 lua_pushcfunction(L, LG_thread_index); // settings M mt LG_thread_index 1832 lua_pushcfunction(L, LG_thread_index); // settings M mt LG_thread_index
1833 lua_setfield(L, -2, "__index"); // settings M mt 1833 lua_setfield(L, -2, "__index"); // settings M mt
1834 lua_getglobal(L, "error"); // settings M mt error 1834 lua_getglobal(L, "error"); // settings M mt error
1835 ASSERT_L( lua_isfunction(L, -1)); 1835 LUA_ASSERT(L, lua_isfunction(L, -1));
1836 lua_setfield(L, -2, "cached_error"); // settings M mt 1836 lua_setfield(L, -2, "cached_error"); // settings M mt
1837 lua_getglobal(L, "tostring"); // settings M mt tostring 1837 lua_getglobal(L, "tostring"); // settings M mt tostring
1838 ASSERT_L( lua_isfunction(L, -1)); 1838 LUA_ASSERT(L, lua_isfunction(L, -1));
1839 lua_setfield(L, -2, "cached_tostring"); // settings M mt 1839 lua_setfield(L, -2, "cached_tostring"); // settings M mt
1840 lua_pushcfunction(L, LG_thread_join); // settings M mt LG_thread_join 1840 lua_pushcfunction(L, LG_thread_join); // settings M mt LG_thread_join
1841 lua_setfield(L, -2, "join"); // settings M mt 1841 lua_setfield(L, -2, "join"); // settings M mt
diff --git a/src/linda.cpp b/src/linda.cpp
index 7b3973d..4635d75 100644
--- a/src/linda.cpp
+++ b/src/linda.cpp
@@ -168,7 +168,7 @@ template <bool OPT>
168 if constexpr (!OPT) 168 if constexpr (!OPT)
169 { 169 {
170 luaL_argcheck(L, linda != nullptr, idx_, "expecting a linda object"); 170 luaL_argcheck(L, linda != nullptr, idx_, "expecting a linda object");
171 ASSERT_L(linda->U == universe_get(L)); 171 LUA_ASSERT(L, linda->U == universe_get(L));
172 } 172 }
173 return linda; 173 return linda;
174} 174}
@@ -218,7 +218,7 @@ int Linda::ProtectedCall(lua_State* L, lua_CFunction f_)
218 if (KL == nullptr) 218 if (KL == nullptr)
219 return 0; 219 return 0;
220 // if we didn't do anything wrong, the keeper stack should be clean 220 // if we didn't do anything wrong, the keeper stack should be clean
221 ASSERT_L(lua_gettop(KL) == 0); 221 LUA_ASSERT(L, lua_gettop(KL) == 0);
222 222
223 // push the function to be called and move it before the arguments 223 // push the function to be called and move it before the arguments
224 lua_pushcfunction(L, f_); 224 lua_pushcfunction(L, f_);
@@ -332,7 +332,7 @@ LUAG_FUNC(linda_send)
332 { 332 {
333 break; 333 break;
334 } 334 }
335 ASSERT_L(pushed.value() == 1); 335 LUA_ASSERT(L, pushed.value() == 1);
336 336
337 ret = lua_toboolean(L, -1) ? true : false; 337 ret = lua_toboolean(L, -1) ? true : false;
338 lua_pop(L, 1); 338 lua_pop(L, 1);
@@ -357,9 +357,9 @@ LUAG_FUNC(linda_send)
357 { 357 {
358 // change status of lane to "waiting" 358 // change status of lane to "waiting"
359 prev_status = lane->m_status; // Running, most likely 359 prev_status = lane->m_status; // Running, most likely
360 ASSERT_L(prev_status == Lane::Running); // but check, just in case 360 LUA_ASSERT(L, prev_status == Lane::Running); // but check, just in case
361 lane->m_status = Lane::Waiting; 361 lane->m_status = Lane::Waiting;
362 ASSERT_L(lane->m_waiting_on == nullptr); 362 LUA_ASSERT(L, lane->m_waiting_on == nullptr);
363 lane->m_waiting_on = &linda->m_read_happened; 363 lane->m_waiting_on = &linda->m_read_happened;
364 } 364 }
365 // could not send because no room: wait until some data was read before trying again, or until timeout is reached 365 // could not send because no room: wait until some data was read before trying again, or until timeout is reached
@@ -502,7 +502,7 @@ LUAG_FUNC(linda_receive)
502 } 502 }
503 if (pushed.value() > 0) 503 if (pushed.value() > 0)
504 { 504 {
505 ASSERT_L(pushed.value() >= expected_pushed_min && pushed.value() <= expected_pushed_max); 505 LUA_ASSERT(L, pushed.value() >= expected_pushed_min && pushed.value() <= expected_pushed_max);
506 // replace sentinels with real nils 506 // replace sentinels with real nils
507 keeper_toggle_nil_sentinels(L, lua_gettop(L) - pushed.value(), LookupMode::FromKeeper); 507 keeper_toggle_nil_sentinels(L, lua_gettop(L) - pushed.value(), LookupMode::FromKeeper);
508 // To be done from within the 'K' locking area 508 // To be done from within the 'K' locking area
@@ -523,9 +523,9 @@ LUAG_FUNC(linda_receive)
523 { 523 {
524 // change status of lane to "waiting" 524 // change status of lane to "waiting"
525 prev_status = lane->m_status; // Running, most likely 525 prev_status = lane->m_status; // Running, most likely
526 ASSERT_L(prev_status == Lane::Running); // but check, just in case 526 LUA_ASSERT(L, prev_status == Lane::Running); // but check, just in case
527 lane->m_status = Lane::Waiting; 527 lane->m_status = Lane::Waiting;
528 ASSERT_L(lane->m_waiting_on == nullptr); 528 LUA_ASSERT(L, lane->m_waiting_on == nullptr);
529 lane->m_waiting_on = &linda->m_write_happened; 529 lane->m_waiting_on = &linda->m_write_happened;
530 } 530 }
531 // not enough data to read: wakeup when data was sent, or when timeout is reached 531 // not enough data to read: wakeup when data was sent, or when timeout is reached
@@ -596,7 +596,7 @@ LUAG_FUNC(linda_set)
596 pushed = keeper_call(linda->U, K->L, KEEPER_API(set), L, linda, 2); 596 pushed = keeper_call(linda->U, K->L, KEEPER_API(set), L, linda, 2);
597 if (pushed.has_value()) // no error? 597 if (pushed.has_value()) // no error?
598 { 598 {
599 ASSERT_L(pushed.value() == 0 || pushed.value() == 1); 599 LUA_ASSERT(L, pushed.value() == 0 || pushed.value() == 1);
600 600
601 if (has_value) 601 if (has_value)
602 { 602 {
@@ -606,7 +606,7 @@ LUAG_FUNC(linda_set)
606 if (pushed.value() == 1) 606 if (pushed.value() == 1)
607 { 607 {
608 // the key was full, but it is no longer the case, tell writers they should wake 608 // the key was full, but it is no longer the case, tell writers they should wake
609 ASSERT_L(lua_type(L, -1) == LUA_TBOOLEAN && lua_toboolean(L, -1) == 1); 609 LUA_ASSERT(L, lua_type(L, -1) == LUA_TBOOLEAN && lua_toboolean(L, -1) == 1);
610 linda->m_read_happened.notify_all(); // To be done from within the 'K' locking area 610 linda->m_read_happened.notify_all(); // To be done from within the 'K' locking area
611 } 611 }
612 } 612 }
@@ -711,10 +711,10 @@ LUAG_FUNC(linda_limit)
711 { 711 {
712 Keeper* const K{ which_keeper(linda->U->keepers, linda->hashSeed()) }; 712 Keeper* const K{ which_keeper(linda->U->keepers, linda->hashSeed()) };
713 pushed = keeper_call(linda->U, K->L, KEEPER_API(limit), L, linda, 2); 713 pushed = keeper_call(linda->U, K->L, KEEPER_API(limit), L, linda, 2);
714 ASSERT_L( pushed.has_value() && (pushed.value() == 0 || pushed.value() == 1)); // no error, optional boolean value saying if we should wake blocked writer threads 714 LUA_ASSERT(L, pushed.has_value() && (pushed.value() == 0 || pushed.value() == 1)); // no error, optional boolean value saying if we should wake blocked writer threads
715 if (pushed.value() == 1) 715 if (pushed.value() == 1)
716 { 716 {
717 ASSERT_L( lua_type( L, -1) == LUA_TBOOLEAN && lua_toboolean( L, -1) == 1); 717 LUA_ASSERT(L, lua_type( L, -1) == LUA_TBOOLEAN && lua_toboolean( L, -1) == 1);
718 linda->m_read_happened.notify_all(); // To be done from within the 'K' locking area 718 linda->m_read_happened.notify_all(); // To be done from within the 'K' locking area
719 } 719 }
720 } 720 }
@@ -931,7 +931,7 @@ DeepPrelude* LindaFactory::newDeepObjectInternal(lua_State* L) const
931void LindaFactory::deleteDeepObjectInternal(lua_State* L, DeepPrelude* o_) const 931void LindaFactory::deleteDeepObjectInternal(lua_State* L, DeepPrelude* o_) const
932{ 932{
933 Linda* const linda{ static_cast<Linda*>(o_) }; 933 Linda* const linda{ static_cast<Linda*>(o_) };
934 ASSERT_L(linda); 934 LUA_ASSERT(L, linda);
935 Keeper* const myK{ which_keeper(linda->U->keepers, linda->hashSeed()) }; 935 Keeper* const myK{ which_keeper(linda->U->keepers, linda->hashSeed()) };
936 // if collected after the universe, keepers are already destroyed, and there is nothing to clear 936 // if collected after the universe, keepers are already destroyed, and there is nothing to clear
937 if (myK) 937 if (myK)
@@ -943,7 +943,7 @@ void LindaFactory::deleteDeepObjectInternal(lua_State* L, DeepPrelude* o_) const
943 Keeper* const K{ need_acquire_release ? keeper_acquire(linda->U->keepers, linda->hashSeed()) : myK }; 943 Keeper* const K{ need_acquire_release ? keeper_acquire(linda->U->keepers, linda->hashSeed()) : myK };
944 // hopefully this won't ever raise an error as we would jump to the closest pcall site while forgetting to release the keeper mutex... 944 // hopefully this won't ever raise an error as we would jump to the closest pcall site while forgetting to release the keeper mutex...
945 [[maybe_unused]] KeeperCallResult const result{ keeper_call(linda->U, K->L, KEEPER_API(clear), L, linda, 0) }; 945 [[maybe_unused]] KeeperCallResult const result{ keeper_call(linda->U, K->L, KEEPER_API(clear), L, linda, 0) };
946 ASSERT_L(result.has_value() && result.value() == 0); 946 LUA_ASSERT(L, result.has_value() && result.value() == 0);
947 if (need_acquire_release) 947 if (need_acquire_release)
948 { 948 {
949 keeper_release(K); 949 keeper_release(K);
diff --git a/src/macros_and_utils.h b/src/macros_and_utils.h
index c01363a..edda76e 100644
--- a/src/macros_and_utils.h
+++ b/src/macros_and_utils.h
@@ -34,7 +34,7 @@ using namespace std::chrono_literals;
34 34
35#ifdef NDEBUG 35#ifdef NDEBUG
36 36
37#define _ASSERT_L(lua,c) //nothing 37#define LUA_ASSERT(L,c) ; //nothing
38 38
39#define STACK_CHECK_START_REL(L, offset_) 39#define STACK_CHECK_START_REL(L, offset_)
40#define STACK_CHECK_START_ABS(L, offset_) 40#define STACK_CHECK_START_ABS(L, offset_)
@@ -44,7 +44,15 @@ using namespace std::chrono_literals;
44 44
45#else // NDEBUG 45#else // NDEBUG
46 46
47#define _ASSERT_L(L, cond_) if ((cond_) == 0) { (void) luaL_error(L, "ASSERT failed: %s:%d '%s'", __FILE__, __LINE__, #cond_);} 47inline void LUA_ASSERT_IMPL(lua_State* L_, bool cond_, char const* file_, size_t const line_, char const* txt_)
48{
49 if (!cond_)
50 {
51 luaL_error(L_, "LUA_ASSERT %s:%llu '%s'", file_, line_, txt_); // doesn't return
52 }
53}
54
55#define LUA_ASSERT(L_, cond_) LUA_ASSERT_IMPL(L_, cond_, __FILE__, __LINE__, #cond_)
48 56
49class StackChecker 57class StackChecker
50{ 58{
@@ -74,7 +82,7 @@ class StackChecker
74 if ((offset_ < 0) || (m_oldtop < 0)) 82 if ((offset_ < 0) || (m_oldtop < 0))
75 { 83 {
76 assert(false); 84 assert(false);
77 luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%d", lua_gettop(m_L), offset_, file_, line_); // doesn't return 85 luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%llu", lua_gettop(m_L), offset_, file_, line_); // doesn't return
78 } 86 }
79 } 87 }
80 88
@@ -85,7 +93,7 @@ class StackChecker
85 if (lua_gettop(m_L) != pos_) 93 if (lua_gettop(m_L) != pos_)
86 { 94 {
87 assert(false); 95 assert(false);
88 luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%d", lua_gettop(m_L), pos_, file_, line_); // doesn't return 96 luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%llu", lua_gettop(m_L), pos_, file_, line_); // doesn't return
89 } 97 }
90 } 98 }
91 99
@@ -105,7 +113,7 @@ class StackChecker
105 if (actual != expected_) 113 if (actual != expected_)
106 { 114 {
107 assert(false); 115 assert(false);
108 luaL_error(m_L, "STACK ASSERT failed (%d not %d): %s:%d", actual, expected_, file_, line_); // doesn't return 116 luaL_error(m_L, "STACK ASSERT failed (%d not %d): %s:%llu", actual, expected_, file_, line_); // doesn't return
109 } 117 }
110 } 118 }
111 } 119 }
@@ -119,8 +127,6 @@ class StackChecker
119 127
120#endif // NDEBUG 128#endif // NDEBUG
121 129
122#define ASSERT_L(c) _ASSERT_L(L,c)
123
124inline void STACK_GROW(lua_State* L, int n_) 130inline void STACK_GROW(lua_State* L, int n_)
125{ 131{
126 if (!lua_checkstack(L, n_)) 132 if (!lua_checkstack(L, n_))
@@ -137,14 +143,14 @@ inline void STACK_GROW(lua_State* L, int n_)
137template<typename T> 143template<typename T>
138[[nodiscard]] T* lua_tofulluserdata(lua_State* L, int index_) 144[[nodiscard]] T* lua_tofulluserdata(lua_State* L, int index_)
139{ 145{
140 ASSERT_L(lua_isnil(L, index_) || lua_type(L, index_) == LUA_TUSERDATA); 146 LUA_ASSERT(L, lua_isnil(L, index_) || lua_type(L, index_) == LUA_TUSERDATA);
141 return static_cast<T*>(lua_touserdata(L, index_)); 147 return static_cast<T*>(lua_touserdata(L, index_));
142} 148}
143 149
144template<typename T> 150template<typename T>
145[[nodiscard]] auto lua_tolightuserdata(lua_State* L, int index_) 151[[nodiscard]] auto lua_tolightuserdata(lua_State* L, int index_)
146{ 152{
147 ASSERT_L(lua_isnil(L, index_) || lua_islightuserdata(L, index_)); 153 LUA_ASSERT(L, lua_isnil(L, index_) || lua_islightuserdata(L, index_));
148 if constexpr (std::is_pointer_v<T>) 154 if constexpr (std::is_pointer_v<T>)
149 { 155 {
150 return static_cast<T>(lua_touserdata(L, index_)); 156 return static_cast<T>(lua_touserdata(L, index_));
diff --git a/src/tools.cpp b/src/tools.cpp
index 98cbf27..3410f4b 100644
--- a/src/tools.cpp
+++ b/src/tools.cpp
@@ -72,7 +72,7 @@ void push_registry_subtable_mode(lua_State* L, RegistryUniqueKey key_, const cha
72 } 72 }
73 } 73 }
74 STACK_CHECK(L, 1); 74 STACK_CHECK(L, 1);
75 ASSERT_L(lua_istable(L, -1)); 75 LUA_ASSERT(L, lua_istable(L, -1));
76} 76}
77 77
78// ################################################################################################# 78// #################################################################################################
@@ -139,7 +139,7 @@ void initialize_allocator_function(Universe* U, lua_State* L)
139 } 139 }
140 else if (lua_type(L, -1) == LUA_TSTRING) // should be "protected" 140 else if (lua_type(L, -1) == LUA_TSTRING) // should be "protected"
141 { 141 {
142 ASSERT_L(strcmp(lua_tostring(L, -1), "protected") == 0); 142 LUA_ASSERT(L, strcmp(lua_tostring(L, -1), "protected") == 0);
143 // set the original allocator to call from inside protection by the mutex 143 // set the original allocator to call from inside protection by the mutex
144 U->protected_allocator.initFrom(L); 144 U->protected_allocator.initFrom(L);
145 U->protected_allocator.installIn(L); 145 U->protected_allocator.installIn(L);
@@ -290,7 +290,7 @@ static void update_lookup_entry(DEBUGSPEW_PARAM_COMMA(Universe* U) lua_State* L,
290 prevName = lua_tolstring( L, -1, &prevNameLength); // nullptr if we got nil (first encounter of this object) 290 prevName = lua_tolstring( L, -1, &prevNameLength); // nullptr if we got nil (first encounter of this object)
291 // push name in fqn stack (note that concatenation will crash if name is a not string or a number) 291 // push name in fqn stack (note that concatenation will crash if name is a not string or a number)
292 lua_pushvalue(L, -3); // ... {bfc} k o name? k 292 lua_pushvalue(L, -3); // ... {bfc} k o name? k
293 ASSERT_L(lua_type(L, -1) == LUA_TNUMBER || lua_type(L, -1) == LUA_TSTRING); 293 LUA_ASSERT(L, lua_type(L, -1) == LUA_TNUMBER || lua_type(L, -1) == LUA_TSTRING);
294 ++_depth; 294 ++_depth;
295 lua_rawseti(L, fqn, _depth); // ... {bfc} k o name? 295 lua_rawseti(L, fqn, _depth); // ... {bfc} k o name?
296 // generate name 296 // generate name
@@ -329,8 +329,8 @@ static void update_lookup_entry(DEBUGSPEW_PARAM_COMMA(Universe* U) lua_State* L,
329 // prepare the stack for database feed 329 // prepare the stack for database feed
330 lua_pushvalue(L, -1); // ... {bfc} k o "f.q.n" "f.q.n" 330 lua_pushvalue(L, -1); // ... {bfc} k o "f.q.n" "f.q.n"
331 lua_pushvalue(L, -3); // ... {bfc} k o "f.q.n" "f.q.n" o 331 lua_pushvalue(L, -3); // ... {bfc} k o "f.q.n" "f.q.n" o
332 ASSERT_L(lua_rawequal(L, -1, -4)); 332 LUA_ASSERT(L, lua_rawequal(L, -1, -4));
333 ASSERT_L(lua_rawequal(L, -2, -3)); 333 LUA_ASSERT(L, lua_rawequal(L, -2, -3));
334 // t["f.q.n"] = o 334 // t["f.q.n"] = o
335 lua_rawset(L, dest); // ... {bfc} k o "f.q.n" 335 lua_rawset(L, dest); // ... {bfc} k o "f.q.n"
336 // t[o] = "f.q.n" 336 // t[o] = "f.q.n"
@@ -387,7 +387,7 @@ static void populate_func_lookup_table_recur(DEBUGSPEW_PARAM_COMMA(Universe* U)
387 387
388 // this table is at breadth_first_cache index 388 // this table is at breadth_first_cache index
389 lua_newtable(L); // ... {_i} {bfc} 389 lua_newtable(L); // ... {_i} {bfc}
390 ASSERT_L( lua_gettop(L) == breadth_first_cache); 390 LUA_ASSERT(L, lua_gettop(L) == breadth_first_cache);
391 // iterate over all entries in the processed table 391 // iterate over all entries in the processed table
392 lua_pushnil(L); // ... {_i} {bfc} nil 392 lua_pushnil(L); // ... {_i} {bfc} nil
393 while( lua_next(L, _i) != 0) // ... {_i} {bfc} k v 393 while( lua_next(L, _i) != 0) // ... {_i} {bfc} k v
@@ -434,7 +434,7 @@ static void populate_func_lookup_table_recur(DEBUGSPEW_PARAM_COMMA(Universe* U)
434 // un-visit this table in case we do need to process it 434 // un-visit this table in case we do need to process it
435 lua_pushvalue(L, -1); // ... {_i} {bfc} k {} {} 435 lua_pushvalue(L, -1); // ... {_i} {bfc} k {} {}
436 lua_rawget(L, cache); // ... {_i} {bfc} k {} n 436 lua_rawget(L, cache); // ... {_i} {bfc} k {} n
437 ASSERT_L(lua_type(L, -1) == LUA_TNUMBER); 437 LUA_ASSERT(L, lua_type(L, -1) == LUA_TNUMBER);
438 visit_count = lua_tointeger(L, -1) - 1; 438 visit_count = lua_tointeger(L, -1) - 1;
439 lua_pop(L, 1); // ... {_i} {bfc} k {} 439 lua_pop(L, 1); // ... {_i} {bfc} k {}
440 lua_pushvalue(L, -1); // ... {_i} {bfc} k {} {} 440 lua_pushvalue(L, -1); // ... {_i} {bfc} k {} {}
@@ -481,7 +481,7 @@ void populate_func_lookup_table(lua_State* L, int i_, char const* name_)
481 STACK_CHECK_START_REL(L, 0); 481 STACK_CHECK_START_REL(L, 0);
482 LOOKUP_REGKEY.pushValue(L); // {} 482 LOOKUP_REGKEY.pushValue(L); // {}
483 STACK_CHECK(L, 1); 483 STACK_CHECK(L, 1);
484 ASSERT_L(lua_istable(L, -1)); 484 LUA_ASSERT(L, lua_istable(L, -1));
485 if (lua_type(L, in_base) == LUA_TFUNCTION) // for example when a module is a simple function 485 if (lua_type(L, in_base) == LUA_TFUNCTION) // for example when a module is a simple function
486 { 486 {
487 name_ = name_ ? name_ : "nullptr"; 487 name_ = name_ ? name_ : "nullptr";
@@ -606,7 +606,7 @@ static constexpr RegistryUniqueKey REG_MTID{ 0x2E68F9B4751584DCull };
606{ 606{
607 DEBUGSPEW_CODE( Universe* const U = universe_get( L)); 607 DEBUGSPEW_CODE( Universe* const U = universe_get( L));
608 char const* fqn; 608 char const* fqn;
609 ASSERT_L( lua_isfunction( L, i) || lua_istable( L, i)); // ... v ... 609 LUA_ASSERT(L, lua_isfunction( L, i) || lua_istable( L, i)); // ... v ...
610 STACK_CHECK_START_REL(L, 0); 610 STACK_CHECK_START_REL(L, 0);
611 STACK_GROW( L, 3); // up to 3 slots are necessary on error 611 STACK_GROW( L, 3); // up to 3 slots are necessary on error
612 if (mode_ == LookupMode::FromKeeper) 612 if (mode_ == LookupMode::FromKeeper)
@@ -619,7 +619,7 @@ static constexpr RegistryUniqueKey REG_MTID{ 0x2E68F9B4751584DCull };
619 else 619 else
620 { 620 {
621 // if this is not a sentinel, this is some user-created table we wanted to lookup 621 // if this is not a sentinel, this is some user-created table we wanted to lookup
622 ASSERT_L(nullptr == f && lua_istable(L, i)); 622 LUA_ASSERT(L, nullptr == f && lua_istable(L, i));
623 // push anything that will convert to nullptr string 623 // push anything that will convert to nullptr string
624 lua_pushnil( L); // ... v ... nil 624 lua_pushnil( L); // ... v ... nil
625 } 625 }
@@ -629,7 +629,7 @@ static constexpr RegistryUniqueKey REG_MTID{ 0x2E68F9B4751584DCull };
629 // fetch the name from the source state's lookup table 629 // fetch the name from the source state's lookup table
630 LOOKUP_REGKEY.pushValue(L); // ... v ... {} 630 LOOKUP_REGKEY.pushValue(L); // ... v ... {}
631 STACK_CHECK( L, 1); 631 STACK_CHECK( L, 1);
632 ASSERT_L( lua_istable( L, -1)); 632 LUA_ASSERT(L, lua_istable( L, -1));
633 lua_pushvalue( L, i); // ... v ... {} v 633 lua_pushvalue( L, i); // ... v ... {} v
634 lua_rawget( L, -2); // ... v ... {} "f.q.n" 634 lua_rawget( L, -2); // ... v ... {} "f.q.n"
635 } 635 }
@@ -701,7 +701,7 @@ static constexpr RegistryUniqueKey REG_MTID{ 0x2E68F9B4751584DCull };
701 case LookupMode::FromKeeper: 701 case LookupMode::FromKeeper:
702 LOOKUP_REGKEY.pushValue(L2); // {} 702 LOOKUP_REGKEY.pushValue(L2); // {}
703 STACK_CHECK(L2, 1); 703 STACK_CHECK(L2, 1);
704 _ASSERT_L(L1, lua_istable(L2, -1)); 704 LUA_ASSERT(L1, lua_istable(L2, -1));
705 lua_pushlstring(L2, fqn, len); // {} "f.q.n" 705 lua_pushlstring(L2, fqn, len); // {} "f.q.n"
706 lua_rawget(L2, -2); // {} t 706 lua_rawget(L2, -2); // {} t
707 // we accept destination lookup failures in the case of transfering the Lanes body function (this will result in the source table being cloned instead) 707 // we accept destination lookup failures in the case of transfering the Lanes body function (this will result in the source table being cloned instead)
@@ -754,7 +754,7 @@ static constexpr RegistryUniqueKey REG_MTID{ 0x2E68F9B4751584DCull };
754{ 754{
755 void const* p{ lua_topointer(L1, i) }; 755 void const* p{ lua_topointer(L1, i) };
756 756
757 _ASSERT_L(L1, L2_cache_i != 0); 757 LUA_ASSERT(L1, L2_cache_i != 0);
758 STACK_GROW(L2, 3); // L2 758 STACK_GROW(L2, 3); // L2
759 STACK_CHECK_START_REL(L2, 0); 759 STACK_CHECK_START_REL(L2, 0);
760 760
@@ -777,7 +777,7 @@ static constexpr RegistryUniqueKey REG_MTID{ 0x2E68F9B4751584DCull };
777 lua_rawset(L2, L2_cache_i); // ... {} 777 lua_rawset(L2, L2_cache_i); // ... {}
778 } 778 }
779 STACK_CHECK(L2, 1); 779 STACK_CHECK(L2, 1);
780 _ASSERT_L(L1, lua_istable( L2, -1)); 780 LUA_ASSERT(L1, lua_istable( L2, -1));
781 return !not_found_in_cache; 781 return !not_found_in_cache;
782} 782}
783 783
@@ -1006,7 +1006,7 @@ void InterCopyContext::lookup_native_func() const
1006 case LookupMode::FromKeeper: 1006 case LookupMode::FromKeeper:
1007 LOOKUP_REGKEY.pushValue(L2); // {} 1007 LOOKUP_REGKEY.pushValue(L2); // {}
1008 STACK_CHECK(L2, 1); 1008 STACK_CHECK(L2, 1);
1009 _ASSERT_L(L1, lua_istable(L2, -1)); 1009 LUA_ASSERT(L1, lua_istable(L2, -1));
1010 lua_pushlstring(L2, fqn, len); // {} "f.q.n" 1010 lua_pushlstring(L2, fqn, len); // {} "f.q.n"
1011 lua_rawget(L2, -2); // {} f 1011 lua_rawget(L2, -2); // {} f
1012 // nil means we don't know how to transfer stuff: user should do something 1012 // nil means we don't know how to transfer stuff: user should do something
@@ -1104,7 +1104,7 @@ static char const* vt_names[] =
1104 1104
1105void InterCopyContext::copy_func() const 1105void InterCopyContext::copy_func() const
1106{ 1106{
1107 _ASSERT_L(L1, L2_cache_i != 0); // ... {cache} ... p 1107 LUA_ASSERT(L1, L2_cache_i != 0); // ... {cache} ... p
1108 STACK_GROW(L1, 2); 1108 STACK_GROW(L1, 2);
1109 STACK_CHECK_START_REL(L1, 0); 1109 STACK_CHECK_START_REL(L1, 0);
1110 1110
@@ -1158,7 +1158,7 @@ void InterCopyContext::copy_func() const
1158 { 1158 {
1159 size_t sz; 1159 size_t sz;
1160 char const* s = lua_tolstring(L1, -1, &sz); // ... b 1160 char const* s = lua_tolstring(L1, -1, &sz); // ... b
1161 _ASSERT_L(L1, s && sz); 1161 LUA_ASSERT(L1, s && sz);
1162 STACK_GROW(L2, 2); 1162 STACK_GROW(L2, 2);
1163 // Note: Line numbers seem to be taken precisely from the 1163 // Note: Line numbers seem to be taken precisely from the
1164 // original function. 'name' is not used since the chunk 1164 // original function. 'name' is not used since the chunk
@@ -1238,7 +1238,7 @@ void InterCopyContext::copy_func() const
1238 // "assigns the value at the top of the stack to the upvalue and returns its name. 1238 // "assigns the value at the top of the stack to the upvalue and returns its name.
1239 // It also pops the value from the stack." 1239 // It also pops the value from the stack."
1240 1240
1241 _ASSERT_L(L1, rc); // not having enough slots? 1241 LUA_ASSERT(L1, rc); // not having enough slots?
1242 } 1242 }
1243 // once all upvalues have been set we are left 1243 // once all upvalues have been set we are left
1244 // with the function at the top of the stack // ... {cache} ... function 1244 // with the function at the top of the stack // ... {cache} ... function
@@ -1262,7 +1262,7 @@ void InterCopyContext::copy_cached_func() const
1262 { 1262 {
1263 void* const aspointer = const_cast<void*>(lua_topointer(L1, L1_i)); 1263 void* const aspointer = const_cast<void*>(lua_topointer(L1, L1_i));
1264 // TBD: Merge this and same code for tables 1264 // TBD: Merge this and same code for tables
1265 _ASSERT_L(L1, L2_cache_i != 0); 1265 LUA_ASSERT(L1, L2_cache_i != 0);
1266 1266
1267 STACK_GROW(L2, 2); 1267 STACK_GROW(L2, 2);
1268 1268
@@ -1297,13 +1297,13 @@ void InterCopyContext::copy_cached_func() const
1297 lua_remove(L2, -2); // ... {cache} ... function 1297 lua_remove(L2, -2); // ... {cache} ... function
1298 } 1298 }
1299 STACK_CHECK(L2, 1); 1299 STACK_CHECK(L2, 1);
1300 _ASSERT_L(L1, lua_isfunction(L2, -1)); 1300 LUA_ASSERT(L1, lua_isfunction(L2, -1));
1301 } 1301 }
1302 else // function is native/LuaJIT: no need to cache 1302 else // function is native/LuaJIT: no need to cache
1303 { 1303 {
1304 lookup_native_func(); // ... {cache} ... function 1304 lookup_native_func(); // ... {cache} ... function
1305 // if the function was in fact a lookup sentinel, we can either get a function or a table here 1305 // if the function was in fact a lookup sentinel, we can either get a function or a table here
1306 _ASSERT_L(L1, lua_isfunction(L2, -1) || lua_istable(L2, -1)); 1306 LUA_ASSERT(L1, lua_isfunction(L2, -1) || lua_istable(L2, -1));
1307 } 1307 }
1308} 1308}
1309 1309
@@ -1421,7 +1421,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const
1421 c.name = valPath ? valPath : name; 1421 c.name = valPath ? valPath : name;
1422 if (c.inter_copy_one()) 1422 if (c.inter_copy_one())
1423 { 1423 {
1424 _ASSERT_L(L1, lua_istable( L2, -3)); 1424 LUA_ASSERT(L1, lua_istable( L2, -3));
1425 lua_rawset(L2, -3); // add to table (pops key & val) 1425 lua_rawset(L2, -3); // add to table (pops key & val)
1426 } 1426 }
1427 else 1427 else
@@ -1494,7 +1494,7 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull };
1494 { 1494 {
1495 if (LookupMode::ToKeeper == mode) // ... u sentinel 1495 if (LookupMode::ToKeeper == mode) // ... u sentinel
1496 { 1496 {
1497 _ASSERT_L(L1, lua_tocfunction(L2, -1) == table_lookup_sentinel); 1497 LUA_ASSERT(L1, lua_tocfunction(L2, -1) == table_lookup_sentinel);
1498 // we want to create a new closure with a 'clone sentinel' function, where the upvalues are the userdata and the metatable fqn 1498 // we want to create a new closure with a 'clone sentinel' function, where the upvalues are the userdata and the metatable fqn
1499 lua_getupvalue(L2, -1, 1); // ... u sentinel fqn 1499 lua_getupvalue(L2, -1, 1); // ... u sentinel fqn
1500 lua_remove(L2, -2); // ... u fqn 1500 lua_remove(L2, -2); // ... u fqn
@@ -1503,7 +1503,7 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull };
1503 } 1503 }
1504 else // from keeper or direct // ... u mt 1504 else // from keeper or direct // ... u mt
1505 { 1505 {
1506 _ASSERT_L(L1, lua_istable(L2, -1)); 1506 LUA_ASSERT(L1, lua_istable(L2, -1));
1507 lua_setmetatable(L2, -2); // ... u 1507 lua_setmetatable(L2, -2); // ... u
1508 } 1508 }
1509 STACK_CHECK(L2, 1); 1509 STACK_CHECK(L2, 1);
@@ -1726,7 +1726,7 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull };
1726 */ 1726 */
1727 if (lookup_table()) 1727 if (lookup_table())
1728 { 1728 {
1729 _ASSERT_L(L1, lua_istable(L2, -1) || (lua_tocfunction(L2, -1) == table_lookup_sentinel)); // from lookup data. can also be table_lookup_sentinel if this is a table we know 1729 LUA_ASSERT(L1, lua_istable(L2, -1) || (lua_tocfunction(L2, -1) == table_lookup_sentinel)); // from lookup data. can also be table_lookup_sentinel if this is a table we know
1730 return true; 1730 return true;
1731 } 1731 }
1732 1732
@@ -1741,10 +1741,10 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull };
1741 */ 1741 */
1742 if (push_cached_table(L2, L2_cache_i, L1, L1_i)) 1742 if (push_cached_table(L2, L2_cache_i, L1, L1_i))
1743 { 1743 {
1744 _ASSERT_L(L1, lua_istable(L2, -1)); // from cache 1744 LUA_ASSERT(L1, lua_istable(L2, -1)); // from cache
1745 return true; 1745 return true;
1746 } 1746 }
1747 _ASSERT_L(L1, lua_istable(L2, -1)); 1747 LUA_ASSERT(L1, lua_istable(L2, -1));
1748 1748
1749 STACK_GROW(L1, 2); 1749 STACK_GROW(L1, 2);
1750 STACK_GROW(L2, 2); 1750 STACK_GROW(L2, 2);
@@ -1907,7 +1907,7 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull };
1907// NOTE: Both the states must be solely in the current OS thread's possession. 1907// NOTE: Both the states must be solely in the current OS thread's possession.
1908[[nodiscard]] InterCopyResult InterCopyContext::inter_copy(int n_) const 1908[[nodiscard]] InterCopyResult InterCopyContext::inter_copy(int n_) const
1909{ 1909{
1910 _ASSERT_L(L1, vt == VT::NORMAL); 1910 LUA_ASSERT(L1, vt == VT::NORMAL);
1911 1911
1912 DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "InterCopyContext::inter_copy()\n" INDENT_END)); 1912 DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "InterCopyContext::inter_copy()\n" INDENT_END));
1913 DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); 1913 DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U });
diff --git a/src/universe.cpp b/src/universe.cpp
index 112c840..fb10067 100644
--- a/src/universe.cpp
+++ b/src/universe.cpp
@@ -75,7 +75,7 @@ Universe::Universe()
75// only called from the master state 75// only called from the master state
76Universe* universe_create(lua_State* L) 76Universe* universe_create(lua_State* L)
77{ 77{
78 ASSERT_L(universe_get(L) == nullptr); 78 LUA_ASSERT(L, universe_get(L) == nullptr);
79 Universe* const U{ lua_newuserdatauv<Universe>(L, 0) }; // universe 79 Universe* const U{ lua_newuserdatauv<Universe>(L, 0) }; // universe
80 U->Universe::Universe(); 80 U->Universe::Universe();
81 STACK_CHECK_START_REL(L, 1); 81 STACK_CHECK_START_REL(L, 1);
@@ -89,7 +89,7 @@ Universe* universe_create(lua_State* L)
89 89
90void universe_store(lua_State* L, Universe* U) 90void universe_store(lua_State* L, Universe* U)
91{ 91{
92 ASSERT_L(!U || universe_get(L) == nullptr); 92 LUA_ASSERT(L, !U || universe_get(L) == nullptr);
93 STACK_CHECK_START_REL(L, 0); 93 STACK_CHECK_START_REL(L, 0);
94 UNIVERSE_LIGHT_REGKEY.setValue(L, [U](lua_State* L) { U ? lua_pushlightuserdata(L, U) : lua_pushnil(L); }); 94 UNIVERSE_LIGHT_REGKEY.setValue(L, [U](lua_State* L) { U ? lua_pushlightuserdata(L, U) : lua_pushnil(L); });
95 STACK_CHECK(L, 0); 95 STACK_CHECK(L, 0);
diff --git a/src/universe.h b/src/universe.h
index 320c400..d0d7864 100644
--- a/src/universe.h
+++ b/src/universe.h
@@ -39,7 +39,7 @@ class AllocatorDefinition
39 [[nodiscard]] static void* operator new(size_t size_, lua_State* L) noexcept { return lua_newuserdatauv(L, size_, 0); } 39 [[nodiscard]] static void* operator new(size_t size_, lua_State* L) noexcept { return lua_newuserdatauv(L, size_, 0); }
40 // always embedded somewhere else or "in-place constructed" as a full userdata 40 // always embedded somewhere else or "in-place constructed" as a full userdata
41 // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception 41 // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception
42 static void operator delete([[maybe_unused]] void* p_, lua_State* L) { ASSERT_L(!"should never be called") }; 42 static void operator delete([[maybe_unused]] void* p_, lua_State* L_) { LUA_ASSERT(L_, !"should never be called"); }
43 43
44 AllocatorDefinition(lua_Alloc allocF_, void* allocUD_) noexcept 44 AllocatorDefinition(lua_Alloc allocF_, void* allocUD_) noexcept
45 : m_allocF{ allocF_ } 45 : m_allocF{ allocF_ }