Browse Source

Merge commit '3feb3d6ce4be0a09a9f8f13d613bed25b523b6e7'

* commit '3feb3d6ce4be0a09a9f8f13d613bed25b523b6e7':
  mem: Introduce av_reallocp

Conflicts:
	doc/APIchanges
	libavutil/mem.c
	libavutil/mem.h
	libavutil/version.h

Merged-by: Michael Niedermayer <michaelni@gmx.at>
tags/n2.1
Michael Niedermayer 12 years ago
parent
commit
c74c3fb142
4 changed files with 39 additions and 1 deletions
  1. +3
    -0
      doc/APIchanges
  2. +16
    -0
      libavutil/mem.c
  3. +19
    -0
      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:

2013-09-xx - xxxxxxx - lavu 52.13.0 - mem.h
Add av_reallocp.

2013-09-04 - 3e1f507 - lavc 55.31.101 - avcodec.h
avcodec_close() argument can be NULL.



+ 16
- 0
libavutil/mem.c View File

@@ -180,6 +180,22 @@ void *av_realloc_f(void *ptr, size_t nelem, size_t elsize)
return r;
}

int av_reallocp(void *ptr, size_t size)
{
void **ptrptr = ptr;
void *ret;

ret = av_realloc(*ptrptr, size);

if (!ret) {
av_freep(ptr);
return AVERROR(ENOMEM);
}

*ptrptr = ret;
return 0;
}

void *av_realloc_array(void *ptr, size_t nmemb, size_t size)
{
if (!size || nmemb >= INT_MAX / size)


+ 19
- 0
libavutil/mem.h View File

@@ -127,6 +127,25 @@ void *av_realloc(void *ptr, size_t size) av_alloc_size(2);
*/
void *av_realloc_f(void *ptr, size_t nelem, size_t elsize);

/**
* Allocate or reallocate a block of memory.
* If *ptr is NULL and size > 0, allocate a new block. If
* size is zero, free the memory block pointed to by ptr.
* @param ptr Pointer to a pointer to a memory block already allocated
* with av_realloc(), or pointer to a pointer to NULL.
* The pointer is updated on success, or freed on failure.
* @param size Size in bytes for the memory block to be allocated or
* reallocated
* @return Zero on success, an AVERROR error code on failure.
* @warning Pointers originating from the av_malloc() family of functions must
* not be passed to av_reallocp(). The former can be implemented using
* memalign() (or other functions), and there is no guarantee that
* pointers from such functions can be passed to realloc() at all.
* The situation is undefined according to POSIX and may crash with
* some libc implementations.
*/
int av_reallocp(void *ptr, size_t size);

/**
* Allocate or reallocate an array.
* If ptr is NULL and nmemb > 0, allocate a new block. If


+ 1
- 1
libavutil/version.h View File

@@ -75,7 +75,7 @@
*/

#define LIBAVUTIL_VERSION_MAJOR 52
#define LIBAVUTIL_VERSION_MINOR 43
#define LIBAVUTIL_VERSION_MINOR 44
#define LIBAVUTIL_VERSION_MICRO 100

#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \


Loading…
Cancel
Save