@@ -169,10 +169,11 @@ static zend_result convert_zstr_to_gmp(mpz_t gmp_number, const zend_string *val,
169
169
static zend_result convert_to_gmp (mpz_t gmpnumber , zval * val , zend_long base , uint32_t arg_pos );
170
170
static void gmp_cmp (zval * return_value , zval * a_arg , zval * b_arg , bool is_operator );
171
171
172
- static bool gmp_zend_parse_arg_into_mpz (
172
+ static bool gmp_zend_parse_arg_into_mpz_ex (
173
173
zval * arg ,
174
174
mpz_ptr * destination_mpz_ptr ,
175
- uint32_t arg_num
175
+ uint32_t arg_num ,
176
+ bool is_operator
176
177
) {
177
178
if (EXPECTED (Z_TYPE_P (arg ) == IS_OBJECT )) {
178
179
if (EXPECTED (instanceof_function (Z_OBJCE_P (arg ), gmp_ce ))) {
@@ -184,7 +185,7 @@ static bool gmp_zend_parse_arg_into_mpz(
184
185
185
186
* destination_mpz_ptr = GMPG (zpp_arg [arg_num - 1 ]);
186
187
if (Z_TYPE_P (arg ) == IS_STRING ) {
187
- return convert_zstr_to_gmp (* destination_mpz_ptr , Z_STR_P (arg ), /* base */ 0 , arg_num ) != FAILURE ;
188
+ return convert_zstr_to_gmp (* destination_mpz_ptr , Z_STR_P (arg ), /* base */ 0 , is_operator ? 0 : arg_num ) != FAILURE ;
188
189
}
189
190
190
191
if (Z_TYPE_P (arg ) == IS_LONG ) {
@@ -194,6 +195,11 @@ static bool gmp_zend_parse_arg_into_mpz(
194
195
return false;
195
196
}
196
197
198
+ static bool gmp_zend_parse_arg_into_mpz (zval * arg , mpz_ptr * destination_mpz_ptr , uint32_t arg_num )
199
+ {
200
+ return gmp_zend_parse_arg_into_mpz_ex (arg , destination_mpz_ptr , arg_num , false);
201
+ }
202
+
197
203
#define GMP_Z_PARAM_INTO_MPZ_PTR (destination_mpz_ptr ) \
198
204
Z_PARAM_PROLOGUE(0, 0); \
199
205
if (UNEXPECTED(!gmp_zend_parse_arg_into_mpz(_arg, &destination_mpz_ptr, _i))) { \
@@ -250,7 +256,6 @@ typedef void (*gmp_binary_op2_t)(mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr);
250
256
typedef gmp_ulong (* gmp_binary_ui_op2_t )(mpz_ptr , mpz_ptr , mpz_srcptr , gmp_ulong );
251
257
252
258
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 );
253
- static inline void gmp_zval_unary_op (zval * return_value , zval * a_arg , gmp_unary_op_t gmp_op );
254
259
255
260
static void gmp_mpz_tdiv_q_ui (mpz_ptr a , mpz_srcptr b , gmp_ulong c ) {
256
261
mpz_tdiv_q_ui (a , b , c );
@@ -452,15 +457,9 @@ typeof_op_failure: ;
452
457
#define DO_BINARY_UI_OP (op ) DO_BINARY_UI_OP_EX(op, op ## _ui, 0)
453
458
#define DO_BINARY_OP (op ) DO_BINARY_UI_OP_EX(op, NULL, 0)
454
459
455
- #define DO_UNARY_OP (op ) \
456
- gmp_zval_unary_op(result, op1, op); \
457
- if (UNEXPECTED(EG(exception))) { \
458
- return FAILURE; \
459
- } \
460
- return SUCCESS;
461
-
462
460
static zend_result gmp_do_operation_ex (uint8_t opcode , zval * result , zval * op1 , zval * op2 ) /* {{{ */
463
461
{
462
+ mpz_ptr gmp_op1 , gmp_result ;
464
463
switch (opcode ) {
465
464
case ZEND_ADD :
466
465
DO_BINARY_UI_OP (mpz_add );
@@ -484,8 +483,14 @@ static zend_result gmp_do_operation_ex(uint8_t opcode, zval *result, zval *op1,
484
483
DO_BINARY_OP (mpz_and );
485
484
case ZEND_BW_XOR :
486
485
DO_BINARY_OP (mpz_xor );
487
- case ZEND_BW_NOT :
488
- DO_UNARY_OP (mpz_com );
486
+ case ZEND_BW_NOT : {
487
+ if (!gmp_zend_parse_arg_into_mpz_ex (op1 , & gmp_op1 , 1 , false)) {
488
+ return FAILURE ;
489
+ }
490
+ gmp_create (result , & gmp_result );
491
+ mpz_com (gmp_result , gmp_op1 );
492
+ return SUCCESS ;
493
+ }
489
494
490
495
default :
491
496
return FAILURE ;
@@ -857,23 +862,6 @@ static inline void gmp_zval_binary_ui_op(zval *return_value, zval *a_arg, zval *
857
862
}
858
863
/* }}} */
859
864
860
- /* Unary operations */
861
-
862
- /* {{{ gmp_zval_unary_op */
863
- static inline void gmp_zval_unary_op (zval * return_value , zval * a_arg , gmp_unary_op_t gmp_op )
864
- {
865
- mpz_ptr gmpnum_a , gmpnum_result ;
866
- gmp_temp_t temp_a ;
867
-
868
- FETCH_GMP_ZVAL (gmpnum_a , a_arg , temp_a , 1 );
869
-
870
- INIT_GMP_RETVAL (gmpnum_result );
871
- gmp_op (gmpnum_result , gmpnum_a );
872
-
873
- FREE_GMP_TEMP (temp_a );
874
- }
875
- /* }}} */
876
-
877
865
static bool gmp_verify_base (zend_long base , uint32_t arg_num )
878
866
{
879
867
if (base && (base < 2 || base > GMP_MAX_BASE )) {
0 commit comments