File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5656#include < boost/type_traits.hpp>
5757#include < lua.hpp>
5858
59+ // Set the older gcc define for tsan if clang or modern gcc tell us we have tsan.
60+ #if defined(__has_feature)
61+ #if __has_feature(thread_sanitizer)
62+ #define __SANITIZE_THREAD__ 1
63+ #endif
64+ #endif
65+
5966#if defined(_MSC_VER) && _MSC_VER < 1900
6067# include " misc/exception.hpp"
6168#endif
@@ -98,7 +105,17 @@ class LuaContext {
98105 explicit LuaContext (bool openDefaultLibs = true )
99106 {
100107 // luaL_newstate can return null if allocation failed
101- mState = luaL_newstate ();
108+ #if defined(__SANITIZE_THREAD__) && defined(LUAJIT_VERSION) && defined(__aarch64__)
109+ // on arm64 with luajit and TSAN, allocation may fail spuriously, so keep retrying a bit
110+ int tries = 100 ;
111+ #else
112+ int tries = 1 ;
113+ #endif
114+ for (; tries > 0 ; tries--) {
115+ mState = luaL_newstate ();
116+ if (mState != nullptr ) { break ; }
117+ }
118+ #undef RETRIES
102119 if (mState == nullptr )
103120 throw std::bad_alloc ();
104121
You can’t perform that action at this time.
0 commit comments