Skip to content

Commit 1cce2e6

Browse files
committed
allow disabling thread usage
1 parent 3c89275 commit 1cce2e6

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

src/asar/CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ option(ASAR_GEN_EXE "Build Asar standalone application" ON)
77
option(ASAR_GEN_DLL "Build Asar shared library" ON)
88
option(ASAR_COVERAGE "Build Asar with coverage tracking support" ON)
99
option(ASAR_GEN_LIB "Build Asar static library" ON)
10+
option(ASAR_USE_THREADS "Run Asar in a new thread to alleviate stack usage problems" ON)
1011
if (MSVC)
1112
message(STATUS "In MSVC you can override MSVC_LIB_TYPE, valid values are D for dynamic and T for static")
1213
endif()
@@ -92,9 +93,11 @@ macro(set_asar_shared_properties target msvc_lib_type_param enable_sanitizer)
9293
target_compile_definitions(${target} PRIVATE "linux")
9394
target_compile_definitions(${target} PRIVATE "stricmp=strcasecmp")
9495

95-
set(THREADS_PREFER_PTHREAD_FLAG ON)
96-
find_package(Threads REQUIRED)
97-
target_link_libraries(${target} PRIVATE Threads::Threads)
96+
if(ASAR_USE_THREADS)
97+
set(THREADS_PREFER_PTHREAD_FLAG ON)
98+
find_package(Threads REQUIRED)
99+
target_link_libraries(${target} PRIVATE Threads::Threads)
100+
endif()
98101
endif()
99102

100103

@@ -136,6 +139,10 @@ macro(set_asar_shared_properties target msvc_lib_type_param enable_sanitizer)
136139
# for some reason this isn't available on MSVC?
137140
target_compile_features(${target} PRIVATE c_std_99)
138141
endif()
142+
143+
if(NOT(ASAR_USE_THREADS))
144+
target_compile_definitions(${target} PRIVATE NO_USE_THREADS)
145+
endif()
139146
endmacro()
140147

141148

src/asar/asar.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,12 @@ const char* get_current_block();
181181
const char* get_previous_file_name();
182182
int get_previous_file_line_no();
183183

184+
#if !defined(NO_USE_THREADS) && !defined(RUN_VIA_THREAD)
184185
// RPG Hacker: This is currently disabled for debug builds, because it causes random crashes
185186
// when used in combination with -fsanitize=address.
186-
#if defined(_WIN32) && defined(NDEBUG)
187-
# define RUN_VIA_FIBER
188-
#else
189-
# define RUN_VIA_THREAD
187+
# if defined(_WIN32) && defined(NDEBUG)
188+
# define RUN_VIA_FIBER
189+
# else
190+
# define RUN_VIA_THREAD
191+
# endif
190192
#endif

src/asar/interface-cli.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -545,19 +545,23 @@ int main(int argc, const char * argv[])
545545

546546
auto execute_patch = [&]()
547547
{
548-
for (pass=0;pass<3;pass++)
549-
{
550-
//pass 1: find which bank all labels are in, for label optimizations
551-
// freespaces are listed as above 0xFFFFFF, to find if it's in the ROM or if it's dynamic
552-
//pass 2: find where exactly all labels are
553-
//pass 3: assemble it all
554-
initstuff();
555-
assemblefile(asmname);
556-
// RPG Hacker: Necessary, because finishpass() can throws warning and errors.
557-
callstack_push cs_push(callstack_entry_type::FILE, filesystem->create_absolute_path(nullptr, asmname));
558-
finishpass();
548+
try {
549+
for (pass=0;pass<3;pass++)
550+
{
551+
//pass 1: find which bank all labels are in, for label optimizations
552+
// freespaces are listed as above 0xFFFFFF, to find if it's in the ROM or if it's dynamic
553+
//pass 2: find where exactly all labels are
554+
//pass 3: assemble it all
555+
initstuff();
556+
assemblefile(asmname);
557+
// RPG Hacker: Necessary, because finishpass() can throws warning and errors.
558+
callstack_push cs_push(callstack_entry_type::FILE, filesystem->create_absolute_path(nullptr, asmname));
559+
finishpass();
560+
}
561+
return true;
562+
} catch(errfatal&) {
563+
return false;
559564
}
560-
return true;
561565
};
562566
#if defined(RUN_VIA_FIBER)
563567
run_as_fiber(execute_patch);

0 commit comments

Comments
 (0)