]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/mem.h
Merge commit '5f408333601a827054335f309defcb246a532b21'
[ffmpeg] / libavutil / mem.h
index 37c1ec3b5e371c3c1092075550f0e4975d50190f..b73b72435bef05ff1478d7aeb178da0acd6c29dc 100644 (file)
@@ -107,8 +107,12 @@ av_alloc_size(1, 2) static inline void *av_malloc_array(size_t nmemb, size_t siz
  * reallocated.
  * @return Pointer to a newly-reallocated block or NULL if the block
  * cannot be reallocated or the function is used to free the memory block.
- * @note av_realloc() is not guaranteed to maintain the alignment of
- *       pointers originating from the av_malloc() family of functions.
+ * @warning Pointers originating from the av_malloc() family of functions must
+ *          not be passed to av_realloc(). 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.
  * @see av_fast_realloc()
  */
 void *av_realloc(void *ptr, size_t size) av_alloc_size(2);
@@ -123,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
@@ -133,8 +156,12 @@ void *av_realloc_f(void *ptr, size_t nelem, size_t elsize);
  * @param size Size of the single element
  * @return Pointer to a newly-reallocated block or NULL if the block
  * cannot be reallocated or the function is used to free the memory block.
- * @note av_realloc_array() is not guaranteed to maintain the alignment of
- *       pointers originating from the av_malloc() family of functions.
+ * @warning Pointers originating from the av_malloc() family of functions must
+ *          not be passed to av_realloc(). 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.
  */
 av_alloc_size(2, 3) void *av_realloc_array(void *ptr, size_t nmemb, size_t size);
 
@@ -148,8 +175,12 @@ av_alloc_size(2, 3) void *av_realloc_array(void *ptr, size_t nmemb, size_t size)
  * @param nmemb Number of elements
  * @param size Size of the single element
  * @return Zero on success, an AVERROR error code on failure.
- * @note av_reallocp_array() is not guaranteed to maintain the alignment of
- *       pointers originating from the av_malloc() family of functions.
+ * @warning Pointers originating from the av_malloc() family of functions must
+ *          not be passed to av_realloc(). 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.
  */
 av_alloc_size(2, 3) int av_reallocp_array(void *ptr, size_t nmemb, size_t size);