Skip to content

Commit 6811222

Browse files
committed
Eliminate uses of ZVAL_ZVAL and friends
Instead add RETURN_COPY(_VALUE) macros will the expected behavior. RETURN_ZVAL doesn't make any sense since PHP 7, but has stuck around, probably because the alternative was to write directly to the return_value variable.
1 parent 5947437 commit 6811222

File tree

10 files changed

+20
-29
lines changed

10 files changed

+20
-29
lines changed

Zend/zend_API.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,8 @@ END_EXTERN_C()
652652
#define RETVAL_ARR(r) ZVAL_ARR(return_value, r)
653653
#define RETVAL_EMPTY_ARRAY() ZVAL_EMPTY_ARRAY(return_value)
654654
#define RETVAL_OBJ(r) ZVAL_OBJ(return_value, r)
655+
#define RETVAL_COPY(zv) ZVAL_COPY(return_value, zv)
656+
#define RETVAL_COPY_VALUE(zv) ZVAL_COPY_VALUE(return_value, zv)
655657
#define RETVAL_ZVAL(zv, copy, dtor) ZVAL_ZVAL(return_value, zv, copy, dtor)
656658
#define RETVAL_FALSE ZVAL_FALSE(return_value)
657659
#define RETVAL_TRUE ZVAL_TRUE(return_value)
@@ -671,6 +673,8 @@ END_EXTERN_C()
671673
#define RETURN_ARR(r) do { RETVAL_ARR(r); return; } while (0)
672674
#define RETURN_EMPTY_ARRAY() do { RETVAL_EMPTY_ARRAY(); return; } while (0)
673675
#define RETURN_OBJ(r) do { RETVAL_OBJ(r); return; } while (0)
676+
#define RETURN_COPY(zv) do { RETVAL_COPY(zv); return; } while (0)
677+
#define RETURN_COPY_VALUE(zv) do { RETVAL_COPY_VALUE(zv); return; } while (0)
674678
#define RETURN_ZVAL(zv, copy, dtor) do { RETVAL_ZVAL(zv, copy, dtor); return; } while (0)
675679
#define RETURN_FALSE do { RETVAL_FALSE; return; } while (0)
676680
#define RETURN_TRUE do { RETVAL_TRUE; return; } while (0)

Zend/zend_closures.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ ZEND_METHOD(Closure, fromCallable)
338338

339339
if (Z_TYPE_P(callable) == IS_OBJECT && instanceof_function(Z_OBJCE_P(callable), zend_ce_closure)) {
340340
/* It's already a closure */
341-
RETURN_ZVAL(callable, 1, 0);
341+
RETURN_COPY(callable);
342342
}
343343

344344
/* create closure as if it were called from parent scope */

Zend/zend_interfaces.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ ZEND_API void zend_user_it_get_current_key(zend_object_iterator *_iter, zval *ke
193193
zend_call_method_with_0_params(Z_OBJ_P(object), iter->ce, &iter->ce->iterator_funcs_ptr->zf_key, "key", &retval);
194194

195195
if (Z_TYPE(retval) != IS_UNDEF) {
196-
ZVAL_ZVAL(key, &retval, 1, 1);
196+
ZVAL_COPY_VALUE(key, &retval);
197197
} else {
198198
if (!EG(exception)) {
199199
zend_error(E_WARNING, "Nothing returned from %s::key()", ZSTR_VAL(iter->ce->name));

ext/oci8/oci8_interface.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,11 +2382,9 @@ PHP_FUNCTION(oci_collection_element_get)
23822382

23832383
PHP_OCI_ZVAL_TO_COLLECTION(tmp, collection);
23842384

2385-
if (php_oci_collection_element_get(collection, element_index, &value)) {
2385+
if (php_oci_collection_element_get(collection, element_index, return_value)) {
23862386
RETURN_FALSE;
23872387
}
2388-
2389-
RETURN_ZVAL(&value, 1, 1);
23902388
}
23912389
/* }}} */
23922390

ext/pcntl/pcntl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ PHP_FUNCTION(pcntl_signal_get_handler)
10281028
}
10291029

10301030
if ((prev_handle = zend_hash_index_find(&PCNTL_G(php_signal_table), signo)) != NULL) {
1031-
RETURN_ZVAL(prev_handle, 1, 0);
1031+
RETURN_COPY(prev_handle);
10321032
} else {
10331033
RETURN_LONG((zend_long)SIG_DFL);
10341034
}

ext/pgsql/pgsql.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,14 +2337,14 @@ PHP_FUNCTION(pg_last_notice)
23372337
if ((notice = zend_hash_get_current_data(Z_ARRVAL_P(notices))) == NULL) {
23382338
RETURN_EMPTY_STRING();
23392339
}
2340-
RETURN_ZVAL(notice, 1, 0);
2340+
RETURN_COPY(notice);
23412341
} else {
23422342
RETURN_EMPTY_STRING();
23432343
}
23442344
break;
23452345
case PGSQL_NOTICE_ALL:
23462346
if (notices) {
2347-
RETURN_ZVAL(notices, 1, 0);
2347+
RETURN_COPY(notices);
23482348
} else {
23492349
array_init(return_value);
23502350
return;

ext/sockets/sockets.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,7 +2278,7 @@ PHP_FUNCTION(socket_export_stream)
22782278
/* Either we already exported a stream or the socket came from an import,
22792279
* just return the existing stream */
22802280
if (!Z_ISUNDEF(socket->zstream)) {
2281-
RETURN_ZVAL(&socket->zstream, 1, 0);
2281+
RETURN_COPY(&socket->zstream);
22822282
}
22832283

22842284
/* Determine if socket is using a protocol with one of the default registered
@@ -2350,7 +2350,7 @@ PHP_FUNCTION(socket_export_stream)
23502350

23512351
php_stream_to_zval(stream, &socket->zstream);
23522352

2353-
RETURN_ZVAL(&socket->zstream, 1, 0);
2353+
RETURN_COPY(&socket->zstream);
23542354
}
23552355
/* }}} */
23562356

ext/spl/spl_directory.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,7 +2053,7 @@ static int spl_filesystem_file_call(spl_filesystem_object *intern, zend_function
20532053
{
20542054
zend_fcall_info fci;
20552055
zend_fcall_info_cache fcic;
2056-
zval *zresource_ptr = &intern->u.file.zresource, retval;
2056+
zval *zresource_ptr = &intern->u.file.zresource;
20572057
int result;
20582058
int num_args = pass_num_args + (arg2 ? 2 : 1);
20592059

@@ -2070,11 +2070,9 @@ static int spl_filesystem_file_call(spl_filesystem_object *intern, zend_function
20702070
WRONG_PARAM_COUNT_WITH_RETVAL(FAILURE);
20712071
}
20722072

2073-
ZVAL_UNDEF(&retval);
2074-
20752073
fci.size = sizeof(fci);
20762074
fci.object = NULL;
2077-
fci.retval = &retval;
2075+
fci.retval = return_value;
20782076
fci.param_count = num_args;
20792077
fci.params = params;
20802078
fci.no_separation = 1;
@@ -2086,10 +2084,8 @@ static int spl_filesystem_file_call(spl_filesystem_object *intern, zend_function
20862084

20872085
result = zend_call_function(&fci, &fcic);
20882086

2089-
if (result == FAILURE || Z_ISUNDEF(retval)) {
2087+
if (result == FAILURE || Z_ISUNDEF_P(return_value)) {
20902088
RETVAL_FALSE;
2091-
} else {
2092-
ZVAL_ZVAL(return_value, &retval, 0, 0);
20932089
}
20942090

20952091
efree(params);

ext/spl/spl_iterators.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,8 +1271,7 @@ SPL_METHOD(RecursiveTreeIterator, key)
12711271
}
12721272

12731273
if (object->flags & RTIT_BYPASS_KEY) {
1274-
RETVAL_ZVAL(&key, 1, 1);
1275-
return;
1274+
RETURN_COPY_VALUE(&key);
12761275
}
12771276

12781277
if (Z_TYPE(key) != IS_STRING) {
@@ -1842,20 +1841,14 @@ SPL_METHOD(RecursiveFilterIterator, __construct)
18421841
SPL_METHOD(RecursiveFilterIterator, hasChildren)
18431842
{
18441843
spl_dual_it_object *intern;
1845-
zval retval;
18461844

18471845
if (zend_parse_parameters_none() == FAILURE) {
18481846
RETURN_THROWS();
18491847
}
18501848

18511849
SPL_FETCH_AND_CHECK_DUAL_IT(intern, ZEND_THIS);
18521850

1853-
zend_call_method_with_0_params(Z_OBJ(intern->inner.zobject), intern->inner.ce, NULL, "haschildren", &retval);
1854-
if (Z_TYPE(retval) != IS_UNDEF) {
1855-
RETURN_ZVAL(&retval, 0, 1);
1856-
} else {
1857-
RETURN_FALSE;
1858-
}
1851+
zend_call_method_with_0_params(Z_OBJ(intern->inner.zobject), intern->inner.ce, NULL, "haschildren", return_value);
18591852
} /* }}} */
18601853

18611854
/* {{{ proto RecursiveFilterIterator RecursiveFilterIterator::getChildren()

ext/standard/array.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3970,7 +3970,7 @@ PHP_FUNCTION(array_keys)
39703970

39713971
/* Base case: empty input */
39723972
if (!elem_count) {
3973-
RETURN_ZVAL(input, 1, 0);
3973+
RETURN_COPY(input);
39743974
}
39753975

39763976
/* Initialize return array */
@@ -4086,7 +4086,7 @@ PHP_FUNCTION(array_values)
40864086
/* Return vector-like packed arrays as-is */
40874087
if (HT_IS_PACKED(arrval) && HT_IS_WITHOUT_HOLES(arrval) &&
40884088
arrval->nNextFreeElement == arrlen) {
4089-
RETURN_ZVAL(input, 1, 0);
4089+
RETURN_COPY(input);
40904090
}
40914091

40924092
/* Initialize return array */
@@ -6064,7 +6064,7 @@ PHP_FUNCTION(array_reduce)
60646064
} ZEND_HASH_FOREACH_END();
60656065

60666066
zend_release_fcall_info_cache(&fci_cache);
6067-
RETVAL_ZVAL(&result, 1, 1);
6067+
RETURN_COPY_VALUE(&result);
60686068
}
60696069
/* }}} */
60706070

0 commit comments

Comments
 (0)