Skip to content

Accept GMP|string|int union in GMP functions #6139

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

Closed
wants to merge 1 commit into from
Closed
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
29 changes: 14 additions & 15 deletions ext/gmp/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,11 +589,8 @@ static int convert_to_gmp(mpz_t gmpnumber, zval *val, zend_long base, uint32_t a
{
switch (Z_TYPE_P(val)) {
case IS_LONG:
case IS_FALSE:
case IS_TRUE: {
mpz_set_si(gmpnumber, zval_get_long(val));
mpz_set_si(gmpnumber, Z_LVAL_P(val));
return SUCCESS;
}
case IS_STRING: {
char *numstr = Z_STRVAL_P(val);
zend_bool skip_lead = 0;
Expand Down Expand Up @@ -623,14 +620,16 @@ static int convert_to_gmp(mpz_t gmpnumber, zval *val, zend_long base, uint32_t a

return SUCCESS;
}
default:
/* if unserializing */
if (arg_pos == 0) {
php_error_docref(NULL, E_WARNING, "Cannot convert variable of type %s to GMP", zend_zval_type_name(val));
default: {
zend_long lval;
if (!zend_parse_arg_long_slow(val, &lval)) {
zend_argument_type_error(arg_pos, "must be of type GMP|string|int, %s given", zend_zval_type_name(val));
return FAILURE;
}
zend_argument_type_error(arg_pos, "must be of type GMP|string|int|bool, %s given", zend_zval_type_name(val));
return FAILURE;

mpz_set_si(gmpnumber, lval);
return SUCCESS;
}
}
}
/* }}} */
Expand Down Expand Up @@ -992,16 +991,16 @@ ZEND_FUNCTION(gmp_export)
ZEND_FUNCTION(gmp_intval)
{
zval *gmpnumber_arg;
mpz_ptr gmpnum;
gmp_temp_t temp_a;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &gmpnumber_arg) == FAILURE){
RETURN_THROWS();
}

if (IS_GMP(gmpnumber_arg)) {
RETVAL_LONG(mpz_get_si(GET_GMP_FROM_ZVAL(gmpnumber_arg)));
} else {
RETVAL_LONG(zval_get_long(gmpnumber_arg));
}
FETCH_GMP_ZVAL(gmpnum, gmpnumber_arg, temp_a, 1);
RETVAL_LONG(mpz_get_si(gmpnum));
FREE_GMP_TEMP(temp_a);
}
/* }}} */

Expand Down
287 changes: 85 additions & 202 deletions ext/gmp/gmp.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,222 +6,105 @@ class GMP
{
}

/** @param int|bool|string $number */
function gmp_init($number, int $base = 0): GMP {}
function gmp_init(int|string $number, int $base = 0): GMP {}

function gmp_import(string $data, int $word_size = 1, int $options = GMP_MSW_FIRST | GMP_NATIVE_ENDIAN): GMP {}

/** @param GMP|int|bool|string $gmpnumber */
function gmp_export($gmpnumber, int $word_size = 1, int $options = GMP_MSW_FIRST | GMP_NATIVE_ENDIAN): string {}

/** @param GMP|int|bool|string $gmpnumber */
function gmp_intval($gmpnumber): int {}

/** @param GMP|int|bool|string $gmpnumber */
function gmp_strval($gmpnumber, int $base = 10): string {}

/**
* @param GMP|int|bool|string $a
* @param GMP|int|bool|string $b
*/
function gmp_add($a, $b): GMP {}

/**
* @param GMP|int|bool|string $a
* @param GMP|int|bool|string $b
*/
function gmp_sub($a, $b): GMP {}

/**
* @param GMP|int|bool|string $a
* @param GMP|int|bool|string $b
*/
function gmp_mul($a, $b): GMP {}

/**
* @param GMP|int|bool|string $a
* @param GMP|int|bool|string $b
*/
function gmp_div_qr($a, $b, int $round = GMP_ROUND_ZERO): array {}

/**
* @param GMP|int|bool|string $a
* @param GMP|int|bool|string $b
*/
function gmp_div_q($a, $b, int $round = GMP_ROUND_ZERO): GMP {}

/**
* @param GMP|int|bool|string $a
* @param GMP|int|bool|string $b
*/
function gmp_div_r($a, $b, int $round = GMP_ROUND_ZERO): GMP {}

/**
* @param GMP|int|bool|string $a
* @param GMP|int|bool|string $b
* @alias gmp_div_q
*/
function gmp_div($a, $b, int $round = GMP_ROUND_ZERO): GMP {}

/**
* @param GMP|int|bool|string $a
* @param GMP|int|bool|string $b
*/
function gmp_mod($a, $b): GMP {}

/**
* @param GMP|int|bool|string $a
* @param GMP|int|bool|string $b
*/
function gmp_divexact($a, $b): GMP {}

/** @param GMP|int|bool|string $a */
function gmp_neg($a): GMP {}

/** @param GMP|int|bool|string $a */
function gmp_abs($a): GMP {}

/** @param GMP|int|bool|string $a */
function gmp_fact($a): GMP {}

/** @param GMP|int|bool|string $a */
function gmp_sqrt($a): GMP {}

/** @param GMP|int|bool|string $a */
function gmp_sqrtrem($a): array {}

/** @param GMP|int|bool|string $a */
function gmp_root($a, int $nth): GMP {}

/** @param GMP|int|bool|string $a */
function gmp_rootrem($a, int $nth): array {}

/** @param GMP|int|bool|string $base */
function gmp_pow($base, int $exp): GMP {}

/**
* @param GMP|int|bool|string $base
* @param GMP|int|bool|string $exp
* @param GMP|int|bool|string $mod
*/
function gmp_powm($base, $exp, $mod): GMP {}

/** @param GMP|int|bool|string $a */
function gmp_perfect_square($a): bool {}

/** @param GMP|int|bool|string $a */
function gmp_perfect_power($a): bool {}

/** @param GMP|int|bool|string $a */
function gmp_prob_prime($a, int $reps = 10): int {}

/**
* @param GMP|int|bool|string $a
* @param GMP|int|bool|string $b
*/
function gmp_gcd($a, $b): GMP {}

/**
* @param GMP|int|bool|string $a
* @param GMP|int|bool|string $b
*/
function gmp_gcdext($a, $b): array {}

/**
* @param GMP|int|bool|string $a
* @param GMP|int|bool|string $b
*/
function gmp_lcm($a, $b): GMP {}

/**
* @param GMP|int|bool|string $a
* @param GMP|int|bool|string $b
*/
function gmp_invert($a, $b): GMP|false {}

/**
* @param GMP|int|bool|string $a
* @param GMP|int|bool|string $b
*/
function gmp_jacobi($a, $b): int {}

/**
* @param GMP|int|bool|string $a
* @param GMP|int|bool|string $b
*/
function gmp_legendre($a, $b): int {}

/**
* @param GMP|int|bool|string $a
* @param GMP|int|bool|string $b
*/
function gmp_kronecker($a, $b): int {}

/**
* @param GMP|int|bool|string $a
* @param GMP|int|bool|string $b
*/
function gmp_cmp($a, $b): int {}

/** @param GMP|int|bool|string $a */
function gmp_sign($a): int {}

/** @param GMP|int|bool|string $seed */
function gmp_random_seed($seed): void {}
function gmp_export(GMP|int|string $gmpnumber, int $word_size = 1, int $options = GMP_MSW_FIRST | GMP_NATIVE_ENDIAN): string {}

function gmp_intval(GMP|int|string $gmpnumber): int {}

function gmp_strval(GMP|int|string $gmpnumber, int $base = 10): string {}

function gmp_add(GMP|int|string $a, GMP|int|string $b): GMP {}

function gmp_sub(GMP|int|string $a, GMP|int|string $b): GMP {}

function gmp_mul(GMP|int|string $a, GMP|int|string $b): GMP {}

function gmp_div_qr(GMP|int|string $a, GMP|int|string $b, int $round = GMP_ROUND_ZERO): array {}

function gmp_div_q(GMP|int|string $a, GMP|int|string $b, int $round = GMP_ROUND_ZERO): GMP {}

function gmp_div_r(GMP|int|string $a, GMP|int|string $b, int $round = GMP_ROUND_ZERO): GMP {}

/** @alias gmp_div_q */
function gmp_div(GMP|int|string $a, GMP|int|string $b, int $round = GMP_ROUND_ZERO): GMP {}

function gmp_mod(GMP|int|string $a, GMP|int|string $b): GMP {}

function gmp_divexact(GMP|int|string $a, GMP|int|string $b): GMP {}

function gmp_neg(GMP|int|string $a): GMP {}

function gmp_abs(GMP|int|string $a): GMP {}

function gmp_fact(GMP|int|string $a): GMP {}

function gmp_sqrt(GMP|int|string $a): GMP {}

function gmp_sqrtrem(GMP|int|string $a): array {}

function gmp_root(GMP|int|string $a, int $nth): GMP {}

function gmp_rootrem(GMP|int|string $a, int $nth): array {}

function gmp_pow(GMP|int|string $base, int $exp): GMP {}

function gmp_powm(GMP|int|string $base, GMP|int|string $exp, GMP|int|string $mod): GMP {}

function gmp_perfect_square(GMP|int|string $a): bool {}

function gmp_perfect_power(GMP|int|string $a): bool {}

function gmp_prob_prime(GMP|int|string $a, int $reps = 10): int {}

function gmp_gcd(GMP|int|string $a, GMP|int|string $b): GMP {}

function gmp_gcdext(GMP|int|string $a, GMP|int|string $b): array {}

function gmp_lcm(GMP|int|string $a, GMP|int|string $b): GMP {}

function gmp_invert(GMP|int|string $a, GMP|int|string $b): GMP|false {}

function gmp_jacobi(GMP|int|string $a, GMP|int|string $b): int {}

function gmp_legendre(GMP|int|string $a, GMP|int|string $b): int {}

function gmp_kronecker(GMP|int|string $a, GMP|int|string $b): int {}

function gmp_cmp(GMP|int|string $a, GMP|int|string $b): int {}

function gmp_sign(GMP|int|string $a): int {}

function gmp_random_seed(GMP|int|string $seed): void {}

function gmp_random_bits(int $bits): GMP {}

/**
* @param GMP|int|bool|string $min
* @param GMP|int|bool|string $max
**/
function gmp_random_range($min, $max): GMP {}

/**
* @param GMP|int|bool|string $a
* @param GMP|int|bool|string $b
*/
function gmp_and($a, $b): GMP {}

/**
* @param GMP|int|bool|string $a
* @param GMP|int|bool|string $b
*/
function gmp_or($a, $b): GMP {}

/** @param GMP|int|bool|string $a */
function gmp_com($a): GMP {}

/**
* @param GMP|int|bool|string $a
* @param GMP|int|bool|string $b
*/
function gmp_xor($a, $b): GMP {}
function gmp_random_range(GMP|int|string $min, GMP|int|string $max): GMP {}

function gmp_and(GMP|int|string $a, GMP|int|string $b): GMP {}

function gmp_or(GMP|int|string $a, GMP|int|string $b): GMP {}

function gmp_com(GMP|int|string $a): GMP {}

function gmp_xor(GMP|int|string $a, GMP|int|string $b): GMP {}

function gmp_setbit(GMP $a, int $index, bool $set_clear = true): void {}

function gmp_clrbit(GMP $a, int $index): void {}

/** @param GMP|int|bool|string $a */
function gmp_testbit($a, int $index): bool {}
function gmp_testbit(GMP|int|string $a, int $index): bool {}

/** @param GMP|int|bool|string $a */
function gmp_scan0($a, int $start): int {}
function gmp_scan0(GMP|int|string $a, int $start): int {}

/** @param GMP|int|bool|string $a */
function gmp_scan1($a, int $start): int {}
function gmp_scan1(GMP|int|string $a, int $start): int {}

/** @param GMP|int|bool|string $a */
function gmp_popcount($a): int {}
function gmp_popcount(GMP|int|string $a): int {}

/**
* @param GMP|int|bool|string $a
* @param GMP|int|bool|string $b
*/
function gmp_hamdist($a, $b): int {}
function gmp_hamdist(GMP|int|string $a, GMP|int|string $b): int {}

/** @param GMP|int|bool|string $a */
function gmp_nextprime($a): GMP {}
function gmp_nextprime(GMP|int|string $a): GMP {}

/** @param GMP|int|bool|string $a */
function gmp_binomial($a, int $b): GMP {}
function gmp_binomial(GMP|int|string $a, int $b): GMP {}
Loading