summaryrefslogtreecommitdiff
path: root/ext/gmp
diff options
context:
space:
mode:
Diffstat (limited to 'ext/gmp')
-rw-r--r--ext/gmp/bug67917.phpt17
-rw-r--r--ext/gmp/gmp.c221
-rw-r--r--ext/gmp/php_gmp.h2
-rw-r--r--ext/gmp/tests/001.phpt21
-rw-r--r--ext/gmp/tests/bug50175.phpt18
-rw-r--r--ext/gmp/tests/gmp_abs.phpt (renamed from ext/gmp/tests/013.phpt)0
-rw-r--r--ext/gmp/tests/gmp_and.phpt (renamed from ext/gmp/tests/029.phpt)0
-rw-r--r--ext/gmp/tests/gmp_clrbit.phpt (renamed from ext/gmp/tests/034.phpt)0
-rw-r--r--ext/gmp/tests/gmp_cmp.phpt (renamed from ext/gmp/tests/026.phpt)0
-rw-r--r--ext/gmp/tests/gmp_com.phpt (renamed from ext/gmp/tests/031.phpt)0
-rw-r--r--ext/gmp/tests/gmp_div_q.phpt (renamed from ext/gmp/tests/009.phpt)0
-rw-r--r--ext/gmp/tests/gmp_div_qr.phpt (renamed from ext/gmp/tests/007.phpt)17
-rw-r--r--ext/gmp/tests/gmp_div_r.phpt (renamed from ext/gmp/tests/008.phpt)0
-rw-r--r--ext/gmp/tests/gmp_divexact.phpt (renamed from ext/gmp/tests/011.phpt)0
-rw-r--r--ext/gmp/tests/gmp_export.phpt80
-rw-r--r--ext/gmp/tests/gmp_fact.phpt (renamed from ext/gmp/tests/014.phpt)0
-rw-r--r--ext/gmp/tests/gmp_gcd.phpt (renamed from ext/gmp/tests/021.phpt)0
-rw-r--r--ext/gmp/tests/gmp_gcdext.phpt (renamed from ext/gmp/tests/022.phpt)0
-rw-r--r--ext/gmp/tests/gmp_hamdist.phpt (renamed from ext/gmp/tests/036.phpt)0
-rw-r--r--ext/gmp/tests/gmp_import.phpt91
-rw-r--r--ext/gmp/tests/gmp_init.phpt (renamed from ext/gmp/tests/040.phpt)0
-rw-r--r--ext/gmp/tests/gmp_intval.phpt (renamed from ext/gmp/tests/004.phpt)0
-rw-r--r--ext/gmp/tests/gmp_invert.phpt (renamed from ext/gmp/tests/023.phpt)0
-rw-r--r--ext/gmp/tests/gmp_jacobi.phpt (renamed from ext/gmp/tests/024.phpt)0
-rw-r--r--ext/gmp/tests/gmp_legendre.phpt (renamed from ext/gmp/tests/025.phpt)0
-rw-r--r--ext/gmp/tests/gmp_mod.phpt (renamed from ext/gmp/tests/010.phpt)0
-rw-r--r--ext/gmp/tests/gmp_neg.phpt (renamed from ext/gmp/tests/012.phpt)0
-rw-r--r--ext/gmp/tests/gmp_or.phpt (renamed from ext/gmp/tests/030.phpt)0
-rw-r--r--ext/gmp/tests/gmp_perfect_square.phpt (renamed from ext/gmp/tests/019.phpt)0
-rw-r--r--ext/gmp/tests/gmp_popcount.phpt (renamed from ext/gmp/tests/035.phpt)0
-rw-r--r--ext/gmp/tests/gmp_pow.phpt (renamed from ext/gmp/tests/015.phpt)0
-rw-r--r--ext/gmp/tests/gmp_pown.phpt (renamed from ext/gmp/tests/016.phpt)9
-rw-r--r--ext/gmp/tests/gmp_prob_prime.phpt (renamed from ext/gmp/tests/020.phpt)0
-rw-r--r--ext/gmp/tests/gmp_random.phpt (renamed from ext/gmp/tests/028.phpt)0
-rw-r--r--ext/gmp/tests/gmp_remroot.phpt (renamed from ext/gmp/tests/041.phpt)49
-rw-r--r--ext/gmp/tests/gmp_root.phpt58
-rw-r--r--ext/gmp/tests/gmp_scan0.phpt (renamed from ext/gmp/tests/037.phpt)0
-rw-r--r--ext/gmp/tests/gmp_scan1.phpt (renamed from ext/gmp/tests/038.phpt)0
-rw-r--r--ext/gmp/tests/gmp_setbit.phpt (renamed from ext/gmp/tests/033.phpt)0
-rw-r--r--ext/gmp/tests/gmp_sign.phpt (renamed from ext/gmp/tests/027.phpt)0
-rw-r--r--ext/gmp/tests/gmp_sqrt.phpt (renamed from ext/gmp/tests/017.phpt)0
-rw-r--r--ext/gmp/tests/gmp_sqrtrem.phpt (renamed from ext/gmp/tests/018.phpt)0
-rw-r--r--ext/gmp/tests/gmp_strval.phpt (renamed from ext/gmp/tests/005.phpt)0
-rw-r--r--ext/gmp/tests/gmp_sub.phpt (renamed from ext/gmp/tests/006.phpt)0
-rw-r--r--ext/gmp/tests/gmp_testbit.phpt (renamed from ext/gmp/tests/039.phpt)5
-rw-r--r--ext/gmp/tests/gmp_xor.phpt (renamed from ext/gmp/tests/032.phpt)0
-rw-r--r--ext/gmp/tests/overloading.phpt60
47 files changed, 541 insertions, 107 deletions
diff --git a/ext/gmp/bug67917.phpt b/ext/gmp/bug67917.phpt
new file mode 100644
index 000000000..93d46cbb6
--- /dev/null
+++ b/ext/gmp/bug67917.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Bug #67917: Using GMP objects with overloaded operators can cause memory exhaustion
+--FILE--
+<?php
+
+$mem1 = memory_get_usage();
+for ($i = 0; $i < 1000; $i++) {
+ $gmp = gmp_init(42);
+ $gmp <<= 1;
+}
+$mem2 = memory_get_usage();
+
+var_dump($mem2 - $mem1 < 100000);
+
+?>
+--EXPECT--
+bool(true)
diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c
index cd50896cc..bad610c0b 100644
--- a/ext/gmp/gmp.c
+++ b/ext/gmp/gmp.c
@@ -43,6 +43,18 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_gmp_init, 0, 0, 1)
ZEND_ARG_INFO(0, base)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO_EX(arginfo_gmp_import, 0, 0, 1)
+ ZEND_ARG_INFO(0, data)
+ ZEND_ARG_INFO(0, word_size)
+ ZEND_ARG_INFO(0, options)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_gmp_export, 0, 0, 1)
+ ZEND_ARG_INFO(0, gmpnumber)
+ ZEND_ARG_INFO(0, word_size)
+ ZEND_ARG_INFO(0, options)
+ZEND_END_ARG_INFO()
+
ZEND_BEGIN_ARG_INFO_EX(arginfo_gmp_intval, 0, 0, 1)
ZEND_ARG_INFO(0, gmpnumber)
ZEND_END_ARG_INFO()
@@ -117,6 +129,8 @@ static ZEND_GINIT_FUNCTION(gmp);
*/
const zend_function_entry gmp_functions[] = {
ZEND_FE(gmp_init, arginfo_gmp_init)
+ ZEND_FE(gmp_import, arginfo_gmp_import)
+ ZEND_FE(gmp_export, arginfo_gmp_export)
ZEND_FE(gmp_intval, arginfo_gmp_intval)
ZEND_FE(gmp_strval, arginfo_gmp_strval)
ZEND_FE(gmp_add, arginfo_gmp_binary)
@@ -204,6 +218,12 @@ typedef struct _gmp_temp {
#define GMP_ROUND_PLUSINF 1
#define GMP_ROUND_MINUSINF 2
+#define GMP_MSW_FIRST (1 << 0)
+#define GMP_LSW_FIRST (1 << 1)
+#define GMP_LITTLE_ENDIAN (1 << 2)
+#define GMP_BIG_ENDIAN (1 << 3)
+#define GMP_NATIVE_ENDIAN (1 << 4)
+
#define GMP_42_OR_NEWER \
((__GNU_MP_VERSION >= 5) || (__GNU_MP_VERSION >= 4 && __GNU_MP_VERSION_MINOR >= 2))
@@ -297,7 +317,7 @@ static void gmp_strval(zval *result, mpz_t gmpnum, long base);
static int convert_to_gmp(mpz_t gmpnumber, zval *val, int base TSRMLS_DC);
static void gmp_cmp(zval *return_value, zval *a_arg, zval *b_arg TSRMLS_DC);
-/*
+/*
* The gmp_*_op functions provide an implementation for several common types
* of GMP functions. The gmp_zval_(unary|binary)_*_op functions have to be manually
* passed zvals to work on, whereas the gmp_(unary|binary)_*_op macros already
@@ -523,7 +543,7 @@ static void shift_operator_helper(gmp_binary_ui_op_t op, zval *return_value, zva
gmp_zval_unary_op(result, op1, op TSRMLS_CC); \
return SUCCESS;
-static int gmp_do_operation(zend_uchar opcode, zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
+static int gmp_do_operation_ex(zend_uchar opcode, zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
{
switch (opcode) {
case ZEND_ADD:
@@ -560,6 +580,26 @@ static int gmp_do_operation(zend_uchar opcode, zval *result, zval *op1, zval *op
}
/* }}} */
+static int gmp_do_operation(zend_uchar opcode, zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
+{
+ zval op1_copy;
+ int retval;
+
+ if (result == op1) {
+ ZVAL_COPY_VALUE(&op1_copy, op1);
+ op1 = &op1_copy;
+ }
+
+ retval = gmp_do_operation_ex(opcode, result, op1, op2 TSRMLS_CC);
+
+ if (retval == SUCCESS && op1 == &op1_copy) {
+ zval_dtor(op1);
+ }
+
+ return retval;
+}
+/* }}} */
+
static int gmp_compare(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
{
gmp_cmp(result, op1, op2 TSRMLS_CC);
@@ -579,7 +619,7 @@ static int gmp_serialize(zval *object, unsigned char **buffer, zend_uint *buf_le
PHP_VAR_SERIALIZE_INIT(serialize_data);
INIT_PZVAL(zv_ptr);
-
+
gmp_strval(zv_ptr, gmpnum, 10);
php_var_serialize(&buf, &zv_ptr, &serialize_data TSRMLS_CC);
zval_dtor(zv_ptr);
@@ -677,6 +717,12 @@ ZEND_MINIT_FUNCTION(gmp)
#endif
REGISTER_STRING_CONSTANT("GMP_VERSION", (char *)gmp_version, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("GMP_MSW_FIRST", GMP_MSW_FIRST, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("GMP_LSW_FIRST", GMP_LSW_FIRST, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("GMP_LITTLE_ENDIAN", GMP_LITTLE_ENDIAN, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("GMP_BIG_ENDIAN", GMP_BIG_ENDIAN, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("GMP_NATIVE_ENDIAN", GMP_NATIVE_ENDIAN, CONST_CS | CONST_PERSISTENT);
+
mp_set_memory_functions(gmp_emalloc, gmp_erealloc, gmp_efree);
return SUCCESS;
@@ -714,7 +760,7 @@ ZEND_MODULE_INFO_D(gmp)
/* {{{ convert_to_gmp
* Convert zval to be gmp number */
-static int convert_to_gmp(mpz_t gmpnumber, zval *val, int base TSRMLS_DC)
+static int convert_to_gmp(mpz_t gmpnumber, zval *val, int base TSRMLS_DC)
{
switch (Z_TYPE_P(val)) {
case IS_LONG:
@@ -727,15 +773,13 @@ static int convert_to_gmp(mpz_t gmpnumber, zval *val, int base TSRMLS_DC)
int skip_lead = 0;
int ret;
- if (Z_STRLEN_P(val) > 2) {
- if (numstr[0] == '0') {
- if (numstr[1] == 'x' || numstr[1] == 'X') {
- base = 16;
- skip_lead = 1;
- } else if (base != 16 && (numstr[1] == 'b' || numstr[1] == 'B')) {
- base = 2;
- skip_lead = 1;
- }
+ if (Z_STRLEN_P(val) > 2 && numstr[0] == '0') {
+ if ((base == 0 || base == 16) && (numstr[1] == 'x' || numstr[1] == 'X')) {
+ base = 16;
+ skip_lead = 1;
+ } else if ((base == 0 || base == 2) && (numstr[1] == 'b' || numstr[1] == 'B')) {
+ base = 2;
+ skip_lead = 1;
}
}
@@ -768,8 +812,8 @@ static void gmp_strval(zval *result, mpz_t gmpnum, long base) /* {{{ */
out_string = emalloc(num_len + 1);
mpz_get_str(out_string, base, gmpnum);
-
- /*
+
+ /*
* From GMP documentation for mpz_sizeinbase():
* The returned value will be exact or 1 too big. If base is a power of
* 2, the returned value will always be exact.
@@ -811,7 +855,7 @@ static void gmp_cmp(zval *return_value, zval *a_arg, zval *b_arg TSRMLS_DC) /* {
FREE_GMP_TEMP(temp_a);
FREE_GMP_TEMP(temp_b);
-
+
RETURN_LONG(res);
}
/* }}} */
@@ -819,14 +863,14 @@ static void gmp_cmp(zval *return_value, zval *a_arg, zval *b_arg TSRMLS_DC) /* {
/* {{{ gmp_zval_binary_ui_op
Execute GMP binary operation.
*/
-static inline void gmp_zval_binary_ui_op(zval *return_value, zval *a_arg, zval *b_arg, gmp_binary_op_t gmp_op, gmp_binary_ui_op_t gmp_ui_op, int check_b_zero TSRMLS_DC)
+static inline void gmp_zval_binary_ui_op(zval *return_value, zval *a_arg, zval *b_arg, gmp_binary_op_t gmp_op, gmp_binary_ui_op_t gmp_ui_op, int check_b_zero TSRMLS_DC)
{
mpz_ptr gmpnum_a, gmpnum_b, gmpnum_result;
int use_ui = 0;
gmp_temp_t temp_a, temp_b;
FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a);
-
+
if (gmp_ui_op && Z_TYPE_P(b_arg) == IS_LONG && Z_LVAL_P(b_arg) >= 0) {
use_ui = 1;
temp_b.is_used = 0;
@@ -922,7 +966,7 @@ static inline void _gmp_binary_ui_op(INTERNAL_FUNCTION_PARAMETERS, gmp_binary_op
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &a_arg, &b_arg) == FAILURE){
return;
}
-
+
gmp_zval_binary_ui_op(return_value, a_arg, b_arg, gmp_op, gmp_ui_op, check_b_zero TSRMLS_CC);
}
/* }}} */
@@ -931,11 +975,11 @@ static inline void _gmp_binary_ui_op(INTERNAL_FUNCTION_PARAMETERS, gmp_binary_op
/* {{{ gmp_zval_unary_op
*/
-static inline void gmp_zval_unary_op(zval *return_value, zval *a_arg, gmp_unary_op_t gmp_op TSRMLS_DC)
+static inline void gmp_zval_unary_op(zval *return_value, zval *a_arg, gmp_unary_op_t gmp_op TSRMLS_DC)
{
mpz_ptr gmpnum_a, gmpnum_result;
gmp_temp_t temp_a;
-
+
FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a);
INIT_GMP_RETVAL(gmpnum_result);
@@ -980,7 +1024,7 @@ static inline void _gmp_unary_op(INTERNAL_FUNCTION_PARAMETERS, gmp_unary_op_t gm
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &a_arg) == FAILURE){
return;
}
-
+
gmp_zval_unary_op(return_value, a_arg, gmp_op TSRMLS_CC);
}
/* }}} */
@@ -996,7 +1040,7 @@ static inline void _gmp_unary_opl(INTERNAL_FUNCTION_PARAMETERS, gmp_unary_opl_t
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &a_arg) == FAILURE){
return;
}
-
+
FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a);
RETVAL_LONG(gmp_op(gmpnum_a));
FREE_GMP_TEMP(temp_a);
@@ -1050,6 +1094,118 @@ ZEND_FUNCTION(gmp_init)
}
/* }}} */
+int gmp_import_export_validate(long size, long options, int *order, int *endian TSRMLS_DC)
+{
+ if (size < 1) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ "Word size must be positive, %ld given", size);
+ return FAILURE;
+ }
+
+ switch (options & (GMP_LSW_FIRST | GMP_MSW_FIRST)) {
+ case GMP_LSW_FIRST:
+ *order = -1;
+ break;
+ case GMP_MSW_FIRST:
+ case 0: /* default */
+ *order = 1;
+ break;
+ default:
+ php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ "Invalid options: Conflicting word orders");
+ return FAILURE;
+ }
+
+ switch (options & (GMP_LITTLE_ENDIAN | GMP_BIG_ENDIAN | GMP_NATIVE_ENDIAN)) {
+ case GMP_LITTLE_ENDIAN:
+ *endian = -1;
+ break;
+ case GMP_BIG_ENDIAN:
+ *endian = 1;
+ break;
+ case GMP_NATIVE_ENDIAN:
+ case 0: /* default */
+ *endian = 0;
+ break;
+ default:
+ php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ "Invalid options: Conflicting word endianness");
+ return FAILURE;
+ }
+
+ return SUCCESS;
+}
+
+/* {{{ proto GMP gmp_import(string data [, int word_size = 1, int options = GMP_MSW_FIRST | GMP_NATIVE_ENDIAN])
+ Imports a GMP number from a binary string */
+ZEND_FUNCTION(gmp_import)
+{
+ char *data;
+ int data_len;
+ long size = 1;
+ long options = GMP_MSW_FIRST | GMP_NATIVE_ENDIAN;
+ int order, endian;
+ mpz_ptr gmpnumber;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &data, &data_len, &size, &options) == FAILURE) {
+ return;
+ }
+
+ if (gmp_import_export_validate(size, options, &order, &endian TSRMLS_CC) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ if ((data_len % size) != 0) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ "Input length must be a multiple of word size");
+ RETURN_FALSE;
+ }
+
+ INIT_GMP_RETVAL(gmpnumber);
+
+ mpz_import(gmpnumber, data_len / size, order, size, endian, 0, data);
+}
+/* }}} */
+
+/* {{{ proto string gmp_export(GMP gmpnumber [, int word_size = 1, int options = GMP_MSW_FIRST | GMP_NATIVE_ENDIAN])
+ Exports a GMP number to a binary string */
+ZEND_FUNCTION(gmp_export)
+{
+ zval *gmpnumber_arg;
+ long size = 1;
+ long options = GMP_MSW_FIRST | GMP_NATIVE_ENDIAN;
+ int order, endian;
+ mpz_ptr gmpnumber;
+ gmp_temp_t temp_a;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|ll", &gmpnumber_arg, &size, &options) == FAILURE) {
+ return;
+ }
+
+ if (gmp_import_export_validate(size, options, &order, &endian TSRMLS_CC) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ FETCH_GMP_ZVAL(gmpnumber, gmpnumber_arg, temp_a);
+
+ if (mpz_sgn(gmpnumber) == 0) {
+ RETURN_EMPTY_STRING();
+ } else {
+ size_t bits_per_word = size * 8;
+ size_t count = (mpz_sizeinbase(gmpnumber, 2) + bits_per_word - 1) / bits_per_word;
+ size_t out_len = count * size;
+
+ char *out_string = emalloc(out_len + 1);
+ mpz_export(out_string, NULL, order, size, endian, 0, gmpnumber);
+ out_string[out_len] = '\0';
+
+ RETURN_STRINGL(out_string, out_len, 0);
+ }
+
+ FREE_GMP_TEMP(temp_a);
+}
+/* }}} */
+
/* {{{ proto int gmp_intval(mixed gmpnumber)
Gets signed long value of GMP number */
ZEND_FUNCTION(gmp_intval)
@@ -1059,7 +1215,7 @@ ZEND_FUNCTION(gmp_intval)
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &gmpnumber_arg) == FAILURE){
return;
}
-
+
if (IS_GMP(gmpnumber_arg)) {
RETVAL_LONG(mpz_get_si(GET_GMP_FROM_ZVAL(gmpnumber_arg)));
} else {
@@ -1206,7 +1362,7 @@ ZEND_FUNCTION(gmp_div_q)
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid rounding mode");
RETURN_FALSE;
}
-
+
}
/* }}} */
@@ -1286,7 +1442,7 @@ ZEND_FUNCTION(gmp_pow)
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Negative exponent not supported");
RETURN_FALSE;
}
-
+
INIT_GMP_RETVAL(gmpnum_result);
if (Z_TYPE_P(base_arg) == IS_LONG && Z_LVAL_P(base_arg) >= 0) {
mpz_ui_pow_ui(gmpnum_result, Z_LVAL_P(base_arg), exp);
@@ -1328,10 +1484,9 @@ ZEND_FUNCTION(gmp_powm)
FETCH_GMP_ZVAL_DEP_DEP(gmpnum_mod, mod_arg, temp_mod, temp_exp, temp_base);
if (!mpz_cmp_ui(gmpnum_mod, 0)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Modulus may not be zero");
FREE_GMP_TEMP(temp_base);
- if (use_ui) {
- FREE_GMP_TEMP(temp_exp);
- }
+ FREE_GMP_TEMP(temp_exp);
FREE_GMP_TEMP(temp_mod);
RETURN_FALSE;
}
@@ -1360,14 +1515,14 @@ ZEND_FUNCTION(gmp_sqrt)
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &a_arg) == FAILURE){
return;
}
-
+
FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a);
if (mpz_sgn(gmpnum_a) < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number has to be greater than or equal to 0");
FREE_GMP_TEMP(temp_a);
RETURN_FALSE;
- }
+ }
INIT_GMP_RETVAL(gmpnum_result);
mpz_sqrt(gmpnum_result, gmpnum_a);
@@ -1394,7 +1549,7 @@ ZEND_FUNCTION(gmp_sqrtrem)
FREE_GMP_TEMP(temp_a);
RETURN_FALSE;
}
-
+
array_init(return_value);
add_index_zval(return_value, 0, gmp_create(&gmpnum_result1 TSRMLS_CC));
add_index_zval(return_value, 1, gmp_create(&gmpnum_result2 TSRMLS_CC));
@@ -1474,7 +1629,7 @@ ZEND_FUNCTION(gmp_rootrem)
mpz_sub(gmpnum_result2, gmpnum_a, gmpnum_result2);
mpz_abs(gmpnum_result2, gmpnum_result2);
#endif
-
+
FREE_GMP_TEMP(temp_a);
}
/* }}} */
diff --git a/ext/gmp/php_gmp.h b/ext/gmp/php_gmp.h
index 05bd56fa9..b3706c534 100644
--- a/ext/gmp/php_gmp.h
+++ b/ext/gmp/php_gmp.h
@@ -31,6 +31,8 @@ ZEND_MODULE_DEACTIVATE_D(gmp);
ZEND_MODULE_INFO_D(gmp);
ZEND_FUNCTION(gmp_init);
+ZEND_FUNCTION(gmp_import);
+ZEND_FUNCTION(gmp_export);
ZEND_FUNCTION(gmp_intval);
ZEND_FUNCTION(gmp_strval);
ZEND_FUNCTION(gmp_add);
diff --git a/ext/gmp/tests/001.phpt b/ext/gmp/tests/001.phpt
deleted file mode 100644
index 5126f7314..000000000
--- a/ext/gmp/tests/001.phpt
+++ /dev/null
@@ -1,21 +0,0 @@
---TEST--
-Check for gmp presence
---SKIPIF--
-<?php if (!extension_loaded("gmp")) print "skip"; ?>
---FILE--
-<?php
-echo "gmp extension is available";
-/*
- you can add regression tests for your extension here
-
- the output of your test code has to be equal to the
- text in the --EXPECT-- section below for the tests
- to pass, differences between the output and the
- expected text are interpreted as failure
-
- see php5/tests/README for further information on
- writing regression tests
-*/
-?>
---EXPECT--
-gmp extension is available
diff --git a/ext/gmp/tests/bug50175.phpt b/ext/gmp/tests/bug50175.phpt
new file mode 100644
index 000000000..0998e029c
--- /dev/null
+++ b/ext/gmp/tests/bug50175.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Bug #50175: gmp_init() results 0 on given base and number starting with 0x or 0b
+--FILE--
+<?php
+
+var_dump(gmp_init('0bcd', 16));
+var_dump(gmp_init('0xyz', 36));
+
+?>
+--EXPECTF--
+object(GMP)#%d (1) {
+ ["num"]=>
+ string(4) "3021"
+}
+object(GMP)#%d (1) {
+ ["num"]=>
+ string(5) "44027"
+}
diff --git a/ext/gmp/tests/013.phpt b/ext/gmp/tests/gmp_abs.phpt
index bb35891f2..bb35891f2 100644
--- a/ext/gmp/tests/013.phpt
+++ b/ext/gmp/tests/gmp_abs.phpt
diff --git a/ext/gmp/tests/029.phpt b/ext/gmp/tests/gmp_and.phpt
index 9bc401031..9bc401031 100644
--- a/ext/gmp/tests/029.phpt
+++ b/ext/gmp/tests/gmp_and.phpt
diff --git a/ext/gmp/tests/034.phpt b/ext/gmp/tests/gmp_clrbit.phpt
index 079d5d669..079d5d669 100644
--- a/ext/gmp/tests/034.phpt
+++ b/ext/gmp/tests/gmp_clrbit.phpt
diff --git a/ext/gmp/tests/026.phpt b/ext/gmp/tests/gmp_cmp.phpt
index 83e7910d1..83e7910d1 100644
--- a/ext/gmp/tests/026.phpt
+++ b/ext/gmp/tests/gmp_cmp.phpt
diff --git a/ext/gmp/tests/031.phpt b/ext/gmp/tests/gmp_com.phpt
index 1e0c1b469..1e0c1b469 100644
--- a/ext/gmp/tests/031.phpt
+++ b/ext/gmp/tests/gmp_com.phpt
diff --git a/ext/gmp/tests/009.phpt b/ext/gmp/tests/gmp_div_q.phpt
index 3b75a48e1..3b75a48e1 100644
--- a/ext/gmp/tests/009.phpt
+++ b/ext/gmp/tests/gmp_div_q.phpt
diff --git a/ext/gmp/tests/007.phpt b/ext/gmp/tests/gmp_div_qr.phpt
index e391c121f..90099249d 100644
--- a/ext/gmp/tests/007.phpt
+++ b/ext/gmp/tests/gmp_div_qr.phpt
@@ -10,11 +10,13 @@ var_dump(gmp_div_qr(""));
var_dump(gmp_div_qr(0,1));
var_dump(gmp_div_qr(1,0));
+var_dump(gmp_div_qr(gmp_init(1), gmp_init(0)));
var_dump(gmp_div_qr(12653,23482734));
var_dump(gmp_div_qr(12653,23482734, 10));
var_dump(gmp_div_qr(1123123,123));
var_dump(gmp_div_qr(1123123,123, 1));
var_dump(gmp_div_qr(1123123,123, 2));
+var_dump(gmp_div_qr(gmp_init(1123123), gmp_init(123)));
var_dump(gmp_div_qr(1123123,123, GMP_ROUND_ZERO));
var_dump(gmp_div_qr(1123123,123, GMP_ROUND_PLUSINF));
var_dump(gmp_div_qr(1123123,123, GMP_ROUND_MINUSINF));
@@ -47,6 +49,9 @@ array(2) {
Warning: gmp_div_qr(): Zero operand not allowed in %s on line %d
bool(false)
+
+Warning: gmp_div_qr(): Zero operand not allowed in %s on line %d
+bool(false)
array(2) {
[0]=>
object(GMP)#%d (1) {
@@ -114,6 +119,18 @@ array(2) {
[0]=>
object(GMP)#%d (1) {
["num"]=>
+ string(4) "9131"
+ }
+ [1]=>
+ object(GMP)#%d (1) {
+ ["num"]=>
+ string(2) "10"
+ }
+}
+array(2) {
+ [0]=>
+ object(GMP)#%d (1) {
+ ["num"]=>
string(4) "9132"
}
[1]=>
diff --git a/ext/gmp/tests/008.phpt b/ext/gmp/tests/gmp_div_r.phpt
index c1874c86f..c1874c86f 100644
--- a/ext/gmp/tests/008.phpt
+++ b/ext/gmp/tests/gmp_div_r.phpt
diff --git a/ext/gmp/tests/011.phpt b/ext/gmp/tests/gmp_divexact.phpt
index a42c1b6b4..a42c1b6b4 100644
--- a/ext/gmp/tests/011.phpt
+++ b/ext/gmp/tests/gmp_divexact.phpt
diff --git a/ext/gmp/tests/gmp_export.phpt b/ext/gmp/tests/gmp_export.phpt
new file mode 100644
index 000000000..fbc8901cf
--- /dev/null
+++ b/ext/gmp/tests/gmp_export.phpt
@@ -0,0 +1,80 @@
+--TEST--
+gmp_export() basic tests
+--SKIPIF--
+<?php if (!extension_loaded("gmp")) echo "skip"; ?>
+--FILE--
+<?php
+
+// Tests taken from GMPs own test suite.
+
+// format is [output, size, options, expected]
+$export = [
+ ['0',1,GMP_BIG_ENDIAN,''],
+ ['0',2,GMP_BIG_ENDIAN,''],
+ ['0',3,GMP_BIG_ENDIAN,''],
+ ['12345678',1,GMP_BIG_ENDIAN,'12345678'],
+ ['12345678',4,GMP_BIG_ENDIAN,'12345678'],
+ ['12345678',4,GMP_LSW_FIRST | GMP_BIG_ENDIAN,'12345678'],
+ ['12345678',1,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'78563412'],
+ ['12345678',4,GMP_LITTLE_ENDIAN,'78563412'],
+ ['12345678',4,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'78563412'],
+ ['123456789ABC',2,GMP_BIG_ENDIAN,'123456789abc'],
+ ['123456789ABC',2,GMP_LSW_FIRST | GMP_BIG_ENDIAN,'9abc56781234'],
+ ['123456789ABC',2,GMP_LITTLE_ENDIAN,'34127856bc9a'],
+ ['123456789ABC',2,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'bc9a78563412'],
+ ['112233445566778899AABBCC',4,GMP_BIG_ENDIAN,'112233445566778899aabbcc'],
+ ['112233445566778899AABBCC',4,GMP_LSW_FIRST | GMP_BIG_ENDIAN,'99aabbcc5566778811223344'],
+ ['112233445566778899AABBCC',4,GMP_LITTLE_ENDIAN,'4433221188776655ccbbaa99'],
+ ['112233445566778899AABBCC',4,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'ccbbaa998877665544332211'],
+ ['100120023003400450056006700780089009A00AB00BC00C',8,GMP_BIG_ENDIAN,'100120023003400450056006700780089009a00ab00bc00c'],
+ ['100120023003400450056006700780089009A00AB00BC00C',8,GMP_LSW_FIRST | GMP_BIG_ENDIAN,'9009a00ab00bc00c50056006700780081001200230034004'],
+ ['100120023003400450056006700780089009A00AB00BC00C',8,GMP_LITTLE_ENDIAN,'044003300220011008800770066005500cc00bb00aa00990'],
+ ['100120023003400450056006700780089009A00AB00BC00C',8,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'0cc00bb00aa0099008800770066005500440033002200110']
+];
+
+$passed = true;
+foreach ($export as $k => $test) {
+ $gmp = gmp_init($test[0], 16);
+ $str = gmp_export($gmp, $test[1], $test[2]);
+ if (is_string($str)) {
+ $result = bin2hex($str);
+ if ($result !== $test[3]) {
+ echo "$k: '$result' !== '{$test[3]}'\n";
+ $passed = false;
+ }
+ } else {
+ $type = gettype($str);
+ echo "$k: $type !== '{$test[3]}'\n";
+ }
+}
+
+var_dump($passed);
+
+// Invalid arguments (zpp failure)
+var_dump(gmp_export());
+
+// Invalid word sizes
+var_dump(gmp_export(123, -1));
+var_dump(gmp_export(123, 0));
+
+// Invalid options
+var_dump(gmp_export(123, 1, GMP_MSW_FIRST | GMP_LSW_FIRST));
+var_dump(gmp_export(123, 1, GMP_BIG_ENDIAN | GMP_LITTLE_ENDIAN));
+
+--EXPECTF--
+bool(true)
+
+Warning: gmp_export() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+
+Warning: gmp_export(): Word size must be positive, -1 given in %s on line %d
+bool(false)
+
+Warning: gmp_export(): Word size must be positive, 0 given in %s on line %d
+bool(false)
+
+Warning: gmp_export(): Invalid options: Conflicting word orders in %s on line %d
+bool(false)
+
+Warning: gmp_export(): Invalid options: Conflicting word endianness in %s on line %d
+bool(false)
diff --git a/ext/gmp/tests/014.phpt b/ext/gmp/tests/gmp_fact.phpt
index 6afccaf93..6afccaf93 100644
--- a/ext/gmp/tests/014.phpt
+++ b/ext/gmp/tests/gmp_fact.phpt
diff --git a/ext/gmp/tests/021.phpt b/ext/gmp/tests/gmp_gcd.phpt
index 275f0bca3..275f0bca3 100644
--- a/ext/gmp/tests/021.phpt
+++ b/ext/gmp/tests/gmp_gcd.phpt
diff --git a/ext/gmp/tests/022.phpt b/ext/gmp/tests/gmp_gcdext.phpt
index 469aa3013..469aa3013 100644
--- a/ext/gmp/tests/022.phpt
+++ b/ext/gmp/tests/gmp_gcdext.phpt
diff --git a/ext/gmp/tests/036.phpt b/ext/gmp/tests/gmp_hamdist.phpt
index c21e03ccb..c21e03ccb 100644
--- a/ext/gmp/tests/036.phpt
+++ b/ext/gmp/tests/gmp_hamdist.phpt
diff --git a/ext/gmp/tests/gmp_import.phpt b/ext/gmp/tests/gmp_import.phpt
new file mode 100644
index 000000000..b7ae6600e
--- /dev/null
+++ b/ext/gmp/tests/gmp_import.phpt
@@ -0,0 +1,91 @@
+--TEST--
+gmp_import() basic tests
+--SKIPIF--
+<?php if (!extension_loaded("gmp")) echo "skip"; ?>
+--FILE--
+<?php
+
+// Tests taken from GMPs own test suite.
+
+// format is [expected, size, options, input]
+$import = [
+ ['0',1,GMP_BIG_ENDIAN,''],
+ ['12345678',1,GMP_BIG_ENDIAN,'12345678'],
+ ['12345678',4,GMP_BIG_ENDIAN,'12345678'],
+ ['12345678',4,GMP_LSW_FIRST | GMP_BIG_ENDIAN,'12345678'],
+ ['12345678',1,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'78563412'],
+ ['12345678',4,GMP_LITTLE_ENDIAN,'78563412'],
+ ['12345678',4,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'78563412'],
+ ['123456789abc',2,GMP_BIG_ENDIAN,'123456789abc'],
+ ['123456789abc',2,GMP_LSW_FIRST | GMP_BIG_ENDIAN,'9abc56781234'],
+ ['123456789abc',2,GMP_LITTLE_ENDIAN,'34127856bc9a'],
+ ['123456789abc',2,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'bc9a78563412'],
+ ['112233445566778899aabbcc',4,GMP_BIG_ENDIAN,'112233445566778899aabbcc'],
+ ['112233445566778899aabbcc',4,GMP_LSW_FIRST | GMP_BIG_ENDIAN,'99aabbcc5566778811223344'],
+ ['112233445566778899aabbcc',4,GMP_LITTLE_ENDIAN,'4433221188776655ccbbaa99'],
+ ['112233445566778899aabbcc',4,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'ccbbaa998877665544332211'],
+ ['100120023003400450056006700780089009a00ab00bc00c',8,GMP_BIG_ENDIAN,'100120023003400450056006700780089009a00ab00bc00c'],
+ ['100120023003400450056006700780089009a00ab00bc00c',8,GMP_LSW_FIRST | GMP_BIG_ENDIAN,'9009a00ab00bc00c50056006700780081001200230034004'],
+ ['100120023003400450056006700780089009a00ab00bc00c',8,GMP_LITTLE_ENDIAN,'044003300220011008800770066005500cc00bb00aa00990'],
+ ['100120023003400450056006700780089009a00ab00bc00c',8,GMP_LSW_FIRST | GMP_LITTLE_ENDIAN,'0cc00bb00aa0099008800770066005500440033002200110']
+];
+
+$passed = true;
+foreach ($import as $k => $test) {
+ $gmp = gmp_import(hex2bin($test[3]), $test[1], $test[2]);
+ if ($gmp instanceof GMP) {
+ $result = gmp_strval($gmp, 16);
+ if ($result !== $test[0]) {
+ echo "$k: '$result' !== '{$test[0]}'\n";
+ $passed = false;
+ }
+ } else {
+ $type = gettype($gmp);
+ echo "$k: $type !== '{$test[0]}'\n";
+ }
+}
+
+var_dump($passed);
+
+// Invalid arguments (zpp failure)
+var_dump(gmp_import());
+
+// Invalid word sizes
+var_dump(gmp_import('a', -1));
+var_dump(gmp_import('a', 0));
+
+// Invalid data lengths
+var_dump(gmp_import('a', 2));
+var_dump(gmp_import('aa', 3));
+var_dump(gmp_import(str_repeat('a', 100), 64));
+
+// Invalid options
+var_dump(gmp_import('a', 1, GMP_MSW_FIRST | GMP_LSW_FIRST));
+var_dump(gmp_import('a', 1, GMP_BIG_ENDIAN | GMP_LITTLE_ENDIAN));
+
+--EXPECTF--
+bool(true)
+
+Warning: gmp_import() expects at least 1 parameter, 0 given in %s on line %d
+NULL
+
+Warning: gmp_import(): Word size must be positive, -1 given in %s on line %d
+bool(false)
+
+Warning: gmp_import(): Word size must be positive, 0 given in %s on line %d
+bool(false)
+
+Warning: gmp_import(): Input length must be a multiple of word size in %s on line %d
+bool(false)
+
+Warning: gmp_import(): Input length must be a multiple of word size in %s on line %d
+bool(false)
+
+Warning: gmp_import(): Input length must be a multiple of word size in %s on line %d
+bool(false)
+
+Warning: gmp_import(): Invalid options: Conflicting word orders in %s on line %d
+bool(false)
+
+Warning: gmp_import(): Invalid options: Conflicting word endianness in %s on line %d
+bool(false)
diff --git a/ext/gmp/tests/040.phpt b/ext/gmp/tests/gmp_init.phpt
index 29640ba70..29640ba70 100644
--- a/ext/gmp/tests/040.phpt
+++ b/ext/gmp/tests/gmp_init.phpt
diff --git a/ext/gmp/tests/004.phpt b/ext/gmp/tests/gmp_intval.phpt
index 088dd08fd..088dd08fd 100644
--- a/ext/gmp/tests/004.phpt
+++ b/ext/gmp/tests/gmp_intval.phpt
diff --git a/ext/gmp/tests/023.phpt b/ext/gmp/tests/gmp_invert.phpt
index 81a90fe16..81a90fe16 100644
--- a/ext/gmp/tests/023.phpt
+++ b/ext/gmp/tests/gmp_invert.phpt
diff --git a/ext/gmp/tests/024.phpt b/ext/gmp/tests/gmp_jacobi.phpt
index 04ddba4f0..04ddba4f0 100644
--- a/ext/gmp/tests/024.phpt
+++ b/ext/gmp/tests/gmp_jacobi.phpt
diff --git a/ext/gmp/tests/025.phpt b/ext/gmp/tests/gmp_legendre.phpt
index 6dde34e1e..6dde34e1e 100644
--- a/ext/gmp/tests/025.phpt
+++ b/ext/gmp/tests/gmp_legendre.phpt
diff --git a/ext/gmp/tests/010.phpt b/ext/gmp/tests/gmp_mod.phpt
index 12e7cad2b..12e7cad2b 100644
--- a/ext/gmp/tests/010.phpt
+++ b/ext/gmp/tests/gmp_mod.phpt
diff --git a/ext/gmp/tests/012.phpt b/ext/gmp/tests/gmp_neg.phpt
index 8ca3471cb..8ca3471cb 100644
--- a/ext/gmp/tests/012.phpt
+++ b/ext/gmp/tests/gmp_neg.phpt
diff --git a/ext/gmp/tests/030.phpt b/ext/gmp/tests/gmp_or.phpt
index 035f070bd..035f070bd 100644
--- a/ext/gmp/tests/030.phpt
+++ b/ext/gmp/tests/gmp_or.phpt
diff --git a/ext/gmp/tests/019.phpt b/ext/gmp/tests/gmp_perfect_square.phpt
index aa596ba9c..aa596ba9c 100644
--- a/ext/gmp/tests/019.phpt
+++ b/ext/gmp/tests/gmp_perfect_square.phpt
diff --git a/ext/gmp/tests/035.phpt b/ext/gmp/tests/gmp_popcount.phpt
index 4b45a0448..4b45a0448 100644
--- a/ext/gmp/tests/035.phpt
+++ b/ext/gmp/tests/gmp_popcount.phpt
diff --git a/ext/gmp/tests/015.phpt b/ext/gmp/tests/gmp_pow.phpt
index e17ecc7ba..e17ecc7ba 100644
--- a/ext/gmp/tests/015.phpt
+++ b/ext/gmp/tests/gmp_pow.phpt
diff --git a/ext/gmp/tests/016.phpt b/ext/gmp/tests/gmp_pown.phpt
index 8a0b34458..f5857b699 100644
--- a/ext/gmp/tests/016.phpt
+++ b/ext/gmp/tests/gmp_pown.phpt
@@ -19,6 +19,9 @@ var_dump(gmp_strval(gmp_powm($n,$e,1000)));
$m = gmp_init(900);
var_dump(gmp_strval(gmp_powm($n,$e,$m)));
+var_dump(gmp_powm(5, 11, 0));
+var_dump(gmp_powm(5, "11", gmp_init(0)));
+
var_dump(gmp_powm(array(),$e,$m));
var_dump(gmp_powm($n,array(),$m));
var_dump(gmp_powm($n,$e,array()));
@@ -46,6 +49,12 @@ string(3) "331"
string(3) "171"
string(3) "371"
+Warning: gmp_powm(): Modulus may not be zero in %s on line %d
+bool(false)
+
+Warning: gmp_powm(): Modulus may not be zero in %s on line %d
+bool(false)
+
Warning: gmp_powm(): Unable to convert variable to GMP - wrong type in %s on line %d
bool(false)
diff --git a/ext/gmp/tests/020.phpt b/ext/gmp/tests/gmp_prob_prime.phpt
index f8f3e6921..f8f3e6921 100644
--- a/ext/gmp/tests/020.phpt
+++ b/ext/gmp/tests/gmp_prob_prime.phpt
diff --git a/ext/gmp/tests/028.phpt b/ext/gmp/tests/gmp_random.phpt
index 3a876aa60..3a876aa60 100644
--- a/ext/gmp/tests/028.phpt
+++ b/ext/gmp/tests/gmp_random.phpt
diff --git a/ext/gmp/tests/041.phpt b/ext/gmp/tests/gmp_remroot.phpt
index 6e6d95928..4a3539d87 100644
--- a/ext/gmp/tests/041.phpt
+++ b/ext/gmp/tests/gmp_remroot.phpt
@@ -1,21 +1,11 @@
--TEST--
-gmp_root() and gmp_rootrem() basic tests
+gmp_rootrem() basic tests
--SKIPIF--
<?php if (!extension_loaded("gmp")) print "skip"; ?>
--FILE--
<?php
-var_dump(gmp_root(1000, 3));
-var_dump(gmp_root(100, 3));
-var_dump(gmp_root(-100, 3));
-
-var_dump(gmp_root(1000, 4));
-var_dump(gmp_root(100, 4));
-var_dump(gmp_root(-100, 4));
-
-var_dump(gmp_root(0, 3));
-var_dump(gmp_root(100, 0));
-var_dump(gmp_root(100, -3));
+var_dump(gmp_rootrem());
var_dump(gmp_rootrem(1000, 3));
var_dump(gmp_rootrem(100, 3));
@@ -31,39 +21,8 @@ var_dump(gmp_rootrem(100, -3));
?>
--EXPECTF--
-object(GMP)#%d (1) {
- ["num"]=>
- string(2) "10"
-}
-object(GMP)#%d (1) {
- ["num"]=>
- string(1) "4"
-}
-object(GMP)#%d (1) {
- ["num"]=>
- string(2) "-4"
-}
-object(GMP)#%d (1) {
- ["num"]=>
- string(1) "5"
-}
-object(GMP)#%d (1) {
- ["num"]=>
- string(1) "3"
-}
-
-Warning: gmp_root(): Can't take even root of negative number in %s on line %d
-bool(false)
-object(GMP)#%d (1) {
- ["num"]=>
- string(1) "0"
-}
-
-Warning: gmp_root(): The root must be positive in %s on line %d
-bool(false)
-
-Warning: gmp_root(): The root must be positive in %s on line %d
-bool(false)
+Warning: gmp_rootrem() expects exactly 2 parameters, 0 given in %s on line %d
+NULL
array(2) {
[0]=>
object(GMP)#%d (1) {
diff --git a/ext/gmp/tests/gmp_root.phpt b/ext/gmp/tests/gmp_root.phpt
new file mode 100644
index 000000000..70faf2705
--- /dev/null
+++ b/ext/gmp/tests/gmp_root.phpt
@@ -0,0 +1,58 @@
+--TEST--
+gmp_root() basic tests
+--SKIPIF--
+<?php if (!extension_loaded("gmp")) print "skip"; ?>
+--FILE--
+<?php
+
+var_dump(gmp_root());
+
+var_dump(gmp_root(1000, 3));
+var_dump(gmp_root(100, 3));
+var_dump(gmp_root(-100, 3));
+
+var_dump(gmp_root(1000, 4));
+var_dump(gmp_root(100, 4));
+var_dump(gmp_root(-100, 4));
+
+var_dump(gmp_root(0, 3));
+var_dump(gmp_root(100, 0));
+var_dump(gmp_root(100, -3));
+
+?>
+--EXPECTF--
+Warning: gmp_root() expects exactly 2 parameters, 0 given in %s on line %d
+NULL
+object(GMP)#%d (1) {
+ ["num"]=>
+ string(2) "10"
+}
+object(GMP)#%d (1) {
+ ["num"]=>
+ string(1) "4"
+}
+object(GMP)#%d (1) {
+ ["num"]=>
+ string(2) "-4"
+}
+object(GMP)#%d (1) {
+ ["num"]=>
+ string(1) "5"
+}
+object(GMP)#%d (1) {
+ ["num"]=>
+ string(1) "3"
+}
+
+Warning: gmp_root(): Can't take even root of negative number in %s on line %d
+bool(false)
+object(GMP)#%d (1) {
+ ["num"]=>
+ string(1) "0"
+}
+
+Warning: gmp_root(): The root must be positive in %s on line %d
+bool(false)
+
+Warning: gmp_root(): The root must be positive in %s on line %d
+bool(false)
diff --git a/ext/gmp/tests/037.phpt b/ext/gmp/tests/gmp_scan0.phpt
index 2a87a968a..2a87a968a 100644
--- a/ext/gmp/tests/037.phpt
+++ b/ext/gmp/tests/gmp_scan0.phpt
diff --git a/ext/gmp/tests/038.phpt b/ext/gmp/tests/gmp_scan1.phpt
index 7ebce9be7..7ebce9be7 100644
--- a/ext/gmp/tests/038.phpt
+++ b/ext/gmp/tests/gmp_scan1.phpt
diff --git a/ext/gmp/tests/033.phpt b/ext/gmp/tests/gmp_setbit.phpt
index 99848959d..99848959d 100644
--- a/ext/gmp/tests/033.phpt
+++ b/ext/gmp/tests/gmp_setbit.phpt
diff --git a/ext/gmp/tests/027.phpt b/ext/gmp/tests/gmp_sign.phpt
index 1efdc28c6..1efdc28c6 100644
--- a/ext/gmp/tests/027.phpt
+++ b/ext/gmp/tests/gmp_sign.phpt
diff --git a/ext/gmp/tests/017.phpt b/ext/gmp/tests/gmp_sqrt.phpt
index d90f53821..d90f53821 100644
--- a/ext/gmp/tests/017.phpt
+++ b/ext/gmp/tests/gmp_sqrt.phpt
diff --git a/ext/gmp/tests/018.phpt b/ext/gmp/tests/gmp_sqrtrem.phpt
index 2fca463da..2fca463da 100644
--- a/ext/gmp/tests/018.phpt
+++ b/ext/gmp/tests/gmp_sqrtrem.phpt
diff --git a/ext/gmp/tests/005.phpt b/ext/gmp/tests/gmp_strval.phpt
index 79fd73ecf..79fd73ecf 100644
--- a/ext/gmp/tests/005.phpt
+++ b/ext/gmp/tests/gmp_strval.phpt
diff --git a/ext/gmp/tests/006.phpt b/ext/gmp/tests/gmp_sub.phpt
index e1d9df67d..e1d9df67d 100644
--- a/ext/gmp/tests/006.phpt
+++ b/ext/gmp/tests/gmp_sub.phpt
diff --git a/ext/gmp/tests/039.phpt b/ext/gmp/tests/gmp_testbit.phpt
index 399c51137..ab40abed7 100644
--- a/ext/gmp/tests/039.phpt
+++ b/ext/gmp/tests/gmp_testbit.phpt
@@ -5,6 +5,8 @@ gmp_testbit() basic tests
--FILE--
<?php
+var_dump(gmp_testbit());
+
$n = gmp_init(0);
var_dump(gmp_testbit($n, -10));
var_dump(gmp_testbit($n, 0));
@@ -38,6 +40,9 @@ var_dump(gmp_strval($n));
echo "Done\n";
?>
--EXPECTF--
+Warning: gmp_testbit() expects exactly 2 parameters, 0 given in %s on line %d
+NULL
+
Warning: gmp_testbit(): Index must be greater than or equal to zero in %s on line %d
bool(false)
bool(false)
diff --git a/ext/gmp/tests/032.phpt b/ext/gmp/tests/gmp_xor.phpt
index 2b0d29a62..2b0d29a62 100644
--- a/ext/gmp/tests/032.phpt
+++ b/ext/gmp/tests/gmp_xor.phpt
diff --git a/ext/gmp/tests/overloading.phpt b/ext/gmp/tests/overloading.phpt
index 0d8f5cfed..3520f58bd 100644
--- a/ext/gmp/tests/overloading.phpt
+++ b/ext/gmp/tests/overloading.phpt
@@ -16,6 +16,10 @@ var_dump($a - $b);
var_dump($a - 17);
var_dump(42 - $b);
+var_dump($a * $b);
+var_dump($a * 17);
+var_dump(42 * $b);
+
var_dump($a / $b);
var_dump($a / 17);
var_dump(42 / $b);
@@ -26,7 +30,9 @@ var_dump($a % 17);
var_dump(42 % $b);
var_dump($a % 0);
-// sl, sr
+var_dump($a ** $b);
+var_dump($a ** 17);
+var_dump(42 ** $b);
var_dump($a | $b);
var_dump($a | 17);
@@ -47,6 +53,9 @@ var_dump(42 << $b);
var_dump($a >> 2);
var_dump(-$a >> 2);
+var_dump($a << -1);
+var_dump($a >> -1);
+
var_dump(~$a);
var_dump(-$a);
var_dump(+$a);
@@ -83,9 +92,14 @@ var_dump(--$a);
var_dump($a--);
var_dump($a);
-$x = gmp_init(3);
-$y = gmp_init(2);
-var_dump($x ** $y);
+// Test operator that was not overloaded
+
+var_dump($a . $b);
+var_dump($a . '17');
+var_dump('42' . $b);
+
+$a .= '17';
+var_dump($a);
?>
--EXPECTF--
@@ -115,6 +129,18 @@ object(GMP)#%d (1) {
}
object(GMP)#%d (1) {
["num"]=>
+ string(3) "714"
+}
+object(GMP)#%d (1) {
+ ["num"]=>
+ string(3) "714"
+}
+object(GMP)#%d (1) {
+ ["num"]=>
+ string(3) "714"
+}
+object(GMP)#%d (1) {
+ ["num"]=>
string(1) "2"
}
object(GMP)#%d (1) {
@@ -145,6 +171,18 @@ Warning: main(): Zero operand not allowed in %s on line %d
bool(false)
object(GMP)#%d (1) {
["num"]=>
+ string(28) "3937657486715347520027492352"
+}
+object(GMP)#%d (1) {
+ ["num"]=>
+ string(28) "3937657486715347520027492352"
+}
+object(GMP)#%d (1) {
+ ["num"]=>
+ string(28) "3937657486715347520027492352"
+}
+object(GMP)#%d (1) {
+ ["num"]=>
string(2) "59"
}
object(GMP)#%d (1) {
@@ -199,6 +237,12 @@ object(GMP)#%d (1) {
["num"]=>
string(3) "-11"
}
+
+Warning: main(): Shift cannot be negative in %s on line %d
+bool(false)
+
+Warning: main(): Shift cannot be negative in %s on line %d
+bool(false)
object(GMP)#%d (1) {
["num"]=>
string(3) "-43"
@@ -260,7 +304,7 @@ object(GMP)#%d (1) {
["num"]=>
string(2) "42"
}
-object(GMP)#%d (1) {
- ["num"]=>
- string(1) "9"
-}
+string(4) "4217"
+string(4) "4217"
+string(4) "4217"
+string(4) "4217"