File tree Expand file tree Collapse file tree 1 file changed +9
-19
lines changed
Expand file tree Collapse file tree 1 file changed +9
-19
lines changed Original file line number Diff line number Diff line change @@ -1258,33 +1258,23 @@ GMP_BINARY_OP_FUNCTION_EX(gmp_or, mpz_ior);
12581258/* {{{ Calculates factorial function */
12591259ZEND_FUNCTION (gmp_fact )
12601260{
1261- zval * a_arg ;
1261+ mpz_ptr gmpnum ;
12621262 mpz_ptr gmpnum_result ;
12631263
12641264 ZEND_PARSE_PARAMETERS_START (1 , 1 )
1265- Z_PARAM_ZVAL ( a_arg )
1265+ GMP_Z_PARAM_INTO_MPZ_PTR ( gmpnum )
12661266 ZEND_PARSE_PARAMETERS_END ();
12671267
1268- if (Z_TYPE_P (a_arg ) == IS_LONG ) {
1269- if (Z_LVAL_P (a_arg ) < 0 ) {
1270- zend_argument_value_error (1 , "must be greater than or equal to 0 ");
1271- RETURN_THROWS ();
1272- }
1273- } else {
1274- mpz_ptr gmpnum ;
1275- gmp_temp_t temp_a ;
1276-
1277- FETCH_GMP_ZVAL (gmpnum , a_arg , temp_a , 1 );
1278- FREE_GMP_TEMP (temp_a );
1279-
1280- if (mpz_sgn (gmpnum ) < 0 ) {
1281- zend_argument_value_error (1 , "must be greater than or equal to 0 ");
1282- RETURN_THROWS ();
1283- }
1268+ if (mpz_sgn (gmpnum ) < 0 ) {
1269+ zend_argument_value_error (1 , "must be greater than or equal to 0 ");
1270+ RETURN_THROWS ();
12841271 }
12851272
1273+ // TODO: Check that we don't an int that is larger than an unsigned long?
1274+ // Could use mpz_fits_slong_p() if we revert to using mpz_get_si()
1275+
12861276 INIT_GMP_RETVAL (gmpnum_result );
1287- mpz_fac_ui (gmpnum_result , zval_get_long ( a_arg ));
1277+ mpz_fac_ui (gmpnum_result , mpz_get_ui ( gmpnum ));
12881278}
12891279/* }}} */
12901280
You can’t perform that action at this time.
0 commit comments