History

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.

Lukasz Marek committed 12 years ago

Commit cd50a441 parent 27256e64 files · +34 −3Browse files

Unified · Split

4 files
  1. doc/APIchanges +3 −0
  2. libavutil/mem.c +13 −0
  3. libavutil/mem.h +17 −2
  4. libavutil/version.h +1 −1
doc/APIchanges+3−0
@@ -15,6 +15,9 @@ libavutil: 2012-10-22 · 14 unmodified lines
1515
1616 API changes, most recent first:
1717
18+2014-03-xx - xxxxxxx - lavu 52.70.100 - mem.h
19+ Add av_dynarray_add_nofree() function.
20+
1821 2014-02-xx - xxxxxxx - lavu 53.08.0 - frame.h
1922 Add av_frame_remove_side_data() for removing a single side data
2023 instance from a frame.
libavutil/mem.c+13−0
@@ -278,6 +278,19 @@ void *av_memdup(const void *p, size_t size) · 277 unmodified lines
278278 return ptr;
279279 }
280280
281+int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
282+{
283+ void **tab = *(void ***)tab_ptr;
284+
285+ AV_DYNARRAY_ADD(INT_MAX, sizeof(*tab), tab, *nb_ptr, {
286+ tab[*nb_ptr] = elem;
287+ *(void ***)tab_ptr = tab;
288+ }, {
289+ return AVERROR(ENOMEM);
290+ });
291+ return 0;
292+}
293+
281294 void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
282295 {
283296 void **tab = *(void ***)tab_ptr;
libavutil/mem.h+17−2
@@ -276,10 +276,25 @@ void av_freep(void *ptr); · 275 unmodified lines
276276 * @param tab_ptr pointer to the array to grow
277277 * @param nb_ptr pointer to the number of elements in the array
278278 * @param elem element to add
279− * @see av_dynarray2_add()
279+ * @see av_dynarray_add_nofree(), av_dynarray2_add()
280280 */
281281 void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem);
282282
283+/**
284+ * Add an element to a dynamic array.
285+ *
286+ * Function has the same functionality as av_dynarray_add(),
287+ * but it doesn't free memory on fails. It returns error code
288+ * instead and leave current buffer untouched.
289+ *
290+ * @param tab_ptr pointer to the array to grow
291+ * @param nb_ptr pointer to the number of elements in the array
292+ * @param elem element to add
293+ * @return >=0 on success, negative otherwise.
294+ * @see av_dynarray_add(), av_dynarray2_add()
295+ */
296+int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem);
297+
283298 /**
284299 * Add an element of size elem_size to a dynamic array.
285300 *
@@ -299,7 +314,7 @@ void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem); · 13 unmodified lines
299314 * the new added element is not filled.
300315 * @return pointer to the data of the element to copy in the new allocated space.
301316 * If NULL, the new allocated space is left uninitialized."
302− * @see av_dynarray_add()
317+ * @see av_dynarray_add(), av_dynarray_add_nofree()
303318 */
304319 void *av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size,
305320 const uint8_t *elem_data);
libavutil/version.h+1−1
@@ -56,7 +56,7 @@ · 55 unmodified lines
5656 */
5757
5858 #define LIBAVUTIL_VERSION_MAJOR 52
59−#define LIBAVUTIL_VERSION_MINOR 69
59+#define LIBAVUTIL_VERSION_MINOR 70
6060 #define LIBAVUTIL_VERSION_MICRO 100
6161
6262 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t