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 @@ -1262,33 +1262,23 @@ GMP_BINARY_OP_FUNCTION_EX(gmp_or, mpz_ior);
12621262/* {{{ Calculates factorial function */
12631263ZEND_FUNCTION (gmp_fact )
12641264{
1265- zval * a_arg ;
1265+ mpz_ptr gmpnum ;
12661266 mpz_ptr gmpnum_result ;
12671267
12681268 ZEND_PARSE_PARAMETERS_START (1 , 1 )
1269- Z_PARAM_ZVAL ( a_arg )
1269+ GMP_Z_PARAM_INTO_MPZ_PTR ( gmpnum )
12701270 ZEND_PARSE_PARAMETERS_END ();
12711271
1272- if (Z_TYPE_P (a_arg ) == IS_LONG ) {
1273- if (Z_LVAL_P (a_arg ) < 0 ) {
1274- zend_argument_value_error (1 , "must be greater than or equal to 0 ");
1275- RETURN_THROWS ();
1276- }
1277- } else {
1278- mpz_ptr gmpnum ;
1279- gmp_temp_t temp_a ;
1280-
1281- FETCH_GMP_ZVAL (gmpnum , a_arg , temp_a , 1 );
1282- FREE_GMP_TEMP (temp_a );
1283-
1284- if (mpz_sgn (gmpnum ) < 0 ) {
1285- zend_argument_value_error (1 , "must be greater than or equal to 0 ");
1286- RETURN_THROWS ();
1287- }
1272+ if (mpz_sgn (gmpnum ) < 0 ) {
1273+ zend_argument_value_error (1 , "must be greater than or equal to 0 ");
1274+ RETURN_THROWS ();
12881275 }
12891276
1277+ // TODO: Check that we don't an int that is larger than an unsigned long?
1278+ // Could use mpz_fits_slong_p() if we revert to using mpz_get_si()
1279+
12901280 INIT_GMP_RETVAL (gmpnum_result );
1291- mpz_fac_ui (gmpnum_result , zval_get_long ( a_arg ));
1281+ mpz_fac_ui (gmpnum_result , mpz_get_ui ( gmpnum ));
12921282}
12931283/* }}} */
12941284
You can’t perform that action at this time.
0 commit comments