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
15 15
16API changes, most recent first:16API changes, most recent first:
17 17
182014-03-xx - xxxxxxx - lavu 52.70.100 - mem.h
19 Add av_dynarray_add_nofree() function.
20
182014-02-xx - xxxxxxx - lavu 53.08.0 - frame.h212014-02-xx - xxxxxxx - lavu 53.08.0 - frame.h
19 Add av_frame_remove_side_data() for removing a single side data22 Add av_frame_remove_side_data() for removing a single side data
20 instance from a frame.23 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
278 return ptr;278 return ptr;
279}279}
280 280
281int 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
281void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)294void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
282{295{
283 void **tab = *(void ***)tab_ptr;296 void **tab = *(void ***)tab_ptr;
libavutil/mem.h+17−2
@@ -276,10 +276,25 @@ void av_freep(void *ptr); · 275 unmodified lines
276 * @param tab_ptr pointer to the array to grow276 * @param tab_ptr pointer to the array to grow
277 * @param nb_ptr pointer to the number of elements in the array277 * @param nb_ptr pointer to the number of elements in the array
278 * @param elem element to add278 * @param elem element to add
279 * @see av_dynarray2_add()279 * @see av_dynarray_add_nofree(), av_dynarray2_add()
280 */280 */
281void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem);281void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem);
282 282
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 */
296int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem);
297
283/**298/**
284 * Add an element of size elem_size to a dynamic array.299 * Add an element of size elem_size to a dynamic array.
285 *300 *
@@ -299,7 +314,7 @@ void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem); · 13 unmodified lines
299 * the new added element is not filled.314 * the new added element is not filled.
300 * @return pointer to the data of the element to copy in the new allocated space.315 * @return pointer to the data of the element to copy in the new allocated space.
301 * If NULL, the new allocated space is left uninitialized."316 * If NULL, the new allocated space is left uninitialized."
302 * @see av_dynarray_add()317 * @see av_dynarray_add(), av_dynarray_add_nofree()
303 */318 */
304void *av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size,319void *av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size,
305 const uint8_t *elem_data);320 const uint8_t *elem_data);
libavutil/version.h+1−1
@@ -56,7 +56,7 @@ · 55 unmodified lines
56 */56 */
57 57
58#define LIBAVUTIL_VERSION_MAJOR 5258#define LIBAVUTIL_VERSION_MAJOR 52
59#define LIBAVUTIL_VERSION_MINOR 6959#define LIBAVUTIL_VERSION_MINOR 70
60#define LIBAVUTIL_VERSION_MICRO 10060#define LIBAVUTIL_VERSION_MICRO 100
61 61
62#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \62#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