From e8b55acd232ceb693d546264966b84b2c9dc1c86 Mon Sep 17 00:00:00 2001 From: ds Date: Mon, 16 Nov 2020 13:11:26 +0300 Subject: [PATCH] Do not keep log file opened while game process active. Rename actions workflow. Fixed mingw-w64 stdcall handling. --- .github/workflows/build.yml | 2 +- ext/crlib/cr-logger.h | 39 +++++++++++++++++++++++++------------ meson.build | 2 +- src/linkage.cpp | 2 +- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ad3cd93..e3b4ce5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: YaPB Build +name: YaPB on: [push, pull_request] diff --git a/ext/crlib/cr-logger.h b/ext/crlib/cr-logger.h index 2f5893b..d320e8f 100644 --- a/ext/crlib/cr-logger.h +++ b/ext/crlib/cr-logger.h @@ -19,21 +19,38 @@ public: using PrintFunction = Lambda ; private: - File handle_; + String filename_; PrintFunction printFun_; public: SimpleLogger () = default; + ~SimpleLogger () = default; - ~SimpleLogger () { - handle_.close (); - } +public: + class LogFile final { + private: + File handle_; + + public: + LogFile (StringRef filename) { + handle_.open (filename, "at"); + } + + ~LogFile () { + handle_.close (); + } + + public: + void print (StringRef msg) { + if (!handle_) { + return; + } + handle_.puts (msg.chars ()); + } + }; private: void logToFile (const char *level, const char *msg) { - if (!handle_) { - return; - } time_t ticks = time (&ticks); tm timeinfo {}; @@ -46,7 +63,8 @@ private: auto timebuf = strings.chars (); strftime (timebuf, StringBuffer::StaticBufferSize, "%Y-%m-%d %H:%M:%S", &timeinfo); - handle_.puts ("%s (%s): %s\n", timebuf, level, msg); + LogFile lf (filename_); + lf.print (strings.format ("%s (%s): %s\n", timebuf, level, msg)); } public: @@ -83,11 +101,8 @@ public: public: void initialize (StringRef filename, PrintFunction printFunction) { - if (handle_) { - handle_.close (); - } printFun_ = cr::move (printFunction); - handle_.open (filename, "at"); + filename_ = filename; } }; diff --git a/meson.build b/meson.build index e4a4e11..faeee08 100644 --- a/meson.build +++ b/meson.build @@ -215,7 +215,7 @@ elif isWindows and (isCLang or isGCC) else ldflags += [ '-static-libgcc', - '-Wl,--add-stdcall-alias' + '-Wl,--kill-at' ] endif diff --git a/src/linkage.cpp b/src/linkage.cpp index 6a201e0..c57340f 100644 --- a/src/linkage.cpp +++ b/src/linkage.cpp @@ -899,7 +899,7 @@ CR_EXPORT void Meta_Init () { // games GiveFnptrsToDll is a bit tricky #if defined(CR_WINDOWS) -# if defined(CR_CXX_MSVC) || defined (CR_CXX_CLANG) +# if defined(CR_CXX_MSVC) || (defined(CR_CXX_CLANG) && !defined(CR_CXX_GCC)) # if defined (CR_ARCH_X86) # pragma comment(linker, "/EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1") # endif