Skip to content

Commit db4fd29

Browse files
committed
Use int64 for zend_long
1 parent 964a404 commit db4fd29

13 files changed

+101
-48
lines changed

Zend/Zend.m4

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ AX_CHECK_COMPILE_FLAG([-fno-common],
216216
[-Werror])
217217
218218
ZEND_CHECK_ALIGNMENT
219+
ZEND_CHECK_INT64
219220
ZEND_CHECK_SIGNALS
220221
ZEND_CHECK_MAX_EXECUTION_TIMERS
221222
])
@@ -419,6 +420,43 @@ AS_VAR_IF([php_cv_align_mm], [failed],
419420
])
420421
])
421422

423+
dnl
424+
dnl ZEND_CHECK_INT64
425+
dnl
426+
dnl Check whether to enable 64 bit integer if supported by the system.
427+
dnl
428+
AC_DEFUN([ZEND_CHECK_INT64], [dnl
429+
AC_COMPILE_IFELSE(
430+
[AC_LANG_PROGRAM(
431+
[[]],
432+
[[
433+
#if !(defined(__x86_64__) || defined(__LP64__) || defined(_LP64) || defined(_WIN64))
434+
#error "Not a 64-bit platform"
435+
#endif
436+
]]
437+
)],
438+
[ZEND_INT64=yes],
439+
[ZEND_INT64=no])
440+
441+
AC_ARG_ENABLE([zend-int64],
442+
[AS_HELP_STRING([--enable-zend-int64], [Enable 64bit integer support (enabled by default on 64bit arch)])],
443+
[ZEND_INT64=$enableval],
444+
[ZEND_INT64=$ZEND_INT64])
445+
446+
AS_VAR_IF([ZEND_INT64], [yes],
447+
AC_CHECK_TYPE([int64_t],,
448+
[AC_MSG_ERROR([int64_t not found])],
449+
[#include <stdint.h>]))
450+
451+
AS_VAR_IF([ZEND_INT64], [yes],
452+
[AC_DEFINE([ZEND_INT64], [1],
453+
[Define to 1 if zend_long as int64 is supported and enabled.])
454+
AS_VAR_APPEND([CFLAGS], [" -DZEND_INT64"])])
455+
456+
AC_MSG_CHECKING([whether to enable 64 bit integer support])
457+
AC_MSG_RESULT([$ZEND_INT64])
458+
])
459+
422460
dnl
423461
dnl ZEND_CHECK_SIGNALS
424462
dnl

Zend/zend_alloc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ static size_t _real_page_size = ZEND_MM_PAGE_SIZE;
174174
#endif
175175

176176
typedef uint32_t zend_mm_page_info; /* 4-byte integer */
177-
typedef zend_ulong zend_mm_bitset; /* 4-byte or 8-byte integer */
177+
typedef size_t zend_mm_bitset; /* 4-byte or 8-byte integer */
178178

179179
#define ZEND_MM_ALIGNED_OFFSET(size, alignment) \
180180
(((size_t)(size)) & ((alignment) - 1))
@@ -587,7 +587,7 @@ static void *zend_mm_mmap(size_t size)
587587
/* number of trailing set (1) bits */
588588
ZEND_ATTRIBUTE_CONST static zend_always_inline int zend_mm_bitset_nts(zend_mm_bitset bitset)
589589
{
590-
#if (defined(__GNUC__) || __has_builtin(__builtin_ctzl)) && SIZEOF_ZEND_LONG == SIZEOF_LONG && defined(PHP_HAVE_BUILTIN_CTZL)
590+
#if (defined(__GNUC__) || __has_builtin(__builtin_ctzl)) && SIZEOF_SIZE_T == SIZEOF_LONG && defined(PHP_HAVE_BUILTIN_CTZL)
591591
return __builtin_ctzl(~bitset);
592592
#elif (defined(__GNUC__) || __has_builtin(__builtin_ctzll)) && defined(PHP_HAVE_BUILTIN_CTZLL)
593593
return __builtin_ctzll(~bitset);
@@ -610,7 +610,7 @@ ZEND_ATTRIBUTE_CONST static zend_always_inline int zend_mm_bitset_nts(zend_mm_bi
610610
if (bitset == (zend_mm_bitset)-1) return ZEND_MM_BITSET_LEN;
611611

612612
n = 0;
613-
#if SIZEOF_ZEND_LONG == 8
613+
#if SIZEOF_SIZE_T == 8
614614
if (sizeof(zend_mm_bitset) == 8) {
615615
if ((bitset & 0xffffffff) == 0xffffffff) {n += 32; bitset = bitset >> Z_UL(32);}
616616
}
@@ -2065,7 +2065,7 @@ static zend_mm_heap *zend_mm_init(void)
20652065
#endif
20662066
zend_mm_init_key(heap);
20672067
#if ZEND_MM_LIMIT
2068-
heap->limit = (size_t)Z_L(-1) >> 1;
2068+
heap->limit = (size_t)-1 >> 1;
20692069
heap->overflow = 0;
20702070
#endif
20712071
#if ZEND_MM_CUSTOM
@@ -3262,7 +3262,7 @@ static void alloc_globals_ctor(zend_alloc_globals *alloc_globals)
32623262
zend_mm_heap *mm_heap = alloc_globals->mm_heap = malloc(sizeof(zend_mm_heap));
32633263
memset(mm_heap, 0, sizeof(zend_mm_heap));
32643264
mm_heap->use_custom_heap = ZEND_MM_CUSTOM_HEAP_STD;
3265-
mm_heap->limit = (size_t)Z_L(-1) >> 1;
3265+
mm_heap->limit = (size_t)-1 >> 1;
32663266
mm_heap->overflow = 0;
32673267

32683268
if (!tracked) {
@@ -3483,7 +3483,7 @@ ZEND_API zend_mm_heap *zend_mm_startup_ex(const zend_mm_handlers *handlers, void
34833483
#endif
34843484
zend_mm_init_key(heap);
34853485
#if ZEND_MM_LIMIT
3486-
heap->limit = (size_t)Z_L(-1) >> 1;
3486+
heap->limit = (size_t)-1 >> 1;
34873487
heap->overflow = 0;
34883488
#endif
34893489
#if ZEND_MM_CUSTOM

Zend/zend_compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12134,7 +12134,7 @@ static void zend_eval_const_expr(zend_ast **ast_ptr) /* {{{ */
1213412134
} else if (Z_TYPE_P(dim) != IS_STRING || is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL, 1) != IS_LONG) {
1213512135
return;
1213612136
}
12137-
if (offset < 0 || (size_t)offset >= Z_STRLEN_P(container)) {
12137+
if (offset < 0 || ZEND_SIZE_T_LTE_ZEND_LONG(Z_STRLEN_P(container), offset)) {
1213812138
return;
1213912139
}
1214012140
c = (uint8_t) Z_STRVAL_P(container)[offset];

Zend/zend_execute.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,11 +2132,11 @@ static zend_never_inline void zend_assign_to_string_offset(zval *str, zval *dim,
21322132
}
21332133
}
21342134

2135-
if ((size_t)offset >= ZSTR_LEN(s)) {
2135+
if (ZEND_SIZE_T_LTE_ZEND_LONG(ZSTR_LEN(s), offset)) {
21362136
/* Extend string if needed */
2137-
zend_long old_len = ZSTR_LEN(s);
2137+
size_t old_len = ZSTR_LEN(s);
21382138
ZVAL_NEW_STR(str, zend_string_extend(s, (size_t)offset + 1, 0));
2139-
memset(Z_STRVAL_P(str) + old_len, ' ', offset - old_len);
2139+
memset(Z_STRVAL_P(str) + old_len, ' ', (size_t)offset - old_len);
21402140
Z_STRVAL_P(str)[offset+1] = 0;
21412141
} else {
21422142
zend_string_forget_hash_val(Z_STR_P(str));
@@ -3094,7 +3094,7 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
30943094
}
30953095
out:
30963096

3097-
if (UNEXPECTED(ZSTR_LEN(str) < ((offset < 0) ? -(size_t)offset : ((size_t)offset + 1)))) {
3097+
if (UNEXPECTED(ZEND_SIZE_T_LT_ZEND_ULONG(ZSTR_LEN(str), ((offset < 0) ? -(zend_ulong)offset : ((zend_ulong)offset + 1))))) {
30983098
if (type != BP_VAR_IS) {
30993099
zend_error(E_WARNING, "Uninitialized string offset " ZEND_LONG_FMT, offset);
31003100
ZVAL_EMPTY_STRING(result);
@@ -3227,7 +3227,7 @@ static zend_never_inline bool ZEND_FASTCALL zend_isset_dim_slow(zval *container,
32273227
if (UNEXPECTED(lval < 0)) { /* Handle negative offset */
32283228
lval += (zend_long)Z_STRLEN_P(container);
32293229
}
3230-
if (EXPECTED(lval >= 0) && (size_t)lval < Z_STRLEN_P(container)) {
3230+
if (EXPECTED(lval >= 0) && ZEND_SIZE_T_GT_ZEND_LONG(Z_STRLEN_P(container), lval)) {
32313231
return 1;
32323232
} else {
32333233
return 0;
@@ -3266,7 +3266,7 @@ static zend_never_inline bool ZEND_FASTCALL zend_isempty_dim_slow(zval *containe
32663266
if (UNEXPECTED(lval < 0)) { /* Handle negative offset */
32673267
lval += (zend_long)Z_STRLEN_P(container);
32683268
}
3269-
if (EXPECTED(lval >= 0) && (size_t)lval < Z_STRLEN_P(container)) {
3269+
if (EXPECTED(lval >= 0) && ZEND_SIZE_T_GT_ZEND_LONG(Z_STRLEN_P(container), lval)) {
32703270
return (Z_STRVAL_P(container)[lval] == '0');
32713271
} else {
32723272
return 1;

Zend/zend_generators.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static void zend_generator_remove_child(zend_generator_node *node, zend_generato
179179
node->child.single = NULL;
180180
} else {
181181
HashTable *ht = node->child.ht;
182-
zend_hash_index_del(ht, (zend_ulong) child);
182+
zend_hash_index_del(ht, (zend_ulong)(uintptr_t)child);
183183
if (node->children == 2) {
184184
zend_generator *other_child;
185185
ZEND_HASH_FOREACH_PTR(ht, other_child) {
@@ -533,11 +533,11 @@ static void zend_generator_add_child(zend_generator *generator, zend_generator *
533533
HashTable *ht = emalloc(sizeof(HashTable));
534534
zend_hash_init(ht, 0, NULL, NULL, 0);
535535
zend_hash_index_add_new_ptr(ht,
536-
(zend_ulong) node->child.single, node->child.single);
536+
(zend_ulong)(uintptr_t)node->child.single, node->child.single);
537537
node->child.ht = ht;
538538
}
539539

540-
zend_hash_index_add_new_ptr(node->child.ht, (zend_ulong) child, child);
540+
zend_hash_index_add_new_ptr(node->child.ht, (zend_ulong)(uintptr_t)child, child);
541541
}
542542

543543
++node->children;

Zend/zend_long.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <stdint.h>
2424

2525
/* This is the heart of the whole int64 enablement in zval. */
26-
#if defined(__x86_64__) || defined(__LP64__) || defined(_LP64) || defined(_WIN64)
26+
#ifdef ZEND_INT64
2727
# define ZEND_ENABLE_ZVAL_LONG64 1
2828
#endif
2929

@@ -97,7 +97,7 @@ typedef int32_t zend_off_t;
9797
do { \
9898
int st = snprintf((s), (len), ZEND_LONG_FMT, (i)); \
9999
(s)[st] = '\0'; \
100-
} while (0)
100+
} while (0)
101101
# define ZEND_ATOL(s) atol((s))
102102
# endif
103103
# define ZEND_STRTOL_PTR strtol

Zend/zend_operators.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,11 +519,11 @@ ZEND_API void zend_reset_lc_ctype_locale(void);
519519
#define ZVAL_OFFSETOF_TYPE \
520520
(offsetof(zval, u1.type_info) - offsetof(zval, value))
521521

522-
#if defined(HAVE_ASM_GOTO) && !__has_feature(memory_sanitizer)
523-
# define ZEND_USE_ASM_ARITHMETIC 1
524-
#else
522+
//#if defined(HAVE_ASM_GOTO) && !__has_feature(memory_sanitizer)
523+
//# define ZEND_USE_ASM_ARITHMETIC 1
524+
//#else
525525
# define ZEND_USE_ASM_ARITHMETIC 0
526-
#endif
526+
//#endif
527527

528528
static zend_always_inline void fast_long_increment_function(zval *op1)
529529
{

Zend/zend_range_check.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,24 @@
5959
#endif
6060

6161
/* Comparison zend_long vs size_t */
62-
#define ZEND_SIZE_T_GT_ZEND_LONG(size, zlong) ((zlong) < 0 || (size) > (size_t)(zlong))
63-
#define ZEND_SIZE_T_GTE_ZEND_LONG(size, zlong) ((zlong) < 0 || (size) >= (size_t)(zlong))
64-
#define ZEND_SIZE_T_LT_ZEND_LONG(size, zlong) ((zlong) >= 0 && (size) < (size_t)(zlong))
65-
#define ZEND_SIZE_T_LTE_ZEND_LONG(size, zlong) ((zlong) >= 0 && (size) <= (size_t)(zlong))
62+
#if SIZEOF_SIZE_T < SIZEOF_ZEND_LONG
63+
# define ZEND_SIZE_T_GT_ZEND_LONG(size, zlong) ((zlong) < 0 || ((zlong) < SIZE_MAX && (size) > (size_t)(zlong)))
64+
# define ZEND_SIZE_T_GT_ZEND_ULONG(size, zulong) (zulong < SIZE_MAX && (size) > (size_t)(zulong))
65+
# define ZEND_SIZE_T_GTE_ZEND_LONG(size, zlong) ((zlong) < 0 || ((zlong) <= SIZE_MAX && (size) >= (size_t)(zlong)))
66+
# define ZEND_SIZE_T_GTE_ZEND_ULONG(size, zulong) ((zulong) <= SIZE_MAX && (size) >= (size_t)(zulong))
67+
# define ZEND_SIZE_T_LT_ZEND_LONG(size, zlong) ((zlong) >= SIZE_MAX || ((zlong) > 0 && (size) < (size_t)(zlong)))
68+
# define ZEND_SIZE_T_LT_ZEND_ULONG(size, zulong) ((zulong) >= SIZE_MAX || (size) < (size_t)(zulong))
69+
# define ZEND_SIZE_T_LTE_ZEND_LONG(size, zlong) ((zlong) > SIZE_MAX || ((zlong) >= 0 && (size) <= (size_t)(zlong)))
70+
# define ZEND_SIZE_T_LTE_ZEND_ULONG(size, zulong) ((zulong) > SIZE_MAX || (size) <= (size_t)(zlong))
71+
#else
72+
# define ZEND_SIZE_T_GT_ZEND_LONG(size, zlong) ((zlong) < 0 || (size) > (size_t)(zlong))
73+
# define ZEND_SIZE_T_GT_ZEND_ULONG(size, zulong) ((size) > (size_t)(zulong))
74+
# define ZEND_SIZE_T_GTE_ZEND_LONG(size, zlong) ((zlong) < 0 || (size) >= (size_t)(zlong))
75+
# define ZEND_SIZE_T_GTE_ZEND_ULONG(size, zulong) ((size) >= (size_t)(zulong))
76+
# define ZEND_SIZE_T_LT_ZEND_LONG(size, zlong) ((zlong) > 0 && (size) < (size_t)(zlong))
77+
# define ZEND_SIZE_T_LT_ZEND_ULONG(size, zulong) ((size) < (size_t)(zulong))
78+
# define ZEND_SIZE_T_LTE_ZEND_LONG(size, zlong) ((zlong) >= 0 && (size) <= (size_t)(zlong))
79+
# define ZEND_SIZE_T_LTE_ZEND_ULONG(size, zulong) ((size) <= (size_t)(zulong))
80+
#endif
6681

6782
#endif /* ZEND_RANGE_CHECK_H */

Zend/zend_string.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ ZEND_API bool ZEND_FASTCALL I_REPLACE_SONAME_FNNAME_ZU(NONE,zend_string_equal_va
393393
}
394394
#endif
395395

396-
#if defined(__GNUC__) && defined(__i386__)
396+
#if SIZEOF_SIZE_T == SIZEOF_ZEND_LONG && defined(__GNUC__) && defined(__i386__)
397397
ZEND_API zend_never_inline NOIPA bool ZEND_FASTCALL zend_string_equal_val(const zend_string *s1, const zend_string *s2)
398398
{
399399
const char *ptr = ZSTR_VAL(s1);
@@ -430,8 +430,7 @@ ZEND_API zend_never_inline NOIPA bool ZEND_FASTCALL zend_string_equal_val(const
430430
: "cc");
431431
return ret;
432432
}
433-
434-
#elif defined(__GNUC__) && defined(__x86_64__) && !defined(__ILP32__)
433+
#elif SIZEOF_SIZE_T == SIZEOF_ZEND_LONG && defined(__GNUC__) && defined(__x86_64__) && !defined(__ILP32__)
435434
ZEND_API zend_never_inline NOIPA bool ZEND_FASTCALL zend_string_equal_val(const zend_string *s1, const zend_string *s2)
436435
{
437436
const char *ptr = ZSTR_VAL(s1);

Zend/zend_string.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ static zend_always_inline bool zend_string_equals_cstr(const zend_string *s1, co
361361
return ZSTR_LEN(s1) == s2_length && !memcmp(ZSTR_VAL(s1), s2, s2_length);
362362
}
363363

364-
#if defined(__GNUC__) && (defined(__i386__) || (defined(__x86_64__) && !defined(__ILP32__)))
364+
#if SIZEOF_SIZE_T == SIZEOF_ZEND_LONG && defined(__GNUC__) && (defined(__i386__) || (defined(__x86_64__) && !defined(__ILP32__)))
365365
BEGIN_EXTERN_C()
366366
ZEND_API bool ZEND_FASTCALL zend_string_equal_val(const zend_string *s1, const zend_string *s2);
367367
END_EXTERN_C()

0 commit comments

Comments
 (0)