Browse Source

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.

Signed-off-by: Lukasz Marek <lukasz.m.luki@gmail.com>
tags/n2.3
Lukasz Marek 11 years ago
parent
commit
cd50a44beb
4 changed files with 34 additions and 3 deletions
  1. +3
    -0
      doc/APIchanges
  2. +13
    -0
      libavutil/mem.c
  3. +17
    -2
      libavutil/mem.h
  4. +1
    -1
      libavutil/version.h

+ 3
- 0
doc/APIchanges View File

@@ -15,6 +15,9 @@ libavutil: 2012-10-22

API changes, most recent first:

2014-03-xx - xxxxxxx - lavu 52.70.100 - mem.h
Add av_dynarray_add_nofree() function.

2014-02-xx - xxxxxxx - lavu 53.08.0 - frame.h
Add av_frame_remove_side_data() for removing a single side data
instance from a frame.


+ 13
- 0
libavutil/mem.c View File

@@ -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] = elem;
*(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;


+ 17
- 2
libavutil/mem.h View File

@@ -276,10 +276,25 @@ 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.
*
@@ -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);


+ 1
- 1
libavutil/version.h View File

@@ -56,7 +56,7 @@
*/

#define LIBAVUTIL_VERSION_MAJOR 52
#define LIBAVUTIL_VERSION_MINOR 69
#define LIBAVUTIL_VERSION_MINOR 70
#define LIBAVUTIL_VERSION_MICRO 100

#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \


Loading…
Cancel
Save