diff --git a/Zend/zend.c b/Zend/zend.c index ea397db1c4b9f..53270763eb314 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -415,7 +415,7 @@ ZEND_API void zend_print_flat_zval_r(zval *expr) /* {{{ */ zend_print_flat_zval_r(Z_REFVAL_P(expr)); break; default: - zend_print_variable(expr); + zend_print_zval(expr, 0); break; } } diff --git a/Zend/zend.h b/Zend/zend.h index 7db86dd986d3a..b1c1e66867338 100644 --- a/Zend/zend.h +++ b/Zend/zend.h @@ -243,6 +243,10 @@ ZEND_API size_t zend_print_zval(zval *expr, int indent); ZEND_API void zend_print_zval_r(zval *expr, int indent); ZEND_API zend_string *zend_print_zval_r_to_str(zval *expr, int indent); ZEND_API void zend_print_flat_zval_r(zval *expr); + +#define zend_print_variable(var) \ + zend_print_zval((var), 0) + ZEND_API ZEND_COLD void zend_output_debug_string(zend_bool trigger_break, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3); ZEND_API void zend_activate(void); diff --git a/Zend/zend_constants.c b/Zend/zend_constants.c index c64de9839b1ed..daf430d1f960f 100644 --- a/Zend/zend_constants.c +++ b/Zend/zend_constants.c @@ -46,7 +46,7 @@ void free_zend_constant(zval *zv) } efree(c); } else { - zval_internal_dtor(&c->value); + zval_internal_ptr_dtor(&c->value); if (c->name) { zend_string_release_ex(c->name, 1); } diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index 8d39de01010d5..eba3b625ab044 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -528,23 +528,6 @@ ZEND_API zend_bool zend_is_executing(void) /* {{{ */ } /* }}} */ -ZEND_API void _zval_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC) /* {{{ */ -{ - i_zval_ptr_dtor(zval_ptr ZEND_FILE_LINE_RELAY_CC); -} -/* }}} */ - -ZEND_API void _zval_internal_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC) /* {{{ */ -{ - if (Z_REFCOUNTED_P(zval_ptr)) { - Z_DELREF_P(zval_ptr); - if (Z_REFCOUNT_P(zval_ptr) == 0) { - _zval_internal_dtor_for_ptr(zval_ptr ZEND_FILE_LINE_CC); - } - } -} -/* }}} */ - ZEND_API int zend_use_undefined_constant(zend_string *name, zend_ast_attr attr, zval *result) /* {{{ */ { char *colon; diff --git a/Zend/zend_variables.c b/Zend/zend_variables.c index 15df7486512d1..32612f6cf020e 100644 --- a/Zend/zend_variables.c +++ b/Zend/zend_variables.c @@ -108,65 +108,32 @@ static void ZEND_FASTCALL zend_ast_ref_destroy_wrapper(zend_ast_ref *ast ZEND_FI } #endif -ZEND_API void _zval_internal_dtor(zval *zvalue ZEND_FILE_LINE_DC) +ZEND_API void _zval_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC) /* {{{ */ { - switch (Z_TYPE_P(zvalue)) { - case IS_STRING: - CHECK_ZVAL_STRING_REL(Z_STR_P(zvalue)); - zend_string_release_ex(Z_STR_P(zvalue), 1); - break; - case IS_ARRAY: - case IS_CONSTANT_AST: - case IS_OBJECT: - case IS_RESOURCE: - zend_error_noreturn(E_CORE_ERROR, "Internal zval's can't be arrays, objects or resources"); - break; - case IS_REFERENCE: { - zend_reference *ref = (zend_reference*)Z_REF_P(zvalue); - - zval_internal_ptr_dtor(&ref->val); - free(ref); - break; - } - case IS_LONG: - case IS_DOUBLE: - case IS_FALSE: - case IS_TRUE: - case IS_NULL: - default: - break; - } + i_zval_ptr_dtor(zval_ptr ZEND_FILE_LINE_RELAY_CC); } +/* }}} */ -ZEND_API void _zval_internal_dtor_for_ptr(zval *zvalue ZEND_FILE_LINE_DC) +ZEND_API void _zval_internal_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC) /* {{{ */ { - switch (Z_TYPE_P(zvalue)) { - case IS_STRING: - CHECK_ZVAL_STRING_REL(Z_STR_P(zvalue)); - zend_string_free(Z_STR_P(zvalue)); - break; - case IS_ARRAY: - case IS_CONSTANT_AST: - case IS_OBJECT: - case IS_RESOURCE: - zend_error_noreturn(E_CORE_ERROR, "Internal zval's can't be arrays, objects or resources"); - break; - case IS_REFERENCE: { - zend_reference *ref = (zend_reference*)Z_REF_P(zvalue); - - zval_internal_ptr_dtor(&ref->val); - free(ref); - break; + if (Z_REFCOUNTED_P(zval_ptr)) { + zend_refcounted *ref = Z_COUNTED_P(zval_ptr); + + if (GC_DELREF(ref) == 0) { + if (Z_TYPE_P(zval_ptr) == IS_STRING) { + zend_string *str = (zend_string*)ref; + + CHECK_ZVAL_STRING_REL(str); + ZEND_ASSERT(!ZSTR_IS_INTERNED(str)); + ZEND_ASSERT((GC_FLAGS(str) & IS_STR_PERSISTENT)); + free(str); + } else { + zend_error_noreturn(E_CORE_ERROR, "Internal zval's can't be arrays, objects, resources or reference"); } - case IS_LONG: - case IS_DOUBLE: - case IS_FALSE: - case IS_TRUE: - case IS_NULL: - default: - break; + } } } +/* }}} */ /* This function should only be used as a copy constructor, i.e. it * should only be called AFTER a zval has been copied to another @@ -183,17 +150,6 @@ ZEND_API void zval_add_ref(zval *p) } } -ZEND_API void zval_add_ref_unref(zval *p) -{ - if (Z_REFCOUNTED_P(p)) { - if (Z_ISREF_P(p)) { - ZVAL_COPY(p, Z_REFVAL_P(p)); - } else { - Z_ADDREF_P(p); - } - } -} - ZEND_API void ZEND_FASTCALL _zval_copy_ctor_func(zval *zvalue ZEND_FILE_LINE_DC) { if (EXPECTED(Z_TYPE_P(zvalue) == IS_ARRAY)) { @@ -206,25 +162,7 @@ ZEND_API void ZEND_FASTCALL _zval_copy_ctor_func(zval *zvalue ZEND_FILE_LINE_DC) } -ZEND_API size_t zend_print_variable(zval *var) -{ - return zend_print_zval(var, 0); -} - - -ZEND_API void _zval_dtor_wrapper(zval *zvalue) -{ - zval_dtor(zvalue); -} - - #if ZEND_DEBUG -ZEND_API void _zval_internal_dtor_wrapper(zval *zvalue) -{ - zval_internal_dtor(zvalue); -} - - ZEND_API void _zval_ptr_dtor_wrapper(zval *zval_ptr) { diff --git a/Zend/zend_variables.h b/Zend/zend_variables.h index 9be2dc8d483a8..154378d71fc51 100644 --- a/Zend/zend_variables.h +++ b/Zend/zend_variables.h @@ -71,42 +71,33 @@ static zend_always_inline void _zval_opt_copy_ctor(zval *zvalue ZEND_FILE_LINE_D } } -ZEND_API size_t zend_print_variable(zval *var); ZEND_API void _zval_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC); -ZEND_API void _zval_internal_dtor_for_ptr(zval *zvalue ZEND_FILE_LINE_DC); -ZEND_API void _zval_internal_dtor(zval *zvalue ZEND_FILE_LINE_DC); ZEND_API void _zval_internal_ptr_dtor(zval *zvalue ZEND_FILE_LINE_DC); -ZEND_API void _zval_dtor_wrapper(zval *zvalue); #define zval_copy_ctor(zvalue) _zval_copy_ctor((zvalue) ZEND_FILE_LINE_CC) #define zval_opt_copy_ctor(zvalue) _zval_opt_copy_ctor((zvalue) ZEND_FILE_LINE_CC) -#define zval_dtor(zvalue) zval_ptr_dtor_nogc(zvalue) #define zval_ptr_dtor(zval_ptr) _zval_ptr_dtor((zval_ptr) ZEND_FILE_LINE_CC) #define zval_ptr_dtor_nogc(zval_ptr) _zval_ptr_dtor_nogc((zval_ptr) ZEND_FILE_LINE_CC) -#define zval_internal_dtor(zvalue) _zval_internal_dtor((zvalue) ZEND_FILE_LINE_CC) #define zval_internal_ptr_dtor(zvalue) _zval_internal_ptr_dtor((zvalue) ZEND_FILE_LINE_CC) -#define zval_dtor_wrapper _zval_dtor_wrapper + +/* Kept for compatibility */ +#define zval_dtor(zvalue) zval_ptr_dtor_nogc(zvalue) +#define zval_internal_dtor(zvalue) _zval_internal_ptr_dtor((zvalue) ZEND_FILE_LINE_CC) #if ZEND_DEBUG ZEND_API void _zval_ptr_dtor_wrapper(zval *zval_ptr); -ZEND_API void _zval_internal_dtor_wrapper(zval *zvalue); ZEND_API void _zval_internal_ptr_dtor_wrapper(zval *zvalue); #define zval_ptr_dtor_wrapper _zval_ptr_dtor_wrapper -#define zval_internal_dtor_wrapper _zval_internal_dtor_wrapper #define zval_internal_ptr_dtor_wrapper _zval_internal_ptr_dtor_wrapper #else #define zval_ptr_dtor_wrapper _zval_ptr_dtor -#define zval_internal_dtor_wrapper _zval_internal_dtor #define zval_internal_ptr_dtor_wrapper _zval_internal_ptr_dtor #endif ZEND_API void zval_add_ref(zval *p); -ZEND_API void zval_add_ref_unref(zval *p); END_EXTERN_C() -#define ZVAL_DESTRUCTOR zval_dtor_wrapper #define ZVAL_PTR_DTOR zval_ptr_dtor_wrapper -#define ZVAL_INTERNAL_DTOR zval_internal_dtor_wrapper #define ZVAL_INTERNAL_PTR_DTOR zval_internal_ptr_dtor_wrapper #endif diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index af57737f2583d..65b3f9faaf5b4 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -6412,7 +6412,7 @@ ZEND_VM_COLD_HANDLER(79, ZEND_EXIT, CONST|TMPVAR|UNUSED|CV, ANY) break; } } - zend_print_variable(ptr); + zend_print_zval(ptr, 0); } } while (0); FREE_OP1(); diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 4ca9f76a039c8..c8e198b0b6532 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -3523,7 +3523,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_EXIT_SPEC_CONST_H break; } } - zend_print_variable(ptr); + zend_print_zval(ptr, 0); } } while (0); @@ -12727,7 +12727,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_EXIT_SPEC_TMPVAR_ break; } } - zend_print_variable(ptr); + zend_print_zval(ptr, 0); } } while (0); zval_ptr_dtor_nogc(free_op1); @@ -30417,7 +30417,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_EXIT_SPEC_UNUSED_ break; } } - zend_print_variable(ptr); + zend_print_zval(ptr, 0); } } while (0); @@ -37487,7 +37487,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_EXIT_SPEC_CV_HAND break; } } - zend_print_variable(ptr); + zend_print_zval(ptr, 0); } } while (0);