Skip to content

Commit 7482b71

Browse files
committed
Address review feedback
1 parent 8d79494 commit 7482b71

File tree

2 files changed

+259
-149
lines changed

2 files changed

+259
-149
lines changed

Zend/zend_vm_def.h

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -452,15 +452,15 @@ ZEND_VM_COLD_CONSTCONST_HANDLER(16, ZEND_IS_IDENTICAL, CONST|TMP|VAR|CV, CONST|T
452452
op1 = GET_OP1_ZVAL_PTR_DEREF(BP_VAR_R);
453453
op2 = GET_OP2_ZVAL_PTR_DEREF(BP_VAR_R);
454454
if (Z_TYPE_P(op1) != Z_TYPE_P(op2)) {
455-
/* They are not identical, return false. Note that this has to check for undefined variable errors when IS_NULL is possible. */
456-
ZEND_VM_C_LABEL(is_different_nothrow):
455+
/* They are not identical, return false. This has to check for __destruct errors (and undefined variable errors when IS_NULL is possible) */
457456
FREE_OP1();
458457
FREE_OP2();
459458
ZEND_VM_SMART_BRANCH(0, 1);
460459
return;
461460
}
462461
if (Z_TYPE_P(op1) <= IS_TRUE) {
463462
/* They are identical, return true */
463+
/* This has to check for undefined variable errors when IS_NULL is possible. */
464464
FREE_OP1();
465465
FREE_OP2();
466466
ZEND_VM_SMART_BRANCH(1, 1);
@@ -469,16 +469,20 @@ ZEND_VM_COLD_CONSTCONST_HANDLER(16, ZEND_IS_IDENTICAL, CONST|TMP|VAR|CV, CONST|T
469469
switch (Z_TYPE_P(op1)) {
470470
case IS_LONG:
471471
result = (Z_LVAL_P(op1) == Z_LVAL_P(op2));
472+
ZEND_VM_C_LABEL(free_nothrow):
473+
FREE_OP1();
474+
FREE_OP2();
475+
ZEND_VM_SMART_BRANCH(result, 0);
472476
break;
473477
case IS_RESOURCE:
474478
result = (Z_RES_P(op1) == Z_RES_P(op2));
475479
break;
476480
case IS_DOUBLE:
477481
result = (Z_DVAL_P(op1) == Z_DVAL_P(op2));
478-
break;
482+
ZEND_VM_C_GOTO(free_nothrow);
479483
case IS_STRING:
480484
result = zend_string_equals(Z_STR_P(op1), Z_STR_P(op2));
481-
break;
485+
ZEND_VM_C_GOTO(free_nothrow);
482486
case IS_ARRAY:
483487
/* This may cause EG(exception) due to infinite nesting, but other zval types won't? */
484488
/* XXX hash_zval_identical_function is not static */
@@ -488,11 +492,12 @@ ZEND_VM_COLD_CONSTCONST_HANDLER(16, ZEND_IS_IDENTICAL, CONST|TMP|VAR|CV, CONST|T
488492
result = (Z_OBJ_P(op1) == Z_OBJ_P(op2));
489493
break;
490494
default:
491-
ZEND_VM_C_GOTO(is_different_nothrow);
495+
result = 1;
492496
}
497+
/* Check if freeing the operands (e.g. __destruct(), freeing resources (not sure about that), etc threw an exception before setting the result or branching */
493498
FREE_OP1();
494499
FREE_OP2();
495-
ZEND_VM_SMART_BRANCH(result, 0);
500+
ZEND_VM_SMART_BRANCH(result, 1);
496501
}
497502

498503
ZEND_VM_COLD_CONSTCONST_HANDLER(17, ZEND_IS_NOT_IDENTICAL, CONST|TMP|VAR|CV, CONST|TMP|VAR|CV, SPEC(COMMUTATIVE))
@@ -506,15 +511,15 @@ ZEND_VM_COLD_CONSTCONST_HANDLER(17, ZEND_IS_NOT_IDENTICAL, CONST|TMP|VAR|CV, CON
506511
op2 = GET_OP2_ZVAL_PTR_DEREF(BP_VAR_R);
507512

508513
if (Z_TYPE_P(op1) != Z_TYPE_P(op2)) {
509-
/* They are not identical, return true. Note that this has to check for undefined variable errors when IS_NULL is possible. */
510-
ZEND_VM_C_LABEL(is_different_nothrow):
511-
FREE_OP1();
514+
/* They are not identical, return true. This has to check for __destruct errors (and undefined variable errors when IS_NULL is possible) */
515+
FREE_OP1();
512516
FREE_OP2();
513517
ZEND_VM_SMART_BRANCH(1, 1);
514518
return;
515519
}
516520
if (Z_TYPE_P(op1) <= IS_TRUE) {
517-
/* They are identical, return false */
521+
/* They are identical, return false. */
522+
/* This has to check for undefined variable errors when IS_NULL is possible. */
518523
FREE_OP1();
519524
FREE_OP2();
520525
ZEND_VM_SMART_BRANCH(0, 1);
@@ -523,16 +528,20 @@ ZEND_VM_COLD_CONSTCONST_HANDLER(17, ZEND_IS_NOT_IDENTICAL, CONST|TMP|VAR|CV, CON
523528
switch (Z_TYPE_P(op1)) {
524529
case IS_LONG:
525530
result = (Z_LVAL_P(op1) != Z_LVAL_P(op2));
531+
ZEND_VM_C_LABEL(free_nothrow):
532+
FREE_OP1();
533+
FREE_OP2();
534+
ZEND_VM_SMART_BRANCH(result, 0);
526535
break;
527536
case IS_RESOURCE:
528537
result = (Z_RES_P(op1) != Z_RES_P(op2));
529538
break;
530539
case IS_DOUBLE:
531540
result = (Z_DVAL_P(op1) != Z_DVAL_P(op2));
532-
break;
541+
ZEND_VM_C_GOTO(free_nothrow);
533542
case IS_STRING:
534543
result = !zend_string_equals(Z_STR_P(op1), Z_STR_P(op2));
535-
break;
544+
ZEND_VM_C_GOTO(free_nothrow);
536545
case IS_ARRAY:
537546
/* This may cause EG(exception) due to infinite nesting, but other zval types won't? */
538547
/* XXX hash_zval_identical_function is not static */
@@ -542,11 +551,12 @@ ZEND_VM_COLD_CONSTCONST_HANDLER(17, ZEND_IS_NOT_IDENTICAL, CONST|TMP|VAR|CV, CON
542551
result = (Z_OBJ_P(op1) != Z_OBJ_P(op2));
543552
break;
544553
default:
545-
ZEND_VM_C_GOTO(is_different_nothrow);
554+
result = 1;
546555
}
556+
/* Check if freeing the operands (e.g. __destruct(), freeing resources (not sure about that), etc threw an exception before setting the result or branching */
547557
FREE_OP1();
548558
FREE_OP2();
549-
ZEND_VM_SMART_BRANCH(result, 0);
559+
ZEND_VM_SMART_BRANCH(result, 1);
550560
}
551561

552562
ZEND_VM_HELPER(zend_is_equal_helper, ANY, ANY, zval *op_1, zval *op_2)

0 commit comments

Comments
 (0)