From 313886e22b5ae5c47d4c74c387a6b8f66e94e17e Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Wed, 27 Nov 2024 15:48:34 +0000 Subject: [PATCH] ext/gmp: Refactor op overloading for ZEND_BW_NOT The only way for the do_operation object handler to be called for unary operations is when the zval is an object. Therefore we know we have a zval of the correct type and there is no need to check for it. --- ext/gmp/gmp.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c index 1d87695c6e3..d60df0e2494 100644 --- a/ext/gmp/gmp.c +++ b/ext/gmp/gmp.c @@ -404,7 +404,7 @@ valueof_op_failure: static zend_result gmp_do_operation_ex(uint8_t opcode, zval *result, zval *op1, zval *op2) /* {{{ */ { - mpz_ptr gmp_op1, gmp_result; + mpz_ptr gmp_result; switch (opcode) { case ZEND_ADD: return binop_operator_helper(mpz_add, result, op1, op2); @@ -429,11 +429,9 @@ static zend_result gmp_do_operation_ex(uint8_t opcode, zval *result, zval *op1, case ZEND_BW_XOR: return binop_operator_helper(mpz_xor, result, op1, op2); case ZEND_BW_NOT: { - if (!gmp_zend_parse_arg_into_mpz_ex(op1, &gmp_op1, 1, false)) { - return FAILURE; - } + ZEND_ASSERT(Z_TYPE_P(op1) == IS_OBJECT && Z_OBJCE_P(op1) == gmp_ce); gmp_create(result, &gmp_result); - mpz_com(gmp_result, gmp_op1); + mpz_com(gmp_result, GET_GMP_FROM_ZVAL(op1)); return SUCCESS; }