Skip to content

Commit 9e75353

Browse files
committed
Use zval_ptr_dtor_nogc to destroy literals
Also move the definition of zval_ptr_dtor_nogc to zend_variables.h (from zend_execute.h/.c) as it's used in a few places.
1 parent c52511c commit 9e75353

6 files changed

Lines changed: 13 additions & 24 deletions

File tree

Zend/zend_ast.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,16 +382,11 @@ static void zend_ast_destroy_ex(zend_ast *ast, zend_bool free) {
382382

383383
switch (ast->kind) {
384384
case ZEND_AST_ZVAL:
385-
{
386385
/* Destroy value without using GC: When opcache moves arrays into SHM it will
387386
* free the zend_array structure, so references to it from outside the op array
388387
* become invalid. GC would cause such a reference in the root buffer. */
389-
zval *zv = zend_ast_get_zval(ast);
390-
if (Z_REFCOUNTED_P(zv) && !Z_DELREF_P(zv)) {
391-
_zval_dtor_func_for_ptr(Z_COUNTED_P(zv) ZEND_FILE_LINE_CC);
392-
}
388+
zval_ptr_dtor_nogc(zend_ast_get_zval(ast));
393389
break;
394-
}
395390
case ZEND_AST_FUNC_DECL:
396391
case ZEND_AST_CLOSURE:
397392
case ZEND_AST_METHOD:

Zend/zend_compile.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,10 +600,7 @@ void zend_do_free(znode *op1 TSRMLS_DC) /* {{{ */
600600
/* Destroy value without using GC: When opcache moves arrays into SHM it will
601601
* free the zend_array structure, so references to it from outside the op array
602602
* become invalid. GC would cause such a reference in the root buffer. */
603-
zval *zv = &op1->u.constant;
604-
if (Z_REFCOUNTED_P(zv) && !Z_DELREF_P(zv)) {
605-
_zval_dtor_func_for_ptr(Z_COUNTED_P(zv) ZEND_FILE_LINE_CC);
606-
}
603+
zval_ptr_dtor_nogc(&op1->u.constant);
607604
}
608605
}
609606
/* }}} */

Zend/zend_execute.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ static const zend_internal_function zend_pass_function = {
8383

8484
#undef zval_ptr_dtor
8585
#define zval_ptr_dtor(zv) i_zval_ptr_dtor(zv ZEND_FILE_LINE_CC TSRMLS_CC)
86-
#define zval_ptr_dtor_nogc(zv) i_zval_ptr_dtor_nogc(zv ZEND_FILE_LINE_CC TSRMLS_CC)
8786

8887
#define PZVAL_LOCK(z) if (Z_REFCOUNTED_P(z)) Z_ADDREF_P((z))
8988
#define SELECTIVE_PZVAL_LOCK(pzv, opline) if (RETURN_VALUE_USED(opline)) { PZVAL_LOCK(pzv); }

Zend/zend_execute.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,6 @@ static zend_always_inline void i_zval_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC
6363
}
6464
}
6565

66-
static zend_always_inline void i_zval_ptr_dtor_nogc(zval *zval_ptr ZEND_FILE_LINE_DC TSRMLS_DC)
67-
{
68-
if (Z_REFCOUNTED_P(zval_ptr)) {
69-
if (!Z_DELREF_P(zval_ptr)) {
70-
ZEND_ASSERT(zval_ptr != &EG(uninitialized_zval));
71-
_zval_dtor_func_for_ptr(Z_COUNTED_P(zval_ptr) ZEND_FILE_LINE_CC);
72-
}
73-
}
74-
}
75-
7666
static zend_always_inline int i_zend_is_true(zval *op TSRMLS_DC)
7767
{
7868
int result;
@@ -237,7 +227,7 @@ static zend_always_inline void zend_vm_stack_free_extra_args(zend_execute_data *
237227
zval *p = end + (call->num_args - first_extra_arg);
238228
do {
239229
p--;
240-
i_zval_ptr_dtor_nogc(p ZEND_FILE_LINE_CC TSRMLS_CC);
230+
zval_ptr_dtor_nogc(p);
241231
} while (p != end);
242232
}
243233
}
@@ -252,7 +242,7 @@ static zend_always_inline void zend_vm_stack_free_args(zend_execute_data *call T
252242

253243
do {
254244
p--;
255-
i_zval_ptr_dtor_nogc(p ZEND_FILE_LINE_CC TSRMLS_CC);
245+
zval_ptr_dtor_nogc(p);
256246
} while (p != end);
257247
}
258248
}

Zend/zend_opcode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ ZEND_API void destroy_op_array(zend_op_array *op_array TSRMLS_DC)
343343
if (literal) {
344344
end = literal + op_array->last_literal;
345345
while (literal < end) {
346-
zval_dtor(literal);
346+
zval_ptr_dtor_nogc(literal);
347347
literal++;
348348
}
349349
efree(op_array->literals);

Zend/zend_variables.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ static zend_always_inline void _zval_dtor(zval *zvalue ZEND_FILE_LINE_DC)
3636
_zval_dtor_func(Z_COUNTED_P(zvalue) ZEND_FILE_LINE_RELAY_CC);
3737
}
3838

39+
static zend_always_inline void _zval_ptr_dtor_nogc(zval *zval_ptr ZEND_FILE_LINE_DC)
40+
{
41+
if (Z_REFCOUNTED_P(zval_ptr) && !Z_DELREF_P(zval_ptr)) {
42+
_zval_dtor_func_for_ptr(Z_COUNTED_P(zval_ptr) ZEND_FILE_LINE_CC);
43+
}
44+
}
45+
3946
ZEND_API void _zval_copy_ctor_func(zval *zvalue ZEND_FILE_LINE_DC);
4047

4148
#define zval_copy_ctor_func(zv) _zval_copy_ctor_func(zv ZEND_FILE_LINE_CC)
@@ -98,6 +105,7 @@ ZEND_API void _zval_dtor_wrapper(zval *zvalue);
98105
#define zval_opt_copy_ctor_no_imm(zvalue) _zval_opt_copy_ctor_no_imm((zvalue) ZEND_FILE_LINE_CC)
99106
#define zval_dtor(zvalue) _zval_dtor((zvalue) ZEND_FILE_LINE_CC)
100107
#define zval_ptr_dtor(zval_ptr) _zval_ptr_dtor((zval_ptr) ZEND_FILE_LINE_CC)
108+
#define zval_ptr_dtor_nogc(zval_ptr) _zval_ptr_dtor_nogc((zval_ptr) ZEND_FILE_LINE_CC)
101109
#define zval_internal_dtor(zvalue) _zval_internal_dtor((zvalue) ZEND_FILE_LINE_CC)
102110
#define zval_internal_ptr_dtor(zvalue) _zval_internal_ptr_dtor((zvalue) ZEND_FILE_LINE_CC)
103111
#define zval_dtor_wrapper _zval_dtor_wrapper

0 commit comments

Comments
 (0)