Skip to content

Commit 24581c9

Browse files
committed
Add PHP_INT_MAX_SAFE constant
1 parent 2beb44a commit 24581c9

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

Zend/zend_long.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ typedef uint64_t zend_ulong;
3434
typedef int64_t zend_off_t;
3535
# define ZEND_LONG_MAX INT64_MAX
3636
# define ZEND_LONG_MIN INT64_MIN
37+
# define ZEND_LONG_SAFE_MAX (2UL << 52UL)-1UL
3738
# define ZEND_ULONG_MAX UINT64_MAX
3839
# define Z_L(i) INT64_C(i)
3940
# define Z_UL(i) UINT64_C(i)
@@ -44,6 +45,7 @@ typedef uint32_t zend_ulong;
4445
typedef int32_t zend_off_t;
4546
# define ZEND_LONG_MAX INT32_MAX
4647
# define ZEND_LONG_MIN INT32_MIN
48+
# define ZEND_LONG_SAFE_MAX INT32_MAX
4749
# define ZEND_ULONG_MAX UINT32_MAX
4850
# define Z_L(i) INT32_C(i)
4951
# define Z_UL(i) UINT32_C(i)

main/main.stub.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@
163163
* @cvalue SIZEOF_ZEND_LONG
164164
*/
165165
const PHP_INT_SIZE = UNKNOWN;
166+
/**
167+
* @var int
168+
* @cvalue ZEND_LONG_SAFE_MAX
169+
*/
170+
const PHP_INT_MAX_SAFE = UNKNOWN;
166171
/**
167172
* @var int
168173
* @cvalue FD_SETSIZE

main/main_arginfo.h

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Test PHP_INT_MIN, PHP_INT_MAX and PHP_INT_SIZE (32-bit)
2+
Test PHP_INT_MIN, PHP_INT_MAX, PHP_INT_MAX_SAFE and PHP_INT_SIZE (32-bit)
33
--SKIPIF--
44
<?php if (PHP_INT_SIZE !== 4)
55
die("skip this test is for 32-bit platforms only"); ?>
@@ -8,10 +8,14 @@ Test PHP_INT_MIN, PHP_INT_MAX and PHP_INT_SIZE (32-bit)
88

99
var_dump(PHP_INT_MIN);
1010
var_dump(PHP_INT_MAX);
11+
var_dump(PHP_INT_MAX_SAFE);
12+
var_dump(PHP_INT_MAX_SAFE === PHP_INT_MAX);
1113
var_dump(PHP_INT_SIZE);
1214

1315
?>
1416
--EXPECT--
1517
int(-2147483648)
1618
int(2147483647)
19+
int(2147483647)
20+
bool(true)
1721
int(4)
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Test PHP_INT_MIN, PHP_INT_MAX and PHP_INT_SIZE (64-bit)
2+
Test PHP_INT_MIN, PHP_INT_MAX, PHP_INT_MAX_SAFE and PHP_INT_SIZE (64-bit)
33
--SKIPIF--
44
<?php if (PHP_INT_SIZE !== 8)
55
die("skip this test is for 64-bit platforms only"); ?>
@@ -8,10 +8,14 @@ Test PHP_INT_MIN, PHP_INT_MAX and PHP_INT_SIZE (64-bit)
88

99
var_dump(PHP_INT_MIN);
1010
var_dump(PHP_INT_MAX);
11+
var_dump(PHP_INT_MAX_SAFE);
12+
var_dump(PHP_INT_MAX_SAFE === (2 << 52)-1);
1113
var_dump(PHP_INT_SIZE);
1214

1315
?>
1416
--EXPECT--
1517
int(-9223372036854775808)
1618
int(9223372036854775807)
19+
int(9007199254740991)
20+
bool(true)
1721
int(8)

0 commit comments

Comments
 (0)