Skip to content

Add PHP_INT_MAX_SAFE constant #19126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Zend/zend_long.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ typedef uint64_t zend_ulong;
typedef int64_t zend_off_t;
# define ZEND_LONG_MAX INT64_MAX
# define ZEND_LONG_MIN INT64_MIN
# define ZEND_LONG_SAFE_MAX (2ULL << 52U)-1U
# define ZEND_ULONG_MAX UINT64_MAX
# define Z_L(i) INT64_C(i)
# define Z_UL(i) UINT64_C(i)
Expand All @@ -44,6 +45,7 @@ typedef uint32_t zend_ulong;
typedef int32_t zend_off_t;
# define ZEND_LONG_MAX INT32_MAX
# define ZEND_LONG_MIN INT32_MIN
# define ZEND_LONG_SAFE_MAX INT32_MAX
# define ZEND_ULONG_MAX UINT32_MAX
# define Z_L(i) INT32_C(i)
# define Z_UL(i) UINT32_C(i)
Expand Down
5 changes: 5 additions & 0 deletions main/main.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@
* @cvalue SIZEOF_ZEND_LONG
*/
const PHP_INT_SIZE = UNKNOWN;
/**
* @var int
* @cvalue ZEND_LONG_SAFE_MAX
*/
const PHP_INT_MAX_SAFE = UNKNOWN;
/**
* @var int
* @cvalue FD_SETSIZE
Expand Down
3 changes: 2 additions & 1 deletion main/main_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion tests/lang/constants/PHP_INT_32bit.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Test PHP_INT_MIN, PHP_INT_MAX and PHP_INT_SIZE (32-bit)
Test PHP_INT_MIN, PHP_INT_MAX, PHP_INT_MAX_SAFE and PHP_INT_SIZE (32-bit)
--SKIPIF--
<?php if (PHP_INT_SIZE !== 4)
die("skip this test is for 32-bit platforms only"); ?>
Expand All @@ -8,10 +8,14 @@ Test PHP_INT_MIN, PHP_INT_MAX and PHP_INT_SIZE (32-bit)

var_dump(PHP_INT_MIN);
var_dump(PHP_INT_MAX);
var_dump(PHP_INT_MAX_SAFE);
var_dump(PHP_INT_MAX_SAFE === PHP_INT_MAX);
var_dump(PHP_INT_SIZE);

?>
--EXPECT--
int(-2147483648)
int(2147483647)
int(2147483647)
bool(true)
int(4)
6 changes: 5 additions & 1 deletion tests/lang/constants/PHP_INT_64bit.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Test PHP_INT_MIN, PHP_INT_MAX and PHP_INT_SIZE (64-bit)
Test PHP_INT_MIN, PHP_INT_MAX, PHP_INT_MAX_SAFE and PHP_INT_SIZE (64-bit)
--SKIPIF--
<?php if (PHP_INT_SIZE !== 8)
die("skip this test is for 64-bit platforms only"); ?>
Expand All @@ -8,10 +8,14 @@ Test PHP_INT_MIN, PHP_INT_MAX and PHP_INT_SIZE (64-bit)

var_dump(PHP_INT_MIN);
var_dump(PHP_INT_MAX);
var_dump(PHP_INT_MAX_SAFE);
var_dump(PHP_INT_MAX_SAFE === (2 << 52)-1);
var_dump(PHP_INT_SIZE);

?>
--EXPECT--
int(-9223372036854775808)
int(9223372036854775807)
int(9007199254740991)
bool(true)
int(8)