diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cancel.cpp | 8 | ||||
-rw-r--r-- | src/cancel.h | 2 | ||||
-rw-r--r-- | src/deep.cpp | 12 | ||||
-rw-r--r-- | src/keeper.cpp | 10 | ||||
-rw-r--r-- | src/lanes.cpp | 48 | ||||
-rw-r--r-- | src/linda.cpp | 16 | ||||
-rw-r--r-- | src/macros_and_utils.h | 64 | ||||
-rw-r--r-- | src/state.cpp | 8 | ||||
-rw-r--r-- | src/tools.cpp | 50 |
9 files changed, 128 insertions, 90 deletions
diff --git a/src/cancel.cpp b/src/cancel.cpp index 0ec5eb5..cff1443 100644 --- a/src/cancel.cpp +++ b/src/cancel.cpp | |||
@@ -213,7 +213,7 @@ CancelOp which_cancel_op(char const* op_string_) | |||
213 | lua_remove(L, idx_); // argument is processed, remove it | 213 | lua_remove(L, idx_); // argument is processed, remove it |
214 | if (op == CancelOp::Invalid) | 214 | if (op == CancelOp::Invalid) |
215 | { | 215 | { |
216 | luaL_error(L, "invalid hook option %s", str); // doesn't return | 216 | raise_luaL_error(L, "invalid hook option %s", str); |
217 | } | 217 | } |
218 | return op; | 218 | return op; |
219 | } | 219 | } |
@@ -235,7 +235,7 @@ LUAG_FUNC(thread_cancel) | |||
235 | lua_remove(L, 2); // argument is processed, remove it | 235 | lua_remove(L, 2); // argument is processed, remove it |
236 | if (hook_count < 1) | 236 | if (hook_count < 1) |
237 | { | 237 | { |
238 | return luaL_error(L, "hook count cannot be < 1"); // doesn't return | 238 | raise_luaL_error(L, "hook count cannot be < 1"); |
239 | } | 239 | } |
240 | } | 240 | } |
241 | 241 | ||
@@ -246,7 +246,7 @@ LUAG_FUNC(thread_cancel) | |||
246 | lua_remove(L, 2); // argument is processed, remove it | 246 | lua_remove(L, 2); // argument is processed, remove it |
247 | if (wait_timeout.count() < 0.0) | 247 | if (wait_timeout.count() < 0.0) |
248 | { | 248 | { |
249 | return luaL_error(L, "cancel timeout cannot be < 0"); // doesn't return | 249 | raise_luaL_error(L, "cancel timeout cannot be < 0"); |
250 | } | 250 | } |
251 | } | 251 | } |
252 | // we wake by default in "hard" mode (remember that hook is hard too), but this can be turned off if desired | 252 | // we wake by default in "hard" mode (remember that hook is hard too), but this can be turned off if desired |
@@ -255,7 +255,7 @@ LUAG_FUNC(thread_cancel) | |||
255 | { | 255 | { |
256 | if (!lua_isboolean(L, 2)) | 256 | if (!lua_isboolean(L, 2)) |
257 | { | 257 | { |
258 | return luaL_error(L, "wake_lindas parameter is not a boolean"); // doesn't return | 258 | raise_luaL_error(L, "wake_lindas parameter is not a boolean"); |
259 | } | 259 | } |
260 | wake_lane = lua_toboolean(L, 2); | 260 | wake_lane = lua_toboolean(L, 2); |
261 | lua_remove(L, 2); // argument is processed, remove it | 261 | lua_remove(L, 2); // argument is processed, remove it |
diff --git a/src/cancel.h b/src/cancel.h index d5c3f7b..bbc7787 100644 --- a/src/cancel.h +++ b/src/cancel.h | |||
@@ -54,7 +54,7 @@ static constexpr UniqueKey kCancelError{ 0x0630345FEF912746ull, "lanes.cancel_er | |||
54 | { | 54 | { |
55 | STACK_GROW(L, 1); | 55 | STACK_GROW(L, 1); |
56 | kCancelError.pushKey(L); // special error value | 56 | kCancelError.pushKey(L); // special error value |
57 | raise_lua_error(L); // doesn't return | 57 | raise_lua_error(L); |
58 | } | 58 | } |
59 | 59 | ||
60 | // ################################################################################################# | 60 | // ################################################################################################# |
diff --git a/src/deep.cpp b/src/deep.cpp index d7efe68..5a62000 100644 --- a/src/deep.cpp +++ b/src/deep.cpp | |||
@@ -351,14 +351,14 @@ int DeepFactory::pushDeepUserdata(DestState L, int nuv_) const | |||
351 | DeepPrelude* const prelude{ newDeepObjectInternal(L) }; | 351 | DeepPrelude* const prelude{ newDeepObjectInternal(L) }; |
352 | if (prelude == nullptr) | 352 | if (prelude == nullptr) |
353 | { | 353 | { |
354 | return luaL_error( L, "DeepFactory::newDeepObjectInternal failed to create deep userdata (out of memory)"); | 354 | raise_luaL_error(L, "DeepFactory::newDeepObjectInternal failed to create deep userdata (out of memory)"); |
355 | } | 355 | } |
356 | 356 | ||
357 | if (prelude->m_magic != kDeepVersion) | 357 | if (prelude->m_magic != kDeepVersion) |
358 | { | 358 | { |
359 | // just in case, don't leak the newly allocated deep userdata object | 359 | // just in case, don't leak the newly allocated deep userdata object |
360 | deleteDeepObjectInternal(L, prelude); | 360 | deleteDeepObjectInternal(L, prelude); |
361 | return luaL_error( L, "Bad Deep Factory: kDeepVersion is incorrect, rebuild your implementation with the latest deep implementation"); | 361 | raise_luaL_error(L, "Bad Deep Factory: kDeepVersion is incorrect, rebuild your implementation with the latest deep implementation"); |
362 | } | 362 | } |
363 | 363 | ||
364 | LUA_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 |
@@ -368,13 +368,13 @@ int DeepFactory::pushDeepUserdata(DestState L, int nuv_) const | |||
368 | { | 368 | { |
369 | // just in case, don't leak the newly allocated deep userdata object | 369 | // just in case, don't leak the newly allocated deep userdata object |
370 | deleteDeepObjectInternal(L, prelude); | 370 | deleteDeepObjectInternal(L, prelude); |
371 | return luaL_error(L, "Bad DeepFactory::newDeepObjectInternal overload: should not push anything on the stack"); | 371 | raise_luaL_error(L, "Bad DeepFactory::newDeepObjectInternal overload: should not push anything on the stack"); |
372 | } | 372 | } |
373 | 373 | ||
374 | char const* const errmsg{ DeepFactory::PushDeepProxy(L, prelude, nuv_, LookupMode::LaneBody) }; // proxy | 374 | char const* const errmsg{ DeepFactory::PushDeepProxy(L, prelude, nuv_, LookupMode::LaneBody) }; // proxy |
375 | if (errmsg != nullptr) | 375 | if (errmsg != nullptr) |
376 | { | 376 | { |
377 | return luaL_error( L, errmsg); | 377 | raise_luaL_error(L, errmsg); |
378 | } | 378 | } |
379 | STACK_CHECK( L, 1); | 379 | STACK_CHECK( L, 1); |
380 | return 1; | 380 | return 1; |
@@ -443,7 +443,7 @@ DeepPrelude* DeepFactory::toDeep(lua_State* L, int index) const | |||
443 | c.L1_i = SourceIndex{ lua_absindex(L1, -1) }; | 443 | c.L1_i = SourceIndex{ lua_absindex(L1, -1) }; |
444 | if (!c.inter_copy_one()) // u uv | 444 | if (!c.inter_copy_one()) // u uv |
445 | { | 445 | { |
446 | luaL_error(L1, "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); // doesn't return | 446 | raise_luaL_error(L1, "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); |
447 | } | 447 | } |
448 | lua_pop(L1, 1); // ... u [uv]* | 448 | lua_pop(L1, 1); // ... u [uv]* |
449 | // this pops the value from the stack | 449 | // this pops the value from the stack |
@@ -459,7 +459,7 @@ DeepPrelude* DeepFactory::toDeep(lua_State* L, int index) const | |||
459 | { | 459 | { |
460 | // raise the error in the proper state (not the keeper) | 460 | // raise the error in the proper state (not the keeper) |
461 | lua_State* const errL{ (mode == LookupMode::FromKeeper) ? L2 : L1 }; | 461 | lua_State* const errL{ (mode == LookupMode::FromKeeper) ? L2 : L1 }; |
462 | luaL_error(errL, errmsg); // doesn't return | 462 | raise_luaL_error(errL, errmsg); |
463 | } | 463 | } |
464 | return true; | 464 | return true; |
465 | } \ No newline at end of file | 465 | } \ No newline at end of file |
diff --git a/src/keeper.cpp b/src/keeper.cpp index 682d70d..51f6388 100644 --- a/src/keeper.cpp +++ b/src/keeper.cpp | |||
@@ -660,7 +660,7 @@ void init_keepers(Universe* U, lua_State* L) | |||
660 | lua_pop(L, 1); // settings | 660 | lua_pop(L, 1); // settings |
661 | if (nb_keepers < 1) | 661 | if (nb_keepers < 1) |
662 | { | 662 | { |
663 | luaL_error(L, "Bad number of keepers (%d)", nb_keepers); // doesn't return | 663 | raise_luaL_error(L, "Bad number of keepers (%d)", nb_keepers); |
664 | } | 664 | } |
665 | STACK_CHECK(L, 0); | 665 | STACK_CHECK(L, 0); |
666 | 666 | ||
@@ -675,7 +675,7 @@ void init_keepers(Universe* U, lua_State* L) | |||
675 | U->keepers = static_cast<Keepers*>(U->internal_allocator.alloc(bytes)); | 675 | U->keepers = static_cast<Keepers*>(U->internal_allocator.alloc(bytes)); |
676 | if (U->keepers == nullptr) | 676 | if (U->keepers == nullptr) |
677 | { | 677 | { |
678 | luaL_error(L, "init_keepers() failed while creating keeper array; out of memory"); // doesn't return | 678 | raise_luaL_error(L, "init_keepers() failed while creating keeper array; out of memory"); |
679 | } | 679 | } |
680 | U->keepers->Keepers::Keepers(); | 680 | U->keepers->Keepers::Keepers(); |
681 | U->keepers->gc_threshold = keepers_gc_threshold; | 681 | U->keepers->gc_threshold = keepers_gc_threshold; |
@@ -692,7 +692,7 @@ void init_keepers(Universe* U, lua_State* L) | |||
692 | KeeperState const K{ create_state(U, L) }; | 692 | KeeperState const K{ create_state(U, L) }; |
693 | if (K == nullptr) | 693 | if (K == nullptr) |
694 | { | 694 | { |
695 | luaL_error(L, "init_keepers() failed while creating keeper states; out of memory"); // doesn't return | 695 | raise_luaL_error(L, "init_keepers() failed while creating keeper states; out of memory"); |
696 | } | 696 | } |
697 | 697 | ||
698 | U->keepers->keeper_array[i].L = K; | 698 | U->keepers->keeper_array[i].L = K; |
@@ -829,7 +829,7 @@ KeeperCallResult keeper_call(Universe* U, KeeperState K, keeper_api_t func_, lua | |||
829 | { // func_ linda args... | 829 | { // func_ linda args... |
830 | lua_call(K, 1 + args, LUA_MULTRET); // result... | 830 | lua_call(K, 1 + args, LUA_MULTRET); // result... |
831 | int const retvals{ lua_gettop(K) - top_K }; | 831 | int const retvals{ lua_gettop(K) - top_K }; |
832 | // note that this can raise a luaL_error while the keeper state (and its mutex) is acquired | 832 | // note that this can raise a lua error while the keeper state (and its mutex) is acquired |
833 | // this may interrupt a lane, causing the destruction of the underlying OS thread | 833 | // this may interrupt a lane, causing the destruction of the underlying OS thread |
834 | // after this, another lane making use of this keeper can get an error code from the mutex-locking function | 834 | // after this, another lane making use of this keeper can get an error code from the mutex-locking function |
835 | // when attempting to grab the mutex again (WINVER <= 0x400 does this, but locks just fine, I don't know about pthread) | 835 | // when attempting to grab the mutex again (WINVER <= 0x400 does this, but locks just fine, I don't know about pthread) |
@@ -862,7 +862,7 @@ KeeperCallResult keeper_call(Universe* U, KeeperState K, keeper_api_t func_, lua | |||
862 | int const gc_usage_after{ lua_gc(K, LUA_GCCOUNT, 0) }; | 862 | int const gc_usage_after{ lua_gc(K, LUA_GCCOUNT, 0) }; |
863 | if (gc_usage_after > gc_threshold) [[unlikely]] | 863 | if (gc_usage_after > gc_threshold) [[unlikely]] |
864 | { | 864 | { |
865 | luaL_error(L, "Keeper GC threshold is too low, need at least %d", gc_usage_after); | 865 | raise_luaL_error(L, "Keeper GC threshold is too low, need at least %d", gc_usage_after); |
866 | } | 866 | } |
867 | } | 867 | } |
868 | } | 868 | } |
diff --git a/src/lanes.cpp b/src/lanes.cpp index d907fcd..e150eea 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp | |||
@@ -556,7 +556,7 @@ static void selfdestruct_add(Lane* lane_) | |||
556 | if (lane != SELFDESTRUCT_END) | 556 | if (lane != SELFDESTRUCT_END) |
557 | { | 557 | { |
558 | // this causes a leak because we don't call U's destructor (which could be bad if the still running lanes are accessing it) | 558 | // this causes a leak because we don't call U's destructor (which could be bad if the still running lanes are accessing it) |
559 | luaL_error(L, "Zombie thread %s refuses to die!", lane->debug_name); // doesn't return | 559 | raise_luaL_error(L, "Zombie thread %s refuses to die!", lane->debug_name); |
560 | } | 560 | } |
561 | } | 561 | } |
562 | 562 | ||
@@ -600,16 +600,16 @@ LUAG_FUNC( set_singlethreaded) | |||
600 | #ifdef _UTILBINDTHREADTOCPU | 600 | #ifdef _UTILBINDTHREADTOCPU |
601 | if (cores > 1) | 601 | if (cores > 1) |
602 | { | 602 | { |
603 | return luaL_error(L, "Limiting to N>1 cores not possible"); | 603 | raise_luaL_error(L, "Limiting to N>1 cores not possible"); |
604 | } | 604 | } |
605 | // requires 'chudInitialize()' | 605 | // requires 'chudInitialize()' |
606 | utilBindThreadToCPU(0); // # of CPU to run on (we cannot limit to 2..N CPUs?) | 606 | utilBindThreadToCPU(0); // # of CPU to run on (we cannot limit to 2..N CPUs?) |
607 | return 0; | 607 | return 0; |
608 | #else | 608 | #else |
609 | return luaL_error(L, "Not available: compile with _UTILBINDTHREADTOCPU"); | 609 | raise_luaL_error(L, "Not available: compile with _UTILBINDTHREADTOCPU"); |
610 | #endif | 610 | #endif |
611 | #else | 611 | #else |
612 | return luaL_error(L, "not implemented"); | 612 | raise_luaL_error(L, "not implemented"); |
613 | #endif | 613 | #endif |
614 | } | 614 | } |
615 | 615 | ||
@@ -645,7 +645,7 @@ LUAG_FUNC( set_error_reporting) | |||
645 | bool const basic{ strcmp(mode, "basic") == 0 }; | 645 | bool const basic{ strcmp(mode, "basic") == 0 }; |
646 | if (!extended && !basic) | 646 | if (!extended && !basic) |
647 | { | 647 | { |
648 | return luaL_error(L, "unsupported error reporting model %s", mode); | 648 | raise_luaL_error(L, "unsupported error reporting model %s", mode); |
649 | } | 649 | } |
650 | 650 | ||
651 | kExtendedStackTraceRegKey.setValue(L, [extended](lua_State* L) { lua_pushboolean(L, extended ? 1 : 0); }); | 651 | kExtendedStackTraceRegKey.setValue(L, [extended](lua_State* L) { lua_pushboolean(L, extended ? 1 : 0); }); |
@@ -769,7 +769,7 @@ LUAG_FUNC(set_thread_priority) | |||
769 | // On some platforms, -3 is equivalent to -2 and +3 to +2 | 769 | // On some platforms, -3 is equivalent to -2 and +3 to +2 |
770 | if (prio < kThreadPrioMin || prio > kThreadPrioMax) | 770 | if (prio < kThreadPrioMin || prio > kThreadPrioMax) |
771 | { | 771 | { |
772 | return luaL_error(L, "priority out of range: %d..+%d (%d)", kThreadPrioMin, kThreadPrioMax, prio); | 772 | raise_luaL_error(L, "priority out of range: %d..+%d (%d)", kThreadPrioMin, kThreadPrioMax, prio); |
773 | } | 773 | } |
774 | THREAD_SET_PRIORITY(static_cast<int>(prio), universe_get(L)->m_sudo); | 774 | THREAD_SET_PRIORITY(static_cast<int>(prio), universe_get(L)->m_sudo); |
775 | return 0; | 775 | return 0; |
@@ -782,7 +782,7 @@ LUAG_FUNC(set_thread_affinity) | |||
782 | lua_Integer const affinity{ luaL_checkinteger(L, 1) }; | 782 | lua_Integer const affinity{ luaL_checkinteger(L, 1) }; |
783 | if (affinity <= 0) | 783 | if (affinity <= 0) |
784 | { | 784 | { |
785 | return luaL_error(L, "invalid affinity (%d)", affinity); | 785 | raise_luaL_error(L, "invalid affinity (%d)", affinity); |
786 | } | 786 | } |
787 | THREAD_SET_AFFINITY( static_cast<unsigned int>(affinity)); | 787 | THREAD_SET_AFFINITY( static_cast<unsigned int>(affinity)); |
788 | return 0; | 788 | return 0; |
@@ -994,7 +994,7 @@ LUAG_FUNC(lane_new) | |||
994 | // On some platforms, -3 is equivalent to -2 and +3 to +2 | 994 | // On some platforms, -3 is equivalent to -2 and +3 to +2 |
995 | if (have_priority && (priority < kThreadPrioMin || priority > kThreadPrioMax)) | 995 | if (have_priority && (priority < kThreadPrioMin || priority > kThreadPrioMax)) |
996 | { | 996 | { |
997 | return luaL_error(L, "Priority out of range: %d..+%d (%d)", kThreadPrioMin, kThreadPrioMax, priority); | 997 | raise_luaL_error(L, "Priority out of range: %d..+%d (%d)", kThreadPrioMin, kThreadPrioMax, priority); |
998 | } | 998 | } |
999 | 999 | ||
1000 | /* --- Create and prepare the sub state --- */ | 1000 | /* --- Create and prepare the sub state --- */ |
@@ -1007,7 +1007,7 @@ LUAG_FUNC(lane_new) | |||
1007 | Lane* const lane{ new (U) Lane{ U, L2 } }; | 1007 | Lane* const lane{ new (U) Lane{ U, L2 } }; |
1008 | if (lane == nullptr) | 1008 | if (lane == nullptr) |
1009 | { | 1009 | { |
1010 | return luaL_error(L, "could not create lane: out of memory"); | 1010 | raise_luaL_error(L, "could not create lane: out of memory"); |
1011 | } | 1011 | } |
1012 | 1012 | ||
1013 | class OnExit | 1013 | class OnExit |
@@ -1125,7 +1125,7 @@ LUAG_FUNC(lane_new) | |||
1125 | // should not happen, was checked in lanes.lua before calling lane_new() | 1125 | // should not happen, was checked in lanes.lua before calling lane_new() |
1126 | if (lua_type(L, required_idx) != LUA_TTABLE) | 1126 | if (lua_type(L, required_idx) != LUA_TTABLE) |
1127 | { | 1127 | { |
1128 | luaL_error(L, "expected required module list as a table, got %s", luaL_typename(L, required_idx)); // doesn't return | 1128 | raise_luaL_error(L, "expected required module list as a table, got %s", luaL_typename(L, required_idx)); |
1129 | } | 1129 | } |
1130 | 1130 | ||
1131 | lua_pushnil(L); // func libs priority globals package required gc_cb [... args ...] nil | 1131 | lua_pushnil(L); // func libs priority globals package required gc_cb [... args ...] nil |
@@ -1133,7 +1133,7 @@ LUAG_FUNC(lane_new) | |||
1133 | { | 1133 | { |
1134 | if (lua_type(L, -1) != LUA_TSTRING || lua_type(L, -2) != LUA_TNUMBER || lua_tonumber(L, -2) != nbRequired) | 1134 | if (lua_type(L, -1) != LUA_TSTRING || lua_type(L, -2) != LUA_TNUMBER || lua_tonumber(L, -2) != nbRequired) |
1135 | { | 1135 | { |
1136 | luaL_error(L, "required module list should be a list of strings"); // doesn't return | 1136 | raise_luaL_error(L, "required module list should be a list of strings"); |
1137 | } | 1137 | } |
1138 | else | 1138 | else |
1139 | { | 1139 | { |
@@ -1147,7 +1147,7 @@ LUAG_FUNC(lane_new) | |||
1147 | if (lua_isnil( L2, -1)) | 1147 | if (lua_isnil( L2, -1)) |
1148 | { | 1148 | { |
1149 | lua_pop( L2, 1); // | 1149 | lua_pop( L2, 1); // |
1150 | luaL_error(L, "cannot pre-require modules without loading 'package' library first"); // doesn't return | 1150 | raise_luaL_error(L, "cannot pre-require modules without loading 'package' library first"); |
1151 | } | 1151 | } |
1152 | else | 1152 | else |
1153 | { | 1153 | { |
@@ -1179,7 +1179,7 @@ LUAG_FUNC(lane_new) | |||
1179 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lane_new: transfer globals\n" INDENT_END)); | 1179 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "lane_new: transfer globals\n" INDENT_END)); |
1180 | if (!lua_istable(L, globals_idx)) | 1180 | if (!lua_istable(L, globals_idx)) |
1181 | { | 1181 | { |
1182 | luaL_error(L, "Expected table, got %s", luaL_typename(L, globals_idx)); // doesn't return | 1182 | raise_luaL_error(L, "Expected table, got %s", luaL_typename(L, globals_idx)); |
1183 | } | 1183 | } |
1184 | 1184 | ||
1185 | DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); | 1185 | DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); |
@@ -1210,7 +1210,7 @@ LUAG_FUNC(lane_new) | |||
1210 | InterCopyResult const res{ c.inter_move(1) }; // func libs priority globals package required gc_cb [... args ...] // func | 1210 | InterCopyResult const res{ c.inter_move(1) }; // func libs priority globals package required gc_cb [... args ...] // func |
1211 | if (res != InterCopyResult::Success) | 1211 | if (res != InterCopyResult::Success) |
1212 | { | 1212 | { |
1213 | luaL_error(L, "tried to copy unsupported types"); // doesn't return | 1213 | raise_luaL_error(L, "tried to copy unsupported types"); |
1214 | } | 1214 | } |
1215 | } | 1215 | } |
1216 | else if (func_type == LuaType::STRING) | 1216 | else if (func_type == LuaType::STRING) |
@@ -1219,12 +1219,12 @@ LUAG_FUNC(lane_new) | |||
1219 | // compile the string | 1219 | // compile the string |
1220 | if (luaL_loadstring(L2, lua_tostring(L, 1)) != 0) // func | 1220 | if (luaL_loadstring(L2, lua_tostring(L, 1)) != 0) // func |
1221 | { | 1221 | { |
1222 | luaL_error(L, "error when parsing lane function code"); // doesn't return | 1222 | raise_luaL_error(L, "error when parsing lane function code"); |
1223 | } | 1223 | } |
1224 | } | 1224 | } |
1225 | else | 1225 | else |
1226 | { | 1226 | { |
1227 | luaL_error(L, "Expected function, got %s", lua_typename(L, func_type)); // doesn't return | 1227 | raise_luaL_error(L, "Expected function, got %s", lua_typename(L, func_type)); |
1228 | } | 1228 | } |
1229 | STACK_CHECK(L, 0); | 1229 | STACK_CHECK(L, 0); |
1230 | STACK_CHECK(L2, 1); | 1230 | STACK_CHECK(L2, 1); |
@@ -1239,7 +1239,7 @@ LUAG_FUNC(lane_new) | |||
1239 | InterCopyResult const res{ c.inter_move(nargs) }; // func libs priority globals package required gc_cb // func [... args ...] | 1239 | InterCopyResult const res{ c.inter_move(nargs) }; // func libs priority globals package required gc_cb // func [... args ...] |
1240 | if (res != InterCopyResult::Success) | 1240 | if (res != InterCopyResult::Success) |
1241 | { | 1241 | { |
1242 | luaL_error(L, "tried to copy unsupported types"); // doesn't return | 1242 | raise_luaL_error(L, "tried to copy unsupported types"); |
1243 | } | 1243 | } |
1244 | } | 1244 | } |
1245 | STACK_CHECK(L, -nargs); | 1245 | STACK_CHECK(L, -nargs); |
@@ -1405,7 +1405,7 @@ LUAG_FUNC(thread_join) | |||
1405 | (InterCopyContext{ U, DestState{ L }, SourceState{ L2 }, {}, {}, {}, {}, {} }.inter_move(n) != InterCopyResult::Success) | 1405 | (InterCopyContext{ U, DestState{ L }, SourceState{ L2 }, {}, {}, {}, {}, {} }.inter_move(n) != InterCopyResult::Success) |
1406 | ) | 1406 | ) |
1407 | { | 1407 | { |
1408 | luaL_error(L, "tried to copy unsupported types"); // doesn't return | 1408 | raise_luaL_error(L, "tried to copy unsupported types"); |
1409 | } | 1409 | } |
1410 | ret = n; | 1410 | ret = n; |
1411 | } | 1411 | } |
@@ -1420,7 +1420,7 @@ LUAG_FUNC(thread_join) | |||
1420 | InterCopyContext c{ U, DestState{ L }, SourceState{ L2 }, {}, {}, {}, {}, {} }; | 1420 | InterCopyContext c{ U, DestState{ L }, SourceState{ L2 }, {}, {}, {}, {}, {} }; |
1421 | if (c.inter_move(n) != InterCopyResult::Success) // nil "err" [trace] | 1421 | if (c.inter_move(n) != InterCopyResult::Success) // nil "err" [trace] |
1422 | { | 1422 | { |
1423 | luaL_error(L, "tried to copy unsupported types: %s", lua_tostring(L, -n)); // doesn't return | 1423 | raise_luaL_error(L, "tried to copy unsupported types: %s", lua_tostring(L, -n)); |
1424 | } | 1424 | } |
1425 | ret = 1 + n; | 1425 | ret = 1 + n; |
1426 | } | 1426 | } |
@@ -1580,7 +1580,7 @@ LUAG_FUNC(thread_index) | |||
1580 | // only "cancel" and "join" are registered as functions, any other string will raise an error | 1580 | // only "cancel" and "join" are registered as functions, any other string will raise an error |
1581 | if (!lua_iscfunction(L, -1)) | 1581 | if (!lua_iscfunction(L, -1)) |
1582 | { | 1582 | { |
1583 | luaL_error(L, "can't index a lane with '%s'", keystr); // doesn't return | 1583 | raise_luaL_error(L, "can't index a lane with '%s'", keystr); |
1584 | } | 1584 | } |
1585 | return 1; | 1585 | return 1; |
1586 | } | 1586 | } |
@@ -1818,7 +1818,7 @@ LUAG_FUNC(configure) | |||
1818 | char const* errmsg{ DeepFactory::PushDeepProxy(DestState{ L }, U->timer_deep, 0, LookupMode::LaneBody) }; // settings M timer_deep | 1818 | char const* errmsg{ DeepFactory::PushDeepProxy(DestState{ L }, U->timer_deep, 0, LookupMode::LaneBody) }; // settings M timer_deep |
1819 | if (errmsg != nullptr) | 1819 | if (errmsg != nullptr) |
1820 | { | 1820 | { |
1821 | return luaL_error(L, errmsg); | 1821 | raise_luaL_error(L, errmsg); |
1822 | } | 1822 | } |
1823 | lua_setfield(L, -2, "timer_gateway"); // settings M | 1823 | lua_setfield(L, -2, "timer_gateway"); // settings M |
1824 | } | 1824 | } |
@@ -1975,10 +1975,10 @@ LANES_API int luaopen_lanes_core( lua_State* L) | |||
1975 | lua_getglobal(L, "jit"); // {jit?} | 1975 | lua_getglobal(L, "jit"); // {jit?} |
1976 | #if LUAJIT_FLAVOR() == 0 | 1976 | #if LUAJIT_FLAVOR() == 0 |
1977 | if (!lua_isnil(L, -1)) | 1977 | if (!lua_isnil(L, -1)) |
1978 | return luaL_error(L, "Lanes is built for PUC-Lua, don't run from LuaJIT"); | 1978 | raise_luaL_error(L, "Lanes is built for PUC-Lua, don't run from LuaJIT"); |
1979 | #else | 1979 | #else |
1980 | if (lua_isnil(L, -1)) | 1980 | if (lua_isnil(L, -1)) |
1981 | return luaL_error(L, "Lanes is built for LuaJIT, don't run from PUC-Lua"); | 1981 | raise_luaL_error(L, "Lanes is built for LuaJIT, don't run from PUC-Lua"); |
1982 | #endif | 1982 | #endif |
1983 | lua_pop(L, 1); // | 1983 | lua_pop(L, 1); // |
1984 | STACK_CHECK(L, 0); | 1984 | STACK_CHECK(L, 0); |
@@ -2012,7 +2012,7 @@ LANES_API int luaopen_lanes_core( lua_State* L) | |||
2012 | int const rc{ luaL_loadfile(L, "lanes.lua") || lua_pcall(L, 0, 1, 0) }; | 2012 | int const rc{ luaL_loadfile(L, "lanes.lua") || lua_pcall(L, 0, 1, 0) }; |
2013 | if (rc != LUA_OK) | 2013 | if (rc != LUA_OK) |
2014 | { | 2014 | { |
2015 | return luaL_error(L, "failed to initialize embedded Lanes"); | 2015 | raise_luaL_error(L, "failed to initialize embedded Lanes"); |
2016 | } | 2016 | } |
2017 | return 1; | 2017 | return 1; |
2018 | } | 2018 | } |
diff --git a/src/linda.cpp b/src/linda.cpp index bc931ac..67a97c2 100644 --- a/src/linda.cpp +++ b/src/linda.cpp | |||
@@ -146,14 +146,14 @@ static void check_key_types(lua_State* L, int start_, int end_) | |||
146 | { | 146 | { |
147 | if (key.equals(L, i)) | 147 | if (key.equals(L, i)) |
148 | { | 148 | { |
149 | luaL_error(L, "argument #%d: can't use %s as a key", i, key.m_debugName); // doesn't return | 149 | raise_luaL_error(L, "argument #%d: can't use %s as a key", i, key.m_debugName); |
150 | break; | 150 | break; |
151 | } | 151 | } |
152 | } | 152 | } |
153 | } | 153 | } |
154 | break; | 154 | break; |
155 | } | 155 | } |
156 | luaL_error(L, "argument #%d: invalid key type (not a boolean, string, number or light userdata)", i); // doesn't return | 156 | raise_luaL_error(L, "argument #%d: invalid key type (not a boolean, string, number or light userdata)", i); |
157 | } | 157 | } |
158 | } | 158 | } |
159 | 159 | ||
@@ -247,7 +247,7 @@ LUAG_FUNC(linda_send) | |||
247 | } | 247 | } |
248 | else | 248 | else |
249 | { | 249 | { |
250 | return luaL_error(L, "no data to send"); | 250 | raise_luaL_error(L, "no data to send"); |
251 | } | 251 | } |
252 | } | 252 | } |
253 | 253 | ||
@@ -331,7 +331,7 @@ LUAG_FUNC(linda_send) | |||
331 | 331 | ||
332 | if (!pushed.has_value()) | 332 | if (!pushed.has_value()) |
333 | { | 333 | { |
334 | luaL_error(L, "tried to copy unsupported types"); // doesn't return | 334 | raise_luaL_error(L, "tried to copy unsupported types"); |
335 | } | 335 | } |
336 | 336 | ||
337 | switch (cancel) | 337 | switch (cancel) |
@@ -410,7 +410,7 @@ LUAG_FUNC(linda_receive) | |||
410 | ++expected_pushed_max; | 410 | ++expected_pushed_max; |
411 | if (expected_pushed_min > expected_pushed_max) | 411 | if (expected_pushed_min > expected_pushed_max) |
412 | { | 412 | { |
413 | return luaL_error(L, "batched min/max error"); | 413 | raise_luaL_error(L, "batched min/max error"); |
414 | } | 414 | } |
415 | } | 415 | } |
416 | else | 416 | else |
@@ -496,7 +496,7 @@ LUAG_FUNC(linda_receive) | |||
496 | 496 | ||
497 | if (!pushed.has_value()) | 497 | if (!pushed.has_value()) |
498 | { | 498 | { |
499 | return luaL_error(L, "tried to copy unsupported types"); | 499 | raise_luaL_error(L, "tried to copy unsupported types"); |
500 | } | 500 | } |
501 | 501 | ||
502 | switch (cancel) | 502 | switch (cancel) |
@@ -716,7 +716,7 @@ LUAG_FUNC(linda_cancel) | |||
716 | } | 716 | } |
717 | else | 717 | else |
718 | { | 718 | { |
719 | return luaL_error(L, "unknown wake hint '%s'", who); | 719 | raise_luaL_error(L, "unknown wake hint '%s'", who); |
720 | } | 720 | } |
721 | return 0; | 721 | return 0; |
722 | } | 722 | } |
@@ -798,7 +798,7 @@ LUAG_FUNC(linda_concat) | |||
798 | } | 798 | } |
799 | if (!atLeastOneLinda) // should not be possible | 799 | if (!atLeastOneLinda) // should not be possible |
800 | { | 800 | { |
801 | return luaL_error(L, "internal error: linda_concat called on non-Linda"); | 801 | raise_luaL_error(L, "internal error: linda_concat called on non-Linda"); |
802 | } | 802 | } |
803 | lua_concat(L, 2); | 803 | lua_concat(L, 2); |
804 | return 1; | 804 | return 1; |
diff --git a/src/macros_and_utils.h b/src/macros_and_utils.h index 068ff26..9bc71e1 100644 --- a/src/macros_and_utils.h +++ b/src/macros_and_utils.h | |||
@@ -17,6 +17,47 @@ extern "C" { | |||
17 | 17 | ||
18 | using namespace std::chrono_literals; | 18 | using namespace std::chrono_literals; |
19 | 19 | ||
20 | // ################################################################################################# | ||
21 | |||
22 | // use this instead of Lua's lua_error | ||
23 | [[noreturn]] static inline void raise_lua_error(lua_State* L_) | ||
24 | { | ||
25 | std::ignore = lua_error(L_); // doesn't return | ||
26 | assert(false); // we should never get here, but i'm paranoid | ||
27 | } | ||
28 | |||
29 | // ################################################################################################# | ||
30 | |||
31 | // use this instead of Lua's luaL_error | ||
32 | template <typename... ARGS> | ||
33 | [[noreturn]] static inline void raise_luaL_error(lua_State* L_, char const* fmt_, ARGS... args_) | ||
34 | { | ||
35 | std::ignore = luaL_error(L_, fmt_, std::forward<ARGS>(args_)...); // doesn't return | ||
36 | assert(false); // we should never get here, but i'm paranoid | ||
37 | } | ||
38 | |||
39 | // ################################################################################################# | ||
40 | |||
41 | // use this instead of Lua's luaL_argerror | ||
42 | template <typename... ARGS> | ||
43 | [[noreturn]] static inline void raise_luaL_argerror(lua_State* L_, int arg_, char const* extramsg_) | ||
44 | { | ||
45 | std::ignore = luaL_argerror(L_, arg_, extramsg_); // doesn't return | ||
46 | assert(false); // we should never get here, but i'm paranoid | ||
47 | } | ||
48 | |||
49 | // ################################################################################################# | ||
50 | |||
51 | // use this instead of Lua's luaL_typeerror | ||
52 | template <typename... ARGS> | ||
53 | [[noreturn]] static inline void raise_luaL_typeerror(lua_State* L_, int arg_, char const* tname_) | ||
54 | { | ||
55 | std::ignore = luaL_typeerror(L_, arg_, tname_); // doesn't return | ||
56 | assert(false); // we should never get here, but i'm paranoid | ||
57 | } | ||
58 | |||
59 | // ################################################################################################# | ||
60 | |||
20 | #define USE_DEBUG_SPEW() 0 | 61 | #define USE_DEBUG_SPEW() 0 |
21 | #if USE_DEBUG_SPEW() | 62 | #if USE_DEBUG_SPEW() |
22 | #define INDENT_BEGIN "%.*s " | 63 | #define INDENT_BEGIN "%.*s " |
@@ -48,7 +89,7 @@ inline void LUA_ASSERT_IMPL(lua_State* L_, bool cond_, char const* file_, size_t | |||
48 | { | 89 | { |
49 | if (!cond_) | 90 | if (!cond_) |
50 | { | 91 | { |
51 | luaL_error(L_, "LUA_ASSERT %s:%llu '%s'", file_, line_, txt_); // doesn't return | 92 | raise_luaL_error(L_, "LUA_ASSERT %s:%llu '%s'", file_, line_, txt_); |
52 | } | 93 | } |
53 | } | 94 | } |
54 | 95 | ||
@@ -82,7 +123,7 @@ class StackChecker | |||
82 | if ((offset_ < 0) || (m_oldtop < 0)) | 123 | if ((offset_ < 0) || (m_oldtop < 0)) |
83 | { | 124 | { |
84 | assert(false); | 125 | assert(false); |
85 | luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%llu", lua_gettop(m_L), offset_, file_, line_); // doesn't return | 126 | raise_luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%llu", lua_gettop(m_L), offset_, file_, line_); |
86 | } | 127 | } |
87 | } | 128 | } |
88 | 129 | ||
@@ -93,7 +134,7 @@ class StackChecker | |||
93 | if (lua_gettop(m_L) != pos_) | 134 | if (lua_gettop(m_L) != pos_) |
94 | { | 135 | { |
95 | assert(false); | 136 | assert(false); |
96 | luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%llu", lua_gettop(m_L), pos_, file_, line_); // doesn't return | 137 | raise_luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%llu", lua_gettop(m_L), pos_, file_, line_); |
97 | } | 138 | } |
98 | } | 139 | } |
99 | 140 | ||
@@ -113,7 +154,7 @@ class StackChecker | |||
113 | if (actual != expected_) | 154 | if (actual != expected_) |
114 | { | 155 | { |
115 | assert(false); | 156 | assert(false); |
116 | luaL_error(m_L, "STACK ASSERT failed (%d not %d): %s:%llu", actual, expected_, file_, line_); // doesn't return | 157 | raise_luaL_error(m_L, "STACK ASSERT failed (%d not %d): %s:%llu", actual, expected_, file_, line_); |
117 | } | 158 | } |
118 | } | 159 | } |
119 | } | 160 | } |
@@ -127,14 +168,18 @@ class StackChecker | |||
127 | 168 | ||
128 | #endif // NDEBUG | 169 | #endif // NDEBUG |
129 | 170 | ||
171 | // ################################################################################################# | ||
172 | |||
130 | inline void STACK_GROW(lua_State* L, int n_) | 173 | inline void STACK_GROW(lua_State* L, int n_) |
131 | { | 174 | { |
132 | if (!lua_checkstack(L, n_)) | 175 | if (!lua_checkstack(L, n_)) |
133 | { | 176 | { |
134 | luaL_error(L, "Cannot grow stack!"); // doesn't return | 177 | raise_luaL_error(L, "Cannot grow stack!"); |
135 | } | 178 | } |
136 | } | 179 | } |
137 | 180 | ||
181 | // ################################################################################################# | ||
182 | |||
138 | #define LUAG_FUNC(func_name) [[nodiscard]] int LG_##func_name(lua_State* L) | 183 | #define LUAG_FUNC(func_name) [[nodiscard]] int LG_##func_name(lua_State* L) |
139 | 184 | ||
140 | // ################################################################################################# | 185 | // ################################################################################################# |
@@ -169,13 +214,6 @@ template <typename T> | |||
169 | 214 | ||
170 | // ################################################################################################# | 215 | // ################################################################################################# |
171 | 216 | ||
172 | // use this instead of Lua's lua_error if possible | ||
173 | [[noreturn]] static inline void raise_lua_error(lua_State* L) | ||
174 | { | ||
175 | std::ignore = lua_error(L); // doesn't return | ||
176 | assert(false); // we should never get here, but i'm paranoid | ||
177 | } | ||
178 | |||
179 | using lua_Duration = std::chrono::template duration<lua_Number>; | 217 | using lua_Duration = std::chrono::template duration<lua_Number>; |
180 | 218 | ||
181 | // ################################################################################################# | 219 | // ################################################################################################# |
@@ -222,7 +260,7 @@ typename T::value_type const& OptionalValue(T const& x_, Ts... args_) | |||
222 | { | 260 | { |
223 | if (!x_.has_value()) | 261 | if (!x_.has_value()) |
224 | { | 262 | { |
225 | luaL_error(std::forward<Ts>(args_)...); // doesn't return | 263 | raise_luaL_error(std::forward<Ts>(args_)...); |
226 | } | 264 | } |
227 | return x_.value(); | 265 | return x_.value(); |
228 | } | 266 | } |
diff --git a/src/state.cpp b/src/state.cpp index 379b63e..9898812 100644 --- a/src/state.cpp +++ b/src/state.cpp | |||
@@ -205,7 +205,7 @@ static void copy_one_time_settings(Universe* U, SourceState L1, DestState L2) | |||
205 | InterCopyContext c{ U, L2, L1, {}, {}, {}, {}, {} }; | 205 | InterCopyContext c{ U, L2, L1, {}, {}, {}, {}, {} }; |
206 | if (c.inter_move(1) != InterCopyResult::Success) // // config | 206 | if (c.inter_move(1) != InterCopyResult::Success) // // config |
207 | { | 207 | { |
208 | luaL_error(L1, "failed to copy settings when loading lanes.core"); // doesn't return | 208 | raise_luaL_error(L1, "failed to copy settings when loading lanes.core"); |
209 | } | 209 | } |
210 | // set L2:_R[kConfigRegKey] = settings | 210 | // set L2:_R[kConfigRegKey] = settings |
211 | kConfigRegKey.setValue(L2, [](lua_State* L) { lua_insert(L, -2); }); // config | 211 | kConfigRegKey.setValue(L2, [](lua_State* L) { lua_insert(L, -2); }); // config |
@@ -229,7 +229,7 @@ void initialize_on_state_create( Universe* U, lua_State* L) | |||
229 | char const* upname = lua_getupvalue(L, -1, 1); // settings on_state_create upval? | 229 | char const* upname = lua_getupvalue(L, -1, 1); // settings on_state_create upval? |
230 | if (upname != nullptr) // should be "" for C functions with upvalues if any | 230 | if (upname != nullptr) // should be "" for C functions with upvalues if any |
231 | { | 231 | { |
232 | (void) luaL_error(L, "on_state_create shouldn't have upvalues"); | 232 | raise_luaL_error(L, "on_state_create shouldn't have upvalues"); |
233 | } | 233 | } |
234 | // remove this C function from the config table so that it doesn't cause problems | 234 | // remove this C function from the config table so that it doesn't cause problems |
235 | // when we transfer the config table in newly created Lua states | 235 | // when we transfer the config table in newly created Lua states |
@@ -274,7 +274,7 @@ lua_State* create_state(Universe* U, lua_State* from_) | |||
274 | 274 | ||
275 | if (L == nullptr) | 275 | if (L == nullptr) |
276 | { | 276 | { |
277 | luaL_error(from_, "luaG_newstate() failed while creating state; out of memory"); // doesn't return | 277 | raise_luaL_error(from_, "luaG_newstate() failed while creating state; out of memory"); |
278 | } | 278 | } |
279 | return L; | 279 | return L; |
280 | } | 280 | } |
@@ -310,7 +310,7 @@ void call_on_state_create(Universe* U, lua_State* L, lua_State* from_, LookupMod | |||
310 | // capture error and raise it in caller state | 310 | // capture error and raise it in caller state |
311 | if (lua_pcall(L, 0, 0, 0) != LUA_OK) | 311 | if (lua_pcall(L, 0, 0, 0) != LUA_OK) |
312 | { | 312 | { |
313 | luaL_error(from_, "on_state_create failed: \"%s\"", lua_isstring(L, -1) ? lua_tostring(L, -1) : lua_typename(L, lua_type(L, -1))); | 313 | raise_luaL_error(from_, "on_state_create failed: \"%s\"", lua_isstring(L, -1) ? lua_tostring(L, -1) : lua_typename(L, lua_type(L, -1))); |
314 | } | 314 | } |
315 | STACK_CHECK(L, 0); | 315 | STACK_CHECK(L, 0); |
316 | } | 316 | } |
diff --git a/src/tools.cpp b/src/tools.cpp index aa8f927..2497ba7 100644 --- a/src/tools.cpp +++ b/src/tools.cpp | |||
@@ -130,7 +130,7 @@ void initialize_allocator_function(Universe* U, lua_State* L) | |||
130 | char const* upname = lua_getupvalue(L, -1, 1); // settings allocator upval? | 130 | char const* upname = lua_getupvalue(L, -1, 1); // settings allocator upval? |
131 | if (upname != nullptr) // should be "" for C functions with upvalues if any | 131 | if (upname != nullptr) // should be "" for C functions with upvalues if any |
132 | { | 132 | { |
133 | (void) luaL_error(L, "config.allocator() shouldn't have upvalues"); | 133 | raise_luaL_error(L, "config.allocator() shouldn't have upvalues"); |
134 | } | 134 | } |
135 | // remove this C function from the config table so that it doesn't cause problems | 135 | // remove this C function from the config table so that it doesn't cause problems |
136 | // when we transfer the config table in newly created Lua states | 136 | // when we transfer the config table in newly created Lua states |
@@ -525,7 +525,7 @@ void populate_func_lookup_table(lua_State* L, int i_, char const* name_) | |||
525 | else | 525 | else |
526 | { | 526 | { |
527 | lua_pop(L, 1); // | 527 | lua_pop(L, 1); // |
528 | luaL_error(L, "unsupported module type %s", lua_typename(L, lua_type(L, in_base))); // doesn't return | 528 | raise_luaL_error(L, "unsupported module type %s", lua_typename(L, lua_type(L, in_base))); |
529 | } | 529 | } |
530 | STACK_CHECK(L, 0); | 530 | STACK_CHECK(L, 0); |
531 | } | 531 | } |
@@ -579,7 +579,7 @@ static constexpr RegistryUniqueKey kMtIdRegKey{ 0xA8895DCF4EC3FE3Cull }; | |||
579 | // function sentinel used to transfer native functions from/to keeper states | 579 | // function sentinel used to transfer native functions from/to keeper states |
580 | [[nodiscard]] static int func_lookup_sentinel(lua_State* L) | 580 | [[nodiscard]] static int func_lookup_sentinel(lua_State* L) |
581 | { | 581 | { |
582 | return luaL_error(L, "function lookup sentinel for %s, should never be called", lua_tostring(L, lua_upvalueindex(1))); | 582 | raise_luaL_error(L, "function lookup sentinel for %s, should never be called", lua_tostring(L, lua_upvalueindex(1))); |
583 | } | 583 | } |
584 | 584 | ||
585 | // ################################################################################################# | 585 | // ################################################################################################# |
@@ -587,7 +587,7 @@ static constexpr RegistryUniqueKey kMtIdRegKey{ 0xA8895DCF4EC3FE3Cull }; | |||
587 | // function sentinel used to transfer native table from/to keeper states | 587 | // function sentinel used to transfer native table from/to keeper states |
588 | [[nodiscard]] static int table_lookup_sentinel(lua_State* L) | 588 | [[nodiscard]] static int table_lookup_sentinel(lua_State* L) |
589 | { | 589 | { |
590 | return luaL_error(L, "table lookup sentinel for %s, should never be called", lua_tostring(L, lua_upvalueindex(1))); | 590 | raise_luaL_error(L, "table lookup sentinel for %s, should never be called", lua_tostring(L, lua_upvalueindex(1))); |
591 | } | 591 | } |
592 | 592 | ||
593 | // ################################################################################################# | 593 | // ################################################################################################# |
@@ -595,7 +595,7 @@ static constexpr RegistryUniqueKey kMtIdRegKey{ 0xA8895DCF4EC3FE3Cull }; | |||
595 | // function sentinel used to transfer cloned full userdata from/to keeper states | 595 | // function sentinel used to transfer cloned full userdata from/to keeper states |
596 | [[nodiscard]] static int userdata_clone_sentinel(lua_State* L) | 596 | [[nodiscard]] static int userdata_clone_sentinel(lua_State* L) |
597 | { | 597 | { |
598 | return luaL_error(L, "userdata clone sentinel for %s, should never be called", lua_tostring(L, lua_upvalueindex(1))); | 598 | raise_luaL_error(L, "userdata clone sentinel for %s, should never be called", lua_tostring(L, lua_upvalueindex(1))); |
599 | } | 599 | } |
600 | 600 | ||
601 | // ################################################################################################# | 601 | // ################################################################################################# |
@@ -663,7 +663,7 @@ static constexpr RegistryUniqueKey kMtIdRegKey{ 0xA8895DCF4EC3FE3Cull }; | |||
663 | gotchaB = ""; | 663 | gotchaB = ""; |
664 | what = (lua_type( L, -1) == LUA_TSTRING) ? lua_tostring( L, -1) : luaL_typename( L, -1); | 664 | what = (lua_type( L, -1) == LUA_TSTRING) ? lua_tostring( L, -1) : luaL_typename( L, -1); |
665 | } | 665 | } |
666 | (void) luaL_error( L, "%s%s '%s' not found in %s origin transfer database.%s", typewhat, gotchaA, what, from ? from : "main", gotchaB); | 666 | raise_luaL_error(L, "%s%s '%s' not found in %s origin transfer database.%s", typewhat, gotchaA, what, from ? from : "main", gotchaB); |
667 | *len_ = 0; | 667 | *len_ = 0; |
668 | return nullptr; | 668 | return nullptr; |
669 | } | 669 | } |
@@ -689,7 +689,7 @@ static constexpr RegistryUniqueKey kMtIdRegKey{ 0xA8895DCF4EC3FE3Cull }; | |||
689 | switch (mode) | 689 | switch (mode) |
690 | { | 690 | { |
691 | default: // shouldn't happen, in theory... | 691 | default: // shouldn't happen, in theory... |
692 | luaL_error(L1, "internal error: unknown lookup mode"); // doesn't return | 692 | raise_luaL_error(L1, "internal error: unknown lookup mode"); |
693 | break; | 693 | break; |
694 | 694 | ||
695 | case LookupMode::ToKeeper: | 695 | case LookupMode::ToKeeper: |
@@ -723,13 +723,13 @@ static constexpr RegistryUniqueKey kMtIdRegKey{ 0xA8895DCF4EC3FE3Cull }; | |||
723 | to = lua_tostring(L2, -1); | 723 | to = lua_tostring(L2, -1); |
724 | lua_pop(L2, 1); // {} t | 724 | lua_pop(L2, 1); // {} t |
725 | // when mode_ == LookupMode::FromKeeper, L is a keeper state and L2 is not, therefore L2 is the state where we want to raise the error | 725 | // when mode_ == LookupMode::FromKeeper, L is a keeper state and L2 is not, therefore L2 is the state where we want to raise the error |
726 | luaL_error( | 726 | raise_luaL_error( |
727 | (mode == LookupMode::FromKeeper) ? L2 : L1 | 727 | (mode == LookupMode::FromKeeper) ? L2 : L1 |
728 | , "INTERNAL ERROR IN %s: table '%s' not found in %s destination transfer database." | 728 | , "INTERNAL ERROR IN %s: table '%s' not found in %s destination transfer database." |
729 | , from ? from : "main" | 729 | , from ? from : "main" |
730 | , fqn | 730 | , fqn |
731 | , to ? to : "main" | 731 | , to ? to : "main" |
732 | ); // doesn't return | 732 | ); |
733 | return false; | 733 | return false; |
734 | } | 734 | } |
735 | lua_remove(L2, -2); // t | 735 | lua_remove(L2, -2); // t |
@@ -936,10 +936,10 @@ static constexpr RegistryUniqueKey kMtIdRegKey{ 0xA8895DCF4EC3FE3Cull }; | |||
936 | */ | 936 | */ |
937 | int luaG_nameof( lua_State* L) | 937 | int luaG_nameof( lua_State* L) |
938 | { | 938 | { |
939 | int what = lua_gettop( L); | 939 | int const what{ lua_gettop(L) }; |
940 | if (what > 1) | 940 | if (what > 1) |
941 | { | 941 | { |
942 | luaL_argerror( L, what, "too many arguments."); | 942 | raise_luaL_argerror( L, what, "too many arguments."); |
943 | } | 943 | } |
944 | 944 | ||
945 | // nil, boolean, light userdata, number and string aren't identifiable | 945 | // nil, boolean, light userdata, number and string aren't identifiable |
@@ -994,7 +994,7 @@ void InterCopyContext::lookup_native_func() const | |||
994 | switch (mode) | 994 | switch (mode) |
995 | { | 995 | { |
996 | default: // shouldn't happen, in theory... | 996 | default: // shouldn't happen, in theory... |
997 | luaL_error(L1, "internal error: unknown lookup mode"); // doesn't return | 997 | raise_luaL_error(L1, "internal error: unknown lookup mode"); |
998 | break; | 998 | break; |
999 | 999 | ||
1000 | case LookupMode::ToKeeper: | 1000 | case LookupMode::ToKeeper: |
@@ -1022,7 +1022,7 @@ void InterCopyContext::lookup_native_func() const | |||
1022 | to = lua_tostring(L2, -1); | 1022 | to = lua_tostring(L2, -1); |
1023 | lua_pop(L2, 1); // {} f | 1023 | lua_pop(L2, 1); // {} f |
1024 | // when mode_ == LookupMode::FromKeeper, L is a keeper state and L2 is not, therefore L2 is the state where we want to raise the error | 1024 | // when mode_ == LookupMode::FromKeeper, L is a keeper state and L2 is not, therefore L2 is the state where we want to raise the error |
1025 | (void) luaL_error( | 1025 | raise_luaL_error( |
1026 | (mode == LookupMode::FromKeeper) ? L2 : L1 | 1026 | (mode == LookupMode::FromKeeper) ? L2 : L1 |
1027 | , "%s%s: function '%s' not found in %s destination transfer database." | 1027 | , "%s%s: function '%s' not found in %s destination transfer database." |
1028 | , lua_isnil(L2, -1) ? "" : "INTERNAL ERROR IN " | 1028 | , lua_isnil(L2, -1) ? "" : "INTERNAL ERROR IN " |
@@ -1127,7 +1127,7 @@ void InterCopyContext::copy_func() const | |||
1127 | B.L = nullptr; | 1127 | B.L = nullptr; |
1128 | if (lua504_dump(L1, buf_writer, &B, 0) != 0) | 1128 | if (lua504_dump(L1, buf_writer, &B, 0) != 0) |
1129 | { | 1129 | { |
1130 | luaL_error(L1, "internal error: function dump failed."); // doesn't return | 1130 | raise_luaL_error(L1, "internal error: function dump failed."); |
1131 | } | 1131 | } |
1132 | 1132 | ||
1133 | // pushes dumped string on 'L1' | 1133 | // pushes dumped string on 'L1' |
@@ -1173,7 +1173,7 @@ void InterCopyContext::copy_func() const | |||
1173 | // "Otherwise, it pushes an error message" | 1173 | // "Otherwise, it pushes an error message" |
1174 | // | 1174 | // |
1175 | STACK_GROW(L1, 1); | 1175 | STACK_GROW(L1, 1); |
1176 | luaL_error(L1, "%s: %s", name, lua_tostring(L2, -1)); // doesn't return | 1176 | raise_luaL_error(L1, "%s: %s", name, lua_tostring(L2, -1)); |
1177 | } | 1177 | } |
1178 | // remove the dumped string | 1178 | // remove the dumped string |
1179 | lua_pop(L1, 1); // ... | 1179 | lua_pop(L1, 1); // ... |
@@ -1217,7 +1217,7 @@ void InterCopyContext::copy_func() const | |||
1217 | c.L1_i = SourceIndex{ lua_gettop(L1) }; | 1217 | c.L1_i = SourceIndex{ lua_gettop(L1) }; |
1218 | if (!c.inter_copy_one()) // ... {cache} ... function <upvalues> | 1218 | if (!c.inter_copy_one()) // ... {cache} ... function <upvalues> |
1219 | { | 1219 | { |
1220 | luaL_error(L1, "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); // doesn't return | 1220 | raise_luaL_error(L1, "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); |
1221 | } | 1221 | } |
1222 | } | 1222 | } |
1223 | lua_pop(L1, 1); // ... _G | 1223 | lua_pop(L1, 1); // ... _G |
@@ -1335,7 +1335,7 @@ void InterCopyContext::copy_cached_func() const | |||
1335 | InterCopyContext const c{ U, L2, L1, L2_cache_i, SourceIndex{ lua_gettop(L1) }, VT::METATABLE, mode, name }; | 1335 | InterCopyContext const c{ U, L2, L1, L2_cache_i, SourceIndex{ lua_gettop(L1) }, VT::METATABLE, mode, name }; |
1336 | if (!c.inter_copy_one()) // _R[kMtIdRegKey] mt? | 1336 | if (!c.inter_copy_one()) // _R[kMtIdRegKey] mt? |
1337 | { | 1337 | { |
1338 | luaL_error(L1, "Error copying a metatable"); // doesn't return | 1338 | raise_luaL_error(L1, "Error copying a metatable"); |
1339 | } | 1339 | } |
1340 | 1340 | ||
1341 | STACK_CHECK(L2, 2); // _R[kMtIdRegKey] mt | 1341 | STACK_CHECK(L2, 2); // _R[kMtIdRegKey] mt |
@@ -1371,7 +1371,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
1371 | { | 1371 | { |
1372 | return; | 1372 | return; |
1373 | // we could raise an error instead of ignoring the table entry, like so: | 1373 | // we could raise an error instead of ignoring the table entry, like so: |
1374 | //luaL_error(L1, "Unable to copy %s key '%s' because of value is of type '%s'", (vt == VT::NORMAL) ? "table" : "metatable", name, luaL_typename(L1, key_i)); // doesn't return | 1374 | //raise_luaL_error(L1, "Unable to copy %s key '%s' because of value is of type '%s'", (vt == VT::NORMAL) ? "table" : "metatable", name, luaL_typename(L1, key_i)); |
1375 | // maybe offer this possibility as a global configuration option, or a linda setting, or as a parameter of the call causing the transfer? | 1375 | // maybe offer this possibility as a global configuration option, or a linda setting, or as a parameter of the call causing the transfer? |
1376 | } | 1376 | } |
1377 | 1377 | ||
@@ -1426,7 +1426,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
1426 | } | 1426 | } |
1427 | else | 1427 | else |
1428 | { | 1428 | { |
1429 | luaL_error(L1, "Unable to copy %s entry '%s' because of value is of type '%s'", (vt == VT::NORMAL) ? "table" : "metatable", valPath, luaL_typename(L1, val_i)); | 1429 | raise_luaL_error(L1, "Unable to copy %s entry '%s' because of value is of type '%s'", (vt == VT::NORMAL) ? "table" : "metatable", valPath, luaL_typename(L1, val_i)); |
1430 | } | 1430 | } |
1431 | } | 1431 | } |
1432 | 1432 | ||
@@ -1504,7 +1504,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
1504 | } | 1504 | } |
1505 | else | 1505 | else |
1506 | { | 1506 | { |
1507 | luaL_error(L1, "Error copying a metatable"); // doesn't return | 1507 | raise_luaL_error(L1, "Error copying a metatable"); |
1508 | } | 1508 | } |
1509 | // first, add the entry in the cache (at this point it is either the actual userdata or the keeper sentinel | 1509 | // first, add the entry in the cache (at this point it is either the actual userdata or the keeper sentinel |
1510 | lua_pushlightuserdata( L2, source); // ... u source | 1510 | lua_pushlightuserdata( L2, source); // ... u source |
@@ -1521,7 +1521,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
1521 | c.L1_i = SourceIndex{ lua_absindex(L1, -1) }; | 1521 | c.L1_i = SourceIndex{ lua_absindex(L1, -1) }; |
1522 | if (!c.inter_copy_one()) // ... u uv | 1522 | if (!c.inter_copy_one()) // ... u uv |
1523 | { | 1523 | { |
1524 | luaL_error(L1, "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); // doesn't return | 1524 | raise_luaL_error(L1, "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); |
1525 | } | 1525 | } |
1526 | lua_pop(L1, 1); // ... mt __lanesclone [uv]* | 1526 | lua_pop(L1, 1); // ... mt __lanesclone [uv]* |
1527 | // this pops the value from the stack | 1527 | // this pops the value from the stack |
@@ -1591,7 +1591,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
1591 | } | 1591 | } |
1592 | else // raise an error | 1592 | else // raise an error |
1593 | { | 1593 | { |
1594 | luaL_error(L1, "can't copy non-deep full userdata across lanes"); // doesn't return | 1594 | raise_luaL_error(L1, "can't copy non-deep full userdata across lanes"); |
1595 | } | 1595 | } |
1596 | 1596 | ||
1597 | STACK_CHECK(L2, 1); | 1597 | STACK_CHECK(L2, 1); |
@@ -1667,7 +1667,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
1667 | c.L1_i = SourceIndex{ lua_absindex(L1, -1) }; | 1667 | c.L1_i = SourceIndex{ lua_absindex(L1, -1) }; |
1668 | if (!c.inter_copy_one()) // ... mt u uv | 1668 | if (!c.inter_copy_one()) // ... mt u uv |
1669 | { | 1669 | { |
1670 | luaL_error(L1, "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); // doesn't return | 1670 | raise_luaL_error(L1, "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); |
1671 | } | 1671 | } |
1672 | lua_pop(L1, 1); // ... u [uv]* | 1672 | lua_pop(L1, 1); // ... u [uv]* |
1673 | // this pops the value from the stack | 1673 | // this pops the value from the stack |
@@ -2010,7 +2010,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
2010 | // raise the error when copying from lane to lane, else just leave it on the stack to be raised later | 2010 | // raise the error when copying from lane to lane, else just leave it on the stack to be raised later |
2011 | if (mode == LookupMode::LaneBody) | 2011 | if (mode == LookupMode::LaneBody) |
2012 | { | 2012 | { |
2013 | lua_error(L1); // doesn't return | 2013 | raise_lua_error(L1); |
2014 | } | 2014 | } |
2015 | return InterCopyResult::Error; | 2015 | return InterCopyResult::Error; |
2016 | } | 2016 | } |
@@ -2057,7 +2057,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
2057 | // raise the error when copying from lane to lane, else just leave it on the stack to be raised later | 2057 | // raise the error when copying from lane to lane, else just leave it on the stack to be raised later |
2058 | if (mode == LookupMode::LaneBody) | 2058 | if (mode == LookupMode::LaneBody) |
2059 | { | 2059 | { |
2060 | lua_error(L1); // doesn't return | 2060 | raise_lua_error(L1); |
2061 | } | 2061 | } |
2062 | lua_pop(L1, 1); | 2062 | lua_pop(L1, 1); |
2063 | break; | 2063 | break; |