Skip to content

Commit

Permalink
Don't try to use C11 atomics, which are not const
Browse files Browse the repository at this point in the history
C11 did not have the const qualifier on atomic_load; C17 does. One can either
use C11 atomics by casting away the constness, which was proposed and rejected
in phpGH-8764, or one can avoid using C11 atomics altogether, instead using C17
atomics if available, which is what this change does.

Fixes phpGH-8881
  • Loading branch information
ryandesign committed Aug 10, 2023
1 parent 7f6e98c commit 49ac664
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Zend/zend_atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || (__GNUC__ > (x)))

/* Builtins are used to avoid library linkage */
#if __has_feature(c_atomic)
#define HAVE_C11_ATOMICS 1
#if __has_feature(c_atomic) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L
#define HAVE_C17_ATOMICS 1
#elif ZEND_GCC_PREREQ(4, 7)
#define HAVE_GNUC_ATOMICS 1
#elif defined(__GNUC__)
Expand All @@ -43,7 +43,7 @@
typedef struct zend_atomic_bool_s {
volatile char value;
} zend_atomic_bool;
#elif defined(HAVE_C11_ATOMICS)
#elif defined(HAVE_C17_ATOMICS)
typedef struct zend_atomic_bool_s {
_Atomic(bool) value;
} zend_atomic_bool;
Expand Down Expand Up @@ -80,7 +80,7 @@ static zend_always_inline void zend_atomic_bool_store_ex(zend_atomic_bool *obj,
(void)InterlockedExchange8(&obj->value, desired);
}

#elif defined(HAVE_C11_ATOMICS)
#elif defined(HAVE_C17_ATOMICS)

#define ZEND_ATOMIC_BOOL_INIT(obj, desired) __c11_atomic_init(&(obj)->value, (desired))

Expand Down

0 comments on commit 49ac664

Please sign in to comment.