Skip to content

Commit bb0c142

Browse files
committed
Drop support for GMP 4.1
* Consistent base conversion support (max: 62) * mpz_remroot always available * Use gmp_randinit_mt instead of LCG
1 parent 581c86c commit bb0c142

File tree

4 files changed

+10
-40
lines changed

4 files changed

+10
-40
lines changed

Diff for: UPGRADING

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ PHP X.Y UPGRADE NOTES
3535
handler, too.
3636

3737
- GMP
38+
. Requires libgmp version 4.2 or newer now.
3839
. gmp_setbit() and gmp_clrbit() now return FALSE for negative indices, making
3940
them consistent with other GMP functions.
4041

Diff for: ext/gmp/config.m4

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
dnl
2-
dnl $Id$
3-
dnl
4-
51
PHP_ARG_WITH(gmp, for GNU MP support,
62
[ --with-gmp[=DIR] Include GNU MP support])
73

@@ -15,14 +11,9 @@ if test "$PHP_GMP" != "no"; then
1511
AC_MSG_ERROR(Unable to locate gmp.h)
1612
fi
1713

18-
PHP_CHECK_LIBRARY(gmp, __gmp_randinit_lc_2exp_size,
14+
PHP_CHECK_LIBRARY(gmp, __gmpz_rootrem,
1915
[],[
20-
PHP_CHECK_LIBRARY(gmp, gmp_randinit_lc_2exp_size,
21-
[],[
22-
AC_MSG_ERROR([GNU MP Library version 4.1.2 or greater required.])
23-
],[
24-
-L$GMP_DIR/$PHP_LIBDIR
25-
])
16+
AC_MSG_ERROR([GNU MP Library version 4.2 or greater required.])
2617
],[
2718
-L$GMP_DIR/$PHP_LIBDIR
2819
])

Diff for: ext/gmp/gmp.c

+7-28
Original file line numberDiff line numberDiff line change
@@ -224,16 +224,7 @@ typedef struct _gmp_temp {
224224
#define GMP_BIG_ENDIAN (1 << 3)
225225
#define GMP_NATIVE_ENDIAN (1 << 4)
226226

227-
#define GMP_42_OR_NEWER \
228-
((__GNU_MP_VERSION >= 5) || (__GNU_MP_VERSION >= 4 && __GNU_MP_VERSION_MINOR >= 2))
229-
230-
/* The maximum base for input and output conversions is 62 from GMP 4.2
231-
* onwards. */
232-
#if GMP_42_OR_NEWER
233-
# define MAX_BASE 62
234-
#else
235-
# define MAX_BASE 36
236-
#endif
227+
#define GMP_MAX_BASE 62
237228

238229
#define IS_GMP(zval) \
239230
(Z_TYPE_P(zval) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zval), gmp_ce TSRMLS_CC))
@@ -1048,8 +1039,8 @@ ZEND_FUNCTION(gmp_init)
10481039
return;
10491040
}
10501041

1051-
if (base && (base < 2 || base > MAX_BASE)) {
1052-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad base for conversion: %pd (should be between 2 and %d)", base, MAX_BASE);
1042+
if (base && (base < 2 || base > GMP_MAX_BASE)) {
1043+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad base for conversion: %pd (should be between 2 and %d)", base, GMP_MAX_BASE);
10531044
RETURN_FALSE;
10541045
}
10551046

@@ -1204,15 +1195,10 @@ ZEND_FUNCTION(gmp_strval)
12041195
return;
12051196
}
12061197

1207-
#if MAX_BASE == 62
1208-
/* Although the maximum base in general in GMP >= 4.2 is 62, mpz_get_str()
1198+
/* Although the maximum base in general in GMP is 62, mpz_get_str()
12091199
* is explicitly limited to -36 when dealing with negative bases. */
1210-
if ((base < 2 && base > -2) || base > MAX_BASE || base < -36) {
1211-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad base for conversion: %pd (should be between 2 and %d or -2 and -36)", base, MAX_BASE);
1212-
#else
1213-
if (base < 2 || base > MAX_BASE) {
1214-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad base for conversion: %pd (should be between 2 and %d)", base, MAX_BASE);
1215-
#endif
1200+
if ((base < 2 && base > -2) || base > GMP_MAX_BASE || base < -36) {
1201+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad base for conversion: %pd (should be between 2 and %d or -2 and -36)", base, GMP_MAX_BASE);
12161202
RETURN_FALSE;
12171203
}
12181204

@@ -1596,14 +1582,7 @@ ZEND_FUNCTION(gmp_rootrem)
15961582
add_next_index_zval(return_value, &result1);
15971583
add_next_index_zval(return_value, &result2);
15981584

1599-
#if GMP_42_OR_NEWER
16001585
mpz_rootrem(gmpnum_result1, gmpnum_result2, gmpnum_a, (gmp_ulong) nth);
1601-
#else
1602-
mpz_root(gmpnum_result1, gmpnum_a, (gmp_ulong) nth);
1603-
mpz_pow_ui(gmpnum_result2, gmpnum_result1, (gmp_ulong) nth);
1604-
mpz_sub(gmpnum_result2, gmpnum_a, gmpnum_result2);
1605-
mpz_abs(gmpnum_result2, gmpnum_result2);
1606-
#endif
16071586

16081587
FREE_GMP_TEMP(temp_a);
16091588
}
@@ -1779,7 +1758,7 @@ ZEND_FUNCTION(gmp_random)
17791758

17801759
if (!GMPG(rand_initialized)) {
17811760
/* Initialize */
1782-
gmp_randinit_lc_2exp_size(GMPG(rand_state), 32L);
1761+
gmp_randinit_mt(GMPG(rand_state));
17831762

17841763
/* Seed */
17851764
gmp_randseed_ui(GMPG(rand_state), GENERATE_SEED());

Diff for: ext/gmp/tests/bug50283.phpt

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Feature Request #50283 (allow base in gmp_strval to use full range: 2 to 62, and -2 to -36)
33
--SKIPIF--
44
<?php if (!extension_loaded("gmp")) print "skip"; ?>
5-
<?php if (version_compare(GMP_VERSION, "4.2.0", "<")) print "skip"; ?>
65
--FILE--
76
<?php
87
$a = gmp_init("0x41682179fbf5");

0 commit comments

Comments
 (0)