summaryrefslogtreecommitdiff
path: root/libavutil
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2011-04-29 17:33:38 +0200
committerAnton Khirnov <anton@khirnov.net>2011-04-29 17:34:56 +0200
commit35ceaa737643008e89a9ba54aaa9ebc0b57683b4 (patch)
treeb6a90b5d1976897852082a35f5a56ef300a34d03 /libavutil
parent9ac1bf88c00dbe7eb2191e2d5325fb104b9d8341 (diff)
Move ff_dynarray_add to lavu and make it public.
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/avutil.h2
-rw-r--r--libavutil/mem.c20
-rw-r--r--libavutil/mem.h9
3 files changed, 30 insertions, 1 deletions
diff --git a/libavutil/avutil.h b/libavutil/avutil.h
index 43f0815fd2..8b8ca40c94 100644
--- a/libavutil/avutil.h
+++ b/libavutil/avutil.h
@@ -40,7 +40,7 @@
#define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
#define LIBAVUTIL_VERSION_MAJOR 51
-#define LIBAVUTIL_VERSION_MINOR 1
+#define LIBAVUTIL_VERSION_MINOR 2
#define LIBAVUTIL_VERSION_MICRO 0
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
diff --git a/libavutil/mem.c b/libavutil/mem.c
index 27bb30b8ef..85e1924e2b 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -171,3 +171,23 @@ char *av_strdup(const char *s)
return ptr;
}
+/* add one element to a dynamic array */
+void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
+{
+ /* see similar ffmpeg.c:grow_array() */
+ int nb, nb_alloc;
+ intptr_t *tab;
+
+ nb = *nb_ptr;
+ tab = *(intptr_t**)tab_ptr;
+ if ((nb & (nb - 1)) == 0) {
+ if (nb == 0)
+ nb_alloc = 1;
+ else
+ nb_alloc = nb * 2;
+ tab = av_realloc(tab, nb_alloc * sizeof(intptr_t));
+ *(intptr_t**)tab_ptr = tab;
+ }
+ tab[nb++] = (intptr_t)elem;
+ *nb_ptr = nb;
+}
diff --git a/libavutil/mem.h b/libavutil/mem.h
index 5dea492021..2be949196c 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -123,4 +123,13 @@ char *av_strdup(const char *s) av_malloc_attrib;
*/
void av_freep(void *ptr);
+/**
+ * Add an element to a dynamic array.
+ *
+ * @param tab_ptr Pointer to the array.
+ * @param nb_ptr Pointer to the number of elements in the array.
+ * @param elem Element to be added.
+ */
+void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem);
+
#endif /* AVUTIL_MEM_H */