Skip to content

Commit 0624961

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

18 files changed

+109
-56
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ ZEND_ATTRIBUTE_CONST static zend_always_inline int zend_mm_bitset_nts(zend_mm_bi
589589
{
590590
#if (defined(__GNUC__) || __has_builtin(__builtin_ctzl)) && SIZEOF_ZEND_LONG == SIZEOF_LONG && defined(PHP_HAVE_BUILTIN_CTZL)
591591
return __builtin_ctzl(~bitset);
592-
#elif (defined(__GNUC__) || __has_builtin(__builtin_ctzll)) && defined(PHP_HAVE_BUILTIN_CTZLL)
592+
#elif (defined(__GNUC__) || __has_builtin(__builtin_ctzll)) && SIZEOF_ZEND_LONG == SIZEOF_LONG_LONG && defined(PHP_HAVE_BUILTIN_CTZLL)
593593
return __builtin_ctzll(~bitset);
594594
#elif defined(_WIN32)
595595
unsigned long index;
@@ -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_execute_API.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, zend_string *
12151215
ALLOC_HASHTABLE(CG(unlinked_uses));
12161216
zend_hash_init(CG(unlinked_uses), 0, NULL, NULL, 0);
12171217
}
1218-
zend_hash_index_add_empty_element(CG(unlinked_uses), (zend_long)(uintptr_t)ce);
1218+
zend_hash_index_add_empty_element(CG(unlinked_uses), (zend_ulong)(uintptr_t)ce);
12191219
return ce;
12201220
}
12211221
return NULL;

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_inheritance.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3299,7 +3299,7 @@ static void check_unrecoverable_load_failure(const zend_class_entry *ce) {
32993299
* a dependence on the inheritance hierarchy of this specific class. Instead we fall back to
33003300
* a fatal error, as would happen if we did not allow exceptions in the first place. */
33013301
if (CG(unlinked_uses)
3302-
&& zend_hash_index_del(CG(unlinked_uses), (zend_long)(uintptr_t)ce) == SUCCESS) {
3302+
&& zend_hash_index_del(CG(unlinked_uses), (zend_ulong)(uintptr_t)ce) == SUCCESS) {
33033303
zend_exception_uncaught_error(
33043304
"During inheritance of %s with variance dependencies", ZSTR_VAL(ce->name));
33053305
}
@@ -3584,7 +3584,7 @@ ZEND_API zend_class_entry *zend_do_link_class(zend_class_entry *ce, zend_string
35843584
}
35853585

35863586
if (CG(unlinked_uses)) {
3587-
zend_hash_index_del(CG(unlinked_uses), (zend_long)(uintptr_t) ce);
3587+
zend_hash_index_del(CG(unlinked_uses), (zend_ulong)(uintptr_t) ce);
35883588
}
35893589

35903590
orig_linking_class = CG(current_linking_class);

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 */

0 commit comments

Comments
 (0)