summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2006-05-27 19:40:06 +0000
committerMarcus Boerger <helly@php.net>2006-05-27 19:40:06 +0000
commit5925a2627542ce7ed4ee9c346f02ca121d990e09 (patch)
tree7425475de8ca4de63022460e6c1792b75dd31226
parentf93bf1007ab5aed2cfb6e672e09c00f5c7b22f7f (diff)
downloadphp-git-5925a2627542ce7ed4ee9c346f02ca121d990e09.tar.gz
- Take care of refcounting in zend_fcall_info_*() functions
- Add docu # I know it is unpopular to add docu here but i think we should add more
-rw-r--r--Zend/zend_API.c16
-rw-r--r--Zend/zend_API.h10
2 files changed, 21 insertions, 5 deletions
diff --git a/Zend/zend_API.c b/Zend/zend_API.c
index 6eb2764d11..e3ccd6749d 100644
--- a/Zend/zend_API.c
+++ b/Zend/zend_API.c
@@ -2903,6 +2903,9 @@ ZEND_API int zend_fcall_info_args(zend_fcall_info *fci, zval *args TSRMLS_DC)
zval **arg, ***params;
if (fci->params) {
+ while (fci->param_count) {
+ zval_ptr_dtor(fci->params[--fci->param_count]);
+ }
efree(fci->params);
}
fci->params = NULL;
@@ -2923,6 +2926,7 @@ ZEND_API int zend_fcall_info_args(zend_fcall_info *fci, zval *args TSRMLS_DC)
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(args), (void **) &arg, &pos) == SUCCESS) {
*params++ = arg;
+ (*arg)->refcount++;
zend_hash_move_forward_ex(Z_ARRVAL_P(args), &pos);
}
return SUCCESS;
@@ -2931,11 +2935,13 @@ ZEND_API int zend_fcall_info_args(zend_fcall_info *fci, zval *args TSRMLS_DC)
ZEND_API int zend_fcall_info_call(zend_fcall_info *fci, zend_fcall_info_cache *fcc, zval **retval_ptr_ptr, zval *args TSRMLS_DC)
{
- zval *retval;
- int result;
+ zval *retval, ***org_params;
+ int result, org_count;
fci->retval_ptr_ptr = retval_ptr_ptr ? retval_ptr_ptr : &retval;
if (args) {
+ org_params = fci->params;
+ org_count = fci->param_count;
zend_fcall_info_args(fci, args TSRMLS_CC);
}
result = zend_call_function(fci, fcc TSRMLS_CC);
@@ -2943,8 +2949,10 @@ ZEND_API int zend_fcall_info_call(zend_fcall_info *fci, zend_fcall_info_cache *f
if (!retval_ptr_ptr && retval) {
zval_ptr_dtor(&retval);
}
- if (args && fci->params) {
- efree(fci->params);
+ if (args) {
+ zend_fcall_info_args(fci, NULL TSRMLS_CC);
+ fci->params = org_params;
+ fci->param_count = org_count;
}
return result;
}
diff --git a/Zend/zend_API.h b/Zend/zend_API.h
index 541218b676..661c1b5fcf 100644
--- a/Zend/zend_API.h
+++ b/Zend/zend_API.h
@@ -653,7 +653,7 @@ typedef struct _zend_fcall_info_cache {
BEGIN_EXTERN_C()
ZEND_API extern zend_fcall_info_cache empty_fcall_info_cache;
-/* Build zend_call_info/cache from a zval*
+/** Build zend_call_info/cache from a zval*
*
* Caller is responsible to provide a return value, otherwise the we will crash.
* fci->retval_ptr_ptr = NULL;
@@ -662,7 +662,15 @@ ZEND_API extern zend_fcall_info_cache empty_fcall_info_cache;
* fci->params = NULL;
*/
ZEND_API int zend_fcall_info_init(zval *callable, zend_fcall_info *fci, zend_fcall_info_cache *fcc TSRMLS_DC);
+
+/** Set or clear the arguments in the zend_call_info struct taking care of
+ * refcount. If args is NULL and arguments are set then those are cleared.
+ */
ZEND_API int zend_fcall_info_args(zend_fcall_info *fci, zval *args TSRMLS_DC);
+
+/** Call a function using information created by zend_fcall_info_init()/args().
+ * If args is given then those replace the arguement info in fci is temporarily.
+ */
ZEND_API int zend_fcall_info_call(zend_fcall_info *fci, zend_fcall_info_cache *fcc, zval **retval, zval *args TSRMLS_DC);
ZEND_API int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TSRMLS_DC);