Skip to content

Commit 6a93b59

Browse files
wantehchangkodawah
authored andcommitted
compat/atomics: add typecasts in atomic_compare_exchange_strong()
The Solaris and Windows emulations of atomic_compare_exchange_strong() need typecasts to avoid compiler warnings, because the functions they call expect a void* pointer but an intptr_t integer is passed. Note that the emulations of atomic_compare_exchange_strong() (except the gcc version) only work for atomic_intptr_t because of the type of the second argument (|expected|). See http://en.cppreference.com/w/c/atomic: _Bool atomic_compare_exchange_strong( volatile A* obj, C* expected, C desired ); The types of the first argument and second argument are different (|A| and |C|, respectively). |C| is the non-atomic type corresponding to |A|. In the emulations of atomic_compare_exchange_strong(), |C| is intptr_t. This implies |A| can only be sig_intptr_t. Signed-off-by: Wan-Teh Chang <[email protected]>
1 parent 2170017 commit 6a93b59

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

compat/atomics/suncc/stdatomic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static inline int atomic_compare_exchange_strong(intptr_t *object, intptr_t *exp
108108
intptr_t desired)
109109
{
110110
intptr_t old = *expected;
111-
*expected = atomic_cas_ptr(object, old, desired);
111+
*expected = (intptr_t)atomic_cas_ptr(object, (void *)old, (void *)desired);
112112
return *expected == old;
113113
}
114114

compat/atomics/win32/stdatomic.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ static inline int atomic_compare_exchange_strong(intptr_t *object, intptr_t *exp
104104
intptr_t desired)
105105
{
106106
intptr_t old = *expected;
107-
*expected = InterlockedCompareExchangePointer(object, desired, old);
107+
*expected = (intptr_t)InterlockedCompareExchangePointer(
108+
(PVOID *)object, (PVOID)desired, (PVOID)old);
108109
return *expected == old;
109110
}
110111

0 commit comments

Comments
 (0)