Skip to content

Commit 4a475a4

Browse files
committed
Replace legacy zval_dtor() by zval_ptr_dtor_nogc() or even more specialized destructors.
zval_dtor() doesn't make a lot of sense in PHP-7.* and it's used incorrectly in some places. Its occurances should be replaced by zval_ptr_dtor() or zval_ptr_dtor_nogc(), or even more specialized destructors.
1 parent d798fd4 commit 4a475a4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+174
-178
lines changed

Zend/zend_API.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3465,7 +3465,7 @@ ZEND_API zend_bool zend_make_callable(zval *callable, zend_string **callable_nam
34653465

34663466
if (zend_is_callable_ex(callable, NULL, IS_CALLABLE_STRICT, callable_name, &fcc, NULL)) {
34673467
if (Z_TYPE_P(callable) == IS_STRING && fcc.calling_scope) {
3468-
zval_dtor(callable);
3468+
zval_ptr_dtor_str(callable);
34693469
array_init(callable);
34703470
add_next_index_str(callable, zend_string_copy(fcc.calling_scope->name));
34713471
add_next_index_str(callable, zend_string_copy(fcc.function_handler->common.function_name));

Zend/zend_ast.c

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,12 @@ static int zend_ast_add_array_element(zval *result, zval *offset, zval *expr)
405405
if (!zend_hash_next_index_insert(Z_ARRVAL_P(result), expr)) {
406406
zend_error(E_WARNING,
407407
"Cannot add element to the array as the next element is already occupied");
408-
zval_ptr_dtor(expr);
408+
zval_ptr_dtor_nogc(expr);
409409
}
410410
break;
411411
case IS_STRING:
412412
zend_symtable_update(Z_ARRVAL_P(result), Z_STR_P(offset), expr);
413-
zval_dtor(offset);
413+
zval_ptr_dtor_str(offset);
414414
break;
415415
case IS_NULL:
416416
zend_symtable_update(Z_ARRVAL_P(result), ZSTR_EMPTY_ALLOC(), expr);
@@ -448,29 +448,29 @@ ZEND_API int ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_c
448448
if (UNEXPECTED(zend_ast_evaluate(&op1, ast->child[0], scope) != SUCCESS)) {
449449
ret = FAILURE;
450450
} else if (UNEXPECTED(zend_ast_evaluate(&op2, ast->child[1], scope) != SUCCESS)) {
451-
zval_dtor(&op1);
451+
zval_ptr_dtor_nogc(&op1);
452452
ret = FAILURE;
453453
} else {
454454
binary_op_type op = get_binary_op(ast->attr);
455455
ret = op(result, &op1, &op2);
456-
zval_dtor(&op1);
457-
zval_dtor(&op2);
456+
zval_ptr_dtor_nogc(&op1);
457+
zval_ptr_dtor_nogc(&op2);
458458
}
459459
break;
460460
case ZEND_AST_GREATER:
461461
case ZEND_AST_GREATER_EQUAL:
462462
if (UNEXPECTED(zend_ast_evaluate(&op1, ast->child[0], scope) != SUCCESS)) {
463463
ret = FAILURE;
464464
} else if (UNEXPECTED(zend_ast_evaluate(&op2, ast->child[1], scope) != SUCCESS)) {
465-
zval_dtor(&op1);
465+
zval_ptr_dtor_nogc(&op1);
466466
ret = FAILURE;
467467
} else {
468468
/* op1 > op2 is the same as op2 < op1 */
469469
binary_op_type op = ast->kind == ZEND_AST_GREATER
470470
? is_smaller_function : is_smaller_or_equal_function;
471471
ret = op(result, &op2, &op1);
472-
zval_dtor(&op1);
473-
zval_dtor(&op2);
472+
zval_ptr_dtor_nogc(&op1);
473+
zval_ptr_dtor_nogc(&op2);
474474
}
475475
break;
476476
case ZEND_AST_UNARY_OP:
@@ -479,7 +479,7 @@ ZEND_API int ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_c
479479
} else {
480480
unary_op_type op = get_unary_op(ast->attr);
481481
ret = op(result, &op1);
482-
zval_dtor(&op1);
482+
zval_ptr_dtor_nogc(&op1);
483483
}
484484
break;
485485
case ZEND_AST_ZVAL:
@@ -517,16 +517,16 @@ ZEND_API int ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_c
517517
}
518518
if (zend_is_true(&op1)) {
519519
if (UNEXPECTED(zend_ast_evaluate(&op2, ast->child[1], scope) != SUCCESS)) {
520-
zval_dtor(&op1);
520+
zval_ptr_dtor_nogc(&op1);
521521
ret = FAILURE;
522522
break;
523523
}
524524
ZVAL_BOOL(result, zend_is_true(&op2));
525-
zval_dtor(&op2);
525+
zval_ptr_dtor_nogc(&op2);
526526
} else {
527527
ZVAL_FALSE(result);
528528
}
529-
zval_dtor(&op1);
529+
zval_ptr_dtor_nogc(&op1);
530530
break;
531531
case ZEND_AST_OR:
532532
if (UNEXPECTED(zend_ast_evaluate(&op1, ast->child[0], scope) != SUCCESS)) {
@@ -537,14 +537,14 @@ ZEND_API int ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_c
537537
ZVAL_TRUE(result);
538538
} else {
539539
if (UNEXPECTED(zend_ast_evaluate(&op2, ast->child[1], scope) != SUCCESS)) {
540-
zval_dtor(&op1);
540+
zval_ptr_dtor_nogc(&op1);
541541
ret = FAILURE;
542542
break;
543543
}
544544
ZVAL_BOOL(result, zend_is_true(&op2));
545-
zval_dtor(&op2);
545+
zval_ptr_dtor_nogc(&op2);
546546
}
547-
zval_dtor(&op1);
547+
zval_ptr_dtor_nogc(&op1);
548548
break;
549549
case ZEND_AST_CONDITIONAL:
550550
if (UNEXPECTED(zend_ast_evaluate(&op1, ast->child[0], scope) != SUCCESS)) {
@@ -556,19 +556,19 @@ ZEND_API int ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_c
556556
*result = op1;
557557
} else {
558558
if (UNEXPECTED(zend_ast_evaluate(result, ast->child[1], scope) != SUCCESS)) {
559-
zval_dtor(&op1);
559+
zval_ptr_dtor_nogc(&op1);
560560
ret = FAILURE;
561561
break;
562562
}
563-
zval_dtor(&op1);
563+
zval_ptr_dtor_nogc(&op1);
564564
}
565565
} else {
566566
if (UNEXPECTED(zend_ast_evaluate(result, ast->child[2], scope) != SUCCESS)) {
567-
zval_dtor(&op1);
567+
zval_ptr_dtor_nogc(&op1);
568568
ret = FAILURE;
569569
break;
570570
}
571-
zval_dtor(&op1);
571+
zval_ptr_dtor_nogc(&op1);
572572
}
573573
break;
574574
case ZEND_AST_COALESCE:
@@ -580,11 +580,11 @@ ZEND_API int ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_c
580580
*result = op1;
581581
} else {
582582
if (UNEXPECTED(zend_ast_evaluate(result, ast->child[1], scope) != SUCCESS)) {
583-
zval_dtor(&op1);
583+
zval_ptr_dtor_nogc(&op1);
584584
ret = FAILURE;
585585
break;
586586
}
587-
zval_dtor(&op1);
587+
zval_ptr_dtor_nogc(&op1);
588588
}
589589
break;
590590
case ZEND_AST_UNARY_PLUS:
@@ -593,7 +593,7 @@ ZEND_API int ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_c
593593
} else {
594594
ZVAL_LONG(&op1, 0);
595595
ret = add_function(result, &op1, &op2);
596-
zval_dtor(&op2);
596+
zval_ptr_dtor_nogc(&op2);
597597
}
598598
break;
599599
case ZEND_AST_UNARY_MINUS:
@@ -602,7 +602,7 @@ ZEND_API int ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_c
602602
} else {
603603
ZVAL_LONG(&op1, 0);
604604
ret = sub_function(result, &op1, &op2);
605-
zval_dtor(&op2);
605+
zval_ptr_dtor_nogc(&op2);
606606
}
607607
break;
608608
case ZEND_AST_ARRAY:
@@ -619,21 +619,21 @@ ZEND_API int ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_c
619619
zend_ast *elem = list->child[i];
620620
if (elem->child[1]) {
621621
if (UNEXPECTED(zend_ast_evaluate(&op1, elem->child[1], scope) != SUCCESS)) {
622-
zval_dtor(result);
622+
zval_ptr_dtor_nogc(result);
623623
return FAILURE;
624624
}
625625
} else {
626626
ZVAL_UNDEF(&op1);
627627
}
628628
if (UNEXPECTED(zend_ast_evaluate(&op2, elem->child[0], scope) != SUCCESS)) {
629-
zval_dtor(&op1);
630-
zval_dtor(result);
629+
zval_ptr_dtor_nogc(&op1);
630+
zval_ptr_dtor_nogc(result);
631631
return FAILURE;
632632
}
633633
if (UNEXPECTED(zend_ast_add_array_element(result, &op1, &op2) != SUCCESS)) {
634-
zval_dtor(&op1);
635-
zval_dtor(&op2);
636-
zval_dtor(result);
634+
zval_ptr_dtor_nogc(&op1);
635+
zval_ptr_dtor_nogc(&op2);
636+
zval_ptr_dtor_nogc(result);
637637
return FAILURE;
638638
}
639639
}
@@ -647,13 +647,13 @@ ZEND_API int ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_c
647647
if (UNEXPECTED(zend_ast_evaluate(&op1, ast->child[0], scope) != SUCCESS)) {
648648
ret = FAILURE;
649649
} else if (UNEXPECTED(zend_ast_evaluate(&op2, ast->child[1], scope) != SUCCESS)) {
650-
zval_dtor(&op1);
650+
zval_ptr_dtor_nogc(&op1);
651651
ret = FAILURE;
652652
} else {
653653
zend_fetch_dimension_const(result, &op1, &op2, (ast->attr == ZEND_DIM_IS) ? BP_VAR_IS : BP_VAR_R);
654654

655-
zval_dtor(&op1);
656-
zval_dtor(&op2);
655+
zval_ptr_dtor_nogc(&op1);
656+
zval_ptr_dtor_nogc(&op2);
657657
}
658658
break;
659659
default:

Zend/zend_compile.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ static int lookup_cv(zend_op_array *op_array, zend_string *name) /* {{{ */{
460460

461461
void zend_del_literal(zend_op_array *op_array, int n) /* {{{ */
462462
{
463-
zval_dtor(CT_CONSTANT_EX(op_array, n));
463+
zval_ptr_dtor_nogc(CT_CONSTANT_EX(op_array, n));
464464
if (n + 1 == op_array->last_literal) {
465465
op_array->last_literal--;
466466
} else {
@@ -3449,7 +3449,7 @@ int zend_compile_func_strlen(znode *result, zend_ast_list *args) /* {{{ */
34493449
if (arg_node.op_type == IS_CONST && Z_TYPE(arg_node.u.constant) == IS_STRING) {
34503450
result->op_type = IS_CONST;
34513451
ZVAL_LONG(&result->u.constant, Z_STRLEN(arg_node.u.constant));
3452-
zval_dtor(&arg_node.u.constant);
3452+
zval_ptr_dtor_str(&arg_node.u.constant);
34533453
} else {
34543454
zend_emit_op_tmp(result, ZEND_STRLEN, &arg_node, NULL);
34553455
}
@@ -4608,7 +4608,7 @@ void zend_resolve_goto_label(zend_op_array *op_array, zend_op *opline) /* {{{ */
46084608
zend_error_noreturn(E_COMPILE_ERROR, "'goto' to undefined label '%s'", Z_STRVAL_P(label));
46094609
}
46104610

4611-
zval_dtor(label);
4611+
zval_ptr_dtor_str(label);
46124612
ZVAL_NULL(label);
46134613

46144614
current = opline->extended_value;
@@ -5101,7 +5101,7 @@ void zend_compile_switch(zend_ast *ast) /* {{{ */
51015101
opline->opcode = ZEND_FREE;
51025102
SET_NODE(opline->op1, &expr_node);
51035103
} else if (expr_node.op_type == IS_CONST) {
5104-
zval_dtor(&expr_node.u.constant);
5104+
zval_ptr_dtor_nogc(&expr_node.u.constant);
51055105
}
51065106

51075107
efree(jmpnz_opnums);
@@ -5377,7 +5377,7 @@ void zend_compile_declare(zend_ast *ast) /* {{{ */
53775377
zval value_zv;
53785378
zend_const_expr_to_zval(&value_zv, value_ast);
53795379
FC(declarables).ticks = zval_get_long(&value_zv);
5380-
zval_dtor(&value_zv);
5380+
zval_ptr_dtor_nogc(&value_zv);
53815381
} else if (zend_string_equals_literal_ci(name, "encoding")) {
53825382

53835383
if (FAILURE == zend_declare_is_first_statement(ast)) {

Zend/zend_constants.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void free_zend_constant(zval *zv)
4040
zend_constant *c = Z_PTR_P(zv);
4141

4242
if (!(c->flags & CONST_PERSISTENT)) {
43-
zval_ptr_dtor(&c->value);
43+
zval_ptr_dtor_nogc(&c->value);
4444
if (c->name) {
4545
zend_string_release_ex(c->name, 0);
4646
}
@@ -514,7 +514,7 @@ ZEND_API int zend_register_constant(zend_constant *c)
514514
zend_error(E_NOTICE,"Constant %s already defined", ZSTR_VAL(name));
515515
zend_string_release(c->name);
516516
if (!(c->flags & CONST_PERSISTENT)) {
517-
zval_dtor(&c->value);
517+
zval_ptr_dtor_nogc(&c->value);
518518
}
519519
ret = FAILURE;
520520
}

Zend/zend_execute_API.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *k
943943
zend_exception_restore();
944944

945945
zval_ptr_dtor(&args[0]);
946-
zval_dtor(&fcall_info.function_name);
946+
zval_ptr_dtor_str(&fcall_info.function_name);
947947

948948
zend_hash_del(EG(in_autoload), lc_name);
949949

@@ -1055,7 +1055,7 @@ ZEND_API int zend_eval_stringl(char *str, size_t str_len, zval *retval_ptr, char
10551055
} else {
10561056
retval = FAILURE;
10571057
}
1058-
zval_dtor(&pv);
1058+
zval_ptr_dtor_str(&pv);
10591059
return retval;
10601060
}
10611061
/* }}} */

Zend/zend_language_scanner.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ static zend_bool strip_multiline_string_indentation(
11951195
return 1;
11961196

11971197
error:
1198-
zval_dtor(zendlval);
1198+
zval_ptr_dtor_str(zendlval);
11991199
ZVAL_UNDEF(zendlval);
12001200

12011201
return 0;
@@ -4743,7 +4743,7 @@ int start_line = CG(zend_lineno);
47434743

47444744
ZVAL_UNDEF(&zv);
47454745
retval = lex_scan(&zv, NULL);
4746-
zval_dtor(&zv);
4746+
zval_ptr_dtor_nogc(&zv);
47474747

47484748
if (EG(exception)) {
47494749
zend_clear_exception();

Zend/zend_language_scanner.l

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@ static zend_bool strip_multiline_string_indentation(
11921192
return 1;
11931193

11941194
error:
1195-
zval_dtor(zendlval);
1195+
zval_ptr_dtor_str(zendlval);
11961196
ZVAL_UNDEF(zendlval);
11971197

11981198
return 0;
@@ -2355,7 +2355,7 @@ skip_escape_conversion:
23552355
23562356
ZVAL_UNDEF(&zv);
23572357
retval = lex_scan(&zv, NULL);
2358-
zval_dtor(&zv);
2358+
zval_ptr_dtor_nogc(&zv);
23592359
23602360
if (EG(exception)) {
23612361
zend_clear_exception();

ext/date/php_date.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,7 +2064,7 @@ static int date_interval_has_property(zval *object, zval *member, int type, void
20642064
if (!obj->initialized) {
20652065
retval = zend_std_has_property(object, member, type, cache_slot);
20662066
if (member == &tmp_member) {
2067-
zval_dtor(member);
2067+
zval_ptr_dtor_str(&tmp_member);
20682068
}
20692069
return retval;
20702070
}
@@ -2084,7 +2084,7 @@ static int date_interval_has_property(zval *object, zval *member, int type, void
20842084
}
20852085

20862086
if (member == &tmp_member) {
2087-
zval_dtor(member);
2087+
zval_ptr_dtor_str(&tmp_member);
20882088
}
20892089

20902090
return retval;
@@ -4159,7 +4159,7 @@ zval *date_interval_read_property(zval *object, zval *member, int type, void **c
41594159
if (!obj->initialized) {
41604160
retval = zend_std_read_property(object, member, type, cache_slot, rv);
41614161
if (member == &tmp_member) {
4162-
zval_dtor(member);
4162+
zval_ptr_dtor_str(&tmp_member);
41634163
}
41644164
return retval;
41654165
}
@@ -4186,7 +4186,7 @@ zval *date_interval_read_property(zval *object, zval *member, int type, void **c
41864186
retval = zend_std_read_property(object, member, type, cache_slot, rv);
41874187

41884188
if (member == &tmp_member) {
4189-
zval_dtor(member);
4189+
zval_ptr_dtor_str(&tmp_member);
41904190
}
41914191

41924192
return retval;
@@ -4203,7 +4203,7 @@ zval *date_interval_read_property(zval *object, zval *member, int type, void **c
42034203
}
42044204

42054205
if (member == &tmp_member) {
4206-
zval_dtor(member);
4206+
zval_ptr_dtor_str(&tmp_member);
42074207
}
42084208

42094209
return retval;
@@ -4227,7 +4227,7 @@ void date_interval_write_property(zval *object, zval *member, zval *value, void
42274227
if (!obj->initialized) {
42284228
zend_std_write_property(object, member, value, cache_slot);
42294229
if (member == &tmp_member) {
4230-
zval_dtor(member);
4230+
zval_ptr_dtor_str(&tmp_member);
42314231
}
42324232
return;
42334233
}
@@ -4255,7 +4255,7 @@ void date_interval_write_property(zval *object, zval *member, zval *value, void
42554255
} while(0);
42564256

42574257
if (member == &tmp_member) {
4258-
zval_dtor(member);
4258+
zval_ptr_dtor_str(&tmp_member);
42594259
}
42604260
}
42614261
/* }}} */
@@ -4287,7 +4287,7 @@ static zval *date_interval_get_property_ptr_ptr(zval *object, zval *member, int
42874287
}
42884288

42894289
if (member == &tmp_member) {
4290-
zval_dtor(member);
4290+
zval_ptr_dtor_str(&tmp_member);
42914291
}
42924292

42934293
return ret;

0 commit comments

Comments
 (0)