From 3f006eced47b35b7d752fdc19c22a7f39f970975 Mon Sep 17 00:00:00 2001 From: Philip Langdale Date: Sat, 20 Feb 2021 16:41:44 -0800 Subject: options: Make validation and help possible for all option types Today, validation is only possible for string type options. But there's no particular reason why it needs to be restricted in this way, and there are potential uses, to allow other options to be validated without forcing the option to have to reimplement parsing from scratch. The first part, simply making the validation function an explicit field instead of overloading priv is simple enough. But if we only do that, then the validation function still needs to deal with the raw pre-parsed string. Instead, we want to allow the value to be parsed before it is validated. That in turn leads to us having validator functions that should be type aware. Unfortunately, that means we need to keep the explicit macro like OPT_STRING_VALIDATE() as a way to enforce the correct typing of the function. Otherwise, we'd have to have the validator take a void * and hope the implementation can cast it correctly. For help, we don't have this problem, as help doesn't look at the value. Then, we turn validators that are really help generators into explicit help functions and where a validator is help + validation, we split them into two parts. I have, however, left functions that need to query information for both help and validation as single functions to avoid code duplication. In this change, I have not added an other OPT_FOO_VALIDATE() macros as they are not needed, but I will add some in a separate change to illustrate the pattern. --- video/out/vulkan/context.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'video/out/vulkan/context.c') diff --git a/video/out/vulkan/context.c b/video/out/vulkan/context.c index 3518d3efd2..9bdeb14d9b 100644 --- a/video/out/vulkan/context.c +++ b/video/out/vulkan/context.c @@ -31,8 +31,9 @@ struct vulkan_opts { }; static int vk_validate_dev(struct mp_log *log, const struct m_option *opt, - struct bstr name, struct bstr param) + struct bstr name, const char **value) { + struct bstr param = bstr0(*value); int ret = M_OPT_INVALID; VkResult res; -- cgit v1.2.3