summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2015-06-12 12:33:23 +0300
committerDmitry Stogov <dmitry@zend.com>2015-06-12 12:33:23 +0300
commit8e10e8f921101e0787c8228d257107a204de3e36 (patch)
tree35bad438a9a49a94a7f0b1e061538e03a49e2b78
parent730d7b8fcad30addc80d685e046b5f05bb3d0190 (diff)
downloadphp-git-8e10e8f921101e0787c8228d257107a204de3e36.tar.gz
Avoid zval duplication in ZVAL_ZVAL() macro (it was necessary only in few places).
Switch from ZVAL_ZVAL() to simpler macros where possible (it makes sense to review remaining places)
-rw-r--r--Zend/zend_API.c2
-rw-r--r--Zend/zend_API.h35
-rw-r--r--Zend/zend_ast.c7
-rw-r--r--Zend/zend_builtin_functions.c10
-rw-r--r--Zend/zend_generators.c8
-rw-r--r--ext/date/php_date.c72
-rw-r--r--ext/intl/timezone/timezone_methods.cpp2
-rw-r--r--ext/phar/phar_object.c4
-rw-r--r--ext/reflection/php_reflection.c4
-rw-r--r--ext/simplexml/simplexml.c14
-rw-r--r--ext/spl/spl_directory.c12
-rw-r--r--ext/spl/spl_iterators.c16
-rw-r--r--ext/spl/spl_observer.c6
-rw-r--r--ext/standard/array.c23
-rw-r--r--ext/standard/streamsfuncs.c4
-rw-r--r--ext/standard/string.c5
-rw-r--r--ext/standard/type.c5
-rw-r--r--ext/tokenizer/tokenizer.c5
18 files changed, 105 insertions, 129 deletions
diff --git a/Zend/zend_API.c b/Zend/zend_API.c
index 3a83f5f7f3..f49957a7ff 100644
--- a/Zend/zend_API.c
+++ b/Zend/zend_API.c
@@ -476,7 +476,7 @@ ZEND_API int ZEND_FASTCALL zend_parse_arg_str_weak(zval *arg, zend_string **dest
zval_dtor(arg);
ZVAL_NULL(arg);
if (!zend_make_printable_zval(z, arg)) {
- ZVAL_ZVAL(arg, z, 1, 1);
+ ZVAL_COPY_VALUE(arg, z);
}
*dest = Z_STR_P(arg);
return 1;
diff --git a/Zend/zend_API.h b/Zend/zend_API.h
index 7de97ff336..b01b041859 100644
--- a/Zend/zend_API.h
+++ b/Zend/zend_API.h
@@ -593,20 +593,17 @@ END_EXTERN_C()
zval *__z = (z); \
zval *__zv = (zv); \
if (EXPECTED(!Z_ISREF_P(__zv))) { \
- ZVAL_COPY_VALUE(__z, __zv); \
- } else { \
- ZVAL_COPY_VALUE(__z, \
- Z_REFVAL_P(__zv)); \
- } \
- if (copy) { \
- zval_opt_copy_ctor(__z); \
- } \
- if (dtor) { \
- if (!copy) { \
- ZVAL_NULL(__zv); \
+ if (copy && !dtor) { \
+ ZVAL_COPY(__z, __zv); \
+ } else { \
+ ZVAL_COPY_VALUE(__z, __zv); \
+ } \
+ } else { \
+ ZVAL_COPY(__z, Z_REFVAL_P(__zv)); \
+ if (dtor || !copy) { \
+ zval_ptr_dtor(__zv); \
} \
- zval_ptr_dtor(__zv); \
- } \
+ } \
} while (0)
#define RETVAL_BOOL(b) ZVAL_BOOL(return_value, b)
@@ -645,18 +642,6 @@ END_EXTERN_C()
#define RETURN_FALSE { RETVAL_FALSE; return; }
#define RETURN_TRUE { RETVAL_TRUE; return; }
-#define RETVAL_ZVAL_FAST(z) do { \
- zval *_z = (z); \
- if (Z_ISREF_P(_z)) { \
- RETVAL_ZVAL(_z, 1, 0); \
- } else { \
- zval_ptr_dtor(return_value); \
- ZVAL_COPY(return_value, _z); \
- } \
-} while (0)
-
-#define RETURN_ZVAL_FAST(z) { RETVAL_ZVAL_FAST(z); return; }
-
#define HASH_OF(p) (Z_TYPE_P(p)==IS_ARRAY ? Z_ARRVAL_P(p) : ((Z_TYPE_P(p)==IS_OBJECT ? Z_OBJ_HT_P(p)->get_properties((p)) : NULL)))
#define ZVAL_IS_NULL(z) (Z_TYPE_P(z) == IS_NULL)
diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c
index aad9b64ffc..fe78bfd31b 100644
--- a/Zend/zend_ast.c
+++ b/Zend/zend_ast.c
@@ -394,7 +394,12 @@ ZEND_API int zend_ast_evaluate(zval *result, zend_ast *ast, zend_class_entry *sc
zval tmp;
zend_fetch_dimension_by_zval(&tmp, &op1, &op2);
- ZVAL_ZVAL(result, &tmp, 1, 1);
+ if (UNEXPECTED(Z_ISREF(tmp))) {
+ ZVAL_DUP(result, Z_REFVAL(tmp));
+ } else {
+ ZVAL_DUP(result, &tmp);
+ }
+ zval_ptr_dtor(&tmp);
zval_dtor(&op1);
zval_dtor(&op2);
}
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index 6b65bdd330..ac6e8f14fa 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -459,7 +459,7 @@ ZEND_FUNCTION(func_get_arg)
} else {
arg = ZEND_CALL_ARG(ex, requested_offset + 1);
}
- RETURN_ZVAL_FAST(arg);
+ RETURN_ZVAL(arg, 1, 0);
}
/* }}} */
@@ -1686,7 +1686,7 @@ ZEND_FUNCTION(set_error_handler)
}
if (Z_TYPE(EG(user_error_handler)) != IS_UNDEF) {
- RETVAL_ZVAL(&EG(user_error_handler), 1, 0);
+ ZVAL_COPY(return_value, &EG(user_error_handler));
zend_stack_push(&EG(user_error_handlers_error_reporting), &EG(user_error_handler_error_reporting));
zend_stack_push(&EG(user_error_handlers), &EG(user_error_handler));
@@ -1697,7 +1697,7 @@ ZEND_FUNCTION(set_error_handler)
return;
}
- ZVAL_DUP(&EG(user_error_handler), error_handler);
+ ZVAL_COPY(&EG(user_error_handler), error_handler);
EG(user_error_handler_error_reporting) = (int)error_type;
}
/* }}} */
@@ -1754,7 +1754,7 @@ ZEND_FUNCTION(set_exception_handler)
}
if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) {
- RETVAL_ZVAL(&EG(user_exception_handler), 1, 0);
+ ZVAL_COPY(return_value, &EG(user_exception_handler));
zend_stack_push(&EG(user_exception_handlers), &EG(user_exception_handler));
}
@@ -1764,7 +1764,7 @@ ZEND_FUNCTION(set_exception_handler)
return;
}
- ZVAL_DUP(&EG(user_exception_handler), exception_handler);
+ ZVAL_COPY(&EG(user_exception_handler), exception_handler);
}
/* }}} */
diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c
index 13304e9fdd..49ad715147 100644
--- a/Zend/zend_generators.c
+++ b/Zend/zend_generators.c
@@ -819,7 +819,7 @@ ZEND_METHOD(Generator, current)
root = zend_generator_get_current(generator);
if (Z_TYPE(root->value) != IS_UNDEF) {
- RETURN_ZVAL_FAST(&root->value);
+ RETURN_ZVAL(&root->value, 1, 0);
}
}
/* }}} */
@@ -840,7 +840,7 @@ ZEND_METHOD(Generator, key)
root = zend_generator_get_current(generator);
if (Z_TYPE(root->key) != IS_UNDEF) {
- RETURN_ZVAL_FAST(&root->key);
+ RETURN_ZVAL(&root->key, 1, 0);
}
}
/* }}} */
@@ -894,7 +894,7 @@ ZEND_METHOD(Generator, send)
root = zend_generator_get_current(generator);
if (Z_TYPE(root->value) != IS_UNDEF) {
- RETURN_ZVAL_FAST(&root->value);
+ RETURN_ZVAL(&root->value, 1, 0);
}
}
/* }}} */
@@ -925,7 +925,7 @@ ZEND_METHOD(Generator, throw)
root = zend_generator_get_current(generator);
if (Z_TYPE(root->value) != IS_UNDEF) {
- RETURN_ZVAL_FAST(&root->value);
+ RETURN_ZVAL(&root->value, 1, 0);
}
} else {
/* If the generator is already closed throw the exception in the
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index d8d6d32862..441e39c4ed 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -2573,18 +2573,16 @@ PHP_FUNCTION(date_create)
zval *timezone_object = NULL;
char *time_str = NULL;
size_t time_str_len = 0;
- zval datetime_object;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|sO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone) == FAILURE) {
RETURN_FALSE;
}
- php_date_instantiate(date_ce_date, &datetime_object);
- if (!php_date_initialize(Z_PHPDATE_P(&datetime_object), time_str, time_str_len, NULL, timezone_object, 0)) {
- zval_dtor(&datetime_object);
+ php_date_instantiate(date_ce_date, return_value);
+ if (!php_date_initialize(Z_PHPDATE_P(return_value), time_str, time_str_len, NULL, timezone_object, 0)) {
+ zval_ptr_dtor(return_value);
RETURN_FALSE;
}
- RETVAL_ZVAL(&datetime_object, 0, 0);
}
/* }}} */
@@ -2596,18 +2594,16 @@ PHP_FUNCTION(date_create_immutable)
zval *timezone_object = NULL;
char *time_str = NULL;
size_t time_str_len = 0;
- zval datetime_object;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|sO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone) == FAILURE) {
RETURN_FALSE;
}
- php_date_instantiate(date_ce_immutable, &datetime_object);
- if (!php_date_initialize(Z_PHPDATE_P(&datetime_object), time_str, time_str_len, NULL, timezone_object, 0)) {
- zval_dtor(&datetime_object);
+ php_date_instantiate(date_ce_immutable, return_value);
+ if (!php_date_initialize(Z_PHPDATE_P(return_value), time_str, time_str_len, NULL, timezone_object, 0)) {
+ zval_ptr_dtor(return_value);
RETURN_FALSE;
}
- RETVAL_ZVAL(&datetime_object, 0, 0);
}
/* }}} */
@@ -2619,18 +2615,16 @@ PHP_FUNCTION(date_create_from_format)
zval *timezone_object = NULL;
char *time_str = NULL, *format_str = NULL;
size_t time_str_len = 0, format_str_len = 0;
- zval datetime_object;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|O!", &format_str, &format_str_len, &time_str, &time_str_len, &timezone_object, date_ce_timezone) == FAILURE) {
RETURN_FALSE;
}
- php_date_instantiate(date_ce_date, &datetime_object);
- if (!php_date_initialize(Z_PHPDATE_P(&datetime_object), time_str, time_str_len, format_str, timezone_object, 0)) {
- zval_dtor(&datetime_object);
+ php_date_instantiate(date_ce_date, return_value);
+ if (!php_date_initialize(Z_PHPDATE_P(return_value), time_str, time_str_len, format_str, timezone_object, 0)) {
+ zval_ptr_dtor(return_value);
RETURN_FALSE;
}
- RETVAL_ZVAL(&datetime_object, 0, 0);
}
/* }}} */
@@ -2642,18 +2636,16 @@ PHP_FUNCTION(date_create_immutable_from_format)
zval *timezone_object = NULL;
char *time_str = NULL, *format_str = NULL;
size_t time_str_len = 0, format_str_len = 0;
- zval datetime_object;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|O!", &format_str, &format_str_len, &time_str, &time_str_len, &timezone_object, date_ce_timezone) == FAILURE) {
RETURN_FALSE;
}
- php_date_instantiate(date_ce_immutable, &datetime_object);
- if (!php_date_initialize(Z_PHPDATE_P(&datetime_object), time_str, time_str_len, format_str, timezone_object, 0)) {
- zval_dtor(&datetime_object);
+ php_date_instantiate(date_ce_immutable, return_value);
+ if (!php_date_initialize(Z_PHPDATE_P(return_value), time_str, time_str_len, format_str, timezone_object, 0)) {
+ zval_ptr_dtor(return_value);
RETURN_FALSE;
}
- RETVAL_ZVAL(&datetime_object, 0, 0);
}
/* }}} */
@@ -3079,11 +3071,11 @@ PHP_FUNCTION(date_modify)
RETURN_FALSE;
}
- if (php_date_modify(object, modify, modify_len)) {
- RETURN_ZVAL(object, 1, 0);
+ if (!php_date_modify(object, modify, modify_len)) {
+ RETURN_FALSE;
}
- RETURN_FALSE;
+ ZVAL_COPY(return_value, object);
}
/* }}} */
@@ -3100,11 +3092,11 @@ PHP_METHOD(DateTimeImmutable, modify)
}
date_clone_immutable(object, &new_object);
- if (php_date_modify(&new_object, modify, modify_len)) {
- RETURN_ZVAL(&new_object, 0, 1);
+ if (!php_date_modify(&new_object, modify, modify_len)) {
+ RETURN_FALSE;
}
- RETURN_FALSE;
+ ZVAL_COPY_VALUE(return_value, &new_object);
}
/* }}} */
@@ -3137,7 +3129,7 @@ PHP_FUNCTION(date_add)
php_date_add(object, interval, return_value);
- RETURN_ZVAL(object, 1, 0);
+ ZVAL_COPY(return_value, object);
}
/* }}} */
@@ -3154,7 +3146,7 @@ PHP_METHOD(DateTimeImmutable, add)
date_clone_immutable(object, &new_object);
php_date_add(&new_object, interval, return_value);
- RETURN_ZVAL(&new_object, 0, 1);
+ ZVAL_COPY_VALUE(return_value, &new_object);
}
/* }}} */
@@ -3192,7 +3184,7 @@ PHP_FUNCTION(date_sub)
php_date_sub(object, interval, return_value);
- RETURN_ZVAL(object, 1, 0);
+ ZVAL_COPY(return_value, object);
}
/* }}} */
@@ -3209,7 +3201,7 @@ PHP_METHOD(DateTimeImmutable, sub)
date_clone_immutable(object, &new_object);
php_date_sub(&new_object, interval, return_value);
- RETURN_ZVAL(&new_object, 0, 1);
+ ZVAL_COPY_VALUE(return_value, &new_object);
}
/* }}} */
@@ -3294,7 +3286,7 @@ PHP_FUNCTION(date_timezone_set)
php_date_timezone_set(object, timezone_object, return_value);
- RETURN_ZVAL(object, 1, 0);
+ ZVAL_COPY(return_value, object);
}
/* }}} */
@@ -3312,7 +3304,7 @@ PHP_METHOD(DateTimeImmutable, setTimezone)
date_clone_immutable(object, &new_object);
php_date_timezone_set(&new_object, timezone_object, return_value);
- RETURN_ZVAL(&new_object, 0, 1);
+ ZVAL_COPY_VALUE(return_value, &new_object);
}
/* }}} */
@@ -3377,7 +3369,7 @@ PHP_FUNCTION(date_time_set)
php_date_time_set(object, h, i, s, return_value);
- RETURN_ZVAL(object, 1, 0);
+ ZVAL_COPY(return_value, object);
}
/* }}} */
@@ -3395,7 +3387,7 @@ PHP_METHOD(DateTimeImmutable, setTime)
date_clone_immutable(object, &new_object);
php_date_time_set(&new_object, h, i, s, return_value);
- RETURN_ZVAL(&new_object, 0, 1);
+ ZVAL_COPY_VALUE(return_value, &new_object);
}
/* }}} */
@@ -3425,7 +3417,7 @@ PHP_FUNCTION(date_date_set)
php_date_date_set(object, y, m, d, return_value);
- RETURN_ZVAL(object, 1, 0);
+ ZVAL_COPY(return_value, object);
}
/* }}} */
@@ -3443,7 +3435,7 @@ PHP_METHOD(DateTimeImmutable, setDate)
date_clone_immutable(object, &new_object);
php_date_date_set(&new_object, y, m, d, return_value);
- RETURN_ZVAL(&new_object, 0, 1);
+ ZVAL_COPY_VALUE(return_value, &new_object);
}
/* }}} */
@@ -3477,7 +3469,7 @@ PHP_FUNCTION(date_isodate_set)
php_date_isodate_set(object, y, w, d, return_value);
- RETURN_ZVAL(object, 1, 0);
+ ZVAL_COPY(return_value, object);
}
/* }}} */
@@ -3495,7 +3487,7 @@ PHP_METHOD(DateTimeImmutable, setISODate)
date_clone_immutable(object, &new_object);
php_date_isodate_set(&new_object, y, w, d, return_value);
- RETURN_ZVAL(&new_object, 0, 1);
+ ZVAL_COPY_VALUE(return_value, &new_object);
}
/* }}} */
@@ -3523,7 +3515,7 @@ PHP_FUNCTION(date_timestamp_set)
php_date_timestamp_set(object, timestamp, return_value);
- RETURN_ZVAL(object, 1, 0);
+ ZVAL_COPY(return_value, object);
}
/* }}} */
@@ -3541,7 +3533,7 @@ PHP_METHOD(DateTimeImmutable, setTimestamp)
date_clone_immutable(object, &new_object);
php_date_timestamp_set(&new_object, timestamp, return_value);
- RETURN_ZVAL(&new_object, 0, 1);
+ ZVAL_COPY_VALUE(return_value, &new_object);
}
/* }}} */
diff --git a/ext/intl/timezone/timezone_methods.cpp b/ext/intl/timezone/timezone_methods.cpp
index 641727d7ed..728f9bde8b 100644
--- a/ext/intl/timezone/timezone_methods.cpp
+++ b/ext/intl/timezone/timezone_methods.cpp
@@ -614,7 +614,7 @@ U_CFUNC PHP_FUNCTION(intltz_to_date_time_zone)
&TIMEZONE_ERROR(to), "intltz_to_date_time_zone", &tmp);
if (ret) {
- RETURN_ZVAL(ret, 1, 1);
+ ZVAL_COPY_VALUE(return_value, ret);
} else {
RETURN_FALSE;
}
diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c
index 8ef5b0f7ed..acb9702872 100644
--- a/ext/phar/phar_object.c
+++ b/ext/phar/phar_object.c
@@ -4005,7 +4005,7 @@ PHP_METHOD(Phar, setMetadata)
ZVAL_UNDEF(&phar_obj->archive->metadata);
}
- ZVAL_ZVAL(&phar_obj->archive->metadata, metadata, 1, 0);
+ ZVAL_COPY(&phar_obj->archive->metadata, metadata);
phar_obj->archive->is_modified = 1;
phar_flush(phar_obj->archive, 0, 0, 0, &error);
@@ -4674,7 +4674,7 @@ PHP_METHOD(PharFileInfo, setMetadata)
ZVAL_UNDEF(&entry_obj->entry->metadata);
}
- ZVAL_ZVAL(&entry_obj->entry->metadata, metadata, 1, 0);
+ ZVAL_COPY(&entry_obj->entry->metadata, metadata);
entry_obj->entry->is_modified = 1;
entry_obj->entry->phar->is_modified = 1;
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index d2ccfe4442..bdb388c570 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -1720,7 +1720,7 @@ ZEND_METHOD(reflection_function, getClosureThis)
if (!Z_ISUNDEF(intern->obj)) {
closure_this = zend_get_closure_this_ptr(&intern->obj);
if (!Z_ISUNDEF_P(closure_this)) {
- RETURN_ZVAL(closure_this, 1, 0);
+ ZVAL_COPY(return_value, closure_this);
}
}
}
@@ -3153,7 +3153,7 @@ ZEND_METHOD(reflection_method, getClosure)
if (Z_OBJCE_P(obj) == zend_ce_closure &&
(mptr->internal_function.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE))
{
- RETURN_ZVAL(obj, 1, 0);
+ ZVAL_COPY(return_value, obj);
} else {
zend_create_closure(return_value, mptr, mptr->common.scope, Z_OBJCE_P(obj), obj);
}
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c
index 2d9e6fd339..9beb946aea 100644
--- a/ext/simplexml/simplexml.c
+++ b/ext/simplexml/simplexml.c
@@ -1930,12 +1930,8 @@ static int sxe_object_cast(zval *readobj, zval *writeobj, int type)
Returns the string content */
SXE_METHOD(__toString)
{
- zval result;
-
- if (sxe_object_cast_ex(getThis(), &result, IS_STRING) == SUCCESS) {
- RETURN_ZVAL(&result, 0, 0);
- } else {
- zval_ptr_dtor(&result);
+ if (sxe_object_cast_ex(getThis(), return_value, IS_STRING) != SUCCESS) {
+ zval_ptr_dtor(return_value);
RETURN_EMPTY_STRING();
}
}
@@ -1979,9 +1975,9 @@ static int sxe_count_elements(zval *object, zend_long *count) /* {{{ */
if (!Z_ISUNDEF(intern->tmp)) {
zval_ptr_dtor(&intern->tmp);
}
- ZVAL_ZVAL(&intern->tmp, &rv, 0, 0);
- convert_to_long(&intern->tmp);
- *count = (zend_long)Z_LVAL(intern->tmp);
+ ZVAL_LONG(&intern->tmp, zval_get_long(&rv));
+ zval_ptr_dtor(&rv);
+ *count = Z_LVAL(intern->tmp);
return SUCCESS;
}
return FAILURE;
diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c
index dbf34f1939..3fed81949a 100644
--- a/ext/spl/spl_directory.c
+++ b/ext/spl/spl_directory.c
@@ -1854,8 +1854,8 @@ static int spl_filesystem_object_cast(zval *readobj, zval *writeobj, int type)
zval *retval_ptr = &retval;
ZVAL_STRINGL(retval_ptr, intern->file_name, intern->file_name_len);
- zval_dtor(readobj);
- ZVAL_ZVAL(writeobj, retval_ptr, 0, 0);
+ zval_ptr_dtor(readobj);
+ ZVAL_COPY_VALUE(writeobj, retval_ptr);
} else {
ZVAL_STRINGL(writeobj, intern->file_name, intern->file_name_len);
}
@@ -1866,8 +1866,8 @@ static int spl_filesystem_object_cast(zval *readobj, zval *writeobj, int type)
zval *retval_ptr = &retval;
ZVAL_STRING(retval_ptr, intern->u.dir.entry.d_name);
- zval_dtor(readobj);
- ZVAL_ZVAL(writeobj, retval_ptr, 0, 0);
+ zval_ptr_dtor(readobj);
+ ZVAL_COPY_VALUE(writeobj, retval_ptr);
} else {
ZVAL_STRING(writeobj, intern->u.dir.entry.d_name);
}
@@ -1878,7 +1878,7 @@ static int spl_filesystem_object_cast(zval *readobj, zval *writeobj, int type)
return SUCCESS;
}
if (readobj == writeobj) {
- zval_dtor(readobj);
+ zval_ptr_dtor(readobj);
}
ZVAL_NULL(writeobj);
return FAILURE;
@@ -2140,7 +2140,7 @@ static int spl_filesystem_file_read_csv(spl_filesystem_object *intern, char deli
php_fgetcsv(intern->u.file.stream, delimiter, enclosure, escape, buf_len, buf, &intern->u.file.current_zval);
if (return_value) {
if (Z_TYPE_P(return_value) != IS_NULL) {
- zval_dtor(return_value);
+ zval_ptr_dtor(return_value);
ZVAL_NULL(return_value);
}
ZVAL_ZVAL(return_value, &intern->u.file.current_zval, 1, 0);
diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c
index 8f77d7088e..aa0854ab78 100644
--- a/ext/spl/spl_iterators.c
+++ b/ext/spl/spl_iterators.c
@@ -494,7 +494,7 @@ static void spl_recursive_it_it_construct(INTERNAL_FUNCTION_PARAMETERS, zend_cla
}
if (user_caching_it_flags) {
- ZVAL_ZVAL(&caching_it_flags, user_caching_it_flags, 1, 0);
+ ZVAL_COPY(&caching_it_flags, user_caching_it_flags);
} else {
ZVAL_LONG(&caching_it_flags, CIT_CATCH_GET_CHILD);
}
@@ -1067,10 +1067,10 @@ static void spl_recursive_tree_iterator_get_entry(spl_recursive_it_object *objec
if (data) {
RETVAL_ZVAL(data, 1, 0);
if (Z_TYPE_P(return_value) == IS_ARRAY) {
- zval_dtor(return_value);
+ zval_ptr_dtor(return_value);
ZVAL_STRINGL(return_value, "Array", sizeof("Array")-1);
} else {
- convert_to_string(return_value);
+ convert_to_string_ex(return_value);
}
}
zend_restore_error_handling(&error_handling);
@@ -1268,9 +1268,7 @@ SPL_METHOD(RecursiveTreeIterator, key)
}
if (object->flags & RTIT_BYPASS_KEY) {
- zval *key_ptr = &key;
- RETVAL_ZVAL(key_ptr, 1, 0);
- zval_dtor(&key);
+ RETVAL_ZVAL(&key, 1, 1);
return;
}
@@ -2089,7 +2087,7 @@ SPL_METHOD(RegexIterator, accept)
}
if (replacement == &tmp_replacement) {
- zval_dtor(replacement);
+ zval_ptr_dtor(replacement);
}
RETVAL_BOOL(count > 0);
}
@@ -3528,7 +3526,7 @@ static int spl_iterator_to_array_apply(zend_object_iterator *iter, void *puser)
return ZEND_HASH_APPLY_STOP;
}
array_set_zval_key(Z_ARRVAL_P(return_value), &key, data);
- zval_dtor(&key);
+ zval_ptr_dtor(&key);
} else {
Z_TRY_ADDREF_P(data);
add_next_index_zval(return_value, data);
@@ -3570,7 +3568,7 @@ PHP_FUNCTION(iterator_to_array)
array_init(return_value);
if (spl_iterator_apply(obj, use_keys ? spl_iterator_to_array_apply : spl_iterator_to_values_apply, (void*)return_value) != SUCCESS) {
- zval_dtor(return_value);
+ zval_ptr_dtor(return_value);
RETURN_NULL();
}
} /* }}} */
diff --git a/ext/spl/spl_observer.c b/ext/spl/spl_observer.c
index ddff20ea4f..e2a55735a3 100644
--- a/ext/spl/spl_observer.c
+++ b/ext/spl/spl_observer.c
@@ -657,7 +657,7 @@ SPL_METHOD(SplObjectStorage, current)
if ((element = zend_hash_get_current_data_ptr_ex(&intern->storage, &intern->pos)) == NULL) {
return;
}
- RETVAL_ZVAL(&element->obj, 1, 0);
+ ZVAL_COPY(return_value, &element->obj);
} /* }}} */
/* {{{ proto mixed SplObjectStorage::getInfo()
@@ -674,7 +674,7 @@ SPL_METHOD(SplObjectStorage, getInfo)
if ((element = zend_hash_get_current_data_ptr_ex(&intern->storage, &intern->pos)) == NULL) {
return;
}
- RETVAL_ZVAL(&element->inf, 1, 0);
+ ZVAL_COPY(return_value, &element->inf);
} /* }}} */
/* {{{ proto mixed SplObjectStorage::setInfo(mixed $inf)
@@ -693,7 +693,7 @@ SPL_METHOD(SplObjectStorage, setInfo)
return;
}
zval_ptr_dtor(&element->inf);
- ZVAL_ZVAL(&element->inf, inf, 1, 0);
+ ZVAL_COPY(&element->inf, inf);
} /* }}} */
/* {{{ proto void SplObjectStorage::next()
diff --git a/ext/standard/array.c b/ext/standard/array.c
index ca72adfaeb..b93efe7919 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -821,7 +821,7 @@ PHP_FUNCTION(end)
entry = Z_INDIRECT_P(entry);
}
- RETURN_ZVAL_FAST(entry);
+ RETURN_ZVAL(entry, 1, 0);
}
}
/* }}} */
@@ -854,7 +854,7 @@ PHP_FUNCTION(prev)
entry = Z_INDIRECT_P(entry);
}
- RETURN_ZVAL_FAST(entry);
+ RETURN_ZVAL(entry, 1, 0);
}
}
/* }}} */
@@ -887,7 +887,7 @@ PHP_FUNCTION(next)
entry = Z_INDIRECT_P(entry);
}
- RETURN_ZVAL_FAST(entry);
+ RETURN_ZVAL(entry, 1, 0);
}
}
/* }}} */
@@ -920,7 +920,7 @@ PHP_FUNCTION(reset)
entry = Z_INDIRECT_P(entry);
}
- RETURN_ZVAL_FAST(entry);
+ RETURN_ZVAL(entry, 1, 0);
}
}
/* }}} */
@@ -950,7 +950,7 @@ PHP_FUNCTION(current)
entry = Z_INDIRECT_P(entry);
}
- RETURN_ZVAL_FAST(entry);
+ RETURN_ZVAL(entry, 1, 0);
}
/* }}} */
@@ -996,7 +996,7 @@ PHP_FUNCTION(min)
RETVAL_NULL();
} else {
if ((result = zend_hash_minmax(Z_ARRVAL(args[0]), php_array_data_compare, 0)) != NULL) {
- RETVAL_ZVAL_FAST(result);
+ RETVAL_ZVAL(result, 1, 0);
} else {
php_error_docref(NULL, E_WARNING, "Array must contain at least one element");
RETVAL_FALSE;
@@ -1016,7 +1016,7 @@ PHP_FUNCTION(min)
}
}
- RETVAL_ZVAL_FAST(min);
+ RETVAL_ZVAL(min, 1, 0);
}
}
/* }}} */
@@ -1043,7 +1043,7 @@ PHP_FUNCTION(max)
RETVAL_NULL();
} else {
if ((result = zend_hash_minmax(Z_ARRVAL(args[0]), php_array_data_compare, 1)) != NULL) {
- RETVAL_ZVAL_FAST(result);
+ RETVAL_ZVAL(result, 1, 0);
} else {
php_error_docref(NULL, E_WARNING, "Array must contain at least one element");
RETVAL_FALSE;
@@ -1063,7 +1063,7 @@ PHP_FUNCTION(max)
}
}
- RETVAL_ZVAL_FAST(max);
+ RETVAL_ZVAL(max, 1, 0);
}
}
/* }}} */
@@ -4701,7 +4701,8 @@ PHP_FUNCTION(array_reduce)
htbl = Z_ARRVAL_P(input);
if (zend_hash_num_elements(htbl) == 0) {
- RETURN_ZVAL(&result, 1, 1);
+ ZVAL_COPY_VALUE(return_value, &result);
+ return;
}
fci.retval = &retval;
@@ -4856,7 +4857,7 @@ PHP_FUNCTION(array_map)
/* Short-circuit: if no callback and only one array, just return it. */
if (!ZEND_FCI_INITIALIZED(fci)) {
- RETVAL_ZVAL(&arrays[0], 1, 0);
+ ZVAL_COPY(return_value, &arrays[0]);
return;
}
diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c
index 965bd67071..9973f0334a 100644
--- a/ext/standard/streamsfuncs.c
+++ b/ext/standard/streamsfuncs.c
@@ -1038,8 +1038,8 @@ PHP_FUNCTION(stream_context_get_params)
add_assoc_zval_ex(return_value, "notification", sizeof("notification")-1, &context->notifier->ptr);
if (Z_REFCOUNTED(context->notifier->ptr)) Z_ADDREF(context->notifier->ptr);
}
- ZVAL_ZVAL(&options, &context->options, 1, 0);
- add_assoc_zval_ex(return_value, "options", sizeof("options")-1, &options);
+ if (Z_REFCOUNTED(context->options)) Z_ADDREF(context->options);
+ add_assoc_zval_ex(return_value, "options", sizeof("options")-1, &context->options);
}
/* }}} */
diff --git a/ext/standard/string.c b/ext/standard/string.c
index 8d95290ca2..bc024a13cd 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -1735,7 +1735,7 @@ PHP_FUNCTION(pathinfo)
}
if (opt == PHP_PATHINFO_ALL) {
- RETURN_ZVAL(&tmp, 0, 1);
+ ZVAL_COPY_VALUE(return_value, &tmp);
} else {
zval *element;
if ((element = zend_hash_get_current_data(Z_ARRVAL(tmp))) != NULL) {
@@ -1743,9 +1743,8 @@ PHP_FUNCTION(pathinfo)
} else {
ZVAL_EMPTY_STRING(return_value);
}
+ zval_ptr_dtor(&tmp);
}
-
- zval_ptr_dtor(&tmp);
}
/* }}} */
diff --git a/ext/standard/type.c b/ext/standard/type.c
index fdf0febe7a..8251a3f155 100644
--- a/ext/standard/type.c
+++ b/ext/standard/type.c
@@ -154,7 +154,7 @@ PHP_FUNCTION(intval)
ZEND_PARSE_PARAMETERS_END();
#endif
- RETVAL_ZVAL(num, 1, 0);
+ ZVAL_DUP(return_value, num);
convert_to_long_base(return_value, (int)base);
}
/* }}} */
@@ -169,8 +169,7 @@ PHP_FUNCTION(floatval)
return;
}
- RETVAL_ZVAL(num, 1, 0);
- convert_to_double(return_value);
+ RETURN_DOUBLE(zval_get_double(num));
}
/* }}} */
diff --git a/ext/tokenizer/tokenizer.c b/ext/tokenizer/tokenizer.c
index 2a4fa90ca2..63405ea6cd 100644
--- a/ext/tokenizer/tokenizer.c
+++ b/ext/tokenizer/tokenizer.c
@@ -257,9 +257,10 @@ static zend_bool tokenize_parse(zval *return_value, zend_string *source)
array_init(&token_stream);
if((success = (zendparse() == SUCCESS))) {
- ZVAL_ZVAL(return_value, &token_stream, 1, 0);
+ ZVAL_COPY_VALUE(return_value, &token_stream);
+ } else {
+ zval_ptr_dtor(&token_stream);
}
- zval_dtor(&token_stream);
zend_ast_destroy(CG(ast));
zend_arena_destroy(CG(ast_arena));