Skip to content

Commit

Permalink
Cleanup SPL instantiation code
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Jul 23, 2020
1 parent fc4d462 commit dc30e1d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 48 deletions.
7 changes: 0 additions & 7 deletions ext/spl/spl_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@

#include "spl_array.h"

/* {{{ spl_instantiate */
PHPAPI void spl_instantiate(zend_class_entry *pce, zval *object)
{
object_init_ex(object, pce);
}
/* }}} */

PHPAPI zend_long spl_offset_convert_to_long(zval *offset) /* {{{ */
{
zend_ulong idx;
Expand Down
52 changes: 12 additions & 40 deletions ext/spl/spl_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,55 +21,27 @@
#include "php_spl.h"
#include "zend_interfaces.h"

PHPAPI void spl_instantiate(zend_class_entry *pce, zval *object);

PHPAPI zend_long spl_offset_convert_to_long(zval *offset);

/* {{{ spl_instantiate_arg_ex1 */
static inline int spl_instantiate_arg_ex1(zend_class_entry *pce, zval *retval, zval *arg1)
static inline void spl_instantiate_arg_ex1(zend_class_entry *pce, zval *retval, zval *arg1)
{
zend_function *func = pce->constructor;
spl_instantiate(pce, retval);

zend_call_method(Z_OBJ_P(retval), pce, &func, ZSTR_VAL(func->common.function_name), ZSTR_LEN(func->common.function_name), NULL, 1, arg1, NULL);
return 0;
object_init_ex(retval, pce);
zend_call_known_instance_method_with_1_params(pce->constructor, Z_OBJ_P(retval), NULL, arg1);
}
/* }}} */

/* {{{ spl_instantiate_arg_ex2 */
static inline int spl_instantiate_arg_ex2(zend_class_entry *pce, zval *retval, zval *arg1, zval *arg2)
static inline void spl_instantiate_arg_ex2(
zend_class_entry *pce, zval *retval, zval *arg1, zval *arg2)
{
zend_function *func = pce->constructor;
spl_instantiate(pce, retval);

zend_call_method(Z_OBJ_P(retval), pce, &func, ZSTR_VAL(func->common.function_name), ZSTR_LEN(func->common.function_name), NULL, 2, arg1, arg2);
return 0;
object_init_ex(retval, pce);
zend_call_known_instance_method_with_2_params(
pce->constructor, Z_OBJ_P(retval), NULL, arg1, arg2);
}
/* }}} */

/* {{{ spl_instantiate_arg_n */
static inline void spl_instantiate_arg_n(zend_class_entry *pce, zval *retval, int argc, zval *argv)
static inline void spl_instantiate_arg_n(
zend_class_entry *pce, zval *retval, uint32_t argc, zval *argv)
{
zend_function *func = pce->constructor;
zend_fcall_info fci;
zend_fcall_info_cache fcc;
zval dummy;

spl_instantiate(pce, retval);

fci.size = sizeof(zend_fcall_info);
ZVAL_STR(&fci.function_name, func->common.function_name);
fci.object = Z_OBJ_P(retval);
fci.retval = &dummy;
fci.param_count = argc;
fci.params = argv;

fcc.function_handler = func;
fcc.called_scope = pce;
fcc.object = Z_OBJ_P(retval);

zend_call_function(&fci, &fcc);
object_init_ex(retval, pce);
zend_call_known_instance_method(pce->constructor, Z_OBJ_P(retval), NULL, argc, argv);
}
/* }}} */

#endif /* SPL_ENGINE_H */
2 changes: 1 addition & 1 deletion ext/spl/spl_iterators.c
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
}
intern->dit_type = DIT_AppendIterator;
zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling);
spl_instantiate(spl_ce_ArrayIterator, &intern->u.append.zarrayit);
object_init_ex(&intern->u.append.zarrayit, spl_ce_ArrayIterator);
zend_call_method_with_0_params(Z_OBJ(intern->u.append.zarrayit), spl_ce_ArrayIterator, &spl_ce_ArrayIterator->constructor, "__construct", NULL);
intern->u.append.iterator = spl_ce_ArrayIterator->get_iterator(spl_ce_ArrayIterator, &intern->u.append.zarrayit, 0);
zend_restore_error_handling(&error_handling);
Expand Down

0 comments on commit dc30e1d

Please sign in to comment.