@@ -266,7 +266,6 @@ typedef void (*gmp_binary_op2_t)(mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr);
266
266
typedef gmp_ulong (* gmp_binary_ui_op2_t )(mpz_ptr , mpz_ptr , mpz_srcptr , gmp_ulong );
267
267
268
268
static inline void gmp_zval_binary_ui_op (zval * return_value , zval * a_arg , zval * b_arg , gmp_binary_op_t gmp_op , gmp_binary_ui_op_t gmp_ui_op , bool check_b_zero , bool is_operator );
269
- static inline void gmp_zval_binary_ui_op2 (zval * return_value , zval * a_arg , zval * b_arg , gmp_binary_op2_t gmp_op , gmp_binary_ui_op2_t gmp_ui_op , int check_b_zero );
270
269
static inline void gmp_zval_unary_op (zval * return_value , zval * a_arg , gmp_unary_op_t gmp_op );
271
270
272
271
static void gmp_mpz_tdiv_q_ui (mpz_ptr a , mpz_srcptr b , gmp_ulong c ) {
@@ -894,58 +893,6 @@ static inline void gmp_zval_binary_ui_op(zval *return_value, zval *a_arg, zval *
894
893
}
895
894
/* }}} */
896
895
897
- /* {{{ gmp_zval_binary_ui_op2
898
- Execute GMP binary operation which returns 2 values.
899
- */
900
- static inline void gmp_zval_binary_ui_op2 (zval * return_value , zval * a_arg , zval * b_arg , gmp_binary_op2_t gmp_op , gmp_binary_ui_op2_t gmp_ui_op , int check_b_zero )
901
- {
902
- mpz_ptr gmpnum_a , gmpnum_b , gmpnum_result1 , gmpnum_result2 ;
903
- gmp_temp_t temp_a , temp_b ;
904
- zval result1 , result2 ;
905
-
906
- FETCH_GMP_ZVAL (gmpnum_a , a_arg , temp_a , 1 );
907
-
908
- if (gmp_ui_op && Z_TYPE_P (b_arg ) == IS_LONG && Z_LVAL_P (b_arg ) >= 0 ) {
909
- gmpnum_b = NULL ;
910
- temp_b .is_used = 0 ;
911
- } else {
912
- FETCH_GMP_ZVAL_DEP (gmpnum_b , b_arg , temp_b , temp_a , 2 );
913
- }
914
-
915
- if (check_b_zero ) {
916
- int b_is_zero = 0 ;
917
- if (!gmpnum_b ) {
918
- b_is_zero = (Z_LVAL_P (b_arg ) == 0 );
919
- } else {
920
- b_is_zero = !mpz_cmp_ui (gmpnum_b , 0 );
921
- }
922
-
923
- if (b_is_zero ) {
924
- zend_throw_exception_ex (zend_ce_division_by_zero_error , 0 , "Division by zero" );
925
- FREE_GMP_TEMP (temp_a );
926
- FREE_GMP_TEMP (temp_b );
927
- RETURN_THROWS ();
928
- }
929
- }
930
-
931
- gmp_create (& result1 , & gmpnum_result1 );
932
- gmp_create (& result2 , & gmpnum_result2 );
933
-
934
- array_init (return_value );
935
- add_next_index_zval (return_value , & result1 );
936
- add_next_index_zval (return_value , & result2 );
937
-
938
- if (!gmpnum_b ) {
939
- gmp_ui_op (gmpnum_result1 , gmpnum_result2 , gmpnum_a , (gmp_ulong ) Z_LVAL_P (b_arg ));
940
- } else {
941
- gmp_op (gmpnum_result1 , gmpnum_result2 , gmpnum_a , gmpnum_b );
942
- }
943
-
944
- FREE_GMP_TEMP (temp_a );
945
- FREE_GMP_TEMP (temp_b );
946
- }
947
- /* }}} */
948
-
949
896
/* {{{ _gmp_binary_ui_op */
950
897
static inline void _gmp_binary_ui_op (INTERNAL_FUNCTION_PARAMETERS , gmp_binary_op_t gmp_op , gmp_binary_ui_op_t gmp_ui_op , int check_b_zero )
951
898
{
@@ -1174,32 +1121,48 @@ ZEND_FUNCTION(gmp_strval)
1174
1121
/* {{{ Divide a by b, returns quotient and reminder */
1175
1122
ZEND_FUNCTION (gmp_div_qr )
1176
1123
{
1177
- zval * a_arg , * b_arg ;
1124
+ mpz_ptr gmpnum_a , gmpnum_b ;
1178
1125
zend_long round = GMP_ROUND_ZERO ;
1179
1126
1180
1127
ZEND_PARSE_PARAMETERS_START (2 , 3 )
1181
- Z_PARAM_ZVAL ( a_arg )
1182
- Z_PARAM_ZVAL ( b_arg )
1128
+ GMP_Z_PARAM_INTO_MPZ_PTR ( gmpnum_a )
1129
+ GMP_Z_PARAM_INTO_MPZ_PTR ( gmpnum_b )
1183
1130
Z_PARAM_OPTIONAL
1184
1131
Z_PARAM_LONG (round )
1185
1132
ZEND_PARSE_PARAMETERS_END ();
1186
1133
1187
- switch (round ) {
1188
- case GMP_ROUND_ZERO :
1189
- gmp_zval_binary_ui_op2 (return_value , a_arg , b_arg , mpz_tdiv_qr , mpz_tdiv_qr_ui , 1 );
1190
- break ;
1191
- case GMP_ROUND_PLUSINF :
1192
- gmp_zval_binary_ui_op2 (return_value , a_arg , b_arg , mpz_cdiv_qr , mpz_cdiv_qr_ui , 1 );
1193
- break ;
1194
- case GMP_ROUND_MINUSINF :
1195
- gmp_zval_binary_ui_op2 (return_value , a_arg , b_arg , mpz_fdiv_qr , mpz_fdiv_qr_ui , 1 );
1196
- break ;
1197
- default :
1134
+ if (mpz_cmp_ui (gmpnum_b , 0 ) == 0 ) {
1135
+ zend_argument_error (zend_ce_division_by_zero_error , 2 , "Division by zero" );
1136
+ RETURN_THROWS ();
1137
+ }
1138
+
1139
+ if (round != GMP_ROUND_ZERO && round != GMP_ROUND_PLUSINF && round != GMP_ROUND_MINUSINF ) {
1198
1140
zend_argument_value_error (3 , "must be one of GMP_ROUND_ZERO, GMP_ROUND_PLUSINF, or GMP_ROUND_MINUSINF" );
1199
1141
RETURN_THROWS ();
1200
1142
}
1143
+
1144
+ zval result1 , result2 ;
1145
+ mpz_ptr gmpnum_result1 , gmpnum_result2 ;
1146
+ gmp_create (& result1 , & gmpnum_result1 );
1147
+ gmp_create (& result2 , & gmpnum_result2 );
1148
+
1149
+ array_init (return_value );
1150
+ add_next_index_zval (return_value , & result1 );
1151
+ add_next_index_zval (return_value , & result2 );
1152
+
1153
+ switch (round ) {
1154
+ case GMP_ROUND_ZERO :
1155
+ mpz_tdiv_qr (gmpnum_result1 , gmpnum_result2 , gmpnum_a , gmpnum_b );
1156
+ break ;
1157
+ case GMP_ROUND_PLUSINF :
1158
+ mpz_cdiv_qr (gmpnum_result1 , gmpnum_result2 , gmpnum_a , gmpnum_b );
1159
+ break ;
1160
+ case GMP_ROUND_MINUSINF :
1161
+ mpz_fdiv_qr (gmpnum_result1 , gmpnum_result2 , gmpnum_a , gmpnum_b );
1162
+ break ;
1163
+ EMPTY_SWITCH_DEFAULT_CASE ()
1164
+ }
1201
1165
}
1202
- /* }}} */
1203
1166
1204
1167
/* {{{ Divide a by b, returns reminder only */
1205
1168
ZEND_FUNCTION (gmp_div_r )
0 commit comments