Skip to content

Conversation

@barracuda156
Copy link

Fixes: #1063

@barracuda156
Copy link
Author

For the record, this works neatly with Ruby 3.3, while Ruby 3.2 also needs -Wno-incompatible-pointer-types to be passed, otherwise this fails:

atomic_reference.c: In function 'ir_compare_and_set':
atomic_reference.c:83:57: error: passing argument 3 of 'OSAtomicCompareAndSwap32' from incompatible pointer type [-Wincompatible-pointer-types]
   83 |   if (OSAtomicCompareAndSwap32(expect_value, new_value, &DATA_PTR(self))) {
In file included from atomic_reference.h:9,
                 from atomic_reference.c:20:
/usr/include/libkern/OSAtomic.h:132:93: note: expected 'volatile int32_t *' {aka 'volatile int *'} but argument is of type 'void **'
  132 | bool    OSAtomicCompareAndSwap32( int32_t __oldValue, int32_t __newValue, volatile int32_t *__theValue );
      |                                                                           ~~~~~~~~~~~~~~~~~~^~~~~~~~~~
make: *** [atomic_reference.o] Error 1

make failed, exit code 2

@eregon
Copy link
Member

eregon commented Oct 7, 2024

Arguments should be explicitly casted to avoid the warning/error.

One problem though is we have no way to test macOS 32-bit, so it should be considered basically unsupported.

@barracuda156
Copy link
Author

@eregon If you suggest a better fix, I can test that locally both on ppc and i386.

VALUE ir_compare_and_set(volatile VALUE self, VALUE expect_value, VALUE new_value) {
#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050
#if defined(__i386__) || defined(__ppc__)
if (OSAtomicCompareAndSwap32(expect_value, new_value, &DATA_PTR(self))) {
Copy link
Member

@eregon eregon Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (OSAtomicCompareAndSwap32(expect_value, new_value, &DATA_PTR(self))) {
if (OSAtomicCompareAndSwap32(expect_value, new_value, (VALUE*) &DATA_PTR(self))) {

Can you try this?
I think it should solve your warning on Ruby 3.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

atomic_reference.c fails to compile on 32-bit due to unconditional usage of 64-bit atomics

2 participants