summaryrefslogtreecommitdiffstats
path: root/core/m_option.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-03-01 11:21:13 +0100
committerwm4 <wm4@nowhere>2013-03-01 11:21:13 +0100
commit9180263c4d7174def26d07eb3e91fe4b459d9698 (patch)
tree186d74c496949241dd7226b5dc43273add7aabf0 /core/m_option.c
parentfdc1560a0ed31f0c275c47ac8cb7521c0c636ddf (diff)
downloadmpv-9180263c4d7174def26d07eb3e91fe4b459d9698.tar.bz2
mpv-9180263c4d7174def26d07eb3e91fe4b459d9698.tar.xz
m_options: more typesafety
Change the option definition macros so that they cause compiler warnings if the type of the referenced option struct member doesn't match the type implied by the macro. The compiler warning printed isn't very telling, but it's better than silently invoking undefined behavior by violating the C strict aliasing rules. Also fix some minor cases that violate the type rules. For the option "no-aspect" we have to add a new option type to handle it properly. Some option types are hard to check, so we don't in these cases.
Diffstat (limited to 'core/m_option.c')
-rw-r--r--core/m_option.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/core/m_option.c b/core/m_option.c
index 507d6cc2c7..6d011ee141 100644
--- a/core/m_option.c
+++ b/core/m_option.c
@@ -179,6 +179,34 @@ const m_option_type_t m_option_type_store = {
.parse = parse_store,
};
+// Same for float types
+
+#undef VAL
+#define VAL(x) (*(float *)(x))
+
+static int parse_store_float(const m_option_t *opt, struct bstr name,
+ struct bstr param, void *dst)
+{
+ if (param.len == 0 || bstrcasecmp0(param, "yes") == 0) {
+ if (dst)
+ VAL(dst) = opt->max;
+ return 0;
+ } else {
+ mp_msg(MSGT_CFGPARSER, MSGL_ERR,
+ "Invalid parameter for %.*s flag: %.*s\n",
+ BSTR_P(name), BSTR_P(param));
+ return M_OPT_DISALLOW_PARAM;
+ }
+}
+
+const m_option_type_t m_option_type_float_store = {
+ // can only be activated
+ .name = "Flag",
+ .size = sizeof(float),
+ .flags = M_OPT_TYPE_OPTIONAL_PARAM,
+ .parse = parse_store_float,
+};
+
// Integer
#undef VAL