From: Sara Golemon Date: Sat, 31 Dec 2016 01:52:31 +0000 (-0800) Subject: Use new param API in standard/file X-Git-Tag: php-7.2.0alpha1~713 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2ea5b64d9a549a0e0a7e51a7682a3b4c903b63d4;p=php Use new param API in standard/file --- diff --git a/ext/standard/file.c b/ext/standard/file.c index f5f489d43f..b41704edde 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -337,9 +337,12 @@ PHP_FUNCTION(flock) php_stream *stream; zend_long operation = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl|z/", &res, &operation, &wouldblock) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_RESOURCE(res) + Z_PARAM_LONG(operation) + Z_PARAM_OPTIONAL + Z_PARAM_ZVAL_DEREF_EX(wouldblock, 0, 1) + ZEND_PARSE_PARAMETERS_END(); PHP_STREAM_TO_ZVAL(stream, res); @@ -386,9 +389,11 @@ PHP_FUNCTION(get_meta_tags) memset(&md, 0, sizeof(md)); /* Parse arguments */ - if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|b", &filename, &filename_len, &use_include_path) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_PATH(filename, filename_len) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(use_include_path) + ZEND_PARSE_PARAMETERS_END(); md.stream = php_stream_open_wrapper(filename, "rb", (use_include_path ? USE_PATH : 0) | REPORT_ERRORS, @@ -526,9 +531,14 @@ PHP_FUNCTION(file_get_contents) zend_string *contents; /* Parse arguments */ - if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|br!ll", &filename, &filename_len, &use_include_path, &zcontext, &offset, &maxlen) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(1, 5) + Z_PARAM_PATH(filename, filename_len) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(use_include_path) + Z_PARAM_RESOURCE_EX(zcontext, 1, 0) + Z_PARAM_LONG(offset) + Z_PARAM_LONG(maxlen) + ZEND_PARSE_PARAMETERS_END(); if (ZEND_NUM_ARGS() == 5 && maxlen < 0) { php_error_docref(NULL, E_WARNING, "length must be greater than or equal to zero"); @@ -579,9 +589,13 @@ PHP_FUNCTION(file_put_contents) php_stream *srcstream = NULL; char mode[3] = "wb"; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "pz/|lr!", &filename, &filename_len, &data, &flags, &zcontext) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(2, 4) + Z_PARAM_PATH(filename, filename_len) + Z_PARAM_ZVAL_DEREF_EX(data, 0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(flags) + Z_PARAM_RESOURCE_EX(zcontext, 1, 0) + ZEND_PARSE_PARAMETERS_END(); if (Z_TYPE_P(data) == IS_RESOURCE) { php_stream_from_zval(srcstream, data); @@ -720,9 +734,13 @@ PHP_FUNCTION(file) zend_string *target_buf; /* Parse arguments */ - if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|lr!", &filename, &filename_len, &flags, &zcontext) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(1, 3) + Z_PARAM_PATH(filename, filename_len) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(flags) + Z_PARAM_RESOURCE_EX(zcontext, 1, 0) + ZEND_PARSE_PARAMETERS_END(); + if (flags < 0 || flags > (PHP_FILE_USE_INCLUDE_PATH | PHP_FILE_IGNORE_NEW_LINES | PHP_FILE_SKIP_EMPTY_LINES | PHP_FILE_NO_DEFAULT_CONTEXT)) { php_error_docref(NULL, E_WARNING, "'" ZEND_LONG_FMT "' flag is not supported", flags); RETURN_FALSE; @@ -803,9 +821,10 @@ PHP_FUNCTION(tempnam) int fd; zend_string *p; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "pp", &dir, &dir_len, &prefix, &prefix_len) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_PATH(dir, dir_len) + Z_PARAM_PATH(prefix, prefix_len) + ZEND_PARSE_PARAMETERS_END(); if (php_check_open_basedir(dir)) { RETURN_FALSE; @@ -857,9 +876,13 @@ PHP_NAMED_FUNCTION(php_if_fopen) php_stream *stream; php_stream_context *context = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ps|br", &filename, &filename_len, &mode, &mode_len, &use_include_path, &zcontext) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(2, 4) + Z_PARAM_PATH(filename, filename_len) + Z_PARAM_STRING(mode, mode_len) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(use_include_path) + Z_PARAM_RESOURCE(zcontext) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); context = php_stream_context_from_zval(zcontext, 0); @@ -909,9 +932,10 @@ PHP_FUNCTION(popen) php_stream *stream; char *posix_mode; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ps", &command, &command_len, &mode, &mode_len) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_PATH(command, command_len) + Z_PARAM_STRING(mode, mode_len) + ZEND_PARSE_PARAMETERS_END(); posix_mode = estrndup(mode, mode_len); #ifndef PHP_WIN32 @@ -950,9 +974,9 @@ PHP_FUNCTION(pclose) zval *res; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &res) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_RESOURCE(res) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); PHP_STREAM_TO_ZVAL(stream, res); @@ -1045,9 +1069,9 @@ PHPAPI PHP_FUNCTION(fgetc) int result; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &res) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_RESOURCE(res) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); PHP_STREAM_TO_ZVAL(stream, res); @@ -1077,9 +1101,12 @@ PHPAPI PHP_FUNCTION(fgetss) char *allowed_tags=NULL; size_t allowed_tags_len=0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|ls", &fd, &bytes, &allowed_tags, &allowed_tags_len) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 3) + Z_PARAM_RESOURCE(fd) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(bytes) + Z_PARAM_STRING(allowed_tags, allowed_tags_len) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); PHP_STREAM_TO_ZVAL(stream, fd); @@ -1122,9 +1149,11 @@ PHP_FUNCTION(fscanf) size_t len; void *what; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs*", &file_handle, &format, &format_len, &args, &argc) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(2, -1) + Z_PARAM_RESOURCE(file_handle) + Z_PARAM_STRING(format, format_len) + Z_PARAM_VARIADIC('*', args, argc) + ZEND_PARSE_PARAMETERS_END(); what = zend_fetch_resource2(Z_RES_P(file_handle), "File-Handle", php_file_le_stream(), php_file_le_pstream()); @@ -1310,9 +1339,13 @@ PHP_FUNCTION(mkdir) zend_bool recursive = 0; php_stream_context *context; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|lbr", &dir, &dir_len, &mode, &recursive, &zcontext) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 4) + Z_PARAM_PATH(dir, dir_len) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(mode) + Z_PARAM_BOOL(recursive) + Z_PARAM_RESOURCE(zcontext) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); context = php_stream_context_from_zval(zcontext, 0); @@ -1329,9 +1362,11 @@ PHP_FUNCTION(rmdir) zval *zcontext = NULL; php_stream_context *context; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|r", &dir, &dir_len, &zcontext) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_PATH(dir, dir_len) + Z_PARAM_OPTIONAL + Z_PARAM_RESOURCE(zcontext) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); context = php_stream_context_from_zval(zcontext, 0); @@ -1351,9 +1386,12 @@ PHP_FUNCTION(readfile) php_stream *stream; php_stream_context *context = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|br!", &filename, &filename_len, &use_include_path, &zcontext) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 3) + Z_PARAM_PATH(filename, filename_len) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(use_include_path) + Z_PARAM_RESOURCE_EX(zcontext, 1, 0) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); context = php_stream_context_from_zval(zcontext, 0); @@ -1381,9 +1419,10 @@ PHP_FUNCTION(umask) BG(umask) = oldumask; } - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &mask) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(mask) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); if (ZEND_NUM_ARGS() == 0) { umask(oldumask); @@ -1403,9 +1442,9 @@ PHPAPI PHP_FUNCTION(fpassthru) size_t size; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &res) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_RESOURCE(res) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); PHP_STREAM_TO_ZVAL(stream, res); @@ -1424,9 +1463,12 @@ PHP_FUNCTION(rename) php_stream_wrapper *wrapper; php_stream_context *context; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "pp|r", &old_name, &old_name_len, &new_name, &new_name_len, &zcontext) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_PATH(old_name, old_name_len) + Z_PARAM_PATH(new_name, new_name_len) + Z_PARAM_OPTIONAL + Z_PARAM_RESOURCE(zcontext) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); wrapper = php_stream_locate_url_wrapper(old_name, NULL, 0); @@ -1461,9 +1503,11 @@ PHP_FUNCTION(unlink) zval *zcontext = NULL; php_stream_context *context = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|r", &filename, &filename_len, &zcontext) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_PATH(filename, filename_len) + Z_PARAM_OPTIONAL + Z_PARAM_RESOURCE(zcontext) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); context = php_stream_context_from_zval(zcontext, 0); @@ -1490,9 +1534,10 @@ PHP_NAMED_FUNCTION(php_if_ftruncate) zend_long size; php_stream *stream; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &fp, &size) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_RESOURCE(fp) + Z_PARAM_LONG(size) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); if (size < 0) { php_error_docref(NULL, E_WARNING, "Negative size is not supported"); @@ -1524,9 +1569,9 @@ PHP_NAMED_FUNCTION(php_if_fstat) "size", "atime", "mtime", "ctime", "blksize", "blocks" }; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &fp) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_RESOURCE(fp) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); PHP_STREAM_TO_ZVAL(stream, fp); @@ -1614,9 +1659,12 @@ PHP_FUNCTION(copy) zval *zcontext = NULL; php_stream_context *context; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "pp|r", &source, &source_len, &target, &target_len, &zcontext) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_PATH(source, source_len) + Z_PARAM_PATH(target, target_len) + Z_PARAM_OPTIONAL + Z_PARAM_RESOURCE(zcontext) + ZEND_PARSE_PARAMETERS_END(); if (php_check_open_basedir(source)) { RETURN_FALSE; @@ -1823,12 +1871,14 @@ PHP_FUNCTION(fputcsv) char *delimiter_str = NULL, *enclosure_str = NULL, *escape_str = NULL; size_t delimiter_str_len = 0, enclosure_str_len = 0, escape_str_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ra|sss", - &fp, &fields, &delimiter_str, &delimiter_str_len, - &enclosure_str, &enclosure_str_len, - &escape_str, &escape_str_len) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(2, 5) + Z_PARAM_RESOURCE(fp) + Z_PARAM_ARRAY(fields) + Z_PARAM_OPTIONAL + Z_PARAM_STRING(delimiter_str, delimiter_str_len) + Z_PARAM_STRING(enclosure_str, enclosure_str_len) + Z_PARAM_STRING(escape_str, escape_str_len) + ZEND_PARSE_PARAMETERS_END(); if (delimiter_str != NULL) { /* Make sure that there is at least one character in string */ @@ -1955,13 +2005,14 @@ PHP_FUNCTION(fgetcsv) char *escape_str = NULL; size_t escape_str_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|zsss", - &fd, &len_zv, &delimiter_str, &delimiter_str_len, - &enclosure_str, &enclosure_str_len, - &escape_str, &escape_str_len) == FAILURE - ) { - return; - } + ZEND_PARSE_PARAMETERS_START(1, 5) + Z_PARAM_RESOURCE(fd) + Z_PARAM_OPTIONAL + Z_PARAM_ZVAL_DEREF(len_zv) + Z_PARAM_STRING(delimiter_str, delimiter_str_len) + Z_PARAM_STRING(enclosure_str, enclosure_str_len) + Z_PARAM_STRING(escape_str, escape_str_len) + ZEND_PARSE_PARAMETERS_END(); if (delimiter_str != NULL) { /* Make sure that there is at least one character in string */ @@ -2436,9 +2487,12 @@ PHP_FUNCTION(fnmatch) size_t pattern_len, filename_len; zend_long flags = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "pp|l", &pattern, &pattern_len, &filename, &filename_len, &flags) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_PATH(pattern, pattern_len) + Z_PARAM_PATH(filename, filename_len) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(flags) + ZEND_PARSE_PARAMETERS_END(); if (filename_len >= MAXPATHLEN) { php_error_docref(NULL, E_WARNING, "Filename exceeds the maximum allowed length of %d characters", MAXPATHLEN);