Skip to content

Commit 2c2ecba

Browse files
Girgiasbooti386bwoebi
authored
Determine value of ZEND_MM_* during config and fix sign conversion (#6981)
Also add a new ZEND_MM_NEED_EIGHT_BYTE_REALIGNMENT definition. This fixes many [-Wsign-conversion] warnings. Co-authored-by: Guillaume Charifi <guillaume.charifi@sfr.fr> Co-authored-by: Bob Weinand <bobwei9@hotmail.com>
1 parent 738adce commit 2c2ecba

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

Zend/Zend.m4

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ typedef union _mm_align_test {
256256
257257
int main()
258258
{
259-
int i = ZEND_MM_ALIGNMENT;
259+
size_t i = ZEND_MM_ALIGNMENT;
260260
int zeros = 0;
261261
FILE *fp;
262262
@@ -266,20 +266,23 @@ int main()
266266
}
267267
268268
fp = fopen("conftest.zend", "w");
269-
fprintf(fp, "%d %d\n", ZEND_MM_ALIGNMENT, zeros);
269+
fprintf(fp, "(size_t)%zu (size_t)%d %d\n", ZEND_MM_ALIGNMENT, zeros, ZEND_MM_ALIGNMENT < 4);
270270
fclose(fp);
271271
272272
return 0;
273273
}
274274
]])], [
275275
LIBZEND_MM_ALIGN=`cat conftest.zend | cut -d ' ' -f 1`
276276
LIBZEND_MM_ALIGN_LOG2=`cat conftest.zend | cut -d ' ' -f 2`
277+
LIBZEND_MM_NEED_EIGHT_BYTE_REALIGNMENT=`cat conftest.zend | cut -d ' ' -f 3`
277278
AC_DEFINE_UNQUOTED(ZEND_MM_ALIGNMENT, $LIBZEND_MM_ALIGN, [ ])
278279
AC_DEFINE_UNQUOTED(ZEND_MM_ALIGNMENT_LOG2, $LIBZEND_MM_ALIGN_LOG2, [ ])
280+
AC_DEFINE_UNQUOTED(ZEND_MM_NEED_EIGHT_BYTE_REALIGNMENT, $LIBZEND_MM_NEED_EIGHT_BYTE_REALIGNMENT, [ ])
279281
], [], [
280282
dnl Cross compilation needs something here.
281-
AC_DEFINE_UNQUOTED(ZEND_MM_ALIGNMENT, 8, [ ])
282-
AC_DEFINE_UNQUOTED(ZEND_MM_ALIGNMENT_LOG2, 3, [ ])
283+
AC_DEFINE(ZEND_MM_ALIGNMENT, 8, [ ])
284+
AC_DEFINE(ZEND_MM_ALIGNMENT_LOG2, 3, [ ])
285+
AC_DEFINE(ZEND_MM_NEED_EIGHT_BYTE_REALIGNMENT, 0, [ ])
283286
])
284287
285288
AC_MSG_RESULT(done)

Zend/zend_alloc.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,7 @@
2727
#include "zend.h"
2828

2929
#ifndef ZEND_MM_ALIGNMENT
30-
# define ZEND_MM_ALIGNMENT Z_UL(8)
31-
# define ZEND_MM_ALIGNMENT_LOG2 Z_L(3)
32-
#elif ZEND_MM_ALIGNMENT < 4
33-
# undef ZEND_MM_ALIGNMENT
34-
# undef ZEND_MM_ALIGNMENT_LOG2
35-
# define ZEND_MM_ALIGNMENT Z_UL(4)
36-
# define ZEND_MM_ALIGNMENT_LOG2 Z_L(2)
30+
# error "ZEND_MM_ALIGNMENT was not defined during configure"
3731
#endif
3832

3933
#define ZEND_MM_ALIGNMENT_MASK ~(ZEND_MM_ALIGNMENT - 1)

ext/opcache/ZendAccelerator.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,7 @@ static zend_persistent_script *store_script_in_file_cache(zend_persistent_script
14841484
/* Align to 64-byte boundary */
14851485
ZCG(mem) = zend_arena_alloc(&CG(arena), memory_used + 64);
14861486
ZCG(mem) = (void*)(((zend_uintptr_t)ZCG(mem) + 63L) & ~63L);
1487-
#elif ZEND_MM_ALIGNMENT < 8
1487+
#elif ZEND_MM_NEED_EIGHT_BYTE_REALIGNMENT
14881488
/* Align to 8-byte boundary */
14891489
ZCG(mem) = zend_arena_alloc(&CG(arena), memory_used + 8);
14901490
ZCG(mem) = (void*)(((zend_uintptr_t)ZCG(mem) + 7L) & ~7L);
@@ -2365,7 +2365,7 @@ static zend_class_entry* zend_accel_inheritance_cache_add(zend_class_entry *ce,
23652365

23662366
zend_shared_alloc_clear_xlat_table();
23672367

2368-
#if ZEND_MM_ALIGNMENT < 8
2368+
#if ZEND_MM_NEED_EIGHT_BYTE_REALIGNMENT
23692369
/* Align to 8-byte boundary */
23702370
ZCG(mem) = zend_shared_alloc(size + 8);
23712371
#else
@@ -2381,7 +2381,7 @@ static zend_class_entry* zend_accel_inheritance_cache_add(zend_class_entry *ce,
23812381

23822382
zend_map_ptr_extend(ZCSG(map_ptr_last));
23832383

2384-
#if ZEND_MM_ALIGNMENT < 8
2384+
#if ZEND_MM_NEED_EIGHT_BYTE_REALIGNMENT
23852385
/* Align to 8-byte boundary */
23862386
ZCG(mem) = (void*)(((zend_uintptr_t)ZCG(mem) + 7L) & ~7L);
23872387
#endif

win32/build/config.w32.h.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
#define DEFAULT_SHORT_OPEN_TAG "1"
2828

2929
/* Platform-Specific Configuration. Should not be changed. */
30+
/* Alignment for Zend memory allocator */
31+
#define ZEND_MM_ALIGNMENT (size_t)8
32+
#define ZEND_MM_ALIGNMENT_LOG2 (size_t)3
33+
#define ZEND_MM_NEED_EIGHT_BYTE_REALIGNMENT 0
3034
#define PHP_SIGCHILD 0
3135
#define HAVE_GETSERVBYNAME 1
3236
#define HAVE_GETSERVBYPORT 1

0 commit comments

Comments
 (0)