Replace I/O manipulators (std::hex, std::dec) with ipc::spec in log
statements. The ipc::fmt system does not support std::iostream
manipulators, which caused compilation failures under MinGW.
Changed files:
- src/libipc/platform/win/mutex.h (lines 78, 96)
- src/libipc/platform/win/semaphore.h (line 71)
The format spec "#x" produces output like "0x102" which matches
the original behavior:
- # flag adds the "0x" prefix automatically
- x outputs lowercase hexadecimal
Fixes: #171
- src/libipc/platform/win/get_sa.h:
* Move 'struct initiator' definition outside get_sa() function
* Rename to 'sa_initiator' to avoid naming conflicts
* Define at namespace ipc::detail scope (above get_sa function)
* Keep template constructor: template <typename Logger> sa_initiator(Logger const &log)
* get_sa() now simply uses: static sa_initiator handle(log);
This fixes the C++ standard violation:
- C++03/11/14/17/20 all prohibit local classes from having member templates
- Error C2892: 'local class shall not have member templates'
- Moving the struct to namespace scope resolves this issue
The struct is now a proper namespace-level definition with a template
constructor, which is fully compliant with C++ standards.
- src/libipc/platform/win/get_sa.h:
* Change from class template to constructor template
* Keep 'struct initiator' as a regular class (not template)
* Make constructor a function template: template <typename Logger> initiator(Logger const &log)
* Instantiate as: static initiator handle(log);
* This is valid C++ as function templates can be defined inside functions
* Fixes the issue that class templates cannot be defined inside functions
The constructor template approach allows proper logger passing while
maintaining valid C++ syntax for local struct definitions.
- 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.
- src/libipc/platform/win/get_sa.h:
* Fix malformed log.error() calls on lines 19 and 23
* Remove extra comma and parenthesis: GetLastError(, -> GetLastError()
* Fix closing parenthesis and bracket placement
* Line 19: GetLastError(, "]"))) -> GetLastError()), "]"
* Line 23: GetLastError(, "]"))) -> GetLastError()), "]"
- src/libipc/platform/win/mutex.h:
* Add missing LIBIPC_LOG() to try_lock() function at line 84
* The function uses log.error() at line 95 and needs logger initialization
These fixes resolve Windows compilation errors related to malformed
log calls and missing LIBIPC_LOG() macro.
- src/libipc/platform/posix/condition.h:
* Replace all %d and %s format specifiers with stream-based syntax
* Update log.error() calls to use proper streaming (e.g., "[", eno, "]")
- src/libipc/platform/posix/semaphore_impl.h:
* Remove %d format specifiers from log.error() calls
* Fix malformed parentheses (e.g., .c_str(, ""))
* Remove unnecessary empty string arguments
* Use stream-based logging consistently
- src/libipc/platform/win/mutex.h:
* Fix malformed GetLastError() parentheses
* Remove %lu format specifier, use explicit cast instead
* Update to stream-based logging syntax
- src/libipc/platform/win/semaphore.h:
* Fix malformed GetLastError() parentheses
* Remove %lu format specifier, use explicit cast instead
* Update to stream-based logging syntax
All format specifiers (%d, %s, %zd, %p, %lu) have been removed and replaced
with proper C++ stream-based logging that is type-safe and consistent with
the new imp/log interface.
- Add LIBIPC_LOG() to functions in platform files that use log.error/warning/debug
- Fixed files:
- POSIX platform: mutex.h, semaphore_impl.h, shm_posix.cpp
- Windows platform: get_sa.h, mutex.h, semaphore.h, shm_win.cpp
- Sync layer: condition.cpp, mutex.cpp, semaphore.cpp
All functions using the new log interface now properly initialize the logger with LIBIPC_LOG()
- Fix multi-parameter log calls with complex formatting in POSIX and Windows platforms
- Replace remaining ipc::error() and ipc::log() calls with log.error() and log.warning()
- Handle special cases:
- POSIX condition.h: pthread_cond_timedwait multi-param formatting
- POSIX get_wait_time.h: calc_wait_time multi-param formatting
- POSIX semaphore_impl.h: sem_timedwait multi-param formatting
- Windows mutex.h: WaitForSingleObject with hex formatting, WAIT_ABANDONED as warning
- Windows semaphore.h: WaitForSingleObject and ReleaseSemaphore calls
- Use std::hex/std::dec for hexadecimal formatting in Windows platform
- All log interface migrations now complete
The acquire() function allocates id_info_t using mem::$new<id_info_t>(),
so the release() function must use mem::$delete(ii) to deallocate it,
not mem::free(ii). This ensures proper allocation/deallocation pairing.
Issue: Memory allocated with mem::$new must be freed with mem::$delete
to maintain consistent memory management semantics.
ISSUE:
MSVC compiler reports warning C4138: '*/' found outside of comment
for patterns like 'void */*p*/' where the pointer asterisk is immediately
followed by a comment start.
AFFECTED FILES:
- include/libipc/mem/new.h (line 30)
- src/libipc/platform/win/mutex.h (line 54)
- src/libipc/platform/win/semaphore.h (line 53)
CHANGES:
Changed 'type */*param*/' to 'type * /*param*/' (added space before comment)
Examples:
- void */*p*/ → void * /*p*/
- char const */*name*/ → char const * /*name*/
This resolves the MSVC warning while maintaining code functionality
and keeping the commented-out parameter names for documentation.
- Remove useless 'ii->size_ = ii->size_;' statement at line 140
- The user-requested size is already set in acquire() function
- Simplify else branch to just a comment for clarity
- No functional change, just code cleanup
Problem:
- Reference counting tests fail on Windows (ReleaseMemory, ReferenceCount,
SubtractReference, HandleRef, HandleSubRef)
- get_ref() and sub_ref() were stub implementations returning 0/doing nothing
- CreateFileMapping HANDLE lacks built-in reference counting mechanism
Solution:
- Implement reference counting using std::atomic<std::int32_t> stored at
the end of shared memory (same strategy as POSIX version)
- Add calc_size() helper to allocate extra space for atomic counter
- Add acc_of() helper to access the atomic counter at the end of memory
- Modify acquire() to allocate calc_size(size) instead of size
- Modify get_mem() to initialize counter to 1 on first mapping
- Modify release() to decrement counter and return ref count before decrement
- Implement get_ref() to return current reference count
- Implement sub_ref() to atomically decrement reference count
- Convert file from Windows (CRLF) to Unix (LF) line endings for consistency
Key Implementation Details:
1. Reference counter stored at end of shared memory (aligned to info_t)
2. First get_mem() call: fetch_add(1) initializes counter to 1
3. release() returns ref count before decrement (for semantics compatibility)
4. Memory layout: [user data][padding][atomic<int32_t> counter]
5. Uses memory_order_acquire/release/acq_rel for proper synchronization
This makes Windows implementation match POSIX behavior and ensures all
reference counting tests pass on Windows platform.