@@ -1658,6 +1658,7 @@ void user_shutdown_function_dtor(zval *zv) /* {{{ */
1658
1658
int i ;
1659
1659
php_shutdown_function_entry * shutdown_function_entry = Z_PTR_P (zv );
1660
1660
1661
+ zval_ptr_dtor (& shutdown_function_entry -> function_name );
1661
1662
for (i = 0 ; i < shutdown_function_entry -> arg_count ; i ++ ) {
1662
1663
zval_ptr_dtor (& shutdown_function_entry -> arguments [i ]);
1663
1664
}
@@ -1682,18 +1683,18 @@ static int user_shutdown_function_call(zval *zv) /* {{{ */
1682
1683
php_shutdown_function_entry * shutdown_function_entry = Z_PTR_P (zv );
1683
1684
zval retval ;
1684
1685
1685
- if (!zend_is_callable (& shutdown_function_entry -> arguments [ 0 ] , 0 , NULL )) {
1686
- zend_string * function_name = zend_get_callable_name (& shutdown_function_entry -> arguments [ 0 ] );
1686
+ if (!zend_is_callable (& shutdown_function_entry -> function_name , 0 , NULL )) {
1687
+ zend_string * function_name = zend_get_callable_name (& shutdown_function_entry -> function_name );
1687
1688
zend_throw_error (NULL , "Registered shutdown function %s() cannot be called, function does not exist" , ZSTR_VAL (function_name ));
1688
1689
zend_string_release (function_name );
1689
1690
return 0 ;
1690
1691
}
1691
1692
1692
1693
if (call_user_function (NULL , NULL ,
1693
- & shutdown_function_entry -> arguments [ 0 ] ,
1694
+ & shutdown_function_entry -> function_name ,
1694
1695
& retval ,
1695
- shutdown_function_entry -> arg_count - 1 ,
1696
- shutdown_function_entry -> arguments + 1 ) == SUCCESS )
1696
+ shutdown_function_entry -> arg_count ,
1697
+ shutdown_function_entry -> arguments ) == SUCCESS )
1697
1698
{
1698
1699
zval_ptr_dtor (& retval );
1699
1700
}
@@ -1787,40 +1788,24 @@ PHPAPI void php_free_shutdown_functions(void) /* {{{ */
1787
1788
/* {{{ Register a user-level function to be called on request termination */
1788
1789
PHP_FUNCTION (register_shutdown_function )
1789
1790
{
1790
- php_shutdown_function_entry shutdown_function_entry ;
1791
- int i ;
1792
-
1793
- shutdown_function_entry .arg_count = ZEND_NUM_ARGS ();
1794
-
1795
- if (shutdown_function_entry .arg_count < 1 ) {
1796
- WRONG_PARAM_COUNT ;
1797
- }
1798
-
1799
- shutdown_function_entry .arguments = (zval * ) safe_emalloc (sizeof (zval ), shutdown_function_entry .arg_count , 0 );
1800
-
1801
- if (zend_get_parameters_array (ZEND_NUM_ARGS (), shutdown_function_entry .arg_count , shutdown_function_entry .arguments ) == FAILURE ) {
1802
- efree (shutdown_function_entry .arguments );
1803
- RETURN_FALSE ;
1804
- }
1791
+ php_shutdown_function_entry entry ;
1792
+ zend_fcall_info fci ;
1793
+ zend_fcall_info_cache fcc ;
1794
+ zval * args ;
1795
+ int arg_count = 0 ;
1805
1796
1806
- /* Prevent entering of anything but valid callback (syntax check only!) */
1807
- if (!zend_is_callable (& shutdown_function_entry .arguments [0 ], 0 , NULL )) {
1808
- zend_string * callback_name = zend_get_callable_name (& shutdown_function_entry .arguments [0 ]);
1809
- zend_argument_type_error (1 , "must be a valid callback, function \"%s\" not found or invalid function name" , ZSTR_VAL (callback_name ));
1810
- efree (shutdown_function_entry .arguments );
1811
- zend_string_release (callback_name );
1797
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "f*" , & fci , & fcc , & args , & arg_count ) == FAILURE ) {
1812
1798
RETURN_THROWS ();
1813
1799
}
1814
1800
1815
- if (!BG (user_shutdown_function_names )) {
1816
- ALLOC_HASHTABLE (BG (user_shutdown_function_names ));
1817
- zend_hash_init (BG (user_shutdown_function_names ), 0 , NULL , user_shutdown_function_dtor , 0 );
1801
+ ZVAL_COPY (& entry .function_name , & fci .function_name );
1802
+ entry .arguments = (zval * ) safe_emalloc (sizeof (zval ), arg_count , 0 );
1803
+ entry .arg_count = arg_count ;
1804
+ for (int i = 0 ; i < arg_count ; i ++ ) {
1805
+ ZVAL_COPY (& entry .arguments [i ], & args [i ]);
1818
1806
}
1819
1807
1820
- for (i = 0 ; i < shutdown_function_entry .arg_count ; i ++ ) {
1821
- Z_TRY_ADDREF (shutdown_function_entry .arguments [i ]);
1822
- }
1823
- zend_hash_next_index_insert_mem (BG (user_shutdown_function_names ), & shutdown_function_entry , sizeof (php_shutdown_function_entry ));
1808
+ append_user_shutdown_function (& entry );
1824
1809
}
1825
1810
/* }}} */
1826
1811
@@ -1846,14 +1831,14 @@ PHPAPI zend_bool remove_user_shutdown_function(const char *function_name, size_t
1846
1831
}
1847
1832
/* }}} */
1848
1833
1849
- PHPAPI zend_bool append_user_shutdown_function (php_shutdown_function_entry shutdown_function_entry ) /* {{{ */
1834
+ PHPAPI zend_bool append_user_shutdown_function (php_shutdown_function_entry * shutdown_function_entry ) /* {{{ */
1850
1835
{
1851
1836
if (!BG (user_shutdown_function_names )) {
1852
1837
ALLOC_HASHTABLE (BG (user_shutdown_function_names ));
1853
1838
zend_hash_init (BG (user_shutdown_function_names ), 0 , NULL , user_shutdown_function_dtor , 0 );
1854
1839
}
1855
1840
1856
- return zend_hash_next_index_insert_mem (BG (user_shutdown_function_names ), & shutdown_function_entry , sizeof (php_shutdown_function_entry )) != NULL ;
1841
+ return zend_hash_next_index_insert_mem (BG (user_shutdown_function_names ), shutdown_function_entry , sizeof (php_shutdown_function_entry )) != NULL ;
1857
1842
}
1858
1843
/* }}} */
1859
1844
0 commit comments