diff options
author | wm4 <wm4@nowhere> | 2012-09-18 16:08:17 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2012-10-12 10:10:31 +0200 |
commit | 426640204b409d1034a1c32ad01b9bc547e93684 (patch) | |
tree | 8dda3035239acb0b7cfea30dd8f05813bd444bce /m_config.c | |
parent | 1a5a7a49293c2c70a5caf9d51dad7bd5aa938471 (diff) | |
download | mpv-426640204b409d1034a1c32ad01b9bc547e93684.tar.bz2 mpv-426640204b409d1034a1c32ad01b9bc547e93684.tar.xz |
options: simplify somewhat by introducing a union for option values
The m_option_value union is supposed to contain a field for each
possible option type (as long as it actually stores data). This helps
avoiding silly temporary memory alocations. Using a pointer to an union
and to a field of the union interchangeably should be allowed by
standard C.
Diffstat (limited to 'm_config.c')
-rw-r--r-- | m_config.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/m_config.c b/m_config.c index 56886e08eb..444847f123 100644 --- a/m_config.c +++ b/m_config.c @@ -330,15 +330,14 @@ static void m_config_add_option(struct m_config *config, } else if (arg->type->flags & M_OPT_TYPE_DYNAMIC) { // Initialize dynamically managed fields from static data (like // string options): copy the option into temporary memory, - // clear the original option (to void m_option freeing the + // clear the original option (to stop m_option from freeing the // static data), copy it back. if (co->data) { - void *temp = talloc_zero_size(NULL, arg->type->size); - m_option_copy(arg, temp, co->data); + union m_option_value temp = {0}; + m_option_copy(arg, &temp, co->data); memset(co->data, 0, arg->type->size); - m_option_copy(arg, co->data, temp); - m_option_free(arg, temp); - talloc_free(temp); + m_option_copy(arg, co->data, &temp); + m_option_free(arg, &temp); } } } |