From 252d7d76a8d49a2df6c3971815c9db24d904ebbd Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sun, 17 Aug 2008 22:14:14 +0000 Subject: - MFH: New parameter parsing API --- ext/standard/array.c | 91 +++++++++++----------------------------------------- 1 file changed, 18 insertions(+), 73 deletions(-) (limited to 'ext/standard/array.c') diff --git a/ext/standard/array.c b/ext/standard/array.c index 21628f3bd5..a7ab6e167d 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -1488,17 +1488,11 @@ static void php_compact_var(HashTable *eg_active_symbol_table, zval *return_valu Creates a hash containing variables and their values */ PHP_FUNCTION(compact) { - zval ***args; /* function arguments array */ - int i; + zval ***args = NULL; /* function arguments array */ + int num_args, i; - if (ZEND_NUM_ARGS() < 1) { - WRONG_PARAM_COUNT; - } - args = (zval ***)safe_emalloc(ZEND_NUM_ARGS(), sizeof(zval **), 0); - - if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &args, &num_args) == FAILURE) { + return; } if (!EG(active_symbol_table)) { @@ -1518,7 +1512,9 @@ PHP_FUNCTION(compact) php_compact_var(EG(active_symbol_table), return_value, *args[i] TSRMLS_CC); } - efree(args); + if (args) { + efree(args); + } } /* }}} */ @@ -1910,29 +1906,13 @@ PHP_FUNCTION(array_push) int i, /* Loop counter */ argc; /* Number of function arguments */ - /* Get the argument count and check it */ - argc = ZEND_NUM_ARGS(); - if (argc < 2) { - WRONG_PARAM_COUNT; - } - - /* Allocate arguments array and get the arguments, checking for errors. */ - args = (zval ***)safe_emalloc(argc, sizeof(zval **), 0); - if (zend_get_parameters_array_ex(argc, args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - /* Get first argument and check that it's an array */ - stack = *args[0]; - if (Z_TYPE_P(stack) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "First argument should be an array"); - efree(args); - RETURN_FALSE; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a+", &stack, &args, &argc) == FAILURE) { + return; } /* For each subsequent argument, make it a reference, increase refcount, and add it to the end of the array */ - for (i=1; i