com php-src: Remove RAND_RANGE() macro: UPGRADING .INTERNALS ext/standard/array.c ext/standard/php_rand .h ext/standard/string.c
| From: | Nikita Popov | Date: | Sat, 09 Dec 2017 16:24:17 +0000 |
| Subject: | com php-src: Remove RAND_RANGE() macro: UPGRADING .INTERNALS ext/standard/array.c ext/standard/php_rand .h ext/standard/string.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-100541@lists.php.net to get a copy of this message | ||
Commit: e4e26f24285511c5aa2a359ff7e93c1748fdda3b
Author: Tom Van Looy <tom@ctors.net> Sun, 3 Dec 2017 22:35:50 +0100
Committer: Nikita Popov <nikita.ppv@gmail.com> Sat, 9 Dec 2017 17:24:17 +0100
Parents: 6d4de4cf0582cf33848826ab78aae58077dc2dea
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=e4e26f24285511c5aa2a359ff7e93c1748fdda3b
Log:
Remove RAND_RANGE() macro
The behavior of RANGE_RANGE() is 7.1 changed completely, from
rescaling an already generated number to generating a number
itself. Because of this str_shuffle() ended up generating two
random numbers on every iteration.
To avoid further misuse the function is dropped entirely. Extensions
for PHP >= 7.1 should directly call php_mt_rand_range().
Changed paths:
M UPGRADING.INTERNALS
M ext/standard/array.c
M ext/standard/php_rand.h
M ext/standard/string.c
Diff:
diff --git a/UPGRADING.INTERNALS b/UPGRADING.INTERNALS
index 7dce0fb..c5a41f2 100644
--- a/UPGRADING.INTERNALS
+++ b/UPGRADING.INTERNALS
@@ -9,6 +9,7 @@ PHP 7.3 INTERNALS UPGRADE NOTES
f. GC_REFCOUNT()
g. zend_get_parameters()
h. zend_register_persistent_resource()
+ i. RAND_RANGE()
2. Build system changes
a. Unix build system changes
@@ -82,6 +83,9 @@ PHP 7.3 INTERNALS UPGRADE NOTES
zend_register_persistent_resource_ex() should beused to register
persistent resources, instead of manual insertion into EG(persistent_list).
+ i. The RANGE_RANGE() macro has been removed. php_mt_rand_range() should be
+ used instead.
+
========================
2. Build system changes
========================
diff --git a/ext/standard/array.c b/ext/standard/array.c
index dfeaef8..05c89d9 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -2968,7 +2968,7 @@ static void php_array_data_shuffle(zval *array) /* {{{ */
}
}
while (--n_left) {
- RAND_RANGE(rnd_idx, 0, n_left, PHP_RAND_MAX);
+ rnd_idx = php_mt_rand_range(0, n_left);
if (rnd_idx != n_left) {
temp = hash->arData[n_left];
hash->arData[n_left] = hash->arData[rnd_idx];
@@ -2993,7 +2993,7 @@ static void php_array_data_shuffle(zval *array) /* {{{ */
}
}
while (--n_left) {
- RAND_RANGE(rnd_idx, 0, n_left, PHP_RAND_MAX);
+ rnd_idx = php_mt_rand_range(0, n_left);
if (rnd_idx != n_left) {
temp = hash->arData[n_left];
hash->arData[n_left] = hash->arData[rnd_idx];
diff --git a/ext/standard/php_rand.h b/ext/standard/php_rand.h
index b4a6613..497a539 100644
--- a/ext/standard/php_rand.h
+++ b/ext/standard/php_rand.h
@@ -63,9 +63,6 @@
#define RAND_RANGE_BADSCALING(__n, __min, __max, __tmax) \
(__n) = (__min) + (zend_long) ((double) ( (double) (__max) - (__min) + 1.0) * ((__n) / ((__tmax) +
1.0)))
-#define RAND_RANGE(__n, __min, __max, __tmax) \
- (__n) = php_mt_rand_range((__min), (__max))
-
#ifdef PHP_WIN32
#define GENERATE_SEED() (((zend_long) (time(0) * GetCurrentProcessId())) ^ ((zend_long) (1000000.0
* php_combined_lcg())))
#else
diff --git a/ext/standard/string.c b/ext/standard/string.c
index 1ef96e9..2526dae 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -5479,8 +5479,7 @@ static void php_string_shuffle(char *str, zend_long len) /* {{{ */
n_left = n_elems;
while (--n_left) {
- rnd_idx = php_rand();
- RAND_RANGE(rnd_idx, 0, n_left, PHP_RAND_MAX);
+ rnd_idx = php_mt_rand_range(0, n_left);
if (rnd_idx != n_left) {
temp = str[n_left];
str[n_left] = str[rnd_idx];