diff mbox series

[FFmpeg-devel,2/3] avformat/tee: use av_dict_pop

Message ID 20230501114456.13898-2-epirat07@gmail.com
State Superseded
Headers show
Series [FFmpeg-devel,1/3] avutil/dict: add av_dict_pop | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Marvin Scholz May 1, 2023, 11:44 a.m. UTC
This is a well-defined way to "steal" the value of the dict entry.
---
 libavformat/tee.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Zhao Zhili June 25, 2023, 12:07 p.m. UTC | #1
> On May 1, 2023, at 19:44, Marvin Scholz <epirat07@gmail.com> wrote:
> 
> This is a well-defined way to "steal" the value of the dict entry.
> ---
> libavformat/tee.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/libavformat/tee.c b/libavformat/tee.c
> index cb555f52fd..70f3f2eb29 100644
> --- a/libavformat/tee.c
> +++ b/libavformat/tee.c
> @@ -157,6 +157,7 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
> {
>     int i, ret;
>     AVDictionary *options = NULL, *bsf_options = NULL;
> +    char *entry_val = NULL;
>     AVDictionaryEntry *entry;
>     char *filename;
>     char *format = NULL, *select = NULL, *on_fail = NULL;
> @@ -171,15 +172,15 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
>         return ret;
> 
> #define CONSUME_OPTION(option, field, action) do {                      \
> -        if ((entry = av_dict_get(options, option, NULL, 0))) {          \
> -            field = entry->value;                                       \
> +        if ((!av_dict_pop(&options, option, NULL, &entry_val, 0))) {    \
> +            field = entry_val;                                          \

Nit: You can remove the extra level of parentheses now.

>             { action }                                                  \
> -            av_dict_set(&options, option, NULL, 0);                     \
> +            av_freep(&entry_val);                                       \
>         }                                                               \
>     } while (0)
> #define STEAL_OPTION(option, field)                                     \
>     CONSUME_OPTION(option, field,                                       \
> -                   entry->value = NULL; /* prevent it from being freed */)
> +                   entry_val = NULL; /* prevent it from being freed */)
> #define PROCESS_OPTION(option, field, function, on_error)               \
>     CONSUME_OPTION(option, field, if ((ret = function) < 0) { { on_error } goto end; })
> 
> -- 
> 2.37.0 (Apple Git-136)
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavformat/tee.c b/libavformat/tee.c
index cb555f52fd..70f3f2eb29 100644
--- a/libavformat/tee.c
+++ b/libavformat/tee.c
@@ -157,6 +157,7 @@  static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
 {
     int i, ret;
     AVDictionary *options = NULL, *bsf_options = NULL;
+    char *entry_val = NULL;
     AVDictionaryEntry *entry;
     char *filename;
     char *format = NULL, *select = NULL, *on_fail = NULL;
@@ -171,15 +172,15 @@  static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
         return ret;
 
 #define CONSUME_OPTION(option, field, action) do {                      \
-        if ((entry = av_dict_get(options, option, NULL, 0))) {          \
-            field = entry->value;                                       \
+        if ((!av_dict_pop(&options, option, NULL, &entry_val, 0))) {    \
+            field = entry_val;                                          \
             { action }                                                  \
-            av_dict_set(&options, option, NULL, 0);                     \
+            av_freep(&entry_val);                                       \
         }                                                               \
     } while (0)
 #define STEAL_OPTION(option, field)                                     \
     CONSUME_OPTION(option, field,                                       \
-                   entry->value = NULL; /* prevent it from being freed */)
+                   entry_val = NULL; /* prevent it from being freed */)
 #define PROCESS_OPTION(option, field, function, on_error)               \
     CONSUME_OPTION(option, field, if ((ret = function) < 0) { { on_error } goto end; })