Skip to content

Don't try to use C11 atomics, which are not const #11931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: PHP-8.2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

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

This wouldn't be suitable for PHP 8.2. Can you share your compiler, compiler version, and target platform? We'll need to work out some detection for whether we need to cast the const away for PHP 8.2 (but for 8.3 we can probably apply this patch).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the linked issue with the compiler and OS information.

What makes you say this wouldn't be suitable for PHP 8.2? I have already applied this patch to MacPorts PHP 8.2 and 8.3 and have not received any reports of problems, though of course that doesn't guarantee there aren't any problems.

Copy link
Contributor

Choose a reason for hiding this comment

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

We cannot just take away HAVE_C11_ATOMICS existing in a patch release.

Copy link
Contributor Author

@ryandesign ryandesign Oct 1, 2023

Choose a reason for hiding this comment

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

If your objection is about changing the name of the macro from HAVE_C11_ATOMICS to HAVE_C17_ATOMICS, then a solution could be not to change the name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I renamed it in order to have the macro name reflect the change in its definition. I did not consider that it might be part of public API that others would use. If it is public API, then another option might be to leave HAVE_C11_ATOMICS defined as it was and just not use it in PHP itself, addition to creating HAVE_C17_ATOMICS and using it as in this PR.

Of course, I don't care how it's fixed, and I'm not very familiar with the code of the PHP project so I don't know what fix is best. All I care about is that it is fixed somehow.

#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