Skip to content

Commit a4fce72

Browse files
committed
Use int64 for zend_long
1 parent 035f95c commit a4fce72

File tree

12 files changed

+87
-34
lines changed

12 files changed

+87
-34
lines changed

Zend/Zend.m4

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ AX_CHECK_COMPILE_FLAG([-fno-common],
211211
[CFLAGS="-fno-common $CFLAGS"])
212212
213213
ZEND_CHECK_ALIGNMENT
214+
ZEND_CHECK_INT64
214215
ZEND_CHECK_SIGNALS
215216
ZEND_CHECK_MAX_EXECUTION_TIMERS
216217
])
@@ -414,6 +415,43 @@ AS_VAR_IF([php_cv_align_mm], [failed],
414415
])
415416
])
416417

418+
dnl
419+
dnl ZEND_CHECK_INT64
420+
dnl
421+
dnl Check whether to enable 64 bit integer if supported by the system.
422+
dnl
423+
AC_DEFUN([ZEND_CHECK_INT64], [dnl
424+
AC_COMPILE_IFELSE(
425+
[AC_LANG_PROGRAM(
426+
[[]],
427+
[[
428+
#if !(defined(__x86_64__) || defined(__LP64__) || defined(_LP64) || defined(_WIN64))
429+
#error "Not a 64-bit platform"
430+
#endif
431+
]]
432+
)],
433+
[ZEND_INT64=yes],
434+
[ZEND_INT64=no])
435+
436+
AC_ARG_ENABLE([zend-int64],
437+
[AS_HELP_STRING([--enable-zend-int64], [Enable 64bit integer support (enabled by default on 64bit arch)])],
438+
[ZEND_INT64=$enableval],
439+
[ZEND_INT64=$ZEND_INT64])
440+
441+
AS_VAR_IF([ZEND_INT64], [yes],
442+
AC_CHECK_TYPE([int64_t],,
443+
[AC_MSG_ERROR([int64_t not found])],
444+
[#include <stdint.h>]))
445+
446+
AS_VAR_IF([ZEND_INT64], [yes],
447+
[AC_DEFINE([ZEND_INT64], [1],
448+
[Define to 1 if zend_long as int64 is supported and enabled.])
449+
AS_VAR_APPEND([CFLAGS], [" -DZEND_INT64"])])
450+
451+
AC_MSG_CHECKING([whether to enable 64 bit integer support])
452+
AC_MSG_RESULT([$ZEND_INT64])
453+
])
454+
417455
dnl
418456
dnl ZEND_CHECK_SIGNALS
419457
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))
@@ -571,7 +571,7 @@ static void *zend_mm_mmap(size_t size)
571571
/* number of trailing set (1) bits */
572572
ZEND_ATTRIBUTE_CONST static zend_always_inline int zend_mm_bitset_nts(zend_mm_bitset bitset)
573573
{
574-
#if (defined(__GNUC__) || __has_builtin(__builtin_ctzl)) && SIZEOF_ZEND_LONG == SIZEOF_LONG && defined(PHP_HAVE_BUILTIN_CTZL)
574+
#if (defined(__GNUC__) || __has_builtin(__builtin_ctzl)) && SIZEOF_SIZE_T == SIZEOF_LONG && defined(PHP_HAVE_BUILTIN_CTZL)
575575
return __builtin_ctzl(~bitset);
576576
#elif (defined(__GNUC__) || __has_builtin(__builtin_ctzll)) && defined(PHP_HAVE_BUILTIN_CTZLL)
577577
return __builtin_ctzll(~bitset);
@@ -594,7 +594,7 @@ ZEND_ATTRIBUTE_CONST static zend_always_inline int zend_mm_bitset_nts(zend_mm_bi
594594
if (bitset == (zend_mm_bitset)-1) return ZEND_MM_BITSET_LEN;
595595

596596
n = 0;
597-
#if SIZEOF_ZEND_LONG == 8
597+
#if SIZEOF_SIZE_T == 8
598598
if (sizeof(zend_mm_bitset) == 8) {
599599
if ((bitset & 0xffffffff) == 0xffffffff) {n += 32; bitset = bitset >> Z_UL(32);}
600600
}
@@ -2082,7 +2082,7 @@ static zend_mm_heap *zend_mm_init(void)
20822082
#endif
20832083
zend_mm_init_key(heap);
20842084
#if ZEND_MM_LIMIT
2085-
heap->limit = (size_t)Z_L(-1) >> 1;
2085+
heap->limit = (size_t)-1 >> 1;
20862086
heap->overflow = 0;
20872087
#endif
20882088
#if ZEND_MM_CUSTOM
@@ -3285,7 +3285,7 @@ static void alloc_globals_ctor(zend_alloc_globals *alloc_globals)
32853285
zend_mm_heap *mm_heap = alloc_globals->mm_heap = malloc(sizeof(zend_mm_heap));
32863286
memset(mm_heap, 0, sizeof(zend_mm_heap));
32873287
mm_heap->use_custom_heap = ZEND_MM_CUSTOM_HEAP_STD;
3288-
mm_heap->limit = (size_t)Z_L(-1) >> 1;
3288+
mm_heap->limit = (size_t)-1 >> 1;
32893289
mm_heap->overflow = 0;
32903290

32913291
if (!tracked) {
@@ -3506,7 +3506,7 @@ ZEND_API zend_mm_heap *zend_mm_startup_ex(const zend_mm_handlers *handlers, void
35063506
#endif
35073507
zend_mm_init_key(heap);
35083508
#if ZEND_MM_LIMIT
3509-
heap->limit = (size_t)Z_L(-1) >> 1;
3509+
heap->limit = (size_t)-1 >> 1;
35103510
heap->overflow = 0;
35113511
#endif
35123512
#if ZEND_MM_CUSTOM

Zend/zend_compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12360,7 +12360,7 @@ static void zend_eval_const_expr(zend_ast **ast_ptr) /* {{{ */
1236012360
} else if (Z_TYPE_P(dim) != IS_STRING || is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL, 1) != IS_LONG) {
1236112361
return;
1236212362
}
12363-
if (offset < 0 || (size_t)offset >= Z_STRLEN_P(container)) {
12363+
if (offset < 0 || ZEND_SIZE_T_LTE_ZEND_LONG(Z_STRLEN_P(container), offset)) {
1236412364
return;
1236512365
}
1236612366
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
@@ -2157,11 +2157,11 @@ static zend_never_inline void zend_assign_to_string_offset(zval *str, zval *dim,
21572157
}
21582158
}
21592159

2160-
if ((size_t)offset >= ZSTR_LEN(s)) {
2160+
if (ZEND_SIZE_T_LTE_ZEND_LONG(ZSTR_LEN(s), offset)) {
21612161
/* Extend string if needed */
2162-
zend_long old_len = ZSTR_LEN(s);
2162+
size_t old_len = ZSTR_LEN(s);
21632163
ZVAL_NEW_STR(str, zend_string_extend(s, (size_t)offset + 1, 0));
2164-
memset(Z_STRVAL_P(str) + old_len, ' ', offset - old_len);
2164+
memset(Z_STRVAL_P(str) + old_len, ' ', (size_t)offset - old_len);
21652165
Z_STRVAL_P(str)[offset+1] = 0;
21662166
} else {
21672167
zend_string_forget_hash_val(Z_STR_P(str));
@@ -3148,7 +3148,7 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
31483148
}
31493149
out:
31503150

3151-
if (UNEXPECTED(ZSTR_LEN(str) < ((offset < 0) ? -(size_t)offset : ((size_t)offset + 1)))) {
3151+
if (UNEXPECTED(ZEND_SIZE_T_LT_ZEND_ULONG(ZSTR_LEN(str), ((offset < 0) ? -(zend_ulong)offset : ((zend_ulong)offset + 1))))) {
31523152
if (type != BP_VAR_IS) {
31533153
zend_error(E_WARNING, "Uninitialized string offset " ZEND_LONG_FMT, offset);
31543154
ZVAL_EMPTY_STRING(result);
@@ -3309,7 +3309,7 @@ static zend_never_inline bool ZEND_FASTCALL zend_isset_dim_slow(zval *container,
33093309
if (UNEXPECTED(lval < 0)) { /* Handle negative offset */
33103310
lval += (zend_long)Z_STRLEN_P(container);
33113311
}
3312-
if (EXPECTED(lval >= 0) && (size_t)lval < Z_STRLEN_P(container)) {
3312+
if (EXPECTED(lval >= 0) && ZEND_SIZE_T_GT_ZEND_LONG(Z_STRLEN_P(container), lval)) {
33133313
return 1;
33143314
} else {
33153315
return 0;
@@ -3348,7 +3348,7 @@ static zend_never_inline bool ZEND_FASTCALL zend_isempty_dim_slow(zval *containe
33483348
if (UNEXPECTED(lval < 0)) { /* Handle negative offset */
33493349
lval += (zend_long)Z_STRLEN_P(container);
33503350
}
3351-
if (EXPECTED(lval >= 0) && (size_t)lval < Z_STRLEN_P(container)) {
3351+
if (EXPECTED(lval >= 0) && ZEND_SIZE_T_GT_ZEND_LONG(Z_STRLEN_P(container), lval)) {
33523352
return (Z_STRVAL_P(container)[lval] == '0');
33533353
} else {
33543354
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) {
@@ -552,11 +552,11 @@ static void zend_generator_add_child(zend_generator *generator, zend_generator *
552552
HashTable *ht = emalloc(sizeof(HashTable));
553553
zend_hash_init(ht, 0, NULL, NULL, 0);
554554
zend_hash_index_add_new_ptr(ht,
555-
(zend_ulong) node->child.single, node->child.single);
555+
(zend_ulong)(uintptr_t)node->child.single, node->child.single);
556556
node->child.ht = ht;
557557
}
558558

559-
zend_hash_index_add_new_ptr(node->child.ht, (zend_ulong) child, child);
559+
zend_hash_index_add_new_ptr(node->child.ht, (zend_ulong)(uintptr_t)child, child);
560560
}
561561

562562
++node->children;

Zend/zend_long.h

Lines changed: 1 addition & 1 deletion
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

Zend/zend_operators.h

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

531-
#if defined(HAVE_ASM_GOTO) && !__has_feature(memory_sanitizer)
532-
# define ZEND_USE_ASM_ARITHMETIC 1
533-
#else
531+
//#if defined(HAVE_ASM_GOTO) && !__has_feature(memory_sanitizer)
532+
//# define ZEND_USE_ASM_ARITHMETIC 1
533+
//#else
534534
# define ZEND_USE_ASM_ARITHMETIC 0
535-
#endif
535+
//#endif
536536

537537
static zend_always_inline void fast_long_increment_function(zval *op1)
538538
{

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)