]> granicus.if.org Git - php/commitdiff
Add FAST_ZPP to various important stream funcs
authorBob Weinand <bobwei9@hotmail.com>
Sun, 20 Sep 2015 02:27:51 +0000 (04:27 +0200)
committerBob Weinand <bobwei9@hotmail.com>
Sun, 20 Sep 2015 02:27:51 +0000 (04:27 +0200)
ext/standard/file.c
ext/standard/streamsfuncs.c
ext/standard/tests/streams/stream_context_set_option_error_001.phpt
ext/standard/tests/streams/stream_context_set_option_error_002.phpt

index 3087144d4473961fe3b1afdd904eeb3d1c5bd8e3..96509040b33c356bea70a4083dc1d0672b315090 100644 (file)
@@ -976,9 +976,15 @@ PHPAPI PHP_FUNCTION(feof)
        zval *res;
        php_stream *stream;
 
+#ifndef FAST_ZPP
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &res) == FAILURE) {
                RETURN_FALSE;
        }
+#else
+       ZEND_PARSE_PARAMETERS_START(1, 1)
+               Z_PARAM_RESOURCE(res)
+       ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+#endif
 
        PHP_STREAM_TO_ZVAL(stream, res);
 
@@ -1002,9 +1008,17 @@ PHPAPI PHP_FUNCTION(fgets)
        zend_string *str;
        php_stream *stream;
 
+#ifndef FAST_ZPP
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &res, &len) == FAILURE) {
                RETURN_FALSE;
        }
+#else
+       ZEND_PARSE_PARAMETERS_START(1, 2)
+               Z_PARAM_RESOURCE(res)
+               Z_PARAM_OPTIONAL
+               Z_PARAM_LONG(len)
+       ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+#endif
 
        PHP_STREAM_TO_ZVAL(stream, res);
 
@@ -1166,9 +1180,18 @@ PHPAPI PHP_FUNCTION(fwrite)
        zend_long maxlen = 0;
        php_stream *stream;
 
+#ifndef FAST_ZPP
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|l", &res, &input, &inputlen, &maxlen) == FAILURE) {
                RETURN_FALSE;
        }
+#else
+       ZEND_PARSE_PARAMETERS_START(2, 3)
+               Z_PARAM_RESOURCE(res)
+               Z_PARAM_STRING(input, inputlen)
+               Z_PARAM_OPTIONAL
+               Z_PARAM_LONG(maxlen)
+       ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+#endif
 
        if (ZEND_NUM_ARGS() == 2) {
                num_bytes = inputlen;
@@ -1198,9 +1221,15 @@ PHPAPI PHP_FUNCTION(fflush)
        int ret;
        php_stream *stream;
 
+#ifndef FAST_ZPP
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &res) == FAILURE) {
                RETURN_FALSE;
        }
+#else
+       ZEND_PARSE_PARAMETERS_START(1, 1)
+               Z_PARAM_RESOURCE(res)
+       ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+#endif
 
        PHP_STREAM_TO_ZVAL(stream, res);
 
@@ -1219,9 +1248,15 @@ PHPAPI PHP_FUNCTION(rewind)
        zval *res;
        php_stream *stream;
 
+#ifndef FAST_ZPP
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &res) == FAILURE) {
                RETURN_FALSE;
        }
+#else
+       ZEND_PARSE_PARAMETERS_START(1, 1)
+               Z_PARAM_RESOURCE(res)
+       ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+#endif
 
        PHP_STREAM_TO_ZVAL(stream, res);
 
@@ -1240,9 +1275,15 @@ PHPAPI PHP_FUNCTION(ftell)
        zend_long ret;
        php_stream *stream;
 
+#ifndef FAST_ZPP
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &res) == FAILURE) {
                RETURN_FALSE;
        }
+#else
+       ZEND_PARSE_PARAMETERS_START(1, 1)
+               Z_PARAM_RESOURCE(res)
+       ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+#endif
 
        PHP_STREAM_TO_ZVAL(stream, res);
 
@@ -1262,9 +1303,18 @@ PHPAPI PHP_FUNCTION(fseek)
        zend_long offset, whence = SEEK_SET;
        php_stream *stream;
 
+#ifndef FAST_ZPP
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl|l", &res, &offset, &whence) == FAILURE) {
                RETURN_FALSE;
        }
+#else
+       ZEND_PARSE_PARAMETERS_START(2, 3)
+               Z_PARAM_RESOURCE(res)
+               Z_PARAM_LONG(offset)
+               Z_PARAM_OPTIONAL
+               Z_PARAM_LONG(whence)
+       ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+#endif
 
        PHP_STREAM_TO_ZVAL(stream, res);
 
@@ -1743,9 +1793,16 @@ PHPAPI PHP_FUNCTION(fread)
        zend_long len;
        php_stream *stream;
 
+#ifndef FAST_ZPP
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &res, &len) == FAILURE) {
                RETURN_FALSE;
        }
+#else
+       ZEND_PARSE_PARAMETERS_START(2, 2)
+               Z_PARAM_RESOURCE(res)
+               Z_PARAM_LONG(len)
+       ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+#endif
 
        PHP_STREAM_TO_ZVAL(stream, res);
 
index a61dbffdc5e2a4254952eba7cbd577f5c416fbd3..eb85bd0184eb0c96de013e5d5ca72951deeaeefd 100644 (file)
@@ -247,9 +247,18 @@ PHP_FUNCTION(stream_socket_accept)
        zval *zstream;
        zend_string *errstr = NULL;
 
+#ifndef FAST_ZPP
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|dz/", &zstream, &timeout, &zpeername) == FAILURE) {
                RETURN_FALSE;
        }
+#else
+       ZEND_PARSE_PARAMETERS_START(1, 3)
+               Z_PARAM_RESOURCE(zstream)
+               Z_PARAM_OPTIONAL
+               Z_PARAM_DOUBLE(timeout)
+               Z_PARAM_ZVAL_EX(zpeername, 0, 1)
+       ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+#endif
 
        php_stream_from_zval(stream, zstream);
 
@@ -297,9 +306,16 @@ PHP_FUNCTION(stream_socket_get_name)
        zend_bool want_peer;
        zend_string *name = NULL;
 
+#ifndef FAST_ZPP
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "rb", &zstream, &want_peer) == FAILURE) {
                RETURN_FALSE;
        }
+#else
+       ZEND_PARSE_PARAMETERS_START(2, 2)
+               Z_PARAM_RESOURCE(zstream)
+               Z_PARAM_BOOL(want_peer)
+       ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+#endif
 
        php_stream_from_zval(stream, zstream);
 
@@ -474,13 +490,20 @@ PHP_FUNCTION(stream_copy_to_stream)
     Retrieves header/meta data from streams/file pointers */
 PHP_FUNCTION(stream_get_meta_data)
 {
-       zval *arg1;
+       zval *zstream;
        php_stream *stream;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &arg1) == FAILURE) {
+#ifndef FAST_ZPP
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zstream) == FAILURE) {
                return;
        }
-       php_stream_from_zval(stream, arg1);
+#else
+       ZEND_PARSE_PARAMETERS_START(1, 1)
+               Z_PARAM_RESOURCE(zstream)
+       ZEND_PARSE_PARAMETERS_END();
+#endif
+
+       php_stream_from_zval(stream, zstream);
 
        array_init(return_value);
 
@@ -522,7 +545,6 @@ PHP_FUNCTION(stream_get_meta_data)
                add_assoc_bool(return_value, "blocked", 1);
                add_assoc_bool(return_value, "eof", php_stream_eof(stream));
        }
-
 }
 /* }}} */
 
@@ -711,17 +733,29 @@ static int stream_array_emulate_read_fd_set(zval *stream_array)
    Runs the select() system call on the sets of streams with a timeout specified by tv_sec and tv_usec */
 PHP_FUNCTION(stream_select)
 {
-       zval                    *r_array, *w_array, *e_array, *sec = NULL;
-       struct timeval  tv;
-       struct timeval *tv_p = NULL;
-       fd_set                  rfds, wfds, efds;
-       php_socket_t    max_fd = 0;
-       int                             retval, sets = 0;
-       zend_long                       usec = 0;
-       int                             set_count, max_set_count = 0;
-
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "a/!a/!a/!z!|l", &r_array, &w_array, &e_array, &sec, &usec) == FAILURE)
+       zval *r_array, *w_array, *e_array;
+       struct timeval tv, *tv_p = NULL;
+       fd_set rfds, wfds, efds;
+       php_socket_t max_fd = 0;
+       int retval, sets = 0;
+       zend_long sec, usec = 0;
+       zend_bool secnull;
+       int set_count, max_set_count = 0;
+
+#ifndef FAST_ZPP
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "a/!a/!a/!l!|l", &r_array, &w_array, &e_array, &sec, &secnull, &usec) == FAILURE) {
                return;
+       }
+#else
+       ZEND_PARSE_PARAMETERS_START(4, 5)
+               Z_PARAM_ARRAY_EX(r_array, 1, 1)
+               Z_PARAM_ARRAY_EX(w_array, 1, 1)
+               Z_PARAM_ARRAY_EX(e_array, 1, 1)
+               Z_PARAM_LONG_EX(sec, secnull, 1, 0)
+               Z_PARAM_OPTIONAL
+               Z_PARAM_LONG(usec)
+       ZEND_PARSE_PARAMETERS_END();
+#endif
 
        FD_ZERO(&rfds);
        FD_ZERO(&wfds);
@@ -756,10 +790,8 @@ PHP_FUNCTION(stream_select)
        PHP_SAFE_MAX_FD(max_fd, max_set_count);
 
        /* If seconds is not set to null, build the timeval, else we wait indefinitely */
-       if (sec != NULL) {
-               convert_to_long_ex(sec);
-
-               if (Z_LVAL_P(sec) < 0) {
+       if (!secnull) {
+               if (sec < 0) {
                        php_error_docref(NULL, E_WARNING, "The seconds parameter must be greater than 0");
                        RETURN_FALSE;
                } else if (usec < 0) {
@@ -767,19 +799,9 @@ PHP_FUNCTION(stream_select)
                        RETURN_FALSE;
                }
 
-#ifdef PHP_WIN32
-               tv.tv_sec = (long)(Z_LVAL_P(sec) + (usec / 1000000));
+               /* Windows, Solaris and BSD do not like microsecond values which are >= 1 sec */
+               tv.tv_sec = (long)(sec + (usec / 1000000));
                tv.tv_usec = (long)(usec % 1000000);
-#else
-               /* Solaris + BSD do not like microsecond values which are >= 1 sec */
-               if (usec > 999999) {
-                       tv.tv_sec = Z_LVAL_P(sec) + (usec / 1000000);
-                       tv.tv_usec = usec % 1000000;
-               } else {
-                       tv.tv_sec = Z_LVAL_P(sec);
-                       tv.tv_usec = usec;
-               }
-#endif
                tv_p = &tv;
        }
 
@@ -787,7 +809,6 @@ PHP_FUNCTION(stream_select)
         * read buffer of any of the streams in the read array, let's pretend
         * that we selected, but return only the readable sockets */
        if (r_array != NULL) {
-
                retval = stream_array_emulate_read_fd_set(r_array);
                if (retval > 0) {
                        if (w_array != NULL) {
@@ -941,9 +962,16 @@ PHP_FUNCTION(stream_context_get_options)
        zval *zcontext;
        php_stream_context *context;
 
+#ifndef FAST_ZPP
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zcontext) == FAILURE) {
                RETURN_FALSE;
        }
+#else
+       ZEND_PARSE_PARAMETERS_START(1, 1)
+               Z_PARAM_RESOURCE(zcontext)
+       ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+#endif
+
        context = decode_context_param(zcontext);
        if (!context) {
                php_error_docref(NULL, E_WARNING, "Invalid stream/context parameter");
@@ -958,34 +986,55 @@ PHP_FUNCTION(stream_context_get_options)
    Set an option for a wrapper */
 PHP_FUNCTION(stream_context_set_option)
 {
-       zval *options = NULL, *zcontext = NULL, *zvalue = NULL;
+       zval *zcontext = NULL;
        php_stream_context *context;
-       char *wrappername, *optionname;
-       size_t wrapperlen, optionlen;
-
-       if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(),
-                               "rssz", &zcontext, &wrappername, &wrapperlen,
-                               &optionname, &optionlen, &zvalue) == FAILURE) {
-               if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(),
-                                       "ra", &zcontext, &options) == FAILURE) {
-                       php_error_docref(NULL, E_WARNING, "called with wrong number or type of parameters; please RTM");
+
+       if (ZEND_NUM_ARGS() == 2) {
+               zval *options;
+
+#ifndef FAST_ZPP
+               if (zend_parse_parameters(, ZEND_NUM_ARGS(), "ra", &zcontext, &options) == FAILURE) {
                        RETURN_FALSE;
                }
-       }
+#else
+               ZEND_PARSE_PARAMETERS_START(2, 2)
+                       Z_PARAM_RESOURCE(zcontext)
+                       Z_PARAM_ARRAY(options)
+               ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+#endif
 
-       /* figure out where the context is coming from exactly */
-       context = decode_context_param(zcontext);
-       if (!context) {
-               php_error_docref(NULL, E_WARNING, "Invalid stream/context parameter");
-               RETURN_FALSE;
-       }
+               /* figure out where the context is coming from exactly */
+               if (!(context = decode_context_param(zcontext))) {
+                       php_error_docref(NULL, E_WARNING, "Invalid stream/context parameter");
+                       RETURN_FALSE;
+               }
 
-       if (options) {
-               /* handle the array syntax */
-               RETVAL_BOOL(parse_context_options(context, options) == SUCCESS);
+               RETURN_BOOL(parse_context_options(context, options) == SUCCESS);
        } else {
-               php_stream_context_set_option(context, wrappername, optionname, zvalue);
-               RETVAL_TRUE;
+               zval *zvalue;
+               char *wrappername, *optionname;
+               size_t wrapperlen, optionlen;
+
+#ifndef FAST_ZPP
+               if (zend_parse_parameters(ZEND_NUM_ARGS(), "rssz", &zcontext, &wrappername, &wrapperlen, &optionname, &optionlen, &zvalue) == FAILURE) {
+                       RETURN_FALSE;
+               }
+#else
+               ZEND_PARSE_PARAMETERS_START(4, 4)
+                       Z_PARAM_RESOURCE(zcontext)
+                       Z_PARAM_STRING(wrappername, wrapperlen)
+                       Z_PARAM_STRING(optionname, optionlen)
+                       Z_PARAM_ZVAL(zvalue)
+               ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+#endif
+
+               /* figure out where the context is coming from exactly */
+               if (!(context = decode_context_param(zcontext))) {
+                       php_error_docref(NULL, E_WARNING, "Invalid stream/context parameter");
+                       RETURN_FALSE;
+               }
+
+               RETURN_BOOL(php_stream_context_set_option(context, wrappername, optionname, zvalue) == SUCCESS);
        }
 }
 /* }}} */
@@ -997,9 +1046,16 @@ PHP_FUNCTION(stream_context_set_params)
        zval *params, *zcontext;
        php_stream_context *context;
 
+#ifndef FAST_ZPP
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "ra", &zcontext, &params) == FAILURE) {
                RETURN_FALSE;
        }
+#else
+       ZEND_PARSE_PARAMETERS_START(2, 2)
+               Z_PARAM_RESOURCE(zcontext)
+               Z_PARAM_ARRAY(params)
+       ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+#endif
 
        context = decode_context_param(zcontext);
        if (!context) {
@@ -1018,9 +1074,15 @@ PHP_FUNCTION(stream_context_get_params)
        zval *zcontext;
        php_stream_context *context;
 
+#ifndef FAST_ZPP
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zcontext) == FAILURE) {
                RETURN_FALSE;
        }
+#else
+       ZEND_PARSE_PARAMETERS_START(1, 1)
+               Z_PARAM_RESOURCE(zcontext)
+       ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+#endif
 
        context = decode_context_param(zcontext);
        if (!context) {
@@ -1272,17 +1334,24 @@ PHP_FUNCTION(stream_get_line)
    Set blocking/non-blocking mode on a socket or stream */
 PHP_FUNCTION(stream_set_blocking)
 {
-       zval *arg1;
-       zend_long block;
+       zval *zstream;
+       zend_bool block;
        php_stream *stream;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &arg1, &block) == FAILURE) {
+#ifndef FAST_ZPP
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "rb", &zstream, &block) == FAILURE) {
                return;
        }
+#else
+       ZEND_PARSE_PARAMETERS_START(2, 2)
+               Z_PARAM_RESOURCE(zstream)
+               Z_PARAM_BOOL(block)
+       ZEND_PARSE_PARAMETERS_END();
+#endif
 
-       php_stream_from_zval(stream, arg1);
+       php_stream_from_zval(stream, zstream);
 
-       if (php_stream_set_option(stream, PHP_STREAM_OPTION_BLOCKING, block ? 1 : 0, NULL) == -1) {
+       if (php_stream_set_option(stream, PHP_STREAM_OPTION_BLOCKING, block, NULL) == -1) {
                RETURN_FALSE;
        }
 
@@ -1439,9 +1508,19 @@ PHP_FUNCTION(stream_socket_enable_crypto)
        zend_bool enable, cryptokindnull;
        int ret;
 
+#ifdef FAST_ZPP
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "rb|l!r", &zstream, &enable, &cryptokind, &cryptokindnull, &zsessstream) == FAILURE) {
                RETURN_FALSE;
        }
+#else
+       ZEND_PARSE_PARAMETERS_START(2, 4)
+               Z_PARAM_RESOURCE(zstream)
+               Z_PARAM_BOOL(enable)
+               Z_PARAM_OPTIONAL
+               Z_PARAM_LONG_EX(cryptokind, cryptokindnull, 1, 0)
+               Z_PARAM_RESOURCE(zsessstream)
+       ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+#endif
 
        php_stream_from_zval(stream, zstream);
 
@@ -1566,13 +1645,21 @@ PHP_FUNCTION(stream_socket_shutdown)
        zval *zstream;
        php_stream *stream;
 
+#ifndef FAST_ZPP
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &zstream, &how) == FAILURE) {
                RETURN_FALSE;
        }
+#else
+       ZEND_PARSE_PARAMETERS_START(2, 2)
+               Z_PARAM_RESOURCE(zstream)
+               Z_PARAM_LONG(how)
+       ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+#endif
 
        if (how != STREAM_SHUT_RD &&
            how != STREAM_SHUT_WR &&
            how != STREAM_SHUT_RDWR) {
+               php_error_docref(NULL, E_WARNING, "Second parameter $how needs to be one of STREAM_SHUT_RD, STREAM_SHUT_WR or STREAM_SHUT_RDWR");
                RETURN_FALSE;
        }
 
index 04b37ca1154b91868bfa3264ec0e6358702b50a5..ad75650b5033033798dd4e3a9c94eebf672ad8a2 100644 (file)
@@ -14,8 +14,8 @@ var_dump(stream_context_set_option($context, 'http'));
 var_dump(stream_context_set_option($context, array(), 'foo', 'bar'));
 ?>
 --EXPECTF--
-Warning: stream_context_set_option(): called with wrong number or type of parameters; please RTM in %s on line %d
+Warning: stream_context_set_option() expects parameter 2 to be array, string given in %s on line %d
 bool(false)
 
-Warning: stream_context_set_option(): called with wrong number or type of parameters; please RTM in %s on line %d
+Warning: stream_context_set_option() expects parameter 2 to be string, array given in %s on line %d
 bool(false)
index e80fd39ed86fb92331410a51283742c9bdb7b78f..ea3a5db85112abacaee6b4fad38f1a623707bc4b 100644 (file)
@@ -11,8 +11,8 @@ $context = stream_context_create();
 var_dump(stream_context_set_option($context));
 ?>
 --EXPECTF--
-Warning: stream_context_set_option(): called with wrong number or type of parameters; please RTM in %s on line %d
+Warning: stream_context_set_option() expects exactly 4 parameters, 0 given in %s on line %d
 bool(false)
 
-Warning: stream_context_set_option(): called with wrong number or type of parameters; please RTM in %s on line %d
+Warning: stream_context_set_option() expects exactly 4 parameters, 1 given in %s on line %d
 bool(false)