php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | |
Patch gmp-memory.patch for GNU MP related Bug #63595Patch version 2014-10-11 06:16 UTC Return to Bug #63595 | Download this patchThis patch is obsolete Obsoleted by patches: Patch Revisions: 2014-10-11 06:50 UTC | 2014-10-11 06:16 UTCDeveloper: remi@php.netLine 1 (now 1), was 137 lines, now 53 lines --- gmp.c.old 2014-10-11 08:03:14.764951256 +0200 +++ gmp.c 2014-10-11 08:49:17.590456127 +0200 @@ -352,6 +352,26 @@ static inline void gmp_zval_unary_ui_op( +++ gmp.c 2014-10-11 08:13:30.892303049 +0200 @@ -352,6 +352,16 @@ static inline void gmp_zval_unary_ui_op( #define gmp_unary_opl(op) _gmp_unary_opl(INTERNAL_FUNCTION_PARAM_PASSTHRU, op) #define gmp_unary_ui_op(op) _gmp_unary_ui_op(INTERNAL_FUNCTION_PARAM_PASSTHRU, op) +static void *(*_save_malloc) (size_t); +static void *(*_save_realloc) (void *, size_t, size_t); +static void (*_save_free) (void *, size_t); +static int _save_count = 0; + +#define GMP_SET_MEMORY do { \ + if (_save_count == 0) { \ + mp_get_memory_functions(&_save_malloc, &_save_realloc, &_save_free); \ + mp_set_memory_functions(gmp_emalloc, gmp_erealloc, gmp_efree); \ + } \ + _save_count++; \ +} while (0) + +#define GMP_END_MEMORY do { \ + _save_count--; \ + if (_save_count == 0) { \ + mp_set_memory_functions(_save_malloc, _save_realloc, _save_free); \ + } \ +} while (0) + mp_get_memory_functions(&_save_malloc, &_save_realloc, &_save_free); \ + mp_set_memory_functions(gmp_emalloc, gmp_erealloc, gmp_efree); \ + } while (0) +#define GMP_END_MEMORY mp_set_memory_functions(_save_malloc, _save_realloc, _save_free) + /* {{{ gmp_emalloc */ static void *gmp_emalloc(size_t size) @@ -391,7 +411,9 @@ static inline long gmp_get_long(zval *zv @@ -391,7 +401,9 @@ static inline long gmp_get_long(zval *zv static void gmp_free_object_storage(gmp_object *intern TSRMLS_DC) /* {{{ */ { + GMP_SET_MEMORY; mpz_clear(intern->num); + GMP_END_MEMORY; zend_object_std_dtor(&intern->std TSRMLS_CC); efree(intern); @@ -406,7 +428,10 @@ static inline zend_object_value gmp_crea @@ -406,7 +418,9 @@ static inline zend_object_value gmp_crea zend_object_std_init(&intern->std, ce TSRMLS_CC); object_properties_init(&intern->std, ce); + GMP_SET_MEMORY; mpz_init(intern->num); + GMP_END_MEMORY; + *gmpnum_target = intern->num; retval.handle = zend_objects_store_put( @@ -545,6 +570,7 @@ static void shift_operator_helper(gmp_bi static int gmp_do_operation_ex(zend_uchar opcode, zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */ { + GMP_SET_MEMORY; switch (opcode) { case ZEND_ADD: DO_BINARY_UI_OP(mpz_add); @@ -575,8 +601,10 @@ static int gmp_do_operation_ex(zend_ucha DO_UNARY_OP(mpz_com); default: + GMP_END_MEMORY; return FAILURE; } + GMP_END_MEMORY; } /* }}} */ @@ -602,7 +630,10 @@ static int gmp_do_operation(zend_uchar o static int gmp_compare(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */ { + GMP_SET_MEMORY; gmp_cmp(result, op1, op2 TSRMLS_CC); + GMP_END_MEMORY; + if (Z_TYPE_P(result) == IS_BOOL) { ZVAL_LONG(result, 1); } @@ -616,6 +647,7 @@ static int gmp_serialize(zval *object, u smart_str buf = {0}; zval zv, *zv_ptr = &zv; php_serialize_data_t serialize_data = (php_serialize_data_t) data; + GMP_SET_MEMORY; PHP_VAR_SERIALIZE_INIT(serialize_data); INIT_PZVAL(zv_ptr); @@ -632,6 +664,7 @@ static int gmp_serialize(zval *object, u *buffer = (unsigned char *) buf.c; *buf_len = buf.len; + GMP_END_MEMORY; return SUCCESS; } /* }}} */ @@ -643,6 +676,7 @@ static int gmp_unserialize(zval **object zval zv, *zv_ptr = &zv; int retval = FAILURE; php_unserialize_data_t unserialize_data = (php_unserialize_data_t) data; + GMP_SET_MEMORY; PHP_VAR_UNSERIALIZE_INIT(unserialize_data); gmp_create_ex(*object, &gmpnum TSRMLS_CC); @@ -679,6 +713,7 @@ static int gmp_unserialize(zval **object exit: zval_dtor(&zv); PHP_VAR_UNSERIALIZE_DESTROY(unserialize_data); + GMP_END_MEMORY; return retval; } /* }}} */ @@ -723,7 +758,8 @@ ZEND_MINIT_FUNCTION(gmp) @@ -723,7 +737,7 @@ ZEND_MINIT_FUNCTION(gmp) 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); + // mp_set_memory_functions(gmp_emalloc, gmp_erealloc, gmp_efree); + _save_malloc = NULL; return SUCCESS; } @@ -734,7 +770,9 @@ ZEND_MINIT_FUNCTION(gmp) ZEND_MODULE_DEACTIVATE_D(gmp) { if (GMPG(rand_initialized)) { + GMP_SET_MEMORY; gmp_randclear(GMPG(rand_state)); + GMP_END_MEMORY; GMPG(rand_initialized) = 0; } @@ -1085,12 +1123,15 @@ ZEND_FUNCTION(gmp_init) @@ -1085,12 +1099,15 @@ ZEND_FUNCTION(gmp_init) php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad base for conversion: %ld (should be between 2 and %d)", base, MAX_BASE); RETURN_FALSE; } + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1150,20 +1191,24 @@ ZEND_FUNCTION(gmp_import) @@ -1150,20 +1167,24 @@ ZEND_FUNCTION(gmp_import) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &data, &data_len, &size, &options) == FAILURE) { return; } + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1181,14 +1226,17 @@ ZEND_FUNCTION(gmp_export) @@ -1181,14 +1202,17 @@ ZEND_FUNCTION(gmp_export) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|ll", &gmpnumber_arg, &size, &options) == FAILURE) { return; } + GMP_SET_MEMORY; + GMP_END_MEMORY; RETURN_EMPTY_STRING(); } else { size_t bits_per_word = size * 8; @@ -1199,10 +1247,12 @@ ZEND_FUNCTION(gmp_export) @@ -1199,10 +1223,12 @@ ZEND_FUNCTION(gmp_export) mpz_export(out_string, NULL, order, size, endian, 0, gmpnumber); out_string[out_len] = '\0'; + GMP_END_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1215,12 +1265,14 @@ ZEND_FUNCTION(gmp_intval) @@ -1215,12 +1241,14 @@ ZEND_FUNCTION(gmp_intval) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &gmpnumber_arg) == FAILURE){ return; } + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1236,6 +1288,7 @@ ZEND_FUNCTION(gmp_strval) @@ -1236,6 +1264,7 @@ ZEND_FUNCTION(gmp_strval) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|l", &gmpnumber_arg, &base) == FAILURE) { return; } + GMP_SET_MEMORY; #if MAX_BASE == 62 /* Although the maximum base in general in GMP >= 4.2 is 62, mpz_get_str() @@ -1254,6 +1307,7 @@ ZEND_FUNCTION(gmp_strval) @@ -1254,6 +1283,7 @@ ZEND_FUNCTION(gmp_strval) gmp_strval(return_value, gmpnum, base); FREE_GMP_TEMP(temp_a); + GMP_END_MEMORY; } /* }}} */ @@ -1261,7 +1315,9 @@ ZEND_FUNCTION(gmp_strval) @@ -1261,7 +1291,9 @@ ZEND_FUNCTION(gmp_strval) Add a and b */ ZEND_FUNCTION(gmp_add) { + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1269,7 +1325,9 @@ ZEND_FUNCTION(gmp_add) @@ -1269,7 +1301,9 @@ ZEND_FUNCTION(gmp_add) Subtract b from a */ ZEND_FUNCTION(gmp_sub) { + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1277,7 +1335,9 @@ ZEND_FUNCTION(gmp_sub) @@ -1277,7 +1311,9 @@ ZEND_FUNCTION(gmp_sub) Multiply a and b */ ZEND_FUNCTION(gmp_mul) { + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1291,6 +1351,7 @@ ZEND_FUNCTION(gmp_div_qr) @@ -1291,6 +1327,7 @@ ZEND_FUNCTION(gmp_div_qr) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|l", &a_arg, &b_arg, &round) == FAILURE) { return; } + GMP_SET_MEMORY; switch (round) { case GMP_ROUND_ZERO: @@ -1304,8 +1365,10 @@ ZEND_FUNCTION(gmp_div_qr) @@ -1304,8 +1341,10 @@ ZEND_FUNCTION(gmp_div_qr) break; default: php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid rounding mode"); + GMP_END_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1319,6 +1382,7 @@ ZEND_FUNCTION(gmp_div_r) @@ -1319,6 +1358,7 @@ ZEND_FUNCTION(gmp_div_r) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|l", &a_arg, &b_arg, &round) == FAILURE) { return; } + GMP_SET_MEMORY; switch (round) { case GMP_ROUND_ZERO: @@ -1332,8 +1396,10 @@ ZEND_FUNCTION(gmp_div_r) @@ -1332,8 +1372,10 @@ ZEND_FUNCTION(gmp_div_r) break; default: php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid rounding mode"); + GMP_END_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1347,6 +1413,7 @@ ZEND_FUNCTION(gmp_div_q) @@ -1347,6 +1389,7 @@ ZEND_FUNCTION(gmp_div_q) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|l", &a_arg, &b_arg, &round) == FAILURE) { return; } + GMP_SET_MEMORY; switch (round) { case GMP_ROUND_ZERO: @@ -1360,9 +1427,10 @@ ZEND_FUNCTION(gmp_div_q) @@ -1360,9 +1403,10 @@ ZEND_FUNCTION(gmp_div_q) break; default: php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid rounding mode"); + GMP_END_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1370,7 +1438,9 @@ ZEND_FUNCTION(gmp_div_q) @@ -1370,7 +1414,9 @@ ZEND_FUNCTION(gmp_div_q) Computes a modulo b */ ZEND_FUNCTION(gmp_mod) { + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1378,7 +1448,9 @@ ZEND_FUNCTION(gmp_mod) @@ -1378,7 +1424,9 @@ ZEND_FUNCTION(gmp_mod) Divide a by b using exact division algorithm */ ZEND_FUNCTION(gmp_divexact) { + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1386,7 +1458,9 @@ ZEND_FUNCTION(gmp_divexact) @@ -1386,7 +1434,9 @@ ZEND_FUNCTION(gmp_divexact) Negates a number */ ZEND_FUNCTION(gmp_neg) { + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1394,7 +1468,9 @@ ZEND_FUNCTION(gmp_neg) @@ -1394,7 +1444,9 @@ ZEND_FUNCTION(gmp_neg) Calculates absolute value */ ZEND_FUNCTION(gmp_abs) { + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1407,21 +1483,25 @@ ZEND_FUNCTION(gmp_fact) @@ -1407,21 +1459,25 @@ ZEND_FUNCTION(gmp_fact) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &a_arg) == FAILURE){ return; } + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1442,6 +1522,7 @@ ZEND_FUNCTION(gmp_pow) @@ -1442,6 +1498,7 @@ ZEND_FUNCTION(gmp_pow) php_error_docref(NULL TSRMLS_CC, E_WARNING, "Negative exponent not supported"); RETURN_FALSE; } + GMP_SET_MEMORY; INIT_GMP_RETVAL(gmpnum_result); if (Z_TYPE_P(base_arg) == IS_LONG && Z_LVAL_P(base_arg) >= 0) { @@ -1451,6 +1532,7 @@ ZEND_FUNCTION(gmp_pow) @@ -1451,6 +1508,7 @@ ZEND_FUNCTION(gmp_pow) mpz_pow_ui(gmpnum_result, gmpnum_base, exp); FREE_GMP_TEMP(temp_base); } + GMP_END_MEMORY; } /* }}} */ @@ -1466,6 +1548,7 @@ ZEND_FUNCTION(gmp_powm) @@ -1466,6 +1524,7 @@ ZEND_FUNCTION(gmp_powm) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &base_arg, &exp_arg, &mod_arg) == FAILURE){ return; } + GMP_SET_MEMORY; FETCH_GMP_ZVAL(gmpnum_base, base_arg, temp_base); @@ -1478,6 +1561,7 @@ ZEND_FUNCTION(gmp_powm) @@ -1478,6 +1537,7 @@ ZEND_FUNCTION(gmp_powm) php_error_docref(NULL TSRMLS_CC, E_WARNING, "Second parameter cannot be less than 0"); FREE_GMP_TEMP(temp_base); FREE_GMP_TEMP(temp_exp); + GMP_END_MEMORY; RETURN_FALSE; } } @@ -1488,6 +1572,7 @@ ZEND_FUNCTION(gmp_powm) @@ -1488,6 +1548,7 @@ ZEND_FUNCTION(gmp_powm) FREE_GMP_TEMP(temp_base); FREE_GMP_TEMP(temp_exp); FREE_GMP_TEMP(temp_mod); + GMP_END_MEMORY; RETURN_FALSE; } @@ -1501,6 +1586,7 @@ ZEND_FUNCTION(gmp_powm) @@ -1501,6 +1562,7 @@ ZEND_FUNCTION(gmp_powm) FREE_GMP_TEMP(temp_base); FREE_GMP_TEMP(temp_mod); + GMP_END_MEMORY; } /* }}} */ @@ -1515,18 +1601,21 @@ ZEND_FUNCTION(gmp_sqrt) @@ -1515,18 +1577,21 @@ ZEND_FUNCTION(gmp_sqrt) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &a_arg) == FAILURE){ return; } + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1541,12 +1630,14 @@ ZEND_FUNCTION(gmp_sqrtrem) @@ -1541,12 +1606,14 @@ ZEND_FUNCTION(gmp_sqrtrem) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &a_arg) == FAILURE){ return; } + GMP_SET_MEMORY; + GMP_END_MEMORY; RETURN_FALSE; } @@ -1556,6 +1647,7 @@ ZEND_FUNCTION(gmp_sqrtrem) @@ -1556,6 +1623,7 @@ ZEND_FUNCTION(gmp_sqrtrem) mpz_sqrtrem(gmpnum_result1, gmpnum_result2, gmpnum_a); FREE_GMP_TEMP(temp_a); + GMP_END_MEMORY; } /* }}} */ @@ -1576,18 +1668,21 @@ ZEND_FUNCTION(gmp_root) @@ -1576,18 +1644,21 @@ ZEND_FUNCTION(gmp_root) php_error_docref(NULL TSRMLS_CC, E_WARNING, "The root must be positive"); RETURN_FALSE; } + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1608,12 +1703,14 @@ ZEND_FUNCTION(gmp_rootrem) @@ -1608,12 +1679,14 @@ ZEND_FUNCTION(gmp_rootrem) php_error_docref(NULL TSRMLS_CC, E_WARNING, "The root must be positive"); RETURN_FALSE; } + GMP_SET_MEMORY; + GMP_END_MEMORY; RETURN_FALSE; } @@ -1631,6 +1728,7 @@ ZEND_FUNCTION(gmp_rootrem) @@ -1631,6 +1704,7 @@ ZEND_FUNCTION(gmp_rootrem) #endif FREE_GMP_TEMP(temp_a); + GMP_END_MEMORY; } /* }}} */ @@ -1645,11 +1743,13 @@ ZEND_FUNCTION(gmp_perfect_square) @@ -1645,11 +1719,13 @@ ZEND_FUNCTION(gmp_perfect_square) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &a_arg) == FAILURE){ return; } + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1665,11 +1765,13 @@ ZEND_FUNCTION(gmp_prob_prime) @@ -1665,11 +1741,13 @@ ZEND_FUNCTION(gmp_prob_prime) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|l", &gmpnumber_arg, &reps) == FAILURE) { return; } + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1677,7 +1779,9 @@ ZEND_FUNCTION(gmp_prob_prime) @@ -1677,7 +1755,9 @@ ZEND_FUNCTION(gmp_prob_prime) Computes greatest common denominator (gcd) of a and b */ ZEND_FUNCTION(gmp_gcd) { + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1692,6 +1796,7 @@ ZEND_FUNCTION(gmp_gcdext) @@ -1692,6 +1772,7 @@ ZEND_FUNCTION(gmp_gcdext) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &a_arg, &b_arg) == FAILURE){ return; } + GMP_SET_MEMORY; FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a); FETCH_GMP_ZVAL_DEP(gmpnum_b, b_arg, temp_b, temp_a); @@ -1704,6 +1809,7 @@ ZEND_FUNCTION(gmp_gcdext) @@ -1704,6 +1785,7 @@ ZEND_FUNCTION(gmp_gcdext) mpz_gcdext(gmpnum_g, gmpnum_s, gmpnum_t, gmpnum_a, gmpnum_b); FREE_GMP_TEMP(temp_a); FREE_GMP_TEMP(temp_b); + GMP_END_MEMORY; } /* }}} */ @@ -1719,6 +1825,7 @@ ZEND_FUNCTION(gmp_invert) @@ -1719,6 +1801,7 @@ ZEND_FUNCTION(gmp_invert) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &a_arg, &b_arg) == FAILURE){ return; } + GMP_SET_MEMORY; FETCH_GMP_ZVAL(gmpnum_a, a_arg, temp_a); FETCH_GMP_ZVAL_DEP(gmpnum_b, b_arg, temp_b, temp_a); @@ -1729,8 +1836,10 @@ ZEND_FUNCTION(gmp_invert) @@ -1729,8 +1812,10 @@ ZEND_FUNCTION(gmp_invert) FREE_GMP_TEMP(temp_b); if (!res) { zval_dtor(return_value); + GMP_END_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1738,7 +1847,9 @@ ZEND_FUNCTION(gmp_invert) @@ -1738,7 +1823,9 @@ ZEND_FUNCTION(gmp_invert) Computes Jacobi symbol */ ZEND_FUNCTION(gmp_jacobi) { + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1746,7 +1857,9 @@ ZEND_FUNCTION(gmp_jacobi) @@ -1746,7 +1833,9 @@ ZEND_FUNCTION(gmp_jacobi) Computes Legendre symbol */ ZEND_FUNCTION(gmp_legendre) { + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1760,7 +1873,9 @@ ZEND_FUNCTION(gmp_cmp) @@ -1760,7 +1849,9 @@ ZEND_FUNCTION(gmp_cmp) return; } + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1777,10 +1892,12 @@ ZEND_FUNCTION(gmp_sign) @@ -1777,10 +1868,12 @@ ZEND_FUNCTION(gmp_sign) return; } + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1794,6 +1911,7 @@ ZEND_FUNCTION(gmp_random) @@ -1794,6 +1887,7 @@ ZEND_FUNCTION(gmp_random) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &limiter) == FAILURE) { return; } + GMP_SET_MEMORY; INIT_GMP_RETVAL(gmpnum_result); @@ -1811,6 +1929,7 @@ ZEND_FUNCTION(gmp_random) @@ -1811,6 +1905,7 @@ ZEND_FUNCTION(gmp_random) #else mpz_urandomb(gmpnum_result, GMPG(rand_state), GMP_ABS (limiter) * __GMP_BITS_PER_MP_LIMB); #endif + GMP_END_MEMORY; } /* }}} */ @@ -1818,7 +1937,9 @@ ZEND_FUNCTION(gmp_random) @@ -1818,7 +1913,9 @@ ZEND_FUNCTION(gmp_random) Calculates logical AND of a and b */ ZEND_FUNCTION(gmp_and) { + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1826,7 +1947,9 @@ ZEND_FUNCTION(gmp_and) @@ -1826,7 +1923,9 @@ ZEND_FUNCTION(gmp_and) Calculates logical OR of a and b */ ZEND_FUNCTION(gmp_or) { + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1834,7 +1957,9 @@ ZEND_FUNCTION(gmp_or) @@ -1834,7 +1933,9 @@ ZEND_FUNCTION(gmp_or) Calculates one's complement of a */ ZEND_FUNCTION(gmp_com) { + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1842,7 +1967,9 @@ ZEND_FUNCTION(gmp_com) @@ -1842,7 +1943,9 @@ ZEND_FUNCTION(gmp_com) Finds next prime of a */ ZEND_FUNCTION(gmp_nextprime) { + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1850,7 +1977,9 @@ ZEND_FUNCTION(gmp_nextprime) @@ -1850,7 +1953,9 @@ ZEND_FUNCTION(gmp_nextprime) Calculates logical exclusive OR of a and b */ ZEND_FUNCTION(gmp_xor) { + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1871,6 +2000,7 @@ ZEND_FUNCTION(gmp_setbit) @@ -1871,6 +1976,7 @@ ZEND_FUNCTION(gmp_setbit) php_error_docref(NULL TSRMLS_CC, E_WARNING, "Index must be greater than or equal to zero"); return; } + GMP_SET_MEMORY; gmpnum_a = GET_GMP_FROM_ZVAL(a_arg); @@ -1879,6 +2009,7 @@ ZEND_FUNCTION(gmp_setbit) @@ -1879,6 +1985,7 @@ ZEND_FUNCTION(gmp_setbit) } else { mpz_clrbit(gmpnum_a, index); } + GMP_END_MEMORY; } /* }}} */ @@ -1898,9 +2029,11 @@ ZEND_FUNCTION(gmp_clrbit) @@ -1898,9 +2005,11 @@ ZEND_FUNCTION(gmp_clrbit) php_error_docref(NULL TSRMLS_CC, E_WARNING, "Index must be greater than or equal to zero"); return; } + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1921,10 +2054,12 @@ ZEND_FUNCTION(gmp_testbit) @@ -1921,10 +2030,12 @@ ZEND_FUNCTION(gmp_testbit) php_error_docref(NULL TSRMLS_CC, E_WARNING, "Index must be greater than or equal to zero"); RETURN_FALSE; } + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1932,7 +2067,9 @@ ZEND_FUNCTION(gmp_testbit) @@ -1932,7 +2043,9 @@ ZEND_FUNCTION(gmp_testbit) Calculates the population count of a */ ZEND_FUNCTION(gmp_popcount) { + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1940,7 +2077,9 @@ ZEND_FUNCTION(gmp_popcount) @@ -1940,7 +2053,9 @@ ZEND_FUNCTION(gmp_popcount) Calculates hamming distance between a and b */ ZEND_FUNCTION(gmp_hamdist) { + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1961,11 +2100,13 @@ ZEND_FUNCTION(gmp_scan0) @@ -1961,11 +2076,13 @@ ZEND_FUNCTION(gmp_scan0) php_error_docref(NULL TSRMLS_CC, E_WARNING, "Starting index must be greater than or equal to zero"); RETURN_FALSE; } + GMP_SET_MEMORY; + GMP_END_MEMORY; } /* }}} */ @@ -1986,11 +2127,13 @@ ZEND_FUNCTION(gmp_scan1) @@ -1986,11 +2103,13 @@ ZEND_FUNCTION(gmp_scan1) php_error_docref(NULL TSRMLS_CC, E_WARNING, "Starting index must be greater than or equal to zero"); RETURN_FALSE; } + GMP_SET_MEMORY; |
Copyright © 2001-2024 The PHP Group All rights reserved. |
Last updated: Sat Apr 20 05:01:27 2024 UTC |