From cd237207d4d059461222798f5f395236a4b14f42 Mon Sep 17 00:00:00 2001 From: faumaray Date: Tue, 27 Oct 2026 05:43:38 +0300 Subject: [PATCH] Log: one facade state per process, in a LogState library Void::Log::Detail::state() was a static in an inline function, which is one object per DLL on Windows: a sink set from one DLL never saw events from another (a plugin's log lines, or any module but the one that set it). The state now lives in Void::LogState, a small compiled module with no dependencies, linked by every module that includes the facade (Async, System, Stacktrace, Testing; the rest through them), so INTERFACE modules can still log and no dependency cycle appears. Tests: VoidTests 1242 pass, 3 skip; run_with_args_builds_correct_argv and run_stdin_forwarded_to_cat fail on NixOS, which has no /bin/echo or /bin/cat (exit 127). Co-Authored-By: Claude Opus 5.5 --- include/Void/Log/Log.hpp | 17 ++++++++--------- src/Async/module.cmake | 4 +++- src/LogState/State.cpp | 15 +++++++++++++++ src/LogState/module.cmake | 1 + src/Stacktrace/module.cmake | 2 +- src/System/module.cmake | 2 +- src/Testing/module.cmake | 1 + 7 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 src/LogState/State.cpp create mode 100644 src/LogState/module.cmake diff --git a/include/Void/Log/Log.hpp b/include/Void/Log/Log.hpp index c721f5c..01dd7a3 100644 --- a/include/Void/Log/Log.hpp +++ b/include/Void/Log/Log.hpp @@ -13,10 +13,11 @@ #include // ── Void::Log — the emission facade -// ─────────────────────────────────────────── Header-only so every module -// (including INTERFACE libraries) can log with zero link dependencies. The full -// sink framework lives in Void::Logging (Logger.hpp); bridge with -// Void/Log/LoggingAdapter.hpp. +// ─────────────────────────────────────────── Header-only apart from its +// state, which Void::LogState (a small library with no dependencies) holds +// once per process, so every module (including INTERFACE libraries) can log by +// linking only that. The full sink framework lives in Void::Logging +// (Logger.hpp); bridge with Void/Log/LoggingAdapter.hpp. // // Integration contract: // * No sink installed (the default) — every call is a single relaxed @@ -85,11 +86,9 @@ namespace Void::Log std::shared_mutex mutex; }; - inline State& state() - { - static State s; - return s; - } + // The process's one State, defined in Void::LogState (a static in an + // inline function would be one per DLL on Windows). + State& state(); } // namespace Detail /// Install the global sink. Any previously installed sink is replaced. diff --git a/src/Async/module.cmake b/src/Async/module.cmake index 262c4d8..8267522 100644 --- a/src/Async/module.cmake +++ b/src/Async/module.cmake @@ -1 +1,3 @@ -void_add_module(Async) +void_add_module(Async + INTERNAL_DEPS LogState +) diff --git a/src/LogState/State.cpp b/src/LogState/State.cpp new file mode 100644 index 0000000..19f3b6c --- /dev/null +++ b/src/LogState/State.cpp @@ -0,0 +1,15 @@ +// The Void::Log facade's one state per process. Compiled into its own small +// library rather than an inline function's static: Windows gives every DLL +// that inlines a function its own static, so a sink set in one DLL would +// never see the events of another. Every module that includes +// links this (it has no dependencies of its own). +#include + +namespace Void::Log::Detail +{ + State& state() + { + static State s; + return s; + } +} // namespace Void::Log::Detail diff --git a/src/LogState/module.cmake b/src/LogState/module.cmake new file mode 100644 index 0000000..cf9edda --- /dev/null +++ b/src/LogState/module.cmake @@ -0,0 +1 @@ +void_add_module(LogState) diff --git a/src/Stacktrace/module.cmake b/src/Stacktrace/module.cmake index 90ba0bd..9401453 100644 --- a/src/Stacktrace/module.cmake +++ b/src/Stacktrace/module.cmake @@ -5,7 +5,7 @@ else() endif() void_add_module(Stacktrace - INTERNAL_DEPS Functional + INTERNAL_DEPS Functional LogState EXTERNAL_DEPS ${_void_stacktrace_target} DEPS_UNIX dl OPTIONS_UNIX -g -fno-omit-frame-pointer diff --git a/src/System/module.cmake b/src/System/module.cmake index a1b6ee8..0d0815a 100644 --- a/src/System/module.cmake +++ b/src/System/module.cmake @@ -1,4 +1,4 @@ void_add_module(System - INTERNAL_DEPS Functional + INTERNAL_DEPS Functional LogState EXTERNAL_DEPS Threads::Threads ) diff --git a/src/Testing/module.cmake b/src/Testing/module.cmake index a2374ef..2d86c6a 100644 --- a/src/Testing/module.cmake +++ b/src/Testing/module.cmake @@ -1,3 +1,4 @@ void_add_module(Testing + INTERNAL_DEPS LogState OPTIONAL_DEPS Stacktrace Log Async Configuration Text )