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 835E8406B9 for ; Tue, 21 Nov 2023 21:15:18 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2C7DF68CCB9; Tue, 21 Nov 2023 23:14:58 +0200 (EET) Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C2C4568CCA4 for ; Tue, 21 Nov 2023 23:14:50 +0200 (EET) Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-6cbc8199a2aso455934b3a.1 for ; Tue, 21 Nov 2023 13:14:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700601289; x=1701206089; darn=ffmpeg.org; 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=TSNmKZwoCMkjxuj7+W7roudmvrQ+hNf3DTrFKouFeZ4=; b=J1JQqkDxP4go+vyIHNhqP3+Vabk+a6FYSx/B716by54VsDQuBbSk4l75dT7iHiPGrH dorx7Za58JS4NTa18JXWUyBt+sFmQSvI/IzvxQ9Aw4l8iRzTi0wXdONQPXmHhfVyAUMH Ttrw5xud4Nhv+KnamCmCnwipOOufyVr4efIXfbPZSEh+v0bnDG/W13/xXgM1mPNeD/jW CSCgTf1SObRbs/6piynuNl14BAc1WlGj1S2nQYvL/JinH4hECnRtI1NO+qXFU3xunxZo Syvglj8I8vBuEV4i6IZ8tD9GE7ro8ntemx8a8350MZb2m7licXQw8twPG8odlNovFbi2 fnRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700601289; x=1701206089; 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=TSNmKZwoCMkjxuj7+W7roudmvrQ+hNf3DTrFKouFeZ4=; b=WYXrPu/PGjmc8Qqr2zMSAD3MZX9HqSNfLnSprp+LY4d5+50Qave7oQc+MNNI6Kg2Zb 6qgNM3wpWYAV3Y81rbFXMD/0MyS56iNN5eHlNdPHMCJ9s1YYjlZu11xp1j5J9V33a6xR d31rJ858CZNNvrT7W+XXbth3t1/8tIgVVVqDxRCfNpHAmch8CuffyCQ0wRVJoCt/TKc2 0PiiGsOGouwwMb1MyD0sZnibAdbUzq8RHeHlFUm5V0iDMnvtc1i37AxpxKKdDAlAoT2j 5iDgb6p5UcB07kWusyJMtfC9mdjIS58AsKh3tQU4VxZByQJlqKGNh7sreERGFhH04rWu jBzA== X-Gm-Message-State: AOJu0Yw2KR+TZa4xVvBgn7ZFYf7ViKI2El/kvMfe1LyHUe/JggFH5Kdc WuTZmxJaaY19AVt4CsVxEQyYXf+6lGc= X-Google-Smtp-Source: AGHT+IGdjRuYkDsn3JLeJdBWoccE8kP3QnJJFukAR/m6R0WqvQlQ5ii9FYsc/2Sy5asFHQaVdfRKyQ== X-Received: by 2002:a05:6a00:1c9c:b0:6cb:a60c:2143 with SMTP id y28-20020a056a001c9c00b006cba60c2143mr458271pfw.9.1700601288655; Tue, 21 Nov 2023 13:14:48 -0800 (PST) Received: from localhost.localdomain (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id bn2-20020a056a00324200b0069ea08a2a99sm8412505pfb.211.2023.11.21.13.14.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 13:14:48 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Nov 2023 18:14:39 -0300 Message-ID: <20231121211442.8723-3-jamrial@gmail.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20231121211442.8723-1-jamrial@gmail.com> References: <20231121211442.8723-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/5] avutil/mem: add av_dynarray2_add_nofree 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: Signed-off-by: James Almer --- libavutil/mem.c | 17 +++++++++++++++++ libavutil/mem.h | 32 +++++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/libavutil/mem.c b/libavutil/mem.c index 36b8940a0c..bd37710968 100644 --- a/libavutil/mem.c +++ b/libavutil/mem.c @@ -356,6 +356,23 @@ void *av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size, return tab_elem_data; } +void *av_dynarray2_add_nofree(void **tab_ptr, int *nb_ptr, size_t elem_size, + const uint8_t *elem_data) +{ + uint8_t *tab_elem_data = NULL; + + FF_DYNARRAY_ADD(INT_MAX, elem_size, *tab_ptr, *nb_ptr, { + tab_elem_data = (uint8_t *)*tab_ptr + (*nb_ptr) * elem_size; + if (elem_data) + memcpy(tab_elem_data, elem_data, elem_size); + else if (CONFIG_MEMORY_POISONING) + memset(tab_elem_data, FF_MEMORY_POISON, elem_size); + }, { + return NULL; + }); + return tab_elem_data; +} + static void fill16(uint8_t *dst, int len) { uint32_t v = AV_RN16(dst - 2); diff --git a/libavutil/mem.h b/libavutil/mem.h index ab7648ac57..c0161be243 100644 --- a/libavutil/mem.h +++ b/libavutil/mem.h @@ -519,7 +519,7 @@ void av_memcpy_backptr(uint8_t *dst, int back, int cnt); * @param[in,out] tab_ptr Pointer to the array to grow * @param[in,out] nb_ptr Pointer to the number of elements in the array * @param[in] elem Element to add - * @see av_dynarray_add_nofree(), av_dynarray2_add() + * @see av_dynarray_add_nofree(), av_dynarray2_add(), av_dynarray2_add_nofree() */ void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem); @@ -531,7 +531,7 @@ void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem); * instead and leave current buffer untouched. * * @return >=0 on success, negative otherwise - * @see av_dynarray_add(), av_dynarray2_add() + * @see av_dynarray_add(), av_dynarray2_add(), av_dynarray2_add_nofree() */ av_warn_unused_result int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem); @@ -557,11 +557,37 @@ int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem); * * @return Pointer to the data of the element to copy in the newly allocated * space - * @see av_dynarray_add(), av_dynarray_add_nofree() + * @see av_dynarray2_add_nofree(), av_dynarray_add(), av_dynarray_add_nofree() */ void *av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size, const uint8_t *elem_data); +/** + * Add an element of size `elem_size` to a dynamic array. + * + * The array is reallocated when its number of elements reaches powers of 2. + * Therefore, the amortized cost of adding an element is constant. + * + * In case of success, the pointer to the array is updated in order to + * point to the new grown array, and the number pointed to by `nb_ptr` + * is incremented. + * In case of failure, the array and `nb_ptr` are left untouched, and NULL + * is returned. + * + * @param[in,out] tab_ptr Pointer to the array to grow + * @param[in,out] nb_ptr Pointer to the number of elements in the array + * @param[in] elem_size Size in bytes of an element in the array + * @param[in] elem_data Pointer to the data of the element to add. If + * `NULL`, the space of the newly added element is + * allocated but left uninitialized. + * + * @return Pointer to the data of the element to copy in the newly allocated + * space on success, NULL otherwise. + * @see av_dynarray2_add(), av_dynarray_add(), av_dynarray_add_nofree() + */ +void *av_dynarray2_add_nofree(void **tab_ptr, int *nb_ptr, size_t elem_size, + const uint8_t *elem_data); + /** * @} */ -- 2.42.1 _______________________________________________ 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".