diff mbox

[FFmpeg-devel,2/2] mem: Make function attribute usage consisten

Message ID 1469856638-16675-2-git-send-email-timothygu99@gmail.com
State Superseded
Headers show

Commit Message

Timothy Gu July 30, 2016, 5:30 a.m. UTC
---
 libavutil/mem.h | 42 +++++++++++++++++++++++++++---------------
 1 file changed, 27 insertions(+), 15 deletions(-)

Comments

Michael Niedermayer July 30, 2016, 9:49 p.m. UTC | #1
On Fri, Jul 29, 2016 at 10:30:38PM -0700, Timothy Gu wrote:
> ---
>  libavutil/mem.h | 42 +++++++++++++++++++++++++++---------------
>  1 file changed, 27 insertions(+), 15 deletions(-)

doesnt build here:

make distclean ; ./configure && make -j12
..
CC      libavdevice/alldevices.o
In file included from ./libavutil/common.h:464:0,
                 from ./libavutil/avutil.h:288,
                 from ./libavutil/log.h:25,
                 from libavdevice/avdevice.h:46,
                 from libavdevice/alldevices.c:22:
./libavutil/mem.h:96:1: error: expected ‘,’ or ‘;’ before ‘{’ token
./libavutil/mem.h:238:1: error: expected ‘,’ or ‘;’ before ‘{’ token
./libavutil/mem.h:95:21: warning: ‘av_malloc_array’ declared ‘static’ but never defined [-Wunused-function]
./libavutil/mem.h:237:21: warning: ‘av_mallocz_array’ declared ‘static’ but never defined [-Wunused-function]
make: *** [libavdevice/alldevices.o] Error 1

gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

[...]
diff mbox

Patch

diff --git a/libavutil/mem.h b/libavutil/mem.h
index 2f53b47..ca936e8 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -80,7 +80,8 @@ 
  * be allocated.
  * @see av_mallocz()
  */
-void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1);
+av_malloc_attrib
+void *av_malloc(size_t size) av_alloc_size(1);
 
 /**
  * Allocate a block of size * nmemb bytes with av_malloc().
@@ -90,7 +91,8 @@  void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1);
  * be allocated.
  * @see av_malloc()
  */
-av_alloc_size(1, 2) static inline void *av_malloc_array(size_t nmemb, size_t size)
+av_malloc_attrib
+static inline void *av_malloc_array(size_t nmemb, size_t size) av_alloc_size(1, 2)
 {
     if (!size || nmemb >= INT_MAX / size)
         return NULL;
@@ -115,6 +117,7 @@  av_alloc_size(1, 2) static inline void *av_malloc_array(size_t nmemb, size_t siz
  *          some libc implementations.
  * @see av_fast_realloc()
  */
+av_malloc_attrib
 void *av_realloc(void *ptr, size_t size) av_alloc_size(2);
 
 /**
@@ -125,7 +128,8 @@  void *av_realloc(void *ptr, size_t size) av_alloc_size(2);
  * - It frees the input block in case of failure, thus avoiding the memory
  *   leak with the classic "buf = realloc(buf); if (!buf) return -1;".
  */
-void *av_realloc_f(void *ptr, size_t nelem, size_t elsize);
+av_malloc_attrib
+void *av_realloc_f(void *ptr, size_t nelem, size_t elsize) av_alloc_size(2, 3);
 
 /**
  * Allocate or reallocate a block of memory.
@@ -145,7 +149,7 @@  void *av_realloc_f(void *ptr, size_t nelem, size_t elsize);
  *          some libc implementations.
  */
 av_warn_unused_result
-int av_reallocp(void *ptr, size_t size);
+int av_reallocp(void *ptr, size_t size) av_alloc_size(2);
 
 /**
  * Allocate or reallocate an array.
@@ -164,7 +168,8 @@  int av_reallocp(void *ptr, size_t size);
  *          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);
+av_malloc_attrib
+void *av_realloc_array(void *ptr, size_t nmemb, size_t size) av_alloc_size(2, 3);
 
 /**
  * Allocate or reallocate an array through a pointer to a pointer.
@@ -183,7 +188,7 @@  av_alloc_size(2, 3) void *av_realloc_array(void *ptr, size_t nmemb, size_t size)
  *          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);
+int av_reallocp_array(void *ptr, size_t nmemb, size_t size) av_alloc_size(2, 3);
 
 /**
  * Free a memory block which has been allocated with av_malloc(z)() or
@@ -203,7 +208,8 @@  void av_free(void *ptr);
  * @return Pointer to the allocated block, NULL if it cannot be allocated.
  * @see av_malloc()
  */
-void *av_mallocz(size_t size) av_malloc_attrib av_alloc_size(1);
+av_malloc_attrib
+void *av_mallocz(size_t size) av_alloc_size(1);
 
 /**
  * Allocate a block of nmemb * size bytes with alignment suitable for all
@@ -215,7 +221,8 @@  void *av_mallocz(size_t size) av_malloc_attrib av_alloc_size(1);
  * @param size
  * @return Pointer to the allocated block, NULL if it cannot be allocated.
  */
-void *av_calloc(size_t nmemb, size_t size) av_malloc_attrib;
+av_malloc_attrib
+void *av_calloc(size_t nmemb, size_t size) av_alloc_size(1, 2);
 
 /**
  * Allocate a block of size * nmemb bytes with av_mallocz().
@@ -226,7 +233,8 @@  void *av_calloc(size_t nmemb, size_t size) av_malloc_attrib;
  * @see av_mallocz()
  * @see av_malloc_array()
  */
-av_alloc_size(1, 2) static inline void *av_mallocz_array(size_t nmemb, size_t size)
+av_malloc_attrib
+static inline void *av_mallocz_array(size_t nmemb, size_t size) av_alloc_size(1, 2)
 {
     if (!size || nmemb >= INT_MAX / size)
         return NULL;
@@ -239,7 +247,8 @@  av_alloc_size(1, 2) static inline void *av_mallocz_array(size_t nmemb, size_t si
  * @return Pointer to a newly-allocated string containing a
  * copy of s or NULL if the string cannot be allocated.
  */
-char *av_strdup(const char *s) av_malloc_attrib;
+av_malloc_attrib
+char *av_strdup(const char *s);
 
 /**
  * Duplicate a substring of the string s.
@@ -249,7 +258,8 @@  char *av_strdup(const char *s) av_malloc_attrib;
  * @return Pointer to a newly-allocated string containing a
  * copy of s or NULL if the string cannot be allocated.
  */
-char *av_strndup(const char *s, size_t len) av_malloc_attrib;
+av_malloc_attrib
+char *av_strndup(const char *s, size_t len) av_alloc_size(2);
 
 /**
  * Duplicate the buffer p.
@@ -257,7 +267,8 @@  char *av_strndup(const char *s, size_t len) av_malloc_attrib;
  * @return Pointer to a newly allocated buffer containing a
  * copy of p or NULL if the buffer cannot be allocated.
  */
-void *av_memdup(const void *p, size_t size);
+av_malloc_attrib
+void *av_memdup(const void *p, size_t size) av_alloc_size(2);
 
 /**
  * Free a memory block which has been allocated with av_malloc(z)() or
@@ -368,7 +379,8 @@  void av_memcpy_backptr(uint8_t *dst, int back, int cnt);
  *
  * @see av_realloc
  */
-void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size);
+av_malloc_attrib
+void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size) av_alloc_size(3);
 
 /**
  * Allocate a buffer, reusing the given one if large enough.
@@ -382,7 +394,7 @@  void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size);
  * @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);
+void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size) av_alloc_size(3);
 
 /**
  * Allocate a buffer, reusing the given one if large enough.
@@ -397,7 +409,7 @@  void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size);
  * @param min_size minimum size of *ptr buffer after returning, *ptr will be NULL and
  *                 *size 0 if an error occurred.
  */
-void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size);
+void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size) av_alloc_size(3);
 
 /**
  * @}