summaryrefslogtreecommitdiffstats
path: root/m_option.h
diff options
context:
space:
mode:
authorUoti Urpala <uau@mplayer2.org>2012-05-20 01:26:38 +0300
committerUoti Urpala <uau@mplayer2.org>2012-07-16 21:08:42 +0300
commit48f0692ab973448de5faa323478d1cba3d42e2af (patch)
tree0d00001f5ad9f04e64613c9759c38be5c80b9f10 /m_option.h
parentdc2a4863af9b0e587ac4ec3e2096639098e99a8f (diff)
downloadmpv-48f0692ab973448de5faa323478d1cba3d42e2af.tar.bz2
mpv-48f0692ab973448de5faa323478d1cba3d42e2af.tar.xz
options: make option struct the talloc parent of options
Allocate dynamically-allocated option values as talloc children of the option struct. This will allow implementing per-object (VO etc) options so that simply freeing the object will free associated options too. This doesn't change quite every allocation in m_option.c, but the exceptions are legacy types which will not matter for new per-object options.
Diffstat (limited to 'm_option.h')
-rw-r--r--m_option.h11
1 files changed, 7 insertions, 4 deletions
diff --git a/m_option.h b/m_option.h
index 9b355ff3e0..648c560305 100644
--- a/m_option.h
+++ b/m_option.h
@@ -192,11 +192,12 @@ struct m_option_type {
* may not be an argument meant for this option
* \param dst Pointer to the memory where the data should be written.
* If NULL the parameter validity should still be checked.
+ * talloc_ctx: talloc context if value type requires allocations
* \return On error a negative value is returned, on success the number
* of arguments consumed. For details see \ref OptionParserReturn.
*/
int (*parse)(const m_option_t *opt, struct bstr name, struct bstr param,
- bool ambiguous_param, void *dst);
+ bool ambiguous_param, void *dst, void *talloc_ctx);
// Print back a value in string form.
/** \param opt The option to print.
@@ -210,8 +211,10 @@ struct m_option_type {
/** \param opt The option to copy.
* \param dst Pointer to the destination memory.
* \param src Pointer to the source memory.
+ * talloc_ctx: talloc context to use in deep copy
*/
- void (*copy)(const m_option_t *opt, void *dst, const void *src);
+ void (*copy)(const m_option_t *opt, void *dst, const void *src,
+ void *talloc_ctx);
// Free the data allocated for a save slot.
/** This is only needed for dynamic types like strings.
@@ -385,7 +388,7 @@ static inline int m_option_parse(const m_option_t *opt, struct bstr name,
struct bstr param, bool ambiguous_param,
void *dst)
{
- return opt->type->parse(opt, name, param, ambiguous_param, dst);
+ return opt->type->parse(opt, name, param, ambiguous_param, dst, NULL);
}
// Helper to print options, see \ref m_option_type::print.
@@ -402,7 +405,7 @@ static inline void m_option_copy(const m_option_t *opt, void *dst,
const void *src)
{
if (opt->type->copy)
- opt->type->copy(opt, dst, src);
+ opt->type->copy(opt, dst, src, NULL);
}
// Helper around \ref m_option_type::free.