diff --git a/ext/phar/phar_internal.h b/ext/phar/phar_internal.h index 0e19645300fee..dc2b2be1202b1 100644 --- a/ext/phar/phar_internal.h +++ b/ext/phar/phar_internal.h @@ -52,7 +52,6 @@ #include "Zend/zend_virtual_cwd.h" #include "ext/spl/spl_array.h" #include "ext/spl/spl_directory.h" -#include "ext/spl/spl_engine.h" #include "ext/spl/spl_exceptions.h" #include "ext/spl/spl_iterators.h" #include "php_phar.h" diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 1da17b247b246..9d16512ec5d13 100644 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -3540,9 +3540,7 @@ PHP_METHOD(Phar, offsetGet) { char *fname, *error; size_t fname_len; - zval zfname; phar_entry_info *entry; - zend_string *sfname; if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &fname, &fname_len) == FAILURE) { RETURN_THROWS(); @@ -3574,10 +3572,16 @@ PHP_METHOD(Phar, offsetGet) efree(entry); } - sfname = strpprintf(0, "phar://%s/%s", phar_obj->archive->fname, fname); + zend_string *sfname = strpprintf(0, "phar://%s/%s", phar_obj->archive->fname, fname); + zval zfname; ZVAL_NEW_STR(&zfname, sfname); - spl_instantiate_arg_ex1(phar_obj->spl.info_class, return_value, &zfname); + + /* Instantiate object and call constructor */ + zend_result is_initialized = object_init_with_constructor(return_value, phar_obj->spl.info_class, 1, &zfname, NULL); zval_ptr_dtor(&zfname); + if (is_initialized == FAILURE) { + RETURN_THROWS(); + } } } /* }}} */ diff --git a/ext/spl/config.m4 b/ext/spl/config.m4 index 589e8681d70ec..a1b3ca13b4702 100644 --- a/ext/spl/config.m4 +++ b/ext/spl/config.m4 @@ -1,5 +1,5 @@ PHP_NEW_EXTENSION(spl, php_spl.c spl_functions.c spl_iterators.c spl_array.c spl_directory.c spl_exceptions.c spl_observer.c spl_dllist.c spl_heap.c spl_fixedarray.c, no,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1) -PHP_INSTALL_HEADERS([ext/spl], [php_spl.h spl_array.h spl_directory.h spl_engine.h spl_exceptions.h spl_functions.h spl_iterators.h spl_observer.h spl_dllist.h spl_heap.h spl_fixedarray.h]) +PHP_INSTALL_HEADERS([ext/spl], [php_spl.h spl_array.h spl_directory.h spl_exceptions.h spl_functions.h spl_iterators.h spl_observer.h spl_dllist.h spl_heap.h spl_fixedarray.h]) PHP_ADD_EXTENSION_DEP(spl, pcre, true) PHP_ADD_EXTENSION_DEP(spl, standard, true) PHP_ADD_EXTENSION_DEP(spl, json) diff --git a/ext/spl/config.w32 b/ext/spl/config.w32 index 92659aa86d2ab..06e87c6633576 100644 --- a/ext/spl/config.w32 +++ b/ext/spl/config.w32 @@ -2,4 +2,4 @@ EXTENSION("spl", "php_spl.c spl_functions.c spl_iterators.c spl_array.c spl_directory.c spl_exceptions.c spl_observer.c spl_dllist.c spl_heap.c spl_fixedarray.c", false /*never shared */, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1"); PHP_SPL="yes"; -PHP_INSTALL_HEADERS("ext/spl", "php_spl.h spl_array.h spl_directory.h spl_engine.h spl_exceptions.h spl_functions.h spl_iterators.h spl_observer.h spl_dllist.h spl_heap.h spl_fixedarray.h"); +PHP_INSTALL_HEADERS("ext/spl", "php_spl.h spl_array.h spl_directory.h spl_exceptions.h spl_functions.h spl_iterators.h spl_observer.h spl_dllist.h spl_heap.h spl_fixedarray.h"); diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index edad4cddca2fb..391d14c354a2a 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -24,7 +24,6 @@ #include "php_spl.h" #include "php_spl_arginfo.h" #include "spl_functions.h" -#include "spl_engine.h" #include "spl_array.h" #include "spl_directory.h" #include "spl_iterators.h" diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index bbe00cd212fea..72cc1f80133f8 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -29,7 +29,6 @@ #include "php_spl.h" #include "spl_functions.h" -#include "spl_engine.h" #include "spl_iterators.h" #include "spl_directory.h" #include "spl_directory_arginfo.h" @@ -1516,7 +1515,6 @@ PHP_METHOD(RecursiveDirectoryIterator, hasChildren) /* {{{ Returns an iterator for the current entry if it is a directory */ PHP_METHOD(RecursiveDirectoryIterator, getChildren) { - zval zpath, zflags; spl_filesystem_object *intern = spl_filesystem_from_obj(Z_OBJ_P(ZEND_THIS)); spl_filesystem_object *subdir; char slash = SPL_HAS_FLAG(intern->flags, SPL_FILE_DIR_UNIXPATHS) ? '/' : DEFAULT_SLASH; @@ -1529,10 +1527,15 @@ PHP_METHOD(RecursiveDirectoryIterator, getChildren) RETURN_THROWS(); } - ZVAL_LONG(&zflags, intern->flags); - ZVAL_STR_COPY(&zpath, intern->file_name); - spl_instantiate_arg_ex2(Z_OBJCE_P(ZEND_THIS), return_value, &zpath, &zflags); - zval_ptr_dtor(&zpath); + zval params[2]; + ZVAL_STR_COPY(¶ms[0], intern->file_name); + ZVAL_LONG(¶ms[1], intern->flags); + + zend_result is_initialized = object_init_with_constructor(return_value, Z_OBJCE_P(ZEND_THIS), 2, params, NULL); + zval_ptr_dtor_str(¶ms[0]); + if (is_initialized == FAILURE) { + RETURN_THROWS(); + } subdir = spl_filesystem_from_obj(Z_OBJ_P(return_value)); if (subdir) { diff --git a/ext/spl/spl_dllist.c b/ext/spl/spl_dllist.c index 072dd7ffc50ea..86da78b2a31eb 100644 --- a/ext/spl/spl_dllist.c +++ b/ext/spl/spl_dllist.c @@ -19,6 +19,7 @@ #endif #include "php.h" +#include "zend_interfaces.h" #include "zend_exceptions.h" #include "zend_hash.h" @@ -26,7 +27,6 @@ #include "ext/standard/php_var.h" #include "zend_smart_str.h" #include "spl_functions.h" -#include "spl_engine.h" #include "spl_iterators.h" #include "spl_dllist.h" #include "spl_dllist_arginfo.h" diff --git a/ext/spl/spl_engine.h b/ext/spl/spl_engine.h deleted file mode 100644 index 48676e8afa66a..0000000000000 --- a/ext/spl/spl_engine.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Copyright (c) The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | https://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Marcus Boerger | - +----------------------------------------------------------------------+ - */ - -#ifndef SPL_ENGINE_H -#define SPL_ENGINE_H - -#include "php.h" -#include "php_spl.h" -#include "zend_interfaces.h" - -static inline void spl_instantiate_arg_ex1(zend_class_entry *pce, zval *retval, zval *arg1) -{ - object_init_ex(retval, pce); - zend_call_known_instance_method_with_1_params(pce->constructor, Z_OBJ_P(retval), NULL, arg1); -} - -static inline void spl_instantiate_arg_ex2( - zend_class_entry *pce, zval *retval, zval *arg1, zval *arg2) -{ - object_init_ex(retval, pce); - zend_call_known_instance_method_with_2_params( - pce->constructor, Z_OBJ_P(retval), NULL, arg1, arg2); -} - -static inline void spl_instantiate_arg_n( - zend_class_entry *pce, zval *retval, uint32_t argc, zval *argv) -{ - object_init_ex(retval, pce); - zend_call_known_instance_method(pce->constructor, Z_OBJ_P(retval), NULL, argc, argv); -} - -#endif /* SPL_ENGINE_H */ diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c index 632957975cdce..e41e879d7dafe 100644 --- a/ext/spl/spl_fixedarray.c +++ b/ext/spl/spl_fixedarray.c @@ -20,12 +20,12 @@ #endif #include "php.h" +#include "zend_interfaces.h" #include "zend_exceptions.h" #include "php_spl.h" #include "spl_fixedarray_arginfo.h" #include "spl_functions.h" -#include "spl_engine.h" #include "spl_fixedarray.h" #include "spl_exceptions.h" #include "spl_iterators.h" diff --git a/ext/spl/spl_heap.c b/ext/spl/spl_heap.c index 2c7f4eda77390..7602d6843a2d3 100644 --- a/ext/spl/spl_heap.c +++ b/ext/spl/spl_heap.c @@ -19,11 +19,11 @@ #endif #include "php.h" +#include "zend_interfaces.h" #include "zend_exceptions.h" #include "php_spl.h" #include "spl_functions.h" -#include "spl_engine.h" #include "spl_iterators.h" #include "spl_heap.h" #include "spl_heap_arginfo.h" diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index dde6695b3fae3..ca32bda7d2d24 100644 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -25,7 +25,6 @@ #include "php_spl.h" #include "spl_functions.h" -#include "spl_engine.h" #include "spl_iterators.h" #include "spl_iterators_arginfo.h" #include "spl_directory.h" @@ -539,7 +538,6 @@ static void spl_recursive_it_it_construct(INTERNAL_FUNCTION_PARAMETERS, zend_cla switch (rit_type) { case RIT_RecursiveTreeIterator: { - zval caching_it_flags; zend_long user_caching_it_flags = CIT_CATCH_GET_CHILD; mode = RIT_SELF_FIRST; flags = RTIT_BYPASS_KEY; @@ -558,10 +556,15 @@ static void spl_recursive_it_it_construct(INTERNAL_FUNCTION_PARAMETERS, zend_cla Z_ADDREF_P(iterator); } - ZVAL_LONG(&caching_it_flags, user_caching_it_flags); - spl_instantiate_arg_ex2(spl_ce_RecursiveCachingIterator, &caching_it, iterator, &caching_it_flags); - zval_ptr_dtor(&caching_it_flags); - zval_ptr_dtor(iterator); + zval params[2]; + ZVAL_COPY_VALUE(¶ms[0], iterator); + ZVAL_LONG(¶ms[1], user_caching_it_flags); + zend_result is_initialized = object_init_with_constructor(&caching_it, spl_ce_RecursiveCachingIterator, 2, params, NULL); + zval_ptr_dtor(¶ms[0]); + if (is_initialized == FAILURE) { + RETURN_THROWS(); + } + iterator = &caching_it; break; } @@ -1674,37 +1677,48 @@ PHP_METHOD(RecursiveFilterIterator, hasChildren) PHP_METHOD(RecursiveFilterIterator, getChildren) { spl_dual_it_object *intern; - zval retval; ZEND_PARSE_PARAMETERS_NONE(); SPL_FETCH_AND_CHECK_DUAL_IT(intern, ZEND_THIS); - zend_call_method_with_0_params(Z_OBJ(intern->inner.zobject), intern->inner.ce, NULL, "getchildren", &retval); - if (!EG(exception) && Z_TYPE(retval) != IS_UNDEF) { - spl_instantiate_arg_ex1(Z_OBJCE_P(ZEND_THIS), return_value, &retval); + zval childrens; + zend_call_method_with_0_params(Z_OBJ(intern->inner.zobject), intern->inner.ce, NULL, "getchildren", &childrens); + if (Z_TYPE(childrens) == IS_UNDEF) { + RETURN_THROWS(); + } + + zend_result is_initialized = object_init_with_constructor(return_value, Z_OBJCE_P(ZEND_THIS), 1, &childrens, NULL); + zval_ptr_dtor(&childrens); + if (is_initialized == FAILURE) { + RETURN_THROWS(); } - zval_ptr_dtor(&retval); } /* }}} */ /* {{{ Return the inner iterator's children contained in a RecursiveCallbackFilterIterator */ PHP_METHOD(RecursiveCallbackFilterIterator, getChildren) { - spl_dual_it_object *intern; - zval retval; + spl_dual_it_object *intern; ZEND_PARSE_PARAMETERS_NONE(); SPL_FETCH_AND_CHECK_DUAL_IT(intern, ZEND_THIS); - zend_call_method_with_0_params(Z_OBJ(intern->inner.zobject), intern->inner.ce, NULL, "getchildren", &retval); - if (!EG(exception) && Z_TYPE(retval) != IS_UNDEF) { - zval callable; - zend_get_callable_zval_from_fcc(&intern->u.callback_filter, &callable); - spl_instantiate_arg_ex2(Z_OBJCE_P(ZEND_THIS), return_value, &retval, &callable); - zval_ptr_dtor(&callable); + zval params[2]; + zend_call_method_with_0_params(Z_OBJ(intern->inner.zobject), intern->inner.ce, NULL, "getchildren", ¶ms[0]); + if (Z_TYPE(params[0]) == IS_UNDEF) { + RETURN_THROWS(); + } + + /* Get callable to pass to the constructor */ + zend_get_callable_zval_from_fcc(&intern->u.callback_filter, ¶ms[1]); + + zend_result is_initialized = object_init_with_constructor(return_value, Z_OBJCE_P(ZEND_THIS), 2, params, NULL); + zval_ptr_dtor(¶ms[0]); + zval_ptr_dtor(¶ms[1]); + if (is_initialized == FAILURE) { + RETURN_THROWS(); } - zval_ptr_dtor(&retval); } /* }}} */ /* {{{ Create a ParentIterator from a RecursiveIterator */ PHP_METHOD(ParentIterator, __construct) @@ -1961,21 +1975,25 @@ PHP_METHOD(RecursiveRegexIterator, getChildren) SPL_FETCH_AND_CHECK_DUAL_IT(intern, ZEND_THIS); zend_call_method_with_0_params(Z_OBJ(intern->inner.zobject), intern->inner.ce, NULL, "getchildren", &retval); - if (!EG(exception)) { - zval args[5]; + if (EG(exception)) { + zval_ptr_dtor(&retval); + RETURN_THROWS(); + } - ZVAL_COPY(&args[0], &retval); - ZVAL_STR_COPY(&args[1], intern->u.regex.regex); - ZVAL_LONG(&args[2], intern->u.regex.mode); - ZVAL_LONG(&args[3], intern->u.regex.flags); - ZVAL_LONG(&args[4], intern->u.regex.preg_flags); + zval args[5]; + ZVAL_COPY_VALUE(&args[0], &retval); + ZVAL_STR_COPY(&args[1], intern->u.regex.regex); + ZVAL_LONG(&args[2], intern->u.regex.mode); + ZVAL_LONG(&args[3], intern->u.regex.flags); + ZVAL_LONG(&args[4], intern->u.regex.preg_flags); - spl_instantiate_arg_n(Z_OBJCE_P(ZEND_THIS), return_value, 5, args); + zend_result is_initialized = object_init_with_constructor(return_value, Z_OBJCE_P(ZEND_THIS), 5, args, NULL); - zval_ptr_dtor(&args[0]); - zval_ptr_dtor(&args[1]); + zval_ptr_dtor(&args[0]); + zval_ptr_dtor_str(&args[1]); + if (is_initialized == FAILURE) { + RETURN_THROWS(); } - zval_ptr_dtor(&retval); } /* }}} */ PHP_METHOD(RecursiveRegexIterator, accept) @@ -2246,7 +2264,7 @@ static inline void spl_caching_it_next(spl_dual_it_object *intern) } /* Recursion ? */ if (intern->dit_type == DIT_RecursiveCachingIterator) { - zval retval, zchildren, zflags; + zval retval; zend_call_method_with_0_params(Z_OBJ(intern->inner.zobject), intern->inner.ce, NULL, "haschildren", &retval); if (EG(exception)) { zval_ptr_dtor(&retval); @@ -2256,28 +2274,39 @@ static inline void spl_caching_it_next(spl_dual_it_object *intern) return; } } else { - if (zend_is_true(&retval)) { - zend_call_method_with_0_params(Z_OBJ(intern->inner.zobject), intern->inner.ce, NULL, "getchildren", &zchildren); + bool has_children = zend_is_true(&retval); + zval_ptr_dtor(&retval); + + if (has_children) { + zval args[2]; + + /* Store the children in the first constructor argument */ + zend_call_method_with_0_params(Z_OBJ(intern->inner.zobject), intern->inner.ce, NULL, "getchildren", &args[0]); if (EG(exception)) { - zval_ptr_dtor(&zchildren); + zval_ptr_dtor(&args[0]); if (intern->u.caching.flags & CIT_CATCH_GET_CHILD) { zend_clear_exception(); } else { - zval_ptr_dtor(&retval); return; } } else { - ZVAL_LONG(&zflags, intern->u.caching.flags & CIT_PUBLIC); - spl_instantiate_arg_ex2(spl_ce_RecursiveCachingIterator, &intern->u.caching.zchildren, &zchildren, &zflags); - zval_ptr_dtor(&zchildren); - } - } - zval_ptr_dtor(&retval); - if (EG(exception)) { - if (intern->u.caching.flags & CIT_CATCH_GET_CHILD) { - zend_clear_exception(); - } else { - return; + ZVAL_LONG(&args[1], intern->u.caching.flags & CIT_PUBLIC); + + zend_result is_initialized = object_init_with_constructor( + &intern->u.caching.zchildren, + spl_ce_RecursiveCachingIterator, + 2, + args, + NULL + ); + zval_ptr_dtor(&args[0]); + if (is_initialized == FAILURE) { + if (intern->u.caching.flags & CIT_CATCH_GET_CHILD) { + zend_clear_exception(); + } else { + return; + } + } } } } diff --git a/ext/spl/spl_observer.c b/ext/spl/spl_observer.c index 155dead21eda3..2a947464dbb4a 100644 --- a/ext/spl/spl_observer.c +++ b/ext/spl/spl_observer.c @@ -28,7 +28,6 @@ #include "php_spl.h" #include "spl_functions.h" -#include "spl_engine.h" #include "spl_observer.h" #include "spl_observer_arginfo.h" #include "spl_iterators.h"