From 4836660b9070b9eef0d30b8ba43f8c82dbbded1f Mon Sep 17 00:00:00 2001 From: Craig Duncan Date: Mon, 26 Aug 2019 17:21:38 +0200 Subject: [PATCH] Convert fileinfo functions arginfo to php stubs We also allow the context for finfo to be null. --- ext/fileinfo/fileinfo.c | 63 ++++----------------------------- ext/fileinfo/fileinfo.stub.php | 54 ++++++++++++++++++++++++++++ ext/fileinfo/fileinfo_arginfo.h | 51 ++++++++++++++++++++++++++ 3 files changed, 112 insertions(+), 56 deletions(-) create mode 100644 ext/fileinfo/fileinfo.stub.php create mode 100644 ext/fileinfo/fileinfo_arginfo.h diff --git a/ext/fileinfo/fileinfo.c b/ext/fileinfo/fileinfo.c index 621e82c75a..2c5e4209c7 100644 --- a/ext/fileinfo/fileinfo.c +++ b/ext/fileinfo/fileinfo.c @@ -34,6 +34,7 @@ #include "ext/standard/info.h" #include "ext/standard/file.h" /* needed for context stuff */ #include "php_fileinfo.h" +#include "fileinfo_arginfo.h" #include "fopen_wrappers.h" /* needed for is_url */ #include "Zend/zend_exceptions.h" @@ -108,63 +109,13 @@ PHP_FILEINFO_API zend_object *finfo_objects_new(zend_class_entry *class_type) } /* }}} */ -/* {{{ arginfo */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_open, 0, 0, 0) - ZEND_ARG_INFO(0, options) - ZEND_ARG_INFO(0, arg) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_close, 0, 0, 1) - ZEND_ARG_INFO(0, finfo) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_set_flags, 0, 0, 2) - ZEND_ARG_INFO(0, finfo) - ZEND_ARG_INFO(0, options) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_method_set_flags, 0, 0, 1) - ZEND_ARG_INFO(0, options) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_file, 0, 0, 2) - ZEND_ARG_INFO(0, finfo) - ZEND_ARG_INFO(0, filename) - ZEND_ARG_INFO(0, options) - ZEND_ARG_INFO(0, context) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_method_file, 0, 0, 1) - ZEND_ARG_INFO(0, filename) - ZEND_ARG_INFO(0, options) - ZEND_ARG_INFO(0, context) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_buffer, 0, 0, 2) - ZEND_ARG_INFO(0, finfo) - ZEND_ARG_INFO(0, string) - ZEND_ARG_INFO(0, options) - ZEND_ARG_INFO(0, context) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_method_buffer, 0, 0, 1) - ZEND_ARG_INFO(0, string) - ZEND_ARG_INFO(0, options) - ZEND_ARG_INFO(0, context) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_mime_content_type, 0, 0, 1) - ZEND_ARG_INFO(0, string) -ZEND_END_ARG_INFO() -/* }}} */ - /* {{{ finfo_class_functions */ static const zend_function_entry finfo_class_functions[] = { - ZEND_ME_MAPPING(__construct, finfo_open, arginfo_finfo_open, ZEND_ACC_PUBLIC) - ZEND_ME_MAPPING(set_flags, finfo_set_flags,arginfo_finfo_method_set_flags, ZEND_ACC_PUBLIC) - ZEND_ME_MAPPING(file, finfo_file, arginfo_finfo_method_file, ZEND_ACC_PUBLIC) - ZEND_ME_MAPPING(buffer, finfo_buffer, arginfo_finfo_method_buffer, ZEND_ACC_PUBLIC) + ZEND_ME_MAPPING(__construct, finfo_open, arginfo_class_finfo___construct, ZEND_ACC_PUBLIC) + ZEND_ME_MAPPING(set_flags, finfo_set_flags,arginfo_class_finfo_set_flags, ZEND_ACC_PUBLIC) + ZEND_ME_MAPPING(file, finfo_file, arginfo_class_finfo_file, ZEND_ACC_PUBLIC) + ZEND_ME_MAPPING(buffer, finfo_buffer, arginfo_class_finfo_buffer, ZEND_ACC_PUBLIC) PHP_FE_END }; /* }}} */ @@ -470,13 +421,13 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mime goto common; } } else if (object) { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|lr", &buffer, &buffer_len, &options, &zcontext) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|lr!", &buffer, &buffer_len, &options, &zcontext) == FAILURE) { return; } FILEINFO_FROM_OBJECT(finfo, object); magic = finfo->magic; } else { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|lr", &zfinfo, &buffer, &buffer_len, &options, &zcontext) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|lr!", &zfinfo, &buffer, &buffer_len, &options, &zcontext) == FAILURE) { return; } if ((finfo = (php_fileinfo *)zend_fetch_resource(Z_RES_P(zfinfo), "file_info", le_fileinfo)) == NULL) { diff --git a/ext/fileinfo/fileinfo.stub.php b/ext/fileinfo/fileinfo.stub.php new file mode 100644 index 0000000000..1b7a3b7562 --- /dev/null +++ b/ext/fileinfo/fileinfo.stub.php @@ -0,0 +1,54 @@ +