Skip to content

Commit

Permalink
Replace legacy zval_dtor() by zval_ptr_dtor_nogc() or even more speci…
Browse files Browse the repository at this point in the history
…alized 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.
  • Loading branch information
dstogov committed Jul 4, 2018
1 parent d798fd4 commit 4a475a4
Show file tree
Hide file tree
Showing 52 changed files with 174 additions and 178 deletions.
2 changes: 1 addition & 1 deletion Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -3465,7 +3465,7 @@ ZEND_API zend_bool zend_make_callable(zval *callable, zend_string **callable_nam

if (zend_is_callable_ex(callable, NULL, IS_CALLABLE_STRICT, callable_name, &fcc, NULL)) {
if (Z_TYPE_P(callable) == IS_STRING && fcc.calling_scope) {
zval_dtor(callable);
zval_ptr_dtor_str(callable);
array_init(callable);
add_next_index_str(callable, zend_string_copy(fcc.calling_scope->name));
add_next_index_str(callable, zend_string_copy(fcc.function_handler->common.function_name));
Expand Down
64 changes: 32 additions & 32 deletions Zend/zend_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,12 @@ static int zend_ast_add_array_element(zval *result, zval *offset, zval *expr)
if (!zend_hash_next_index_insert(Z_ARRVAL_P(result), expr)) {
zend_error(E_WARNING,
"Cannot add element to the array as the next element is already occupied");
zval_ptr_dtor(expr);
zval_ptr_dtor_nogc(expr);
}
break;
case IS_STRING:
zend_symtable_update(Z_ARRVAL_P(result), Z_STR_P(offset), expr);
zval_dtor(offset);
zval_ptr_dtor_str(offset);
break;
case IS_NULL:
zend_symtable_update(Z_ARRVAL_P(result), ZSTR_EMPTY_ALLOC(), expr);
Expand Down Expand Up @@ -448,29 +448,29 @@ ZEND_API int ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_c
if (UNEXPECTED(zend_ast_evaluate(&op1, ast->child[0], scope) != SUCCESS)) {
ret = FAILURE;
} else if (UNEXPECTED(zend_ast_evaluate(&op2, ast->child[1], scope) != SUCCESS)) {
zval_dtor(&op1);
zval_ptr_dtor_nogc(&op1);
ret = FAILURE;
} else {
binary_op_type op = get_binary_op(ast->attr);
ret = op(result, &op1, &op2);
zval_dtor(&op1);
zval_dtor(&op2);
zval_ptr_dtor_nogc(&op1);
zval_ptr_dtor_nogc(&op2);
}
break;
case ZEND_AST_GREATER:
case ZEND_AST_GREATER_EQUAL:
if (UNEXPECTED(zend_ast_evaluate(&op1, ast->child[0], scope) != SUCCESS)) {
ret = FAILURE;
} else if (UNEXPECTED(zend_ast_evaluate(&op2, ast->child[1], scope) != SUCCESS)) {
zval_dtor(&op1);
zval_ptr_dtor_nogc(&op1);
ret = FAILURE;
} else {
/* op1 > op2 is the same as op2 < op1 */
binary_op_type op = ast->kind == ZEND_AST_GREATER
? is_smaller_function : is_smaller_or_equal_function;
ret = op(result, &op2, &op1);
zval_dtor(&op1);
zval_dtor(&op2);
zval_ptr_dtor_nogc(&op1);
zval_ptr_dtor_nogc(&op2);
}
break;
case ZEND_AST_UNARY_OP:
Expand All @@ -479,7 +479,7 @@ ZEND_API int ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_c
} else {
unary_op_type op = get_unary_op(ast->attr);
ret = op(result, &op1);
zval_dtor(&op1);
zval_ptr_dtor_nogc(&op1);
}
break;
case ZEND_AST_ZVAL:
Expand Down Expand Up @@ -517,16 +517,16 @@ ZEND_API int ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_c
}
if (zend_is_true(&op1)) {
if (UNEXPECTED(zend_ast_evaluate(&op2, ast->child[1], scope) != SUCCESS)) {
zval_dtor(&op1);
zval_ptr_dtor_nogc(&op1);
ret = FAILURE;
break;
}
ZVAL_BOOL(result, zend_is_true(&op2));
zval_dtor(&op2);
zval_ptr_dtor_nogc(&op2);
} else {
ZVAL_FALSE(result);
}
zval_dtor(&op1);
zval_ptr_dtor_nogc(&op1);
break;
case ZEND_AST_OR:
if (UNEXPECTED(zend_ast_evaluate(&op1, ast->child[0], scope) != SUCCESS)) {
Expand All @@ -537,14 +537,14 @@ ZEND_API int ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_c
ZVAL_TRUE(result);
} else {
if (UNEXPECTED(zend_ast_evaluate(&op2, ast->child[1], scope) != SUCCESS)) {
zval_dtor(&op1);
zval_ptr_dtor_nogc(&op1);
ret = FAILURE;
break;
}
ZVAL_BOOL(result, zend_is_true(&op2));
zval_dtor(&op2);
zval_ptr_dtor_nogc(&op2);
}
zval_dtor(&op1);
zval_ptr_dtor_nogc(&op1);
break;
case ZEND_AST_CONDITIONAL:
if (UNEXPECTED(zend_ast_evaluate(&op1, ast->child[0], scope) != SUCCESS)) {
Expand All @@ -556,19 +556,19 @@ ZEND_API int ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_c
*result = op1;
} else {
if (UNEXPECTED(zend_ast_evaluate(result, ast->child[1], scope) != SUCCESS)) {
zval_dtor(&op1);
zval_ptr_dtor_nogc(&op1);
ret = FAILURE;
break;
}
zval_dtor(&op1);
zval_ptr_dtor_nogc(&op1);
}
} else {
if (UNEXPECTED(zend_ast_evaluate(result, ast->child[2], scope) != SUCCESS)) {
zval_dtor(&op1);
zval_ptr_dtor_nogc(&op1);
ret = FAILURE;
break;
}
zval_dtor(&op1);
zval_ptr_dtor_nogc(&op1);
}
break;
case ZEND_AST_COALESCE:
Expand All @@ -580,11 +580,11 @@ ZEND_API int ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_c
*result = op1;
} else {
if (UNEXPECTED(zend_ast_evaluate(result, ast->child[1], scope) != SUCCESS)) {
zval_dtor(&op1);
zval_ptr_dtor_nogc(&op1);
ret = FAILURE;
break;
}
zval_dtor(&op1);
zval_ptr_dtor_nogc(&op1);
}
break;
case ZEND_AST_UNARY_PLUS:
Expand All @@ -593,7 +593,7 @@ ZEND_API int ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_c
} else {
ZVAL_LONG(&op1, 0);
ret = add_function(result, &op1, &op2);
zval_dtor(&op2);
zval_ptr_dtor_nogc(&op2);
}
break;
case ZEND_AST_UNARY_MINUS:
Expand All @@ -602,7 +602,7 @@ ZEND_API int ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_c
} else {
ZVAL_LONG(&op1, 0);
ret = sub_function(result, &op1, &op2);
zval_dtor(&op2);
zval_ptr_dtor_nogc(&op2);
}
break;
case ZEND_AST_ARRAY:
Expand All @@ -619,21 +619,21 @@ ZEND_API int ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_c
zend_ast *elem = list->child[i];
if (elem->child[1]) {
if (UNEXPECTED(zend_ast_evaluate(&op1, elem->child[1], scope) != SUCCESS)) {
zval_dtor(result);
zval_ptr_dtor_nogc(result);
return FAILURE;
}
} else {
ZVAL_UNDEF(&op1);
}
if (UNEXPECTED(zend_ast_evaluate(&op2, elem->child[0], scope) != SUCCESS)) {
zval_dtor(&op1);
zval_dtor(result);
zval_ptr_dtor_nogc(&op1);
zval_ptr_dtor_nogc(result);
return FAILURE;
}
if (UNEXPECTED(zend_ast_add_array_element(result, &op1, &op2) != SUCCESS)) {
zval_dtor(&op1);
zval_dtor(&op2);
zval_dtor(result);
zval_ptr_dtor_nogc(&op1);
zval_ptr_dtor_nogc(&op2);
zval_ptr_dtor_nogc(result);
return FAILURE;
}
}
Expand All @@ -647,13 +647,13 @@ ZEND_API int ZEND_FASTCALL zend_ast_evaluate(zval *result, zend_ast *ast, zend_c
if (UNEXPECTED(zend_ast_evaluate(&op1, ast->child[0], scope) != SUCCESS)) {
ret = FAILURE;
} else if (UNEXPECTED(zend_ast_evaluate(&op2, ast->child[1], scope) != SUCCESS)) {
zval_dtor(&op1);
zval_ptr_dtor_nogc(&op1);
ret = FAILURE;
} else {
zend_fetch_dimension_const(result, &op1, &op2, (ast->attr == ZEND_DIM_IS) ? BP_VAR_IS : BP_VAR_R);

zval_dtor(&op1);
zval_dtor(&op2);
zval_ptr_dtor_nogc(&op1);
zval_ptr_dtor_nogc(&op2);
}
break;
default:
Expand Down
10 changes: 5 additions & 5 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ static int lookup_cv(zend_op_array *op_array, zend_string *name) /* {{{ */{

void zend_del_literal(zend_op_array *op_array, int n) /* {{{ */
{
zval_dtor(CT_CONSTANT_EX(op_array, n));
zval_ptr_dtor_nogc(CT_CONSTANT_EX(op_array, n));
if (n + 1 == op_array->last_literal) {
op_array->last_literal--;
} else {
Expand Down Expand Up @@ -3449,7 +3449,7 @@ int zend_compile_func_strlen(znode *result, zend_ast_list *args) /* {{{ */
if (arg_node.op_type == IS_CONST && Z_TYPE(arg_node.u.constant) == IS_STRING) {
result->op_type = IS_CONST;
ZVAL_LONG(&result->u.constant, Z_STRLEN(arg_node.u.constant));
zval_dtor(&arg_node.u.constant);
zval_ptr_dtor_str(&arg_node.u.constant);
} else {
zend_emit_op_tmp(result, ZEND_STRLEN, &arg_node, NULL);
}
Expand Down Expand Up @@ -4608,7 +4608,7 @@ void zend_resolve_goto_label(zend_op_array *op_array, zend_op *opline) /* {{{ */
zend_error_noreturn(E_COMPILE_ERROR, "'goto' to undefined label '%s'", Z_STRVAL_P(label));
}

zval_dtor(label);
zval_ptr_dtor_str(label);
ZVAL_NULL(label);

current = opline->extended_value;
Expand Down Expand Up @@ -5101,7 +5101,7 @@ void zend_compile_switch(zend_ast *ast) /* {{{ */
opline->opcode = ZEND_FREE;
SET_NODE(opline->op1, &expr_node);
} else if (expr_node.op_type == IS_CONST) {
zval_dtor(&expr_node.u.constant);
zval_ptr_dtor_nogc(&expr_node.u.constant);
}

efree(jmpnz_opnums);
Expand Down Expand Up @@ -5377,7 +5377,7 @@ void zend_compile_declare(zend_ast *ast) /* {{{ */
zval value_zv;
zend_const_expr_to_zval(&value_zv, value_ast);
FC(declarables).ticks = zval_get_long(&value_zv);
zval_dtor(&value_zv);
zval_ptr_dtor_nogc(&value_zv);
} else if (zend_string_equals_literal_ci(name, "encoding")) {

if (FAILURE == zend_declare_is_first_statement(ast)) {
Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void free_zend_constant(zval *zv)
zend_constant *c = Z_PTR_P(zv);

if (!(c->flags & CONST_PERSISTENT)) {
zval_ptr_dtor(&c->value);
zval_ptr_dtor_nogc(&c->value);
if (c->name) {
zend_string_release_ex(c->name, 0);
}
Expand Down Expand Up @@ -514,7 +514,7 @@ ZEND_API int zend_register_constant(zend_constant *c)
zend_error(E_NOTICE,"Constant %s already defined", ZSTR_VAL(name));
zend_string_release(c->name);
if (!(c->flags & CONST_PERSISTENT)) {
zval_dtor(&c->value);
zval_ptr_dtor_nogc(&c->value);
}
ret = FAILURE;
}
Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_execute_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *k
zend_exception_restore();

zval_ptr_dtor(&args[0]);
zval_dtor(&fcall_info.function_name);
zval_ptr_dtor_str(&fcall_info.function_name);

zend_hash_del(EG(in_autoload), lc_name);

Expand Down Expand Up @@ -1055,7 +1055,7 @@ ZEND_API int zend_eval_stringl(char *str, size_t str_len, zval *retval_ptr, char
} else {
retval = FAILURE;
}
zval_dtor(&pv);
zval_ptr_dtor_str(&pv);
return retval;
}
/* }}} */
Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_language_scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ static zend_bool strip_multiline_string_indentation(
return 1;

error:
zval_dtor(zendlval);
zval_ptr_dtor_str(zendlval);
ZVAL_UNDEF(zendlval);

return 0;
Expand Down Expand Up @@ -4743,7 +4743,7 @@ int start_line = CG(zend_lineno);

ZVAL_UNDEF(&zv);
retval = lex_scan(&zv, NULL);
zval_dtor(&zv);
zval_ptr_dtor_nogc(&zv);

if (EG(exception)) {
zend_clear_exception();
Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_language_scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ static zend_bool strip_multiline_string_indentation(
return 1;

error:
zval_dtor(zendlval);
zval_ptr_dtor_str(zendlval);
ZVAL_UNDEF(zendlval);

return 0;
Expand Down Expand Up @@ -2355,7 +2355,7 @@ skip_escape_conversion:
ZVAL_UNDEF(&zv);
retval = lex_scan(&zv, NULL);
zval_dtor(&zv);
zval_ptr_dtor_nogc(&zv);
if (EG(exception)) {
zend_clear_exception();
Expand Down
16 changes: 8 additions & 8 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -2064,7 +2064,7 @@ static int date_interval_has_property(zval *object, zval *member, int type, void
if (!obj->initialized) {
retval = zend_std_has_property(object, member, type, cache_slot);
if (member == &tmp_member) {
zval_dtor(member);
zval_ptr_dtor_str(&tmp_member);
}
return retval;
}
Expand All @@ -2084,7 +2084,7 @@ static int date_interval_has_property(zval *object, zval *member, int type, void
}

if (member == &tmp_member) {
zval_dtor(member);
zval_ptr_dtor_str(&tmp_member);
}

return retval;
Expand Down Expand Up @@ -4159,7 +4159,7 @@ zval *date_interval_read_property(zval *object, zval *member, int type, void **c
if (!obj->initialized) {
retval = zend_std_read_property(object, member, type, cache_slot, rv);
if (member == &tmp_member) {
zval_dtor(member);
zval_ptr_dtor_str(&tmp_member);
}
return retval;
}
Expand All @@ -4186,7 +4186,7 @@ zval *date_interval_read_property(zval *object, zval *member, int type, void **c
retval = zend_std_read_property(object, member, type, cache_slot, rv);

if (member == &tmp_member) {
zval_dtor(member);
zval_ptr_dtor_str(&tmp_member);
}

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

if (member == &tmp_member) {
zval_dtor(member);
zval_ptr_dtor_str(&tmp_member);
}

return retval;
Expand All @@ -4227,7 +4227,7 @@ void date_interval_write_property(zval *object, zval *member, zval *value, void
if (!obj->initialized) {
zend_std_write_property(object, member, value, cache_slot);
if (member == &tmp_member) {
zval_dtor(member);
zval_ptr_dtor_str(&tmp_member);
}
return;
}
Expand Down Expand Up @@ -4255,7 +4255,7 @@ void date_interval_write_property(zval *object, zval *member, zval *value, void
} while(0);

if (member == &tmp_member) {
zval_dtor(member);
zval_ptr_dtor_str(&tmp_member);
}
}
/* }}} */
Expand Down Expand Up @@ -4287,7 +4287,7 @@ static zval *date_interval_get_property_ptr_ptr(zval *object, zval *member, int
}

if (member == &tmp_member) {
zval_dtor(member);
zval_ptr_dtor_str(&tmp_member);
}

return ret;
Expand Down
Loading

0 comments on commit 4a475a4

Please sign in to comment.