]> git.sesse.net Git - ffmpeg/commitdiff
mem: Introduce av_reallocp
authorLuca Barbato <lu_zero@gentoo.org>
Sun, 15 Sep 2013 19:42:07 +0000 (21:42 +0200)
committerLuca Barbato <lu_zero@gentoo.org>
Mon, 16 Sep 2013 17:36:37 +0000 (19:36 +0200)
doc/APIchanges
libavutil/mem.c
libavutil/mem.h
libavutil/version.h

index 2b3b58ddce2a82a0dcc0a11bb66bb3bfc4c3b8f8..58b64936074eb330ee4cd78e92aafbcf976124a4 100644 (file)
@@ -13,6 +13,9 @@ libavutil:     2012-10-22
 
 API changes, most recent first:
 
+2013-09-xx - xxxxxxx - lavu 52.13.0 - mem.h
+  Add av_reallocp.
+
 2013-08-xx - xxxxxxx - lavc 55.16.0 - avcodec.h
   Extend AVPacket API with av_packet_unref, av_packet_ref,
   av_packet_move_ref, av_packet_copy_props, av_packet_free_side_data.
index 5f64f56a0d0aa657d03ae5942187ad1e788ce5be..172180e7b9ab13e8f407df0166e5fe7ab6fab122 100644 (file)
@@ -136,6 +136,22 @@ void *av_realloc(void *ptr, size_t size)
 #endif
 }
 
+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)
index b473dd746058d0a6bd07593f8c7d6a5a8cc2a186..f51682bb089330a4f9583b5df478a6cfaa12065a 100644 (file)
@@ -116,6 +116,25 @@ av_alloc_size(1, 2) static inline void *av_malloc_array(size_t nmemb, size_t siz
  */
 void *av_realloc(void *ptr, size_t size) av_alloc_size(2);
 
+/**
+ * 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
index c760d8d75059e058e7ccc20c26b1058d2464d176..935c5053903b9f85795209c69ff88143e0121de6 100644 (file)
@@ -37,7 +37,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR 52
-#define LIBAVUTIL_VERSION_MINOR 14
+#define LIBAVUTIL_VERSION_MINOR 15
 #define LIBAVUTIL_VERSION_MICRO  0
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \