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 27BC346A48 for ; Sun, 2 Jul 2023 11:49:40 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0510F68BF9B; Sun, 2 Jul 2023 14:49:37 +0300 (EEST) Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6CEFC68BF05 for ; Sun, 2 Jul 2023 14:49:30 +0300 (EEST) Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-991fe70f21bso406476266b.3 for ; Sun, 02 Jul 2023 04:49:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688298569; x=1690890569; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=wznSa+pvDW7Dxb7KuLJWPqpKYBDaDbHzH4ZrH/JsOLQ=; b=af/0r/tXPIXaqu0ChyPkRCSRmMoBLsg6R9H8wxMEbrMSPqry3Af/IA0HxuypuMzXCw RSPrKzZUO7JtMb824RyifpYnHGGZBmuXWxPr1YupdyHZ9FKHpk4vlu1ZCp1TsHghaqU4 wimF5rlkBpHblknjEezrWGokj2hbthcYXLQXc4RfBrYaxGS9diOUzg8JtPkpPvg4PlbH rSNJlmqAYTjsnYHg60fLIfh8EDB88+5jCEQ/3ZJ82Vq6dpOmCLD/vtbpxmLIkAgRlkKN cgFB/zFiKSNFDiVu7FlrjTAfHb8sQTEO9S+Bdv/Zai9YSS7byQ2xUQzXwx0oPCMG88a4 jDZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688298569; x=1690890569; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wznSa+pvDW7Dxb7KuLJWPqpKYBDaDbHzH4ZrH/JsOLQ=; b=N3T4tKVdxncijqI6wVCBgAy3UKTt+ElXCDqvKZ9ZovWegkDIrA+wrO6EoUn6JyE3tv Ax0vgk479TrKmxP0a5CaWT9+anqI6KCdpJteK8cybaDjz/EdLLz+l6xc7C62eCC3HnPo QMhRN1lnvtuEanDYqvKmQ1V8u4Qsjm3F4+5roetQCnq506CgfB7TQXM54ypQNJ3Rv+we AuwnepsgTIZoceHx+FLkuCaxxqfNeBodTm7V6JFDaMjSDIlC8xHZsOyPQTzVa7Hqgm38 P0Oz5+6eomT3KuBc+7HIchGSbX9ppAKSvqu8OzDqCAiJQgFsGJIBJ2VY+F8YEYq7DHVc 5B3g== X-Gm-Message-State: ABy/qLbMmcCePaxLjHS3ZnzUN0uFrSHqml9/BPc6doKt3tIPglr3rKzd /MV8N5i2dNmGIIiIGDwPUv7uuEGM6Qs= X-Google-Smtp-Source: APBJJlEAbZeIg0tw5gkhHs1dbFhz0Exr541LZ4urCEH+bB8jWvDVUAHYO1l4ADVYoWrEddb2F51HwA== X-Received: by 2002:a17:906:4ed1:b0:992:b3a3:81f4 with SMTP id i17-20020a1709064ed100b00992b3a381f4mr5116069ejv.50.1688298569461; Sun, 02 Jul 2023 04:49:29 -0700 (PDT) Received: from [172.16.250.1] (84-112-104-25.cable.dynamic.surfer.at. [84.112.104.25]) by smtp.gmail.com with ESMTPSA id u4-20020a17090617c400b0099297c99314sm4943890eje.113.2023.07.02.04.49.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Jul 2023 04:49:28 -0700 (PDT) From: Marvin Scholz To: FFmpeg development discussions and patches Date: Sun, 02 Jul 2023 13:49:27 +0200 X-Mailer: MailMate (1.14r5964) Message-ID: In-Reply-To: <20230702084307.GA4218@mariano> References: <20230501114456.13898-1-epirat07@gmail.com> <20230625104907.53071-1-epirat07@gmail.com> <20230702084307.GA4218@mariano> MIME-Version: 1.0 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 2 Jul 2023, at 10:43, Stefano Sabatini wrote: > 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 > Can whoever ends up merging this maybe add that? If not, I can send a new revision with this change next weekend or so. > [...] > > 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". _______________________________________________ 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".