Skip to content

Commit e5a3011

Browse files
committed
DEBUG replace gmp_zval_binary_ui_op macro
1 parent 2fc0878 commit e5a3011

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

ext/gmp/gmp.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,33 @@ static int gmp_do_operation_ex(zend_uchar opcode, zval *result, zval *op1, zval
370370
{
371371
switch (opcode) {
372372
case ZEND_ADD:
373-
gmp_zval_binary_ui_op(result, op1, op2, mpz_add, mpz_add_ui, false, true);
373+
374+
mpz_ptr gmpnum_a, gmpnum_b, gmpnum_result;
375+
gmp_temp_t temp_a, temp_b;
376+
377+
FETCH_GMP_ZVAL(gmpnum_a, op1, temp_a, 0);
378+
379+
if (mpz_add_ui && Z_TYPE_P(op2) == IS_LONG && Z_LVAL_P(op2) >= 0) {
380+
gmpnum_b = NULL;
381+
temp_b.is_used = 0;
382+
} else {
383+
FETCH_GMP_ZVAL_DEP(gmpnum_b, op2, temp_b, temp_a, 0);
384+
}
385+
386+
INIT_GMP_RETVAL(gmpnum_result);
387+
388+
if (!gmpnum_b) {
389+
mpz_add_ui(gmpnum_result, gmpnum_a, (gmp_ulong) Z_LVAL_P(op2));
390+
} else {
391+
mpz_add(gmpnum_result, gmpnum_a, gmpnum_b);
392+
}
393+
394+
FREE_GMP_TEMP(temp_a);
395+
FREE_GMP_TEMP(temp_b);
396+
397+
398+
399+
374400
if (UNEXPECTED(EG(exception))) { return FAILURE; }
375401
return SUCCESS;
376402
case ZEND_SUB:

0 commit comments

Comments
 (0)