Skip to content

Commit 957e49b

Browse files
committed
tree: alignof is always available
As we now require C11
1 parent 7141eef commit 957e49b

5 files changed

Lines changed: 26 additions & 91 deletions

File tree

‎Zend/Zend.m4‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -389,14 +389,9 @@ typedef union _mm_align_test {
389389
long lng;
390390
} mm_align_test;
391391
392-
#if (defined (__GNUC__) && __GNUC__ >= 2)
393-
#define ZEND_MM_ALIGNMENT (__alignof__ (mm_align_test))
394-
#else
395-
#define ZEND_MM_ALIGNMENT (sizeof(mm_align_test))
396-
#endif
397-
398392
int main(void)
399393
{
394+
size_t ZEND_MM_ALIGNMENT = alignof(mm_align_test);
400395
size_t i = ZEND_MM_ALIGNMENT;
401396
int zeros = 0;
402397
FILE *fp;

‎configure.ac‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -493,19 +493,6 @@ PHP_CHECK_AVX512_SUPPORTS
493493
dnl Check AVX512 VBMI
494494
PHP_CHECK_AVX512_VBMI_SUPPORTS
495495

496-
dnl Check for __alignof__ support in the compiler
497-
AC_CACHE_CHECK([whether the compiler supports __alignof__],
498-
[php_cv_have_alignof],
499-
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
500-
int align = __alignof__(int);
501-
(void)align;
502-
])],
503-
[php_cv_have_alignof=yes],
504-
[php_cv_have_alignof=no])])
505-
AS_VAR_IF([php_cv_have_alignof], [yes],
506-
[AC_DEFINE([HAVE_ALIGNOF], [1],
507-
[Define to 1 if the compiler supports '__alignof__'.])])
508-
509496
dnl Check for structure members.
510497
AC_CHECK_MEMBERS([struct tm.tm_gmtoff],,,[#include <time.h>])
511498
AC_CHECK_MEMBERS(m4_normalize([

‎ext/hash/hash.c‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,10 @@
2626
#include "zend_exceptions.h"
2727
#include "zend_interfaces.h"
2828
#include "zend_smart_str.h"
29+
#include <stdalign.h>
2930

3031
#include "hash_arginfo.h"
3132

32-
#ifdef PHP_WIN32
33-
# define __alignof__ __alignof
34-
#else
35-
# ifndef HAVE_ALIGNOF
36-
# include <stddef.h>
37-
# define __alignof__(type) offsetof (struct { char c; type member;}, member)
38-
# endif
39-
#endif
40-
4133
static HashTable php_hash_hashtable;
4234
zend_class_entry *php_hashcontext_ce;
4335
static zend_object_handlers php_hashcontext_handlers;
@@ -138,16 +130,16 @@ static size_t parse_serialize_spec(
138130
/* parse size */
139131
if (*spec == 's' || *spec == 'S') {
140132
*sz = 2;
141-
alignment = __alignof__(uint16_t); /* usually 2 */
133+
alignment = alignof(uint16_t); /* usually 2 */
142134
} else if (*spec == 'l' || *spec == 'L') {
143135
*sz = 4;
144-
alignment = __alignof__(uint32_t); /* usually 4 */
136+
alignment = alignof(uint32_t); /* usually 4 */
145137
} else if (*spec == 'q' || *spec == 'Q') {
146138
*sz = 8;
147-
alignment = __alignof__(uint64_t); /* usually 8 */
139+
alignment = alignof(uint64_t); /* usually 8 */
148140
} else if (*spec == 'i' || *spec == 'I') {
149141
*sz = sizeof(int);
150-
alignment = __alignof__(int); /* usually 4 */
142+
alignment = alignof(int); /* usually 4 */
151143
} else {
152144
ZEND_ASSERT(*spec == 'b' || *spec == 'B');
153145
*sz = 1;

‎ext/standard/crypt_sha256.c‎

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,9 @@
88
#include <errno.h>
99
#include <limits.h>
1010

11-
#ifdef PHP_WIN32
12-
# define __alignof__ __alignof
13-
#else
14-
# ifndef HAVE_ALIGNOF
15-
# include <stddef.h>
16-
# define __alignof__(type) offsetof (struct { char c; type member;}, member)
17-
# endif
18-
#endif
19-
2011
#include <stdio.h>
2112
#include <stdlib.h>
13+
#include <stdalign.h>
2214

2315
#ifdef PHP_WIN32
2416
# include <string.h>
@@ -260,14 +252,7 @@ static void sha256_process_bytes(const void *buffer, size_t len, struct sha256_c
260252

261253
/* Process available complete blocks. */
262254
if (len >= 64) {
263-
/* To check alignment gcc has an appropriate operator. Other
264-
compilers don't. */
265-
#if __GNUC__ >= 2
266-
# define UNALIGNED_P(p) (((uintptr_t) p) % __alignof__ (uint32_t) != 0)
267-
#else
268-
# define UNALIGNED_P(p) (((uintptr_t) p) % sizeof (uint32_t) != 0)
269-
#endif
270-
if (UNALIGNED_P (buffer))
255+
if ((uintptr_t)buffer % alignof(uint32_t) != 0)
271256
while (len > 64) {
272257
sha256_process_block(memcpy(ctx->buffer, buffer, 64), 64, ctx);
273258
buffer = (const char *) buffer + 64;
@@ -317,13 +302,8 @@ static const char b64t[64] ZEND_NONSTRING =
317302

318303
char * php_sha256_crypt_r(const char *key, const char *salt, char *buffer, int buflen)
319304
{
320-
#ifdef PHP_WIN32
321-
ZEND_SET_ALIGNED(32, unsigned char alt_result[32]);
322-
ZEND_SET_ALIGNED(32, unsigned char temp_result[32]);
323-
#else
324-
ZEND_SET_ALIGNED(__alignof__ (uint32_t), unsigned char alt_result[32]);
325-
ZEND_SET_ALIGNED(__alignof__ (uint32_t), unsigned char temp_result[32]);
326-
#endif
305+
ZEND_SET_ALIGNED(alignof(uint32_t), unsigned char alt_result[32]);
306+
ZEND_SET_ALIGNED(alignof(uint32_t), unsigned char temp_result[32]);
327307

328308
struct sha256_ctx ctx;
329309
struct sha256_ctx alt_ctx;
@@ -371,15 +351,15 @@ char * php_sha256_crypt_r(const char *key, const char *salt, char *buffer, int b
371351
SET_ALLOCA_FLAG(use_heap_key);
372352
SET_ALLOCA_FLAG(use_heap_salt);
373353

374-
if ((uintptr_t)key % __alignof__ (uint32_t) != 0) {
375-
tmp_key = (char *) do_alloca(key_len + __alignof__(uint32_t), use_heap_key);
376-
key = copied_key = memcpy(tmp_key + __alignof__(uint32_t) - (uintptr_t)tmp_key % __alignof__(uint32_t), key, key_len);
354+
if ((uintptr_t)key % alignof(uint32_t) != 0) {
355+
tmp_key = (char *) do_alloca(key_len + alignof(uint32_t), use_heap_key);
356+
key = copied_key = memcpy(tmp_key + alignof(uint32_t) - (uintptr_t)tmp_key % alignof(uint32_t), key, key_len);
377357
}
378358

379-
if ((uintptr_t)salt % __alignof__(uint32_t) != 0) {
380-
tmp_salt = (char *) do_alloca(salt_len + 1 + __alignof__(uint32_t), use_heap_salt);
359+
if ((uintptr_t)salt % alignof(uint32_t) != 0) {
360+
tmp_salt = (char *) do_alloca(salt_len + 1 + alignof(uint32_t), use_heap_salt);
381361
salt = copied_salt =
382-
memcpy(tmp_salt + __alignof__(uint32_t) - (uintptr_t)tmp_salt % __alignof__ (uint32_t), salt, salt_len);
362+
memcpy(tmp_salt + alignof(uint32_t) - (uintptr_t)tmp_salt % alignof(uint32_t), salt, salt_len);
383363
copied_salt[salt_len] = 0;
384364
}
385365

‎ext/standard/crypt_sha512.c‎

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,10 @@
77

88
#include <errno.h>
99
#include <limits.h>
10-
#ifdef PHP_WIN32
11-
# define __alignof__ __alignof
12-
#else
13-
# ifndef HAVE_ALIGNOF
14-
# include <stddef.h>
15-
# define __alignof__(type) offsetof (struct { char c; type member;}, member)
16-
# endif
17-
#endif
1810

1911
#include <stdio.h>
2012
#include <stdlib.h>
13+
#include <stdalign.h>
2114

2215
#ifdef PHP_WIN32
2316
# include <string.h>
@@ -294,14 +287,7 @@ sha512_process_bytes(const void *buffer, size_t len, struct sha512_ctx *ctx) {
294287
/* Process available complete blocks. */
295288
if (len >= 128) {
296289
#ifndef _STRING_ARCH_unaligned
297-
/* To check alignment gcc has an appropriate operator. Other
298-
compilers don't. */
299-
# if __GNUC__ >= 2
300-
# define UNALIGNED_P(p) (((uintptr_t) p) % __alignof__ (uint64_t) != 0)
301-
# else
302-
# define UNALIGNED_P(p) (((uintptr_t) p) % sizeof(uint64_t) != 0)
303-
# endif
304-
if (UNALIGNED_P(buffer))
290+
if ((uintptr_t)buffer % alignof(uint64_t) != 0)
305291
while (len > 128) {
306292
sha512_process_block(memcpy(ctx->buffer, buffer, 128), 128, ctx);
307293
buffer = (const char *) buffer + 128;
@@ -355,13 +341,8 @@ static const char b64t[64] ZEND_NONSTRING =
355341

356342
char *
357343
php_sha512_crypt_r(const char *key, const char *salt, char *buffer, int buflen) {
358-
#ifdef PHP_WIN32
359-
ZEND_SET_ALIGNED(64, unsigned char alt_result[64]);
360-
ZEND_SET_ALIGNED(64, unsigned char temp_result[64]);
361-
#else
362-
ZEND_SET_ALIGNED(__alignof__ (uint64_t), unsigned char alt_result[64]);
363-
ZEND_SET_ALIGNED(__alignof__ (uint64_t), unsigned char temp_result[64]);
364-
#endif
344+
ZEND_SET_ALIGNED(alignof(uint64_t), unsigned char alt_result[64]);
345+
ZEND_SET_ALIGNED(alignof(uint64_t), unsigned char temp_result[64]);
365346
struct sha512_ctx ctx;
366347
struct sha512_ctx alt_ctx;
367348
size_t salt_len;
@@ -409,15 +390,15 @@ php_sha512_crypt_r(const char *key, const char *salt, char *buffer, int buflen)
409390
SET_ALLOCA_FLAG(use_heap_key);
410391
SET_ALLOCA_FLAG(use_heap_salt);
411392

412-
if ((uintptr_t)key % __alignof__ (uint64_t) != 0) {
413-
tmp_key = (char *) do_alloca(key_len + __alignof__ (uint64_t), use_heap_key);
393+
if ((uintptr_t)key % alignof(uint64_t) != 0) {
394+
tmp_key = (char *) do_alloca(key_len + alignof(uint64_t), use_heap_key);
414395
key = copied_key =
415-
memcpy(tmp_key + __alignof__(uint64_t) - (uintptr_t)tmp_key % __alignof__(uint64_t), key, key_len);
396+
memcpy(tmp_key + alignof(uint64_t) - (uintptr_t)tmp_key % alignof(uint64_t), key, key_len);
416397
}
417398

418-
if ((uintptr_t)salt % __alignof__ (uint64_t) != 0) {
419-
tmp_salt = (char *) do_alloca(salt_len + 1 + __alignof__(uint64_t), use_heap_salt);
420-
salt = copied_salt = memcpy(tmp_salt + __alignof__(uint64_t) - (uintptr_t)tmp_salt % __alignof__(uint64_t), salt, salt_len);
399+
if ((uintptr_t)salt % alignof(uint64_t) != 0) {
400+
tmp_salt = (char *) do_alloca(salt_len + 1 + alignof(uint64_t), use_heap_salt);
401+
salt = copied_salt = memcpy(tmp_salt + alignof(uint64_t) - (uintptr_t)tmp_salt % alignof(uint64_t), salt, salt_len);
421402
copied_salt[salt_len] = 0;
422403
}
423404

0 commit comments

Comments
 (0)