OSDN Git Service

Merge commit 'cce3e0a49f0dd030262c28d9c53de0bd2fd909c4'
authorMichael Niedermayer <michaelni@gmx.at>
Thu, 14 Nov 2013 14:04:04 +0000 (15:04 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Thu, 14 Nov 2013 14:04:04 +0000 (15:04 +0100)
* commit 'cce3e0a49f0dd030262c28d9c53de0bd2fd909c4':
  Move av_fast_{m,re}alloc from lavc to lavu.

Conflicts:
libavcodec/avcodec.h
libavcodec/utils.c
libavutil/mem.c
libavutil/version.h

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
doc/APIchanges
libavcodec/avcodec.h
libavcodec/utils.c
libavcodec/version.h
libavutil/mem.c
libavutil/mem.h
libavutil/version.h

diff --cc doc/APIchanges
Simple merge
@@@ -4869,32 -4202,11 +4873,11 @@@ AVBitStreamFilter *av_bitstream_filter_
  /* memory */
  
  /**
-  * Reallocate the given block if it is not large enough, otherwise do nothing.
-  *
-  * @see av_realloc
-  */
- void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size);
- /**
-  * Allocate a buffer, reusing the given one if large enough.
-  *
-  * Contrary to av_fast_realloc the current buffer contents might not be
-  * preserved and on error the old buffer is freed, thus no special
-  * handling to avoid memleaks is necessary.
 - * Allocate a buffer with padding, reusing the given one if large enough.
-- *
-  * @param ptr pointer to pointer to already allocated buffer, overwritten with pointer to new buffer
-  * @param size size of the buffer *ptr points to
-  * @param min_size minimum size of *ptr buffer after returning, *ptr will be NULL and
-  *                 *size 0 if an error occurred.
-  */
- void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size);
- /**
   * Same behaviour av_fast_malloc but the buffer has additional
 - * FF_INPUT_PADDING_SIZE at the end which will always memset to 0.
 + * FF_INPUT_BUFFER_PADDING_SIZE at the end which will always be 0.
   *
 + * In addition the whole buffer will initially and after resizes
 + * be 0-initialized so that no uninitialized data will ever appear.
   */
  void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size);
  
@@@ -117,59 -54,22 +117,47 @@@ static int volatile entangled_thread_co
  static void *codec_mutex;
  static void *avformat_mutex;
  
- void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
+ #if FF_API_FAST_MALLOC && CONFIG_SHARED && HAVE_SYMVER
+ FF_SYMVER(void*, av_fast_realloc, (void *ptr, unsigned int *size, size_t min_size), "LIBAVCODEC_55")
  {
-     if (min_size < *size)
-         return ptr;
-     min_size = FFMAX(17 * min_size / 16 + 32, min_size);
-     ptr = av_realloc(ptr, min_size);
-     /* we could set this to the unmodified min_size but this is safer
-      * if the user lost the ptr and uses NULL now
-      */
-     if (!ptr)
-         min_size = 0;
-     *size = min_size;
+     return av_fast_realloc(ptr, size, min_size);
+ }
  
-     return ptr;
+ FF_SYMVER(void, av_fast_malloc, (void *ptr, unsigned int *size, size_t min_size), "LIBAVCODEC_55")
+ {
+     av_fast_malloc(ptr, size, min_size);
  }
+ #endif
  
 -void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
 +static inline int ff_fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc)
  {
      void **p = ptr;
- void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
- {
-     ff_fast_malloc(ptr, size, min_size, 0);
- }
 +    if (min_size < *size)
 +        return 0;
 +    min_size = FFMAX(17 * min_size / 16 + 32, min_size);
 +    av_free(*p);
 +    *p = zero_realloc ? av_mallocz(min_size) : av_malloc(min_size);
 +    if (!*p)
 +        min_size = 0;
 +    *size = min_size;
 +    return 1;
 +}
 +
 +void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
 +{
 +    uint8_t **p = ptr;
 +    if (min_size > SIZE_MAX - FF_INPUT_BUFFER_PADDING_SIZE) {
 +        av_freep(p);
 +        *size = 0;
 +        return;
 +    }
 +    if (!ff_fast_malloc(p, size, min_size + FF_INPUT_BUFFER_PADDING_SIZE, 1))
 +        memset(*p + min_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
 +}
 +
 +void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size)
 +{
 +    uint8_t **p = ptr;
      if (min_size > SIZE_MAX - FF_INPUT_BUFFER_PADDING_SIZE) {
          av_freep(p);
          *size = 0;
Simple merge
diff --cc libavutil/mem.c
@@@ -36,8 -34,8 +36,9 @@@
  #include <malloc.h>
  #endif
  
 +#include "avassert.h"
  #include "avutil.h"
+ #include "common.h"
  #include "intreadwrite.h"
  #include "mem.h"
  
@@@ -463,3 -346,34 +464,41 @@@ void av_memcpy_backptr(uint8_t *dst, in
      }
  }
  
 -void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
+ void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
+ {
+     if (min_size < *size)
+         return ptr;
+     min_size = FFMAX(17 * min_size / 16 + 32, min_size);
+     ptr = av_realloc(ptr, min_size);
+     /* we could set this to the unmodified min_size but this is safer
+      * if the user lost the ptr and uses NULL now
+      */
+     if (!ptr)
+         min_size = 0;
+     *size = min_size;
+     return ptr;
+ }
 -        return;
++static inline int ff_fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc)
+ {
+     void **p = ptr;
+     if (min_size < *size)
 -    *p = av_malloc(min_size);
++        return 0;
+     min_size = FFMAX(17 * min_size / 16 + 32, min_size);
+     av_free(*p);
++    *p = zero_realloc ? av_mallocz(min_size) : av_malloc(min_size);
+     if (!*p)
+         min_size = 0;
+     *size = min_size;
++    return 1;
+ }
++
++void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
++{
++    ff_fast_malloc(ptr, size, min_size, 0);
++}
++
diff --cc libavutil/mem.h
Simple merge
@@@ -74,9 -36,9 +74,9 @@@
   * @{
   */
  
 -#define LIBAVUTIL_VERSION_MAJOR 52
 -#define LIBAVUTIL_VERSION_MINOR 18
 -#define LIBAVUTIL_VERSION_MICRO  0
 +#define LIBAVUTIL_VERSION_MAJOR  52
- #define LIBAVUTIL_VERSION_MINOR  52
++#define LIBAVUTIL_VERSION_MINOR  53
 +#define LIBAVUTIL_VERSION_MICRO 100
  
  #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
                                                 LIBAVUTIL_VERSION_MINOR, \