]> granicus.if.org Git - php/commitdiff
- New parameter parsing API
authorFelipe Pena <felipe@php.net>
Fri, 20 Jun 2008 14:53:57 +0000 (14:53 +0000)
committerFelipe Pena <felipe@php.net>
Fri, 20 Jun 2008 14:53:57 +0000 (14:53 +0000)
14 files changed:
ext/standard/ftok.c
ext/standard/image.c
ext/standard/info.c
ext/standard/pack.c
ext/standard/quot_print.c
ext/standard/streamsfuncs.c
ext/standard/tests/file/stream_rfc2397_002.phpt
ext/standard/tests/general_functions/floatval.phpt
ext/standard/tests/general_functions/gettype_settype_error.phpt
ext/standard/tests/general_functions/strval.phpt
ext/standard/tests/serialize/serialization_error_001.phpt
ext/standard/tests/streams/stream_get_meta_data_file_error.phpt
ext/standard/tests/streams/stream_set_timeout_error.phpt
ext/standard/var.c

index f9ef6adf9d1188ab39d012f2a2d645d97d2d012e..7298a8db6190806044553c3ba3d375af7dfc5209 100644 (file)
    Convert a pathname and a project identifier to a System V IPC key */
 PHP_FUNCTION(ftok)
 {
-       zval **pathname, **proj;
+       char *pathname, *proj;
+       int pathname_len, proj_len;
        key_t k;
 
-       if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &pathname, &proj) == FAILURE) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, &pathname, &pathname_len, &proj, &proj_len) == FAILURE) {
+               return;
        }
 
-       convert_to_string_ex(pathname);
-       convert_to_string_ex(proj);
-
-       if (Z_STRLEN_PP(pathname)==0){
+       if (pathname_len == 0){
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Pathname is invalid");
                RETURN_LONG(-1);
        }
 
-       if (Z_STRLEN_PP(proj)!=1){
+       if (proj_len != 1){
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Project identifier is invalid");
                RETURN_LONG(-1);
     }
 
-       if ((PG(safe_mode) && (!php_checkuid(Z_STRVAL_PP(pathname), NULL, CHECKUID_CHECK_FILE_AND_DIR))) || php_check_open_basedir(Z_STRVAL_PP(pathname) TSRMLS_CC)) {
+       if ((PG(safe_mode) && (!php_checkuid(pathname, NULL, CHECKUID_CHECK_FILE_AND_DIR))) || php_check_open_basedir(pathname TSRMLS_CC)) {
                RETURN_LONG(-1);
        }
 
-       k = ftok(Z_STRVAL_PP(pathname),Z_STRVAL_PP(proj)[0]);
+       k = ftok(pathname, proj[0]);
        if (k == -1) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "ftok() failed - %s", strerror(errno));
        }
index e1fe1a14e8dbfa90ff00a298b954979177636859..c2f640ed4501b9f67e1a8dce3d18b3df1d1590ea 100644 (file)
@@ -1160,15 +1160,13 @@ PHPAPI char * php_image_type_to_mime_type(int image_type)
    Get Mime-Type for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype */
 PHP_FUNCTION(image_type_to_mime_type)
 {
-       zval **p_image_type;
-       int arg_c = ZEND_NUM_ARGS();
+       long p_image_type;
 
-       if ((arg_c!=1) || zend_get_parameters_ex(arg_c, &p_image_type) == FAILURE) {
-               RETVAL_FALSE;
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &p_image_type) == FAILURE) {
+               return;
        }
-       convert_to_long_ex(p_image_type);
-       ZVAL_STRING(return_value, (char*)php_image_type_to_mime_type(Z_LVAL_PP(p_image_type)), 1);
+
+       ZVAL_STRING(return_value, (char*)php_image_type_to_mime_type(p_image_type), 1);
 }
 /* }}} */
 
@@ -1300,40 +1298,22 @@ PHPAPI int php_getimagetype(php_stream * stream, char *filetype TSRMLS_DC)
    Get the size of an image as 4-element array */
 PHP_FUNCTION(getimagesize)
 {
-       zval **arg1, **info = NULL;
-       int itype = 0;
-       char *temp;
+       zval **info = NULL;
+       char *arg1, *temp;
+       int arg1_len, itype = 0, argc = ZEND_NUM_ARGS();
        struct gfxinfo *result = NULL;
        php_stream * stream = NULL;
 
-       switch(ZEND_NUM_ARGS()) {
-
-       case 1:
-               if (zend_get_parameters_ex(1, &arg1) == FAILURE) {
-                       RETVAL_FALSE;
-                       WRONG_PARAM_COUNT;
-               }
-               convert_to_string_ex(arg1);
-               break;
-
-       case 2:
-               if (zend_get_parameters_ex(2, &arg1, &info) == FAILURE) {
-                       RETVAL_FALSE;
-                       WRONG_PARAM_COUNT;
-               }
+       if (zend_parse_parameters(argc TSRMLS_CC, "s|Z", &arg1, &arg1_len, &info) == FAILURE) {
+               return;
+       }
+       
+       if (argc == 2) {
                zval_dtor(*info);
-
                array_init(*info);
-
-               convert_to_string_ex(arg1);
-               break;
-
-       default:
-               RETVAL_FALSE;
-               WRONG_PARAM_COUNT;
        }
 
-       stream = php_stream_open_wrapper(Z_STRVAL_PP(arg1), "rb", STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL);
+       stream = php_stream_open_wrapper(arg1, "rb", STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL);
 
        if (!stream) {
                RETURN_FALSE;
@@ -1342,7 +1322,7 @@ PHP_FUNCTION(getimagesize)
        itype = php_getimagetype(stream, NULL TSRMLS_CC);
        switch( itype) {
                case IMAGE_FILETYPE_GIF:
-                       result = php_handle_gif (stream TSRMLS_CC);
+                       result = php_handle_gif(stream TSRMLS_CC);
                        break;
                case IMAGE_FILETYPE_JPEG:
                        if (info) {
index 1378512cd7a611bac901968e70229b5bda30ed4b..5a766042416ade9c1b6c53a1b0f0b5a965b878cd 100644 (file)
@@ -1033,20 +1033,23 @@ PHP_FUNCTION(phpinfo)
 PHP_FUNCTION(phpversion)
 {
        zval **arg;
+       const char *version;
        int argc = ZEND_NUM_ARGS();
 
        if (argc == 0) {
                RETURN_STRING(PHP_VERSION, 1);
-       } else if (argc == 1 && zend_get_parameters_ex(1, &arg) == SUCCESS) {
-               const char *version;
+       } else {
+               if (zend_parse_parameters(argc TSRMLS_CC, "Z", &arg) == FAILURE) {
+                       return;
+               }
+                       
                convert_to_string_ex(arg);
                version = zend_get_module_version(Z_STRVAL_PP(arg));
+               
                if (version == NULL) {
                        RETURN_FALSE;
                }
                RETURN_STRING(version, 1);
-       } else {
-               WRONG_PARAM_COUNT;
        }
 }
 /* }}} */
index 57075440098fab4f0d7c27a75ac6955f5db1aa5c..48bdc879df21981a36992a91d7fc0d4dddeda124 100644 (file)
@@ -514,26 +514,19 @@ static long php_unpack(char *data, int size, int issigned, int *map)
    Unpack binary string into named array elements according to format argument */
 PHP_FUNCTION(unpack)
 {
-       zval **formatarg;
-       zval **inputarg;
-       char *format;
-       char *input;
-       int formatlen;
-       int inputpos, inputlen;
-       int i;
+       char *format, *input, *formatarg, *inputarg;
+       int formatlen, formatarg_len, inputarg_len;
+       int inputpos, inputlen, i;
 
-       if (ZEND_NUM_ARGS() != 2 || 
-        zend_get_parameters_ex(2, &formatarg, &inputarg) == FAILURE) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &formatarg, &formatarg_len,
+               &inputarg, &inputarg_len) == FAILURE) {
+               return;
        }
 
-       convert_to_string_ex(formatarg);
-       convert_to_string_ex(inputarg);
-
-       format = Z_STRVAL_PP(formatarg);
-       formatlen = Z_STRLEN_PP(formatarg);
-       input = Z_STRVAL_PP(inputarg);
-       inputlen = Z_STRLEN_PP(inputarg);
+       format = formatarg;
+       formatlen = formatarg_len;
+       input = inputarg;
+       inputlen = inputarg_len;
        inputpos = 0;
 
        array_init(return_value);
index 48f0f77c69723f083972ea8e5f269194a7e43520..a1e537940d6e07b9726520706a6b0045fd12111e 100644 (file)
@@ -151,22 +151,20 @@ PHPAPI unsigned char *php_quot_print_decode(const unsigned char *str, size_t len
    Convert a quoted-printable string to an 8 bit string */
 PHP_FUNCTION(quoted_printable_decode)
 {
-       zval **arg1;
-       char *str_in, *str_out;
-       int i = 0, j = 0, k;
+       char *arg1, *str_in, *str_out;
+       int arg1_len, i = 0, j = 0, k;
 
-       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg1, &arg1_len) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
-       convert_to_string_ex(arg1);
     
-       if (Z_STRLEN_PP(arg1) == 0) {
+       if (arg1_len == 0) {
                /* shortcut */
                RETURN_EMPTY_STRING();
        }
 
-       str_in = Z_STRVAL_PP(arg1);
-       str_out = emalloc(Z_STRLEN_PP(arg1) + 1);
+       str_in = arg1;
+       str_out = emalloc(arg1_len + 1);
        while (str_in[i]) {
                switch (str_in[i]) {
                case '=':
index 80fe31c5b0a5f512fc982fcad76d543aafa489e8..6649ec4cd67ffc33c8411db01bd45e0ddcca513e 100644 (file)
@@ -454,14 +454,14 @@ PHP_FUNCTION(stream_copy_to_stream)
     Retrieves header/meta data from streams/file pointers */
 PHP_FUNCTION(stream_get_meta_data)
 {
-       zval **arg1;
+       zval *arg1;
        php_stream *stream;
        zval *newval;
 
-       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) {
+               return;
        }
-       php_stream_from_zval(stream, arg1);
+       php_stream_from_zval(stream, &arg1);
 
        array_init(return_value);
        
@@ -1219,52 +1219,53 @@ PHP_FUNCTION(stream_get_line)
    Set blocking/non-blocking mode on a socket or stream */
 PHP_FUNCTION(stream_set_blocking)
 {
-       zval **arg1, **arg2;
+       zval *arg1;
        int block;
+       long arg2;
        php_stream *stream;
 
-       if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &arg1, &arg2) == FAILURE) {
+               return;
        }
 
-       php_stream_from_zval(stream, arg1);
+       php_stream_from_zval(stream, &arg1);
 
-       convert_to_long_ex(arg2);
-       block = Z_LVAL_PP(arg2);
+       block = arg2;
 
-       if (php_stream_set_option(stream, PHP_STREAM_OPTION_BLOCKING, block == 0 ? 0 : 1, NULL) == -1)
+       if (php_stream_set_option(stream, PHP_STREAM_OPTION_BLOCKING, block == 0 ? 0 : 1, NULL) == -1) {
                RETURN_FALSE;
+       }
+
        RETURN_TRUE;
 }
 
 /* }}} */
 
-/* {{{ proto bool stream_set_timeout(resource stream, int seconds, int microseconds)
+/* {{{ proto bool stream_set_timeout(resource stream, int seconds [, int microseconds])
    Set timeout on stream read to seconds + microseonds */
 #if HAVE_SYS_TIME_H || defined(PHP_WIN32)
 PHP_FUNCTION(stream_set_timeout)
 {
-       zval **socket, **seconds, **microseconds;
+       zval *socket;
+       long seconds, microseconds;
        struct timeval t;
        php_stream *stream;
+       int argc = ZEND_NUM_ARGS();
 
-       if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 3 ||
-               zend_get_parameters_ex(ZEND_NUM_ARGS(), &socket, &seconds, &microseconds)==FAILURE) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(argc TSRMLS_CC, "rl|l", &socket, &seconds, &microseconds) == FAILURE) {
+               return;
        }
 
-       php_stream_from_zval(stream, socket);
+       php_stream_from_zval(stream, &socket);
 
-       convert_to_long_ex(seconds);
-       t.tv_sec = Z_LVAL_PP(seconds);
+       t.tv_sec = seconds;
 
-       if (ZEND_NUM_ARGS() == 3) {
-               convert_to_long_ex(microseconds);
-               t.tv_usec = Z_LVAL_PP(microseconds) % 1000000;
-               t.tv_sec += Z_LVAL_PP(microseconds) / 1000000;
-       }
-       else
+       if (argc == 3) {
+               t.tv_usec = microseconds % 1000000;
+               t.tv_sec += microseconds / 1000000;
+       } else {
                t.tv_usec = 0;
+       }
 
        if (PHP_STREAM_OPTION_RETURN_OK == php_stream_set_option(stream, PHP_STREAM_OPTION_READ_TIMEOUT, 0, &t)) {
                RETURN_TRUE;
@@ -1279,14 +1280,15 @@ PHP_FUNCTION(stream_set_timeout)
    Set file write buffer */
 PHP_FUNCTION(stream_set_write_buffer)
 {
-       zval **arg1, **arg2;
+       zval *arg1;
        int ret;
+       long arg2;
        size_t buff;
        php_stream *stream;
 
        switch (ZEND_NUM_ARGS()) {
        case 2:
-               if (zend_get_parameters_ex(2, &arg1, &arg2)==FAILURE) {
+               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &arg1, &arg2) == FAILURE) {
                        RETURN_FALSE;
                }
                break;
@@ -1296,10 +1298,9 @@ PHP_FUNCTION(stream_set_write_buffer)
                break;
        }
        
-       php_stream_from_zval(stream, arg1);
-       
-       convert_to_long_ex(arg2);
-       buff = Z_LVAL_PP(arg2);
+       php_stream_from_zval(stream, &arg1);
+
+       buff = arg2;
 
        /* if buff is 0 then set to non-buffered */
        if (buff == 0) {
index b75d372d876b8c85fa9d3c15d59b4a57f7383cae..980863bb5c02b44793b3d58ebb2338d2ff6632ef 100755 (executable)
@@ -52,7 +52,7 @@ array(7) {
 NULL
 
 Warning: fopen(data://): failed to open stream: rfc2397: no comma in URL in %sstream_rfc2397_002.php on line %d
-bool(false)
+NULL
 NULL
 array(7) {
   ["wrapper_type"]=>
@@ -73,15 +73,15 @@ array(7) {
 NULL
 
 Warning: fopen(data://;base64): failed to open stream: rfc2397: no comma in URL in %sstream_rfc2397_002.php on line %d
-bool(false)
+NULL
 NULL
 
 Warning: fopen(data://foo,): failed to open stream: rfc2397: illegal media type in %sstream_rfc2397_002.php on line %d
-bool(false)
+NULL
 NULL
 
 Warning: fopen(data://foo=bar,): failed to open stream: rfc2397: illegal media type in %sstream_rfc2397_002.php on line %d
-bool(false)
+NULL
 NULL
 array(8) {
   ["wrapper_type"]=>
@@ -104,7 +104,7 @@ array(8) {
 NULL
 
 Warning: fopen(data://text/plain;foo,): failed to open stream: rfc2397: illegal parameter in %sstream_rfc2397_002.php on line %d
-bool(false)
+NULL
 NULL
 array(9) {
   ["wrapper_type"]=>
@@ -129,7 +129,7 @@ array(9) {
 string(3) "bar"
 
 Warning: fopen(data://text/plain;foo=bar;bla,): failed to open stream: rfc2397: illegal parameter in %sstream_rfc2397_002.php on line %d
-bool(false)
+NULL
 NULL
 array(9) {
   ["wrapper_type"]=>
@@ -154,7 +154,7 @@ array(9) {
 string(3) "bar"
 
 Warning: fopen(data://text/plain;foo=bar;bar=baz): failed to open stream: rfc2397: no comma in URL in %sstream_rfc2397_002.php on line %d
-bool(false)
+NULL
 NULL
 array(10) {
   ["wrapper_type"]=>
index bb28368e241ff562794d393df381079a44c7d8ac..b427bda7d5ecf72b91d696a3abf602a52497388c 100644 (file)
@@ -192,16 +192,16 @@ float(0)
 
 *** Testing error conditions ***
 
-Warning: Wrong parameter count for floatval() in %s on line %d
+Warning: floatval() expects exactly 1 parameter, 0 given in %s on line %d
 NULL
 
-Warning: Wrong parameter count for doubleval() in %s on line %d
+Warning: doubleval() expects exactly 1 parameter, 0 given in %s on line %d
 NULL
 
-Warning: Wrong parameter count for floatval() in %s on line %d
+Warning: floatval() expects exactly 1 parameter, 2 given in %s on line %d
 NULL
 
-Warning: Wrong parameter count for doubleval() in %s on line %d
+Warning: doubleval() expects exactly 1 parameter, 2 given in %s on line %d
 NULL
 
 Done
index 3a61842daa929f23dea5da5b35d0dae75f63a4ff..2c6aac687529ac689ecc7d46a6dc3c79f5d1785d 100644 (file)
@@ -37,18 +37,18 @@ echo "Done\n";
 
 *** Testing gettype(): error conditions ***
 
-Warning: Wrong parameter count for gettype() in %s on line %d
+Warning: gettype() expects exactly 1 parameter, 0 given in %s on line %d
 NULL
 
-Warning: Wrong parameter count for gettype() in %s on line %d
+Warning: gettype() expects exactly 1 parameter, 2 given in %s on line %d
 NULL
 
 *** Testing settype(): error conditions ***
 
-Warning: Wrong parameter count for settype() in %s on line %d
+Warning: settype() expects exactly 2 parameters, 0 given in %s on line %d
 NULL
 
-Warning: Wrong parameter count for settype() in %s on line %d
+Warning: settype() expects exactly 2 parameters, 3 given in %s on line %d
 NULL
 
 Warning: settype(): Invalid type in %s on line %d
index 8cf827303d817d50911e1edbe34bc68e53984e14..bcaa5b90f064b1686121711b9896882e5865c0f1 100644 (file)
@@ -302,9 +302,9 @@ string(0) ""
 
 *** Testing error conditions ***
 
-Warning: Wrong parameter count for strval() in %s on line %d
+Warning: strval() expects exactly 1 parameter, 0 given in %s on line %d
 NULL
 
-Warning: Wrong parameter count for strval() in %s on line %d
+Warning: strval() expects exactly 1 parameter, 2 given in %s on line %d
 NULL
 Done
index 3f530580d6bbd9489c6811592418306269ef7726..da6f50cc02b29c00161cb547c66cbe8db08fd61b 100644 (file)
@@ -28,15 +28,15 @@ echo "Done";
 --EXPECTF--
 *** Testing serialize()/unserialize() : error conditions ***
 
-Warning: Wrong parameter count for serialize() in %s on line 16
+Warning: serialize() expects exactly 1 parameter, 0 given in %s on line 16
 NULL
 
 Warning: unserialize() expects exactly 1 parameter, 0 given in %s on line 17
 bool(false)
 
-Warning: Wrong parameter count for serialize() in %s on line 20
+Warning: serialize() expects exactly 1 parameter, 2 given in %s on line 20
 NULL
 
 Warning: unserialize() expects exactly 1 parameter, 2 given in %s on line 21
 bool(false)
-Done
\ No newline at end of file
+Done
index 912c4055a2c12e5725e8a679a5f8b4e511776d12..390694a0627d290f11479d8aa0aa743c77a48624 100644 (file)
@@ -37,18 +37,18 @@ echo "Done";
 
 -- Testing stream_get_meta_data() function with Zero arguments --
 
-Warning: Wrong parameter count for stream_get_meta_data() in %s on line %i
+Warning: stream_get_meta_data() expects exactly 1 parameter, 0 given in %s on line %i
 NULL
 
 -- Testing stream_get_meta_data() function with more than expected no. of arguments --
 
-Warning: Wrong parameter count for stream_get_meta_data() in %s on line %i
+Warning: stream_get_meta_data() expects exactly 1 parameter, 2 given in %s on line %i
 NULL
 
 -- Testing stream_get_meta_data() function with invalid stream resource --
 
-Warning: stream_get_meta_data(): supplied argument is not a valid stream resource in %s on line %i
-bool(false)
+Warning: stream_get_meta_data() expects parameter 1 to be resource, null given in %s on line %i
+NULL
 
 -- Testing stream_get_meta_data() function with closed stream resource --
 
index 1e8e60bd2a3c96b4eb4a890ad066c539c7345206..e2c17c018733d4c8b70ba00ba82b419818e0d3f8 100644 (file)
@@ -56,12 +56,12 @@ echo "Done";
 
 -- Testing stream_set_timeout() function with more than expected no. of arguments --
 
-Warning: Wrong parameter count for stream_set_timeout() in %s on line %i
+Warning: stream_set_timeout() expects at most 3 parameters, 4 given in %s on line %i
 NULL
 
 -- Testing stream_set_timeout() function with less than expected no. of arguments --
 
-Warning: Wrong parameter count for stream_set_timeout() in %s on line %i
+Warning: stream_set_timeout() expects at least 2 parameters, 1 given in %s on line %i
 NULL
 
 -- Testing stream_set_timeout() function with a closed socket --
@@ -71,8 +71,8 @@ bool(false)
 
 -- Testing stream_set_timeout() function with an invalid stream --
 
-Warning: stream_set_timeout(): supplied argument is not a valid stream resource in %s on line %i
-bool(false)
+Warning: stream_set_timeout() expects parameter 1 to be resource, integer given in %s on line %i
+NULL
 
 -- Testing stream_set_timeout() function with a stream that does not support timeouts --
 bool(false)
index 6000672b9813bb55c1540c4cf6417bfef7d83988..8b525167766ee04f67bc1113a9c0f0fc8680914b 100644 (file)
@@ -838,8 +838,8 @@ PHP_FUNCTION(serialize)
        php_serialize_data_t var_hash;
        smart_str buf = {0};
 
-       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &struc) == FAILURE) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &struc) == FAILURE) {
+               return;
        }
 
        Z_TYPE_P(return_value) = IS_STRING;