diff options
Diffstat (limited to '')
-rw-r--r-- | src/cancel.cpp | 14 | ||||
-rw-r--r-- | src/cancel.h | 8 | ||||
-rw-r--r-- | src/deep.cpp | 6 | ||||
-rw-r--r-- | src/keeper.cpp | 9 | ||||
-rw-r--r-- | src/lanes.cpp | 10 | ||||
-rw-r--r-- | src/linda.cpp | 8 | ||||
-rw-r--r-- | src/macros_and_utils.h | 22 | ||||
-rw-r--r-- | src/state.cpp | 2 |
8 files changed, 44 insertions, 35 deletions
diff --git a/src/cancel.cpp b/src/cancel.cpp index 73e50f5..c0867a9 100644 --- a/src/cancel.cpp +++ b/src/cancel.cpp | |||
@@ -50,7 +50,7 @@ THE SOFTWARE. | |||
50 | * Called by cancellation hooks and/or pending Linda operations (because then | 50 | * Called by cancellation hooks and/or pending Linda operations (because then |
51 | * the check won't affect performance). | 51 | * the check won't affect performance). |
52 | * | 52 | * |
53 | * Returns CANCEL_SOFT/HARD if any locks are to be exited, and 'cancel_error()' called, | 53 | * Returns CANCEL_SOFT/HARD if any locks are to be exited, and 'raise_cancel_error()' called, |
54 | * to make execution of the lane end. | 54 | * to make execution of the lane end. |
55 | */ | 55 | */ |
56 | static inline CancelRequest cancel_test(lua_State* L) | 56 | static inline CancelRequest cancel_test(lua_State* L) |
@@ -78,13 +78,13 @@ LUAG_FUNC( cancel_test) | |||
78 | // ################################################################################################ | 78 | // ################################################################################################ |
79 | // ################################################################################################ | 79 | // ################################################################################################ |
80 | 80 | ||
81 | static void cancel_hook( lua_State* L, [[maybe_unused]] lua_Debug* ar) | 81 | static void cancel_hook(lua_State* L, [[maybe_unused]] lua_Debug* ar) |
82 | { | 82 | { |
83 | DEBUGSPEW_CODE( fprintf( stderr, "cancel_hook\n")); | 83 | DEBUGSPEW_CODE(fprintf(stderr, "cancel_hook\n")); |
84 | if (cancel_test(L) != CancelRequest::None) | 84 | if (cancel_test(L) != CancelRequest::None) |
85 | { | 85 | { |
86 | lua_sethook( L, nullptr, 0, 0); | 86 | lua_sethook(L, nullptr, 0, 0); |
87 | cancel_error( L); | 87 | raise_cancel_error(L); |
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
@@ -158,7 +158,7 @@ static CancelResult thread_cancel_hard(lua_State* L, Lane* s, double secs_, bool | |||
158 | result = THREAD_WAIT(&s->thread, waitkill_timeout_, &s->done_signal, &s->done_lock, &s->status) ? CancelResult::Killed : CancelResult::Timeout; | 158 | result = THREAD_WAIT(&s->thread, waitkill_timeout_, &s->done_signal, &s->done_lock, &s->status) ? CancelResult::Killed : CancelResult::Timeout; |
159 | if (result == CancelResult::Timeout) | 159 | if (result == CancelResult::Timeout) |
160 | { | 160 | { |
161 | (void) luaL_error( L, "force-killed lane failed to terminate within %f second%s", waitkill_timeout_, waitkill_timeout_ > 1 ? "s" : ""); | 161 | std::ignore = luaL_error( L, "force-killed lane failed to terminate within %f second%s", waitkill_timeout_, waitkill_timeout_ > 1 ? "s" : ""); |
162 | } | 162 | } |
163 | #else | 163 | #else |
164 | (void) waitkill_timeout_; // unused | 164 | (void) waitkill_timeout_; // unused |
@@ -238,7 +238,7 @@ static CancelOp which_op( lua_State* L, int idx_) | |||
238 | lua_remove( L, idx_); // argument is processed, remove it | 238 | lua_remove( L, idx_); // argument is processed, remove it |
239 | if( op == CO_Invalid) | 239 | if( op == CO_Invalid) |
240 | { | 240 | { |
241 | luaL_error( L, "invalid hook option %s", str); | 241 | std::ignore = luaL_error( L, "invalid hook option %s", str); |
242 | } | 242 | } |
243 | return op; | 243 | return op; |
244 | } | 244 | } |
diff --git a/src/cancel.h b/src/cancel.h index 9a20774..9299ae1 100644 --- a/src/cancel.h +++ b/src/cancel.h | |||
@@ -46,18 +46,18 @@ enum CancelOp | |||
46 | }; | 46 | }; |
47 | 47 | ||
48 | // crc64/we of string "CANCEL_ERROR" generated at http://www.nitrxgen.net/hashgen/ | 48 | // crc64/we of string "CANCEL_ERROR" generated at http://www.nitrxgen.net/hashgen/ |
49 | static constexpr UniqueKey CANCEL_ERROR{ 0xe97d41626cc97577ull }; // 'cancel_error' sentinel | 49 | static constexpr UniqueKey CANCEL_ERROR{ 0xe97d41626cc97577ull }; // 'raise_cancel_error' sentinel |
50 | 50 | ||
51 | // crc64/we of string "CANCEL_TEST_KEY" generated at http://www.nitrxgen.net/hashgen/ | 51 | // crc64/we of string "CANCEL_TEST_KEY" generated at http://www.nitrxgen.net/hashgen/ |
52 | static constexpr UniqueKey CANCEL_TEST_KEY{ 0xe66f5960c57d133aull }; // used as registry key | 52 | static constexpr UniqueKey CANCEL_TEST_KEY{ 0xe66f5960c57d133aull }; // used as registry key |
53 | 53 | ||
54 | CancelResult thread_cancel(lua_State* L, Lane* s, CancelOp op_, double secs_, bool force_, double waitkill_timeout_); | 54 | CancelResult thread_cancel(lua_State* L, Lane* s, CancelOp op_, double secs_, bool force_, double waitkill_timeout_); |
55 | 55 | ||
56 | static inline int cancel_error( lua_State* L) | 56 | [[noreturn]] static inline void raise_cancel_error(lua_State* L) |
57 | { | 57 | { |
58 | STACK_GROW( L, 1); | 58 | STACK_GROW(L, 1); |
59 | CANCEL_ERROR.push(L); // special error value | 59 | CANCEL_ERROR.push(L); // special error value |
60 | return lua_error( L); // doesn't return | 60 | raise_lua_error(L); // doesn't return |
61 | } | 61 | } |
62 | 62 | ||
63 | // ################################################################################################ | 63 | // ################################################################################################ |
diff --git a/src/deep.cpp b/src/deep.cpp index f59e051..74ecfb8 100644 --- a/src/deep.cpp +++ b/src/deep.cpp | |||
@@ -184,7 +184,7 @@ static int deep_userdata_gc( lua_State* L) | |||
184 | // top was set to 0, then userdata was pushed. "delete" might want to pop the userdata (we don't care), but should not push anything! | 184 | // top was set to 0, then userdata was pushed. "delete" might want to pop the userdata (we don't care), but should not push anything! |
185 | if ( lua_gettop( L) > 1) | 185 | if ( lua_gettop( L) > 1) |
186 | { | 186 | { |
187 | luaL_error( L, "Bad idfunc(eDO_delete): should not push anything"); | 187 | return luaL_error( L, "Bad idfunc(eDO_delete): should not push anything"); |
188 | } | 188 | } |
189 | } | 189 | } |
190 | *proxy = nullptr; // make sure we don't use it any more, just in case | 190 | *proxy = nullptr; // make sure we don't use it any more, just in case |
@@ -478,8 +478,8 @@ bool copydeep(Universe* U, lua_State* L2, int L2_cache_i, lua_State* L, int i, L | |||
478 | if (errmsg != nullptr) | 478 | if (errmsg != nullptr) |
479 | { | 479 | { |
480 | // raise the error in the proper state (not the keeper) | 480 | // raise the error in the proper state (not the keeper) |
481 | lua_State* errL = (mode_ == eLM_FromKeeper) ? L2 : L; | 481 | lua_State* const errL { (mode_ == eLM_FromKeeper) ? L2 : L }; |
482 | luaL_error( errL, errmsg); | 482 | std::ignore = luaL_error(errL, errmsg); |
483 | } | 483 | } |
484 | return true; | 484 | return true; |
485 | } \ No newline at end of file | 485 | } \ No newline at end of file |
diff --git a/src/keeper.cpp b/src/keeper.cpp index cb2b0a9..1919a68 100644 --- a/src/keeper.cpp +++ b/src/keeper.cpp | |||
@@ -655,7 +655,7 @@ void init_keepers(Universe* U, lua_State* L) | |||
655 | lua_pop(L, 1); // | 655 | lua_pop(L, 1); // |
656 | if (nb_keepers < 1) | 656 | if (nb_keepers < 1) |
657 | { | 657 | { |
658 | (void) luaL_error(L, "Bad number of keepers (%d)", nb_keepers); | 658 | std::ignore = luaL_error(L, "Bad number of keepers (%d)", nb_keepers); |
659 | } | 659 | } |
660 | 660 | ||
661 | // Keepers contains an array of 1 Keeper, adjust for the actual number of keeper states | 661 | // Keepers contains an array of 1 Keeper, adjust for the actual number of keeper states |
@@ -664,8 +664,7 @@ void init_keepers(Universe* U, lua_State* L) | |||
664 | U->keepers = static_cast<Keepers*>(U->internal_allocator.alloc(bytes)); | 664 | U->keepers = static_cast<Keepers*>(U->internal_allocator.alloc(bytes)); |
665 | if (U->keepers == nullptr) | 665 | if (U->keepers == nullptr) |
666 | { | 666 | { |
667 | (void) luaL_error(L, "init_keepers() failed while creating keeper array; out of memory"); | 667 | std::ignore = luaL_error(L, "init_keepers() failed while creating keeper array; out of memory"); |
668 | return; | ||
669 | } | 668 | } |
670 | memset(U->keepers, 0, bytes); | 669 | memset(U->keepers, 0, bytes); |
671 | U->keepers->nb_keepers = nb_keepers; | 670 | U->keepers->nb_keepers = nb_keepers; |
@@ -677,7 +676,6 @@ void init_keepers(Universe* U, lua_State* L) | |||
677 | if (K == nullptr) | 676 | if (K == nullptr) |
678 | { | 677 | { |
679 | std::ignore = luaL_error(L, "init_keepers() failed while creating keeper states; out of memory"); | 678 | std::ignore = luaL_error(L, "init_keepers() failed while creating keeper states; out of memory"); |
680 | return; | ||
681 | } | 679 | } |
682 | 680 | ||
683 | U->keepers->keeper_array[i].L = K; | 681 | U->keepers->keeper_array[i].L = K; |
@@ -709,8 +707,7 @@ void init_keepers(Universe* U, lua_State* L) | |||
709 | { | 707 | { |
710 | // if something went wrong, the error message is at the top of the stack | 708 | // if something went wrong, the error message is at the top of the stack |
711 | lua_remove(L, -2); // error_msg | 709 | lua_remove(L, -2); // error_msg |
712 | (void) lua_error(L); | 710 | raise_lua_error(L); |
713 | return; | ||
714 | } | 711 | } |
715 | } | 712 | } |
716 | lua_pop(L, 1); // | 713 | lua_pop(L, 1); // |
diff --git a/src/lanes.cpp b/src/lanes.cpp index a378a88..2f17e6e 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp | |||
@@ -1110,7 +1110,7 @@ LUAG_FUNC( lane_new) | |||
1110 | if( lua_isnil( L2, -1)) | 1110 | if( lua_isnil( L2, -1)) |
1111 | { | 1111 | { |
1112 | lua_pop( L2, 1); // | 1112 | lua_pop( L2, 1); // |
1113 | luaL_error( L, "cannot pre-require modules without loading 'package' library first"); | 1113 | return luaL_error( L, "cannot pre-require modules without loading 'package' library first"); |
1114 | } | 1114 | } |
1115 | else | 1115 | else |
1116 | { | 1116 | { |
@@ -1119,7 +1119,7 @@ LUAG_FUNC( lane_new) | |||
1119 | { | 1119 | { |
1120 | // propagate error to main state if any | 1120 | // propagate error to main state if any |
1121 | luaG_inter_move( U, L2, L, 1, eLM_LaneBody); // func libs priority globals package required gc_cb [... args ...] n "modname" error | 1121 | luaG_inter_move( U, L2, L, 1, eLM_LaneBody); // func libs priority globals package required gc_cb [... args ...] n "modname" error |
1122 | return lua_error( L); | 1122 | raise_lua_error(L); |
1123 | } | 1123 | } |
1124 | // after requiring the module, register the functions it exported in our name<->function database | 1124 | // after requiring the module, register the functions it exported in our name<->function database |
1125 | populate_func_lookup_table( L2, -1, name); | 1125 | populate_func_lookup_table( L2, -1, name); |
@@ -1538,11 +1538,9 @@ LUAG_FUNC( thread_index) | |||
1538 | lua_pushliteral( L, "Unexpected status: "); | 1538 | lua_pushliteral( L, "Unexpected status: "); |
1539 | lua_pushstring( L, thread_status_string( s)); | 1539 | lua_pushstring( L, thread_status_string( s)); |
1540 | lua_concat( L, 2); | 1540 | lua_concat( L, 2); |
1541 | lua_error( L); | 1541 | raise_lua_error(L); |
1542 | break; | ||
1543 | } | 1542 | } |
1544 | // fall through if we are killed, as we got nil, "killed" on the stack | 1543 | [[fallthrough]]; // fall through if we are killed, as we got nil, "killed" on the stack |
1545 | [[fallthrough]]; | ||
1546 | 1544 | ||
1547 | case DONE: // got regular return values | 1545 | case DONE: // got regular return values |
1548 | { | 1546 | { |
diff --git a/src/linda.cpp b/src/linda.cpp index 2830593..e1633b0 100644 --- a/src/linda.cpp +++ b/src/linda.cpp | |||
@@ -165,7 +165,7 @@ static void check_key_types(lua_State* L, int start_, int end_) | |||
165 | { | 165 | { |
166 | continue; | 166 | continue; |
167 | } | 167 | } |
168 | (void) luaL_error( L, "argument #%d: invalid key type (not a boolean, string, number or light userdata)", i); | 168 | std::ignore = luaL_error(L, "argument #%d: invalid key type (not a boolean, string, number or light userdata)", i); |
169 | } | 169 | } |
170 | } | 170 | } |
171 | 171 | ||
@@ -192,7 +192,7 @@ LUAG_FUNC(linda_protected_call) | |||
192 | // if there was an error, forward it | 192 | // if there was an error, forward it |
193 | if( rc != LUA_OK) | 193 | if( rc != LUA_OK) |
194 | { | 194 | { |
195 | return lua_error( L); | 195 | raise_lua_error(L); |
196 | } | 196 | } |
197 | // return whatever the actual operation provided | 197 | // return whatever the actual operation provided |
198 | return lua_gettop( L); | 198 | return lua_gettop( L); |
@@ -339,7 +339,7 @@ LUAG_FUNC( linda_send) | |||
339 | 339 | ||
340 | case CancelRequest::Hard: | 340 | case CancelRequest::Hard: |
341 | // raise an error interrupting execution only in case of hard cancel | 341 | // raise an error interrupting execution only in case of hard cancel |
342 | return cancel_error( L); // raises an error and doesn't return | 342 | raise_cancel_error(L); // raises an error and doesn't return |
343 | 343 | ||
344 | default: | 344 | default: |
345 | lua_pushboolean( L, ret); // true (success) or false (timeout) | 345 | lua_pushboolean( L, ret); // true (success) or false (timeout) |
@@ -494,7 +494,7 @@ LUAG_FUNC( linda_receive) | |||
494 | 494 | ||
495 | case CancelRequest::Hard: | 495 | case CancelRequest::Hard: |
496 | // raise an error interrupting execution only in case of hard cancel | 496 | // raise an error interrupting execution only in case of hard cancel |
497 | return cancel_error( L); // raises an error and doesn't return | 497 | raise_cancel_error(L); // raises an error and doesn't return |
498 | 498 | ||
499 | default: | 499 | default: |
500 | return pushed; | 500 | return pushed; |
diff --git a/src/macros_and_utils.h b/src/macros_and_utils.h index 63bc8d1..31027d6 100644 --- a/src/macros_and_utils.h +++ b/src/macros_and_utils.h | |||
@@ -11,6 +11,7 @@ extern "C" { | |||
11 | #endif // __cplusplus | 11 | #endif // __cplusplus |
12 | 12 | ||
13 | #include <cassert> | 13 | #include <cassert> |
14 | #include <tuple> | ||
14 | #include <type_traits> | 15 | #include <type_traits> |
15 | 16 | ||
16 | #define USE_DEBUG_SPEW() 0 | 17 | #define USE_DEBUG_SPEW() 0 |
@@ -71,7 +72,7 @@ class StackChecker | |||
71 | if ((offset_ < 0) || (m_oldtop < 0)) | 72 | if ((offset_ < 0) || (m_oldtop < 0)) |
72 | { | 73 | { |
73 | assert(false); | 74 | assert(false); |
74 | (void) luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%d", lua_gettop(m_L), offset_, file_, line_); | 75 | std::ignore = luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%d", lua_gettop(m_L), offset_, file_, line_); |
75 | } | 76 | } |
76 | } | 77 | } |
77 | 78 | ||
@@ -82,7 +83,7 @@ class StackChecker | |||
82 | if (lua_gettop(m_L) != pos_) | 83 | if (lua_gettop(m_L) != pos_) |
83 | { | 84 | { |
84 | assert(false); | 85 | assert(false); |
85 | (void) luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%d", lua_gettop(m_L), pos_, file_, line_); | 86 | std::ignore = luaL_error(m_L, "STACK INIT ASSERT failed (%d not %d): %s:%d", lua_gettop(m_L), pos_, file_, line_); |
86 | } | 87 | } |
87 | } | 88 | } |
88 | 89 | ||
@@ -102,7 +103,7 @@ class StackChecker | |||
102 | if (actual != expected_) | 103 | if (actual != expected_) |
103 | { | 104 | { |
104 | assert(false); | 105 | assert(false); |
105 | luaL_error(m_L, "STACK ASSERT failed (%d not %d): %s:%d", actual, expected_, file_, line_); | 106 | std::ignore = luaL_error(m_L, "STACK ASSERT failed (%d not %d): %s:%d", actual, expected_, file_, line_); |
106 | } | 107 | } |
107 | } | 108 | } |
108 | } | 109 | } |
@@ -121,11 +122,15 @@ class StackChecker | |||
121 | inline void STACK_GROW(lua_State* L, int n_) | 122 | inline void STACK_GROW(lua_State* L, int n_) |
122 | { | 123 | { |
123 | if (!lua_checkstack(L, n_)) | 124 | if (!lua_checkstack(L, n_)) |
124 | luaL_error(L, "Cannot grow stack!"); | 125 | { |
126 | std::ignore = luaL_error(L, "Cannot grow stack!"); | ||
127 | } | ||
125 | } | 128 | } |
126 | 129 | ||
127 | #define LUAG_FUNC( func_name) int LG_##func_name( lua_State* L) | 130 | #define LUAG_FUNC( func_name) int LG_##func_name( lua_State* L) |
128 | 131 | ||
132 | // ################################################################################################# | ||
133 | |||
129 | // a small helper to extract a full userdata pointer from the stack in a safe way | 134 | // a small helper to extract a full userdata pointer from the stack in a safe way |
130 | template<typename T> | 135 | template<typename T> |
131 | T* lua_tofulluserdata(lua_State* L, int index_) | 136 | T* lua_tofulluserdata(lua_State* L, int index_) |
@@ -153,3 +158,12 @@ T* lua_newuserdatauv(lua_State* L, int nuvalue_) | |||
153 | { | 158 | { |
154 | return static_cast<T*>(lua_newuserdatauv(L, sizeof(T), nuvalue_)); | 159 | return static_cast<T*>(lua_newuserdatauv(L, sizeof(T), nuvalue_)); |
155 | } | 160 | } |
161 | |||
162 | // ################################################################################################# | ||
163 | |||
164 | // use this instead of Lua's lua_error if possible | ||
165 | [[noreturn]] static inline void raise_lua_error(lua_State* L) | ||
166 | { | ||
167 | std::ignore = lua_error(L); // doesn't return | ||
168 | assert(false); // we should never get here, but i'm paranoid | ||
169 | } | ||
diff --git a/src/state.cpp b/src/state.cpp index 817d5b4..b52bdb5 100644 --- a/src/state.cpp +++ b/src/state.cpp | |||
@@ -82,7 +82,7 @@ static int luaG_new_require( lua_State* L) | |||
82 | 82 | ||
83 | if( rc != LUA_OK) // LUA_ERRRUN / LUA_ERRMEM ? | 83 | if( rc != LUA_OK) // LUA_ERRRUN / LUA_ERRMEM ? |
84 | { | 84 | { |
85 | return lua_error( L); | 85 | raise_lua_error(L); |
86 | } | 86 | } |
87 | // should be 1 for Lua <= 5.3, 1 or 2 starting with Lua 5.4 | 87 | // should be 1 for Lua <= 5.3, 1 or 2 starting with Lua 5.4 |
88 | return lua_gettop(L); // result(s) | 88 | return lua_gettop(L); // result(s) |