]> granicus.if.org Git - php/commitdiff
- New parsing parameter API
authorDavid Coallier <davidc@php.net>
Tue, 24 Jun 2008 22:53:01 +0000 (22:53 +0000)
committerDavid Coallier <davidc@php.net>
Tue, 24 Jun 2008 22:53:01 +0000 (22:53 +0000)
- Tests have been adjusted, if you have something else failing
  let me know now! All tests seem to pass fine at the moment.

ext/standard/formatted_print.c

index 2d81fae2a568350f21cb348e9a7a388cd5213ec4..8dcadfe7a624da3ec47e664ad4086939959ca8f5 100644 (file)
@@ -373,26 +373,22 @@ php_sprintf_getnumber(char *buffer, int *pos)
 static char *
 php_formatted_print(int ht, int *len, int use_array, int format_offset TSRMLS_DC)
 {
-       zval ***args, **z_format;
+       zval ***args = NULL, **z_format;
        int argc, size = 240, inpos = 0, outpos = 0, temppos;
        int alignment, currarg, adjusting, argnum, width, precision;
        char *format, *result, padding;
        int always_sign;
 
-       argc = ZEND_NUM_ARGS();
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &args, &argc) == FAILURE) {
+               return;
+       }
 
        /* verify the number of args */
        if ((use_array && argc != (2 + format_offset)) 
                        || (!use_array && argc < (1 + format_offset))) {
                WRONG_PARAM_COUNT_WITH_RETVAL(NULL);
        }
-       args = (zval ***)safe_emalloc(argc, sizeof(zval *), 0);
 
-       if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
-               efree(args);
-               WRONG_PARAM_COUNT_WITH_RETVAL(NULL);
-       }
-       
        if (use_array) {
                int i = 1;
                zval ***newargs;
@@ -690,6 +686,7 @@ PHP_FUNCTION(vsprintf)
        if ((result=php_formatted_print(ht, &len, 1, 0 TSRMLS_CC))==NULL) {
                RETURN_FALSE;
        }
+
        RETVAL_STRINGL(result, len, 0);
 }
 /* }}} */
@@ -731,18 +728,17 @@ PHP_FUNCTION(vprintf)
 PHP_FUNCTION(fprintf)
 {
        php_stream *stream;
-       zval **arg1;
+       zval **arg1 = NULL;
+       zval **args = NULL;
+       int num_args;
        char *result;
+       zval **format;
        int len;
-       
-       if (ZEND_NUM_ARGS() < 2) {
-               WRONG_PARAM_COUNT;
-       }
-       
-       if (zend_get_parameters_ex(1, &arg1)==FAILURE) {
-               RETURN_FALSE;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z+", &arg1, &args) == FAILURE) {
+               return;
        }
-       
+
        php_stream_from_zval(stream, arg1);
 
        if ((result=php_formatted_print(ht, &len, 0, 1 TSRMLS_CC))==NULL) {