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);
1262
1262
/* {{{ Calculates factorial function */
1263
1263
ZEND_FUNCTION (gmp_fact )
1264
1264
{
1265
- zval * a_arg ;
1265
+ mpz_ptr gmpnum ;
1266
1266
mpz_ptr gmpnum_result ;
1267
1267
1268
1268
ZEND_PARSE_PARAMETERS_START (1 , 1 )
1269
- Z_PARAM_ZVAL ( a_arg )
1269
+ GMP_Z_PARAM_INTO_MPZ_PTR ( gmpnum )
1270
1270
ZEND_PARSE_PARAMETERS_END ();
1271
1271
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 ();
1288
1275
}
1289
1276
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
+
1290
1280
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 ));
1292
1282
}
1293
1283
/* }}} */
1294
1284
You can’t perform that action at this time.
0 commit comments