Skip to content

Commit c5e45a1

Browse files
authored
tree-wide: Replace ZEND_STATIC_ASSERT() by static_assert() (#21228)
* tree-wide: Replace `ZEND_STATIC_ASSERT()` by `static_assert()` * zend_portability: Remove `ZEND_STATIC_ASSERT()`
1 parent 8991945 commit c5e45a1

8 files changed

Lines changed: 8 additions & 15 deletions

File tree

‎UPGRADING.INTERNALS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ PHP 8.7 INTERNALS UPGRADE NOTES
1616

1717
- Removed zend_execute_scripts(). Manually call zend_execute_script() in a loop
1818
instead.
19+
- Removed ZEND_STATIC_ASSERT(). Use C11 static_assert() directly instead.
1920

2021
========================
2122
2. Build system changes

‎Zend/zend_compile.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5944,7 +5944,7 @@ static void zend_compile_static_var_common(zend_string *var_name, zval *value, u
59445944
opline->op1_type = IS_CV;
59455945
opline->op1.var = lookup_cv(var_name);
59465946

5947-
ZEND_STATIC_ASSERT(sizeof(Bucket) % 8 == 0, "Bucket size not compatible with storing flags in lower three bits");
5947+
static_assert(sizeof(Bucket) % 8 == 0, "Bucket size not compatible with storing flags in lower three bits");
59485948
opline->extended_value = (uint32_t)((char*)value - (char*)CG(active_op_array)->static_variables->arData) | mode;
59495949
}
59505950
/* }}} */

‎Zend/zend_compile.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ struct _zend_execute_data {
713713
(call)->This.u2.num_args
714714

715715
/* Ensure the correct alignment before slots calculation */
716-
ZEND_STATIC_ASSERT(ZEND_MM_ALIGNED_SIZE(sizeof(zval)) == sizeof(zval),
716+
static_assert(ZEND_MM_ALIGNED_SIZE(sizeof(zval)) == sizeof(zval),
717717
"zval must be aligned by ZEND_MM_ALIGNMENT");
718718
/* A number of call frame slots (zvals) reserved for zend_execute_data. */
719719
#define ZEND_CALL_FRAME_SLOT \

‎Zend/zend_execute.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ struct _zend_vm_stack {
295295
};
296296

297297
/* Ensure the correct alignment before slots calculation */
298-
ZEND_STATIC_ASSERT(ZEND_MM_ALIGNED_SIZE(sizeof(zval)) == sizeof(zval),
298+
static_assert(ZEND_MM_ALIGNED_SIZE(sizeof(zval)) == sizeof(zval),
299299
"zval must be aligned by ZEND_MM_ALIGNMENT");
300300
/* A number of call frame slots (zvals) reserved for _zend_vm_stack. */
301301
#define ZEND_VM_STACK_HEADER_SLOTS \

‎Zend/zend_portability.h‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -862,14 +862,6 @@ extern "C++" {
862862
/** @deprecated */
863863
#define ZEND_CGG_DIAGNOSTIC_IGNORED_END ZEND_DIAGNOSTIC_IGNORED_END
864864

865-
#if defined(__cplusplus)
866-
# define ZEND_STATIC_ASSERT(c, m) static_assert((c), m)
867-
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11 */
868-
# define ZEND_STATIC_ASSERT(c, m) _Static_assert((c), m)
869-
#else
870-
# define ZEND_STATIC_ASSERT(c, m)
871-
#endif
872-
873865
#if !defined(ZEND_WIN32)
874866
typedef max_align_t zend_max_align_t;
875867
#else

‎ext/date/time_duration.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
#define NANOS_IN_MILLI 1000000
2626
#define MILLIS_IN_SEC 1000
2727

28-
ZEND_STATIC_ASSERT(NANOS_IN_MICRO * MICROS_IN_SEC == NANOS_IN_SEC, "");
29-
ZEND_STATIC_ASSERT(NANOS_IN_MILLI * MILLIS_IN_SEC == NANOS_IN_SEC, "");
28+
static_assert(NANOS_IN_MICRO * MICROS_IN_SEC == NANOS_IN_SEC, "");
29+
static_assert(NANOS_IN_MILLI * MILLIS_IN_SEC == NANOS_IN_SEC, "");
3030

3131
#define Z_PARAM_ULONG(l) { \
3232
zend_long __##l; \

‎ext/random/engine_mt19937.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
*/
8686

8787
#define N 624 /* length of state vector */
88-
ZEND_STATIC_ASSERT(
88+
static_assert(
8989
N == sizeof(((php_random_status_state_mt19937*)0)->state) / sizeof(((php_random_status_state_mt19937*)0)->state[0]),
9090
"Assumed length of Mt19937 state vector does not match actual size."
9191
);

‎ext/random/php_random_zend_utils.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ typedef struct php_random_bytes_insecure_state_for_zend {
2525
php_random_status_state_xoshiro256starstar xoshiro256starstar_state;
2626
} php_random_bytes_insecure_state_for_zend;
2727

28-
ZEND_STATIC_ASSERT(sizeof(zend_random_bytes_insecure_state) >= sizeof(php_random_bytes_insecure_state_for_zend), "");
28+
static_assert(sizeof(zend_random_bytes_insecure_state) >= sizeof(php_random_bytes_insecure_state_for_zend), "");
2929

3030
ZEND_ATTRIBUTE_NONNULL PHPAPI void php_random_bytes_insecure_for_zend(
3131
zend_random_bytes_insecure_state *state, void *bytes, size_t size);

0 commit comments

Comments
 (0)