fix(log): use template to pass logger to initiator and fix format error

- src/libipc/platform/win/get_sa.h:
  * Convert initiator struct to template with Logger parameter
  * Pass log object from get_sa() to initiator constructor via template
  * Use 'static initiator<decltype(log)> handle(log)' to instantiate
  * This allows initiator constructor to properly access log object
  * Syntax: initiator(Logger const &log) receives the logger

- src/libipc/platform/win/semaphore.h:
  * Fix format error on line 79: remove extra characters '"}]'
  * Correct closing of log.error() statement
  * Before: log.error(...)"}]
  * After:  log.error(...);

These fixes resolve the static struct initialization issue and
code format error in Windows platform.
This commit is contained in:
木头云 2025-12-15 11:54:04 +00:00
parent 66a66f15ec
commit afd1467e03
2 changed files with 8 additions and 6 deletions

View File

@ -7,14 +7,14 @@ namespace detail {
inline LPSECURITY_ATTRIBUTES get_sa() {
LIBIPC_LOG();
static struct initiator {
template <typename Logger>
struct initiator {
SECURITY_DESCRIPTOR sd_;
SECURITY_ATTRIBUTES sa_;
bool succ_ = false;
initiator() {
initiator(Logger const &log) {
if (!::InitializeSecurityDescriptor(&sd_, SECURITY_DESCRIPTOR_REVISION)) {
log.error("fail InitializeSecurityDescriptor[", static_cast<int>(::GetLastError()), "]");
return;
@ -28,7 +28,9 @@ inline LPSECURITY_ATTRIBUTES get_sa() {
sa_.lpSecurityDescriptor = &sd_;
succ_ = true;
}
} handle;
};
static initiator<decltype(log)> handle(log);
return handle.succ_ ? &handle.sa_ : nullptr;
}

View File

@ -76,7 +76,7 @@ public:
bool post(std::uint32_t count) noexcept {
LIBIPC_LOG();
if (!::ReleaseSemaphore(h_, static_cast<LONG>(count), NULL)) {
log.error("fail ReleaseSemaphore[", ::GetLastError(), "]");"}]
log.error("fail ReleaseSemaphore[", ::GetLastError(), "]");
return false;
}
return true;