]> granicus.if.org Git - php/commitdiff
Add Z_PARAM_RESOURCE_OR_NULL()
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 9 Apr 2020 13:39:11 +0000 (15:39 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 9 Apr 2020 13:39:11 +0000 (15:39 +0200)
As a more explicit alternative to Z_PARAM_RESOURCE_EX(, 1, 0).

Zend/zend_API.h
ext/standard/file.c
ext/standard/url.c

index 799f1760ba55b3e108bebb034be55f44762942a5..16efa3422216e398b74f9293b78cdd801502c869 100644 (file)
@@ -1517,6 +1517,9 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_value_error(uint32_t arg_num
 #define Z_PARAM_RESOURCE(dest) \
        Z_PARAM_RESOURCE_EX(dest, 0, 0)
 
+#define Z_PARAM_RESOURCE_OR_NULL(dest) \
+       Z_PARAM_RESOURCE_EX(dest, 1, 0)
+
 /* old "s" */
 #define Z_PARAM_STRING_EX2(dest, dest_len, check_null, deref, separate) \
                Z_PARAM_PROLOGUE(deref, separate); \
index 5cde0ef978152c2d4694a980dfd5ec2d628b0eac..f6a75946d1440e881bc633eeed88d6104adafd6d 100644 (file)
@@ -534,7 +534,7 @@ PHP_FUNCTION(file_get_contents)
                Z_PARAM_PATH(filename, filename_len)
                Z_PARAM_OPTIONAL
                Z_PARAM_BOOL(use_include_path)
-               Z_PARAM_RESOURCE_EX(zcontext, 1, 0)
+               Z_PARAM_RESOURCE_OR_NULL(zcontext)
                Z_PARAM_LONG(offset)
                Z_PARAM_LONG(maxlen)
        ZEND_PARSE_PARAMETERS_END();
@@ -593,7 +593,7 @@ PHP_FUNCTION(file_put_contents)
                Z_PARAM_ZVAL(data)
                Z_PARAM_OPTIONAL
                Z_PARAM_LONG(flags)
-               Z_PARAM_RESOURCE_EX(zcontext, 1, 0)
+               Z_PARAM_RESOURCE_OR_NULL(zcontext)
        ZEND_PARSE_PARAMETERS_END();
 
        if (Z_TYPE_P(data) == IS_RESOURCE) {
@@ -738,7 +738,7 @@ PHP_FUNCTION(file)
                Z_PARAM_PATH(filename, filename_len)
                Z_PARAM_OPTIONAL
                Z_PARAM_LONG(flags)
-               Z_PARAM_RESOURCE_EX(zcontext, 1, 0)
+               Z_PARAM_RESOURCE_OR_NULL(zcontext)
        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)) {
@@ -879,7 +879,7 @@ PHP_FUNCTION(fopen)
                Z_PARAM_STRING(mode, mode_len)
                Z_PARAM_OPTIONAL
                Z_PARAM_BOOL(use_include_path)
-               Z_PARAM_RESOURCE_EX(zcontext, 1, 0)
+               Z_PARAM_RESOURCE_OR_NULL(zcontext)
        ZEND_PARSE_PARAMETERS_END();
 
        context = php_stream_context_from_zval(zcontext, 0);
@@ -1296,7 +1296,7 @@ PHP_FUNCTION(mkdir)
                Z_PARAM_OPTIONAL
                Z_PARAM_LONG(mode)
                Z_PARAM_BOOL(recursive)
-               Z_PARAM_RESOURCE_EX(zcontext, 1, 0)
+               Z_PARAM_RESOURCE_OR_NULL(zcontext)
        ZEND_PARSE_PARAMETERS_END();
 
        context = php_stream_context_from_zval(zcontext, 0);
@@ -1317,7 +1317,7 @@ PHP_FUNCTION(rmdir)
        ZEND_PARSE_PARAMETERS_START(1, 2)
                Z_PARAM_PATH(dir, dir_len)
                Z_PARAM_OPTIONAL
-               Z_PARAM_RESOURCE_EX(zcontext, 1, 0)
+               Z_PARAM_RESOURCE_OR_NULL(zcontext)
        ZEND_PARSE_PARAMETERS_END();
 
        context = php_stream_context_from_zval(zcontext, 0);
@@ -1342,7 +1342,7 @@ PHP_FUNCTION(readfile)
                Z_PARAM_PATH(filename, filename_len)
                Z_PARAM_OPTIONAL
                Z_PARAM_BOOL(use_include_path)
-               Z_PARAM_RESOURCE_EX(zcontext, 1, 0)
+               Z_PARAM_RESOURCE_OR_NULL(zcontext)
        ZEND_PARSE_PARAMETERS_END();
 
        context = php_stream_context_from_zval(zcontext, 0);
@@ -1419,7 +1419,7 @@ PHP_FUNCTION(rename)
                Z_PARAM_PATH(old_name, old_name_len)
                Z_PARAM_PATH(new_name, new_name_len)
                Z_PARAM_OPTIONAL
-               Z_PARAM_RESOURCE_EX(zcontext, 1, 0)
+               Z_PARAM_RESOURCE_OR_NULL(zcontext)
        ZEND_PARSE_PARAMETERS_END();
 
        wrapper = php_stream_locate_url_wrapper(old_name, NULL, 0);
@@ -1458,7 +1458,7 @@ PHP_FUNCTION(unlink)
        ZEND_PARSE_PARAMETERS_START(1, 2)
                Z_PARAM_PATH(filename, filename_len)
                Z_PARAM_OPTIONAL
-               Z_PARAM_RESOURCE_EX(zcontext, 1, 0)
+               Z_PARAM_RESOURCE_OR_NULL(zcontext)
        ZEND_PARSE_PARAMETERS_END();
 
        context = php_stream_context_from_zval(zcontext, 0);
@@ -1603,7 +1603,7 @@ PHP_FUNCTION(copy)
                Z_PARAM_PATH(source, source_len)
                Z_PARAM_PATH(target, target_len)
                Z_PARAM_OPTIONAL
-               Z_PARAM_RESOURCE_EX(zcontext, 1, 0)
+               Z_PARAM_RESOURCE_OR_NULL(zcontext)
        ZEND_PARSE_PARAMETERS_END();
 
        if (php_check_open_basedir(source)) {
index f2ef2c16d93a930fcab6a2f848a720edfeed5559..e3e04a9cd9e588525513967f254d10aaf1a97e60 100644 (file)
@@ -672,7 +672,7 @@ PHP_FUNCTION(get_headers)
                Z_PARAM_PATH(url, url_len)
                Z_PARAM_OPTIONAL
                Z_PARAM_LONG(format)
-               Z_PARAM_RESOURCE_EX(zcontext, 1, 0)
+               Z_PARAM_RESOURCE_OR_NULL(zcontext)
        ZEND_PARSE_PARAMETERS_END();
 
        context = php_stream_context_from_zval(zcontext, 0);