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 4F20146583 for ; Sun, 21 May 2023 23:52:47 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EA4BC68C08B; Mon, 22 May 2023 02:52:44 +0300 (EEST) Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9821368B9C5 for ; Mon, 22 May 2023 02:52:38 +0300 (EEST) Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-30a8dc89c33so408955f8f.0 for ; Sun, 21 May 2023 16:52:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684713157; x=1687305157; 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=EZ47Un6sOrsGJVfHY5XC9SZ5AWDVmtyfXKf3oXoAYtY=; b=W3lL5GEIwTeiHetMmeRVMda/6Qu6sYj1tZ5aRZS8NgVgVTp8FuOInK6BFtkjmpUWQH IvKPQjwrsaheFRJi2Y47aiZJDw9zZpmk6xg8iQXc+GqHmfyTKeYKaIEqPv47giJQ5FiV KyRn62NyLPq//BlnNHorhIQCVXfh+slEIBs50qCm5te73dpBN03JO7S02BfmreOdjiM7 CHjiSkQXOJJefHH0esyVTaTdVFS6hxvWnnEB1q2FXjgxRrwzhZI1k2J3T53caPpL7hwZ mmgpDZpkI5Yn41k6yujNesX7E/wYp8L3f2baeRdAcI0w/m6hTEunY7JP4AUed2T4yPx2 SmkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684713157; x=1687305157; 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=EZ47Un6sOrsGJVfHY5XC9SZ5AWDVmtyfXKf3oXoAYtY=; b=Kmrgsn5gocidsYCx2TRdLGpRb+235mVFNe8F0120DIyq63eNpui6EdtFy0+wnOwrAD lsfBDH5G9TpjXXJFL4yvrknNvvPEl5mdbzrDi/fmuBhR16qBJoAaCEt2zsGg+5HYluiT Kzf5QO2u1N8r5zhQThTWNHUCNHDXSvzq7vDQzkmH365YozJWVZAypMbWrenLwGJcbEF6 4c2DLUxT+9Xcjoop2VUSEENDAsXjpPhAyyJ3vdNHkZFCAETJg1QC+KB4RBrTwaAsCyRv eMyFjzaCLx8UPseSd30/weAZOzkhY9nSUzuWn0P4dLm7ir+xIsnnRo+84cf+ZnjxomuW hc4g== X-Gm-Message-State: AC+VfDxcb6mec8Xe0cHZD/ZuR7FSDcjXGV/BLBQjZaHXACt7u6AEtk0G SytHreypjSSsGB6C8n5pr1FECBsEwfc= X-Google-Smtp-Source: ACHHUZ7zSgyUCOm8LxeRMKqDTMDQR177hzuisMb5z0dgG0mVokcVZcsBaCc9MXzwhsLCwPFSBLTSWQ== X-Received: by 2002:a5d:4811:0:b0:309:2e6e:78e1 with SMTP id l17-20020a5d4811000000b003092e6e78e1mr6136775wrq.49.1684713157202; Sun, 21 May 2023 16:52:37 -0700 (PDT) Received: from mariano ([91.254.67.164]) by smtp.gmail.com with ESMTPSA id u10-20020a5d514a000000b003079693eff2sm5859089wrt.41.2023.05.21.16.52.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 May 2023 16:52:36 -0700 (PDT) Received: by mariano (Postfix, from userid 1000) id 64B70BFB73; Mon, 22 May 2023 01:52:35 +0200 (CEST) Date: Mon, 22 May 2023 01:52:35 +0200 From: Stefano Sabatini To: FFmpeg development discussions and patches Message-ID: <20230521235235.GC14958@mariano> Mail-Followup-To: FFmpeg development discussions and patches References: <20230501114456.13898-1-epirat07@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230501114456.13898-1-epirat07@gmail.com> User-Agent: Mutt/1.13.2 (2019-12-18) Subject: Re: [FFmpeg-devel] [PATCH 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 Monday 2023-05-01 13:44:54 +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. > --- > doc/APIchanges | 4 ++++ > libavutil/dict.c | 27 +++++++++++++++++++++++++++ > libavutil/dict.h | 20 ++++++++++++++++++++ > libavutil/tests/dict.c | 34 ++++++++++++++++++++++++++++++++++ > libavutil/version.h | 2 +- > tests/ref/fate/dict | 12 ++++++++++++ > 6 files changed, 98 insertions(+), 1 deletion(-) > > diff --git a/doc/APIchanges b/doc/APIchanges > index 0b609e3d3b..5b807873b7 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-04-29 - xxxxxxxxxx - lavu 58.7.100 - dict.c > + Add av_dict_pop() to remove an entry from a dict > + and get ownership of the removed key/value. > + > 2023-04-10 - xxxxxxxxxx - lavu 58.6.100 - frame.h > av_frame_get_plane_buffer() now accepts const AVFrame*. > > 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); > + } I'm not sure this is the right behavior. Should we clear the dictionary when it is empty? What if you need to refill it later? > + 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..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 Not sure the `foo` syntax is supported by doxygen (and probably we should eschew it for consistency with the other doxys). > + * the found key and/or value can be returned using the `out_key`/`out_value` > + * arguments. _______________________________________________ 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".