[FFmpeg-devel] [PATCH 1/4] lavu: add simple array implementation

Nicolas George george at nsup.org
Sun Mar 23 17:41:46 CET 2014


> On 22.03.2014 21:13, Michael Niedermayer wrote:
> >use of intptr_t is certainly not correct
> >void* and intptr_t might for example have different endianness or
> >size. intptr_t just has to be able to store a pointer,
> >a architecture with segment:offset pointers might have
> >48bit pointers but a 64bit intptr_t.
> >Above is of course hypothetical, and based on my understanding of
> >ISO C, i dont know if these occur on any relevant platforms and of
> >course i might be misinterpreting the spec

FWIV, I understand the spec the same way as you and I fully support your
change, thanks.

Le tridi 3 germinal, an CCXXII, Lukasz Marek a écrit :
> >From 69f261b585c8636bffc9427021bbd575302a41f0 Mon Sep 17 00:00:00 2001
> From: Lukasz Marek <lukasz.m.luki at gmail.com>
> Date: Tue, 25 Feb 2014 01:06:06 +0100
> Subject: [PATCH] lavu/mem: add av_dynarray_add_nofree function
> 
> av_dynarray_add_nofree function have similar functionality
> as existing av_dynarray_add, but it doesn't deallocate memory
> on fails.
> 
> TODO: minor bump and update doc/APIChanges
> 
> Signed-off-by: Lukasz Marek <lukasz.m.luki at gmail.com>
> ---
>  libavutil/mem.c | 13 +++++++++++++
>  libavutil/mem.h | 19 +++++++++++++++++--
>  2 files changed, 30 insertions(+), 2 deletions(-)
> 
> diff --git a/libavutil/mem.c b/libavutil/mem.c
> index e0d0d90..fdf219b 100644
> --- a/libavutil/mem.c
> +++ b/libavutil/mem.c
> @@ -278,6 +278,19 @@ void *av_memdup(const void *p, size_t size)
>      return ptr;
>  }
>  
> +int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
> +{
> +    void **tab = *(void ***)tab_ptr;
> +
> +    AV_DYNARRAY_ADD(INT_MAX, sizeof(*tab), tab, *nb_ptr, {

> +        tab[*nb_ptr] = (intptr_t)elem;

The cast seems wrong.

> +        *(void ***)tab_ptr = tab;
> +    }, {
> +        return AVERROR(ENOMEM);
> +    });
> +    return 0;
> +}
> +
>  void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
>  {
>      void **tab = *(void ***)tab_ptr;
> diff --git a/libavutil/mem.h b/libavutil/mem.h
> index 703ce81..801c53f 100644
> --- a/libavutil/mem.h
> +++ b/libavutil/mem.h
> @@ -276,11 +276,26 @@ void av_freep(void *ptr);
>   * @param tab_ptr pointer to the array to grow
>   * @param nb_ptr  pointer to the number of elements in the array
>   * @param elem    element to add
> - * @see av_dynarray2_add()
> + * @see av_dynarray_add_nofree(), av_dynarray2_add()
>   */
>  void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem);
>  
>  /**
> + * Add an element to a dynamic array.
> + *
> + * Function has the same functionality as av_dynarray_add(),
> + * but it doesn't free memory on fails. It returns error code
> + * instead and leave current buffer untouched.
> + *
> + * @param tab_ptr pointer to the array to grow
> + * @param nb_ptr  pointer to the number of elements in the array
> + * @param elem    element to add
> + * @return >=0 on success, negative otherwise.
> + * @see av_dynarray_add(), av_dynarray2_add()
> + */
> +int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem);
> +
> +/**
>   * Add an element of size elem_size to a dynamic array.
>   *
>   * The array is reallocated when its number of elements reaches powers of 2.
> @@ -299,7 +314,7 @@ void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem);
>   *                  the new added element is not filled.
>   * @return          pointer to the data of the element to copy in the new allocated space.
>   *                  If NULL, the new allocated space is left uninitialized."
> - * @see av_dynarray_add()
> + * @see 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);

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140323/d762449a/attachment.asc>


More information about the ffmpeg-devel mailing list