From 3f19f5112a7be3e4aa7ab1704d25de54645be373 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 14 May 2019 14:57:10 +0200 Subject: [PATCH] Add RETURN_EMPTY_ARRAY() / RETVAL_EMPTY_ARRAY() The usual wrappers around ZVAL_EMPTY_ARRAY()... --- Zend/zend_API.h | 2 ++ Zend/zend_builtin_functions.c | 2 +- ext/libxml/libxml.c | 2 +- ext/mysqli/mysqli_nonapi.c | 8 ++++---- ext/reflection/php_reflection.c | 21 ++++++++------------- ext/simplexml/simplexml.c | 2 +- ext/spl/spl_fixedarray.c | 2 +- ext/sqlite3/sqlite3.c | 2 +- ext/standard/array.c | 23 ++++++++--------------- 9 files changed, 27 insertions(+), 37 deletions(-) diff --git a/Zend/zend_API.h b/Zend/zend_API.h index 648dbe7c77..577feb025d 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -614,6 +614,7 @@ END_EXTERN_C() #define RETVAL_EMPTY_STRING() ZVAL_EMPTY_STRING(return_value) #define RETVAL_RES(r) ZVAL_RES(return_value, r) #define RETVAL_ARR(r) ZVAL_ARR(return_value, r) +#define RETVAL_EMPTY_ARRAY(r) ZVAL_EMPTY_ARRAY(return_value) #define RETVAL_OBJ(r) ZVAL_OBJ(return_value, r) #define RETVAL_ZVAL(zv, copy, dtor) ZVAL_ZVAL(return_value, zv, copy, dtor) #define RETVAL_FALSE ZVAL_FALSE(return_value) @@ -632,6 +633,7 @@ END_EXTERN_C() #define RETURN_EMPTY_STRING() { RETVAL_EMPTY_STRING(); return; } #define RETURN_RES(r) { RETVAL_RES(r); return; } #define RETURN_ARR(r) { RETVAL_ARR(r); return; } +#define RETURN_EMPTY_ARRAY(r) { RETVAL_EMPTY_ARRAY(r); return; } #define RETURN_OBJ(r) { RETVAL_OBJ(r); return; } #define RETURN_ZVAL(zv, copy, dtor) { RETVAL_ZVAL(zv, copy, dtor); return; } #define RETURN_FALSE { RETVAL_FALSE; return; } diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index cfc78db4ea..b8b8257569 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -566,7 +566,7 @@ ZEND_FUNCTION(func_get_args) } ZEND_HASH_FILL_END(); Z_ARRVAL_P(return_value)->nNumOfElements = arg_count; } else { - ZVAL_EMPTY_ARRAY(return_value); + RETURN_EMPTY_ARRAY(); } } /* }}} */ diff --git a/ext/libxml/libxml.c b/ext/libxml/libxml.c index b8603fdf38..7471065494 100644 --- a/ext/libxml/libxml.c +++ b/ext/libxml/libxml.c @@ -1060,7 +1060,7 @@ static PHP_FUNCTION(libxml_get_errors) error = zend_llist_get_next(LIBXML(error_list)); } } else { - ZVAL_EMPTY_ARRAY(return_value); + RETURN_EMPTY_ARRAY(); } } /* }}} */ diff --git a/ext/mysqli/mysqli_nonapi.c b/ext/mysqli/mysqli_nonapi.c index 78302a7e6f..3ffa8d05dd 100644 --- a/ext/mysqli/mysqli_nonapi.c +++ b/ext/mysqli/mysqli_nonapi.c @@ -422,7 +422,7 @@ PHP_FUNCTION(mysqli_error_list) add_next_index_zval(return_value, &single_error); } } else { - ZVAL_EMPTY_ARRAY(return_value); + RETURN_EMPTY_ARRAY(); } #else if (mysql_errno(mysql->mysql)) { @@ -434,7 +434,7 @@ PHP_FUNCTION(mysqli_error_list) add_assoc_string_ex(&single_error, "error", sizeof("error") - 1, mysql_error(mysql->mysql)); add_next_index_zval(return_value, &single_error); } else { - ZVAL_EMPTY_ARRAY(return_value); + RETURN_EMPTY_ARRAY(); } #endif } @@ -468,7 +468,7 @@ PHP_FUNCTION(mysqli_stmt_error_list) add_next_index_zval(return_value, &single_error); } } else { - ZVAL_EMPTY_ARRAY(return_value); + RETURN_EMPTY_ARRAY(); } #else if (mysql_stmt_errno(stmt->stmt)) { @@ -480,7 +480,7 @@ PHP_FUNCTION(mysqli_stmt_error_list) add_assoc_string_ex(&single_error, "error", sizeof("error") - 1, mysql_stmt_error(stmt->stmt)); add_next_index_zval(return_value, &single_error); } else { - ZVAL_EMPTY_ARRAY(return_value); + RETURN_EMPTY_ARRAY(); } #endif } diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index f1037ef694..86f66a4e2e 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1789,7 +1789,7 @@ ZEND_METHOD(reflection_function, getStaticVariables) } ZEND_HASH_FOREACH_END(); zend_hash_copy(Z_ARRVAL_P(return_value), ht, zval_add_ref); } else { - ZVAL_EMPTY_ARRAY(return_value); + RETURN_EMPTY_ARRAY(); } } /* }}} */ @@ -1977,8 +1977,7 @@ ZEND_METHOD(reflection_function, getParameters) } if (!num_args) { - ZVAL_EMPTY_ARRAY(return_value); - return; + RETURN_EMPTY_ARRAY(); } array_init(return_value); @@ -4796,7 +4795,7 @@ ZEND_METHOD(reflection_class, getInterfaces) zend_hash_update(Z_ARRVAL_P(return_value), ce->interfaces[i]->name, &interface); } } else { - ZVAL_EMPTY_ARRAY(return_value); + RETURN_EMPTY_ARRAY(); } } /* }}} */ @@ -4816,8 +4815,7 @@ ZEND_METHOD(reflection_class, getInterfaceNames) if (!ce->num_interfaces) { /* Return an empty array if this class implements no interfaces */ - ZVAL_EMPTY_ARRAY(return_value); - return; + RETURN_EMPTY_ARRAY(); } ZEND_ASSERT(ce->ce_flags & ZEND_ACC_LINKED); @@ -4843,8 +4841,7 @@ ZEND_METHOD(reflection_class, getTraits) GET_REFLECTION_OBJECT_PTR(ce); if (!ce->num_traits) { - ZVAL_EMPTY_ARRAY(return_value); - return; + RETURN_EMPTY_ARRAY(); } array_init(return_value); @@ -4876,8 +4873,7 @@ ZEND_METHOD(reflection_class, getTraitNames) GET_REFLECTION_OBJECT_PTR(ce); if (!ce->num_traits) { - ZVAL_EMPTY_ARRAY(return_value); - return; + RETURN_EMPTY_ARRAY(); } array_init(return_value); @@ -4918,7 +4914,7 @@ ZEND_METHOD(reflection_class, getTraitAliases) i++; } } else { - ZVAL_EMPTY_ARRAY(return_value); + RETURN_EMPTY_ARRAY(); } } /* }}} */ @@ -5892,8 +5888,7 @@ ZEND_METHOD(reflection_extension, getDependencies) if (!dep) { - ZVAL_EMPTY_ARRAY(return_value); - return; + RETURN_EMPTY_ARRAY(); } array_init(return_value); diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index e8ba1f505a..7f94091c25 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1360,7 +1360,7 @@ SXE_METHOD(xpath) } } } else { - ZVAL_EMPTY_ARRAY(return_value); + RETVAL_EMPTY_ARRAY(); } xmlXPathFreeObject(retval); diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c index ce93f2aef5..071826dad0 100644 --- a/ext/spl/spl_fixedarray.c +++ b/ext/spl/spl_fixedarray.c @@ -642,7 +642,7 @@ SPL_METHOD(SplFixedArray, toArray) } } } else { - ZVAL_EMPTY_ARRAY(return_value); + RETURN_EMPTY_ARRAY(); } } /* }}} */ diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index 4f7d496972..4d97279c22 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -679,7 +679,7 @@ PHP_METHOD(sqlite3, querySingle) if (!entire_row) { RETVAL_NULL(); } else { - ZVAL_EMPTY_ARRAY(return_value); + RETVAL_EMPTY_ARRAY(); } break; } diff --git a/ext/standard/array.c b/ext/standard/array.c index 7d41b99645..34f1284384 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -2665,8 +2665,7 @@ PHP_FUNCTION(array_fill) } } } else if (EXPECTED(num == 0)) { - ZVAL_EMPTY_ARRAY(return_value); - return; + RETURN_EMPTY_ARRAY(); } else { php_error_docref(NULL, E_WARNING, "Number of elements can't be negative"); RETURN_FALSE; @@ -3503,8 +3502,7 @@ PHP_FUNCTION(array_slice) /* Clamp the offset.. */ if (offset > num_in) { - ZVAL_EMPTY_ARRAY(return_value); - return; + RETURN_EMPTY_ARRAY(); } else if (offset < 0 && (offset = (num_in + offset)) < 0) { offset = 0; } @@ -3517,8 +3515,7 @@ PHP_FUNCTION(array_slice) } if (length <= 0) { - ZVAL_EMPTY_ARRAY(return_value); - return; + RETURN_EMPTY_ARRAY(); } /* Initialize returned array */ @@ -4050,8 +4047,7 @@ PHP_FUNCTION(array_values) /* Return empty input as is */ arrlen = zend_hash_num_elements(arrval); if (!arrlen) { - ZVAL_EMPTY_ARRAY(return_value); - return; + RETURN_EMPTY_ARRAY(); } /* Return vector-like packed arrays as-is */ @@ -5456,8 +5452,7 @@ PHP_FUNCTION(array_diff) RETURN_NULL(); } } - ZVAL_EMPTY_ARRAY(return_value); - return; + RETURN_EMPTY_ARRAY(); } else if (num == 1) { int found = 0; zend_string *search_str, *tmp_search_str; @@ -5474,8 +5469,7 @@ PHP_FUNCTION(array_diff) RETURN_NULL(); } } - ZVAL_EMPTY_ARRAY(return_value); - return; + RETURN_EMPTY_ARRAY(); } search_str = zval_get_tmp_string(value, &tmp_search_str); @@ -5501,7 +5495,7 @@ PHP_FUNCTION(array_diff) zend_tmp_string_release(tmp_search_str); if (found) { - ZVAL_EMPTY_ARRAY(return_value); + RETVAL_EMPTY_ARRAY(); } else { ZVAL_COPY(return_value, &args[0]); } @@ -6435,8 +6429,7 @@ PHP_FUNCTION(array_combine) } if (!num_keys) { - ZVAL_EMPTY_ARRAY(return_value); - return; + RETURN_EMPTY_ARRAY(); } array_init_size(return_value, num_keys); -- 2.40.0