From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id C318E40AE1 for ; Sun, 2 Jul 2023 08:43:20 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ABFA868C09C; Sun, 2 Jul 2023 11:43:16 +0300 (EEST) Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3A99068BF9B for ; Sun, 2 Jul 2023 11:43:11 +0300 (EEST) Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-98934f000a5so390640466b.2 for ; Sun, 02 Jul 2023 01:43:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688287390; x=1690879390; h=user-agent:in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=SElSH1tQU2HDPVrrcDKWnNdMnqmBqAOfa6X3SIFSCDo=; b=MLN+APB8X0pTjMguTfH/bB1PSXqKTGgTYTAVrMXuJTqIie9uHrh46H/Rqru+qXAYGs 0LiYyI7pdFvTOWSaImPD8sBp7lhY6z5lO0nmyZigEj0N8RRf5FfTPdI/HMagKScM7vAM LRGr1Qbuqy8bhvh2I8gwnNl3UV51DffiTQXo6QSxpwms2TWe8NP54evQ/sqFULARvX2c 6RSZu7wUX6VrWw2UpDu86YN+ZrqQ5SK5vMZOY4zxUl3jsJI+9qsdf3zWHmFDgiDRDs+l bWsaGedV9hQfK3WDnwAgNuOYAWMI8xEHrxCSk0me5m1N5g+fy2wV3ujWkPTAgGNnDsFh f8vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688287390; x=1690879390; h=user-agent:in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=SElSH1tQU2HDPVrrcDKWnNdMnqmBqAOfa6X3SIFSCDo=; b=dd7ILWN1fnBxKbhAl6ckV6XIaeLMNp31M5rgMg7X1OfxW2WYEmnwMdzqAyqrIX9cVP b/2JIXlfEaHYXJQK3tVwRQszISjKySkYRFR1SxWisuKLVOkZ6xnXES0+6BLlM+RwwIyT ufTM/fRM3nLX1cSoJsC1dyqEAYZtGg1tkvwIaCOhajJZhRSlsE+EkkVpzOlSgbdkW1ws S96T9txfAhz7BHQrUT0HC5g5GhFXohB6OkQFUPpVlVveRgzph5DIfGUGQFxTL7doB/H+ PkViPodGGH0ArBAPlhizcrMu7Mb3dVjZmK6H9wCclpWb7eQ1HVwenQ6yJQIIQ7OStXq8 lGBw== X-Gm-Message-State: ABy/qLaVC/T+LXx9VW4eK2jw9KYHB7GnkqBd7ffrbF0OhceWFQ2g+HbH L351mKb8cDE0ixFk5NMZ9IWx4jTVeAM= X-Google-Smtp-Source: APBJJlGLu2tGN9TqOrTDn6d0c3GesmXrffmJqTH6Sxe2cGhKBi091pPmaDUN0UsaTy64N1EpMq6xfQ== X-Received: by 2002:a17:906:d8d1:b0:974:1ef1:81ad with SMTP id re17-20020a170906d8d100b009741ef181admr4706316ejb.4.1688287389465; Sun, 02 Jul 2023 01:43:09 -0700 (PDT) Received: from mariano ([91.254.84.241]) by smtp.gmail.com with ESMTPSA id k7-20020a170906a38700b00985ed2f1584sm10161769ejz.187.2023.07.02.01.43.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jul 2023 01:43:08 -0700 (PDT) Received: by mariano (Postfix, from userid 1000) id 55BCCBFB73; Sun, 2 Jul 2023 10:43:07 +0200 (CEST) Date: Sun, 2 Jul 2023 10:43:07 +0200 From: Stefano Sabatini To: FFmpeg development discussions and patches Message-ID: <20230702084307.GA4218@mariano> Mail-Followup-To: FFmpeg development discussions and patches References: <20230501114456.13898-1-epirat07@gmail.com> <20230625104907.53071-1-epirat07@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230625104907.53071-1-epirat07@gmail.com> User-Agent: Mutt/1.13.2 (2019-12-18) Subject: Re: [FFmpeg-devel] [PATCH v2 1/3] avutil/dict: add av_dict_pop X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On date Sunday 2023-06-25 12:49:05 +0200, Marvin Scholz wrote: > This new API allows to remove an entry and obtain ownership of the > key/value that was associated with the removed entry. > --- > > Changes since v1: > - Clarify documentation about av_free having to be used. > - Fix fate test to not rely on specific error code value > > doc/APIchanges | 4 ++++ > libavutil/dict.c | 27 +++++++++++++++++++++++++++ > libavutil/dict.h | 26 ++++++++++++++++++++++++++ > libavutil/tests/dict.c | 38 ++++++++++++++++++++++++++++++++++++++ > libavutil/version.h | 4 ++-- > tests/ref/fate/dict | 12 ++++++++++++ > 6 files changed, 109 insertions(+), 2 deletions(-) > > diff --git a/doc/APIchanges b/doc/APIchanges > index f040211f7d..d55821f682 100644 > --- a/doc/APIchanges > +++ b/doc/APIchanges > @@ -2,6 +2,10 @@ The last version increases of all libraries were on 2023-02-09 > > API changes, most recent first: > > +2023-06-02 - xxxxxxxxxx - lavu 58.14.100 - dict.h > + Add av_dict_pop() to remove an entry from a dict > + and get ownership of the removed key/value. > + > 2023-05-29 - xxxxxxxxxx - lavc 60.16.100 - avcodec.h codec_id.h > Add AV_CODEC_ID_EVC, FF_PROFILE_EVC_BASELINE, and FF_PROFILE_EVC_MAIN. > > diff --git a/libavutil/dict.c b/libavutil/dict.c > index f673977a98..ac41771994 100644 > --- a/libavutil/dict.c > +++ b/libavutil/dict.c > @@ -173,6 +173,33 @@ int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, > return av_dict_set(pm, key, valuestr, flags); > } > > +int av_dict_pop(AVDictionary **pm, const char *key, > + char **out_key, char **out_value, int flags) > +{ > + AVDictionary *m = *pm; > + AVDictionaryEntry *entry = NULL; > + entry = (AVDictionaryEntry *)av_dict_get(m, key, NULL, flags); > + if (!entry) > + return AVERROR(ENOENT); > + > + if (out_key) > + *out_key = entry->key; > + else > + av_free(entry->key); > + > + if (out_value) > + *out_value = entry->value; > + else > + av_free(entry->value); > + > + *entry = m->elems[--m->count]; > + if (m && !m->count) { > + av_freep(&m->elems); > + av_freep(pm); > + } > + return 0; > +} > + > static int parse_key_value_pair(AVDictionary **pm, const char **buf, > const char *key_val_sep, const char *pairs_sep, > int flags) > diff --git a/libavutil/dict.h b/libavutil/dict.h > index 713c9e361a..31d38dabec 100644 > --- a/libavutil/dict.h > +++ b/libavutil/dict.h > @@ -172,6 +172,32 @@ 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 @p key and remove it, if found. Optionally > + * the found key and/or value can be returned using the @p out_key and > + * @p out_value arguments. Note: I checked the code and we see that in some cases we use `param` (e.g. in mem.h) but I prefer this format (although apparently not used in other places) since it looks more consistent with the doxygen syntax. > + * > + * 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 using av_dict_free() by > + * the caller. May be NULL. > + * @param out_value Pointer whose pointee will be set to the matched > + * entry value. Must be freed using av_dict_free() by > + * the caller. May be NULL. missing docs for flags, something like: @param flags flags passed to av_dict_get to look for the entry should be fine [...] Looks good otherwise, thanks. _______________________________________________ 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".