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.
This commit is contained in:
Gina Peter Banyard 2024-11-27 15:48:34 +00:00
parent 7e1d035077
commit 313886e22b

View file

@ -404,7 +404,7 @@ valueof_op_failure:
static zend_result gmp_do_operation_ex(uint8_t opcode, zval *result, zval *op1, zval *op2) /* {{{ */ 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) { switch (opcode) {
case ZEND_ADD: case ZEND_ADD:
return binop_operator_helper(mpz_add, result, op1, op2); 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: case ZEND_BW_XOR:
return binop_operator_helper(mpz_xor, result, op1, op2); return binop_operator_helper(mpz_xor, result, op1, op2);
case ZEND_BW_NOT: { case ZEND_BW_NOT: {
if (!gmp_zend_parse_arg_into_mpz_ex(op1, &gmp_op1, 1, false)) { ZEND_ASSERT(Z_TYPE_P(op1) == IS_OBJECT && Z_OBJCE_P(op1) == gmp_ce);
return FAILURE;
}
gmp_create(result, &gmp_result); gmp_create(result, &gmp_result);
mpz_com(gmp_result, gmp_op1); mpz_com(gmp_result, GET_GMP_FROM_ZVAL(op1));
return SUCCESS; return SUCCESS;
} }