Skip to content

Commit afd1467

Browse files
committed
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.
1 parent 66a66f1 commit afd1467

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/libipc/platform/win/get_sa.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ namespace detail {
77

88
inline LPSECURITY_ATTRIBUTES get_sa() {
99
LIBIPC_LOG();
10-
static struct initiator {
11-
10+
11+
template <typename Logger>
12+
struct initiator {
1213
SECURITY_DESCRIPTOR sd_;
1314
SECURITY_ATTRIBUTES sa_;
14-
1515
bool succ_ = false;
1616

17-
initiator() {
17+
initiator(Logger const &log) {
1818
if (!::InitializeSecurityDescriptor(&sd_, SECURITY_DESCRIPTOR_REVISION)) {
1919
log.error("fail InitializeSecurityDescriptor[", static_cast<int>(::GetLastError()), "]");
2020
return;
@@ -28,7 +28,9 @@ inline LPSECURITY_ATTRIBUTES get_sa() {
2828
sa_.lpSecurityDescriptor = &sd_;
2929
succ_ = true;
3030
}
31-
} handle;
31+
};
32+
33+
static initiator<decltype(log)> handle(log);
3234
return handle.succ_ ? &handle.sa_ : nullptr;
3335
}
3436

src/libipc/platform/win/semaphore.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class semaphore {
7676
bool post(std::uint32_t count) noexcept {
7777
LIBIPC_LOG();
7878
if (!::ReleaseSemaphore(h_, static_cast<LONG>(count), NULL)) {
79-
log.error("fail ReleaseSemaphore[", ::GetLastError(), "]");"}]
79+
log.error("fail ReleaseSemaphore[", ::GetLastError(), "]");
8080
return false;
8181
}
8282
return true;

0 commit comments

Comments
 (0)