[FFmpeg-devel] [PATCH 1/3] avutil/dict: add av_dict_pop

Anton Khirnov anton at khirnov.net
Mon Jun 5 13:04:52 EEST 2023


Quoting Marvin Scholz (2023-05-01 13:44:54)
> diff --git a/libavutil/dict.h b/libavutil/dict.h
> index 713c9e361a..b2ab55a026 100644
> --- a/libavutil/dict.h
> +++ b/libavutil/dict.h
> @@ -172,6 +172,26 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags
>   */
>  int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags);
>  
> +/**
> + * Remove the entry with the given key from the dictionary.
> + *
> + * Search for an entry matching `key` and remove it, if found. Optionally
> + * the found key and/or value can be returned using the `out_key`/`out_value`
> + * arguments.
> + *
> + * If more than one entry matches, only one entry is removed and returned
> + * on each call. Which entry is returned first in that case is undefined.
> + *
> + * @param pm        Pointer to a pointer to a dictionary struct.
> + * @param key       Entry key to match.
> + * @param out_key   Pointer whose pointee will be set to the matched
> + *                  entry key. Must be freed by the caller. May be NULL.
> + * @param out_value Pointer whose pointee will be set to the matched
> + *                  entry value. Must be freed by the caller. May be NULL.

freed using av_free()

Should also mention what the function's return value is.


> diff --git a/tests/ref/fate/dict b/tests/ref/fate/dict
> index 7205e4c845..bdb097cb03 100644
> --- a/tests/ref/fate/dict
> +++ b/tests/ref/fate/dict
> @@ -48,3 +48,15 @@ Testing av_dict_set_int()
>  Testing av_dict_set() with existing AVDictionaryEntry.key as key
>  new val OK
>  new val OK
> +
> +Testing av_dict_pop() with existing AVDictionaryEntry.key as key
> +test-key: test-value (Return code: 0)
> +(null)
> +
> +Testing av_dict_pop() with nonexistent key
> +(null): (null) (Return code: -2)

I don't think anything guarantees that ENOENT has to be -2 on all
platforms we support.

-- 
Anton Khirnov


More information about the ffmpeg-devel mailing list