From 5e566f8cf633882cd153731944cba9f5503cfb0a Mon Sep 17 00:00:00 2001 From: Li Jin Date: Tue, 16 Sep 2025 09:15:51 +0800 Subject: Increased call stack size. --- src/yue.cpp | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/yue.cpp b/src/yue.cpp index fc57767..2c3a469 100644 --- a/src/yue.cpp +++ b/src/yue.cpp @@ -30,6 +30,38 @@ using namespace std::chrono_literals; #include "ghc/fs_std.hpp" #include "linenoise.hpp" +#if __has_include() +#include +template +std::future async(const std::function& f) { + using Fn = std::packaged_task; + auto task = new Fn(f); + std::future fut = task->get_future(); + + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setstacksize(&attr, 8 * 1024 * 1024); + + pthread_t th; + pthread_create(&th, &attr, + [](void* p)->void* { + std::unique_ptr fn(static_cast(p)); + (*fn)(); + return nullptr; + }, + task); + pthread_attr_destroy(&attr); + pthread_detach(th); + return fut; +} +#else +template +std::future async(const std::function& f) { + // fallback: ignore stack size + return std::async(std::launch::async, f); +} +#endif + #if not(defined YUE_NO_MACRO && defined YUE_COMPILER_ONLY) #define _DEFER(code, line) std::shared_ptr _defer_##line(nullptr, [&](auto) { \ code; \ @@ -699,7 +731,7 @@ int main(int narg, const char** args) { } std::list> results; for (const auto& file : files) { - auto task = std::async(std::launch::async, [=]() { + auto task = async([=]() { #ifndef YUE_COMPILER_ONLY return compileFile(fs::absolute(file.first), config, fullWorkPath, fullTargetPath, minify, rewrite); #else @@ -737,7 +769,7 @@ int main(int narg, const char** args) { #endif // YUE_NO_WATCHER std::list>> results; for (const auto& file : files) { - auto task = std::async(std::launch::async, [=]() { + auto task = async>([=]() { std::ifstream input(file.first, std::ios::in); if (input) { std::string s( -- cgit v1.2.3-55-g6feb