#elif defined(__GNUC__)
#define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n)))
#define DECLARE_ASM_CONST(n,t,v) static const t v attribute_used __attribute__ ((aligned (n)))
-#elif defined(_MSVC)
+#elif defined(_MSC_VER)
#define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v
#define DECLARE_ASM_CONST(n,t,v) __declspec(align(n)) static const t v
+#elif defined(HAVE_INLINE_ASM)
+ #error The asm code needs alignment, but we do not know how to do it for this compiler.
#else
-// #warning No align and asm directives, this might fail.
#define DECLARE_ALIGNED(n,t,v) t v
#define DECLARE_ASM_CONST(n,t,v) static const t v
#endif
+#if defined(__GNUC__) && (__GNU__ > 3 || __GNU__ == 3 && __GNU_MINOR__ > 0)
+ #define av_malloc_attrib __attribute__((__malloc__))
+#else
+ #define av_malloc_attrib
+#endif
+
+#if defined(__GNUC__) && (__GNU__ > 4 || __GNU__ == 4 && __GNU_MINOR__ > 1)
+ #define av_alloc_size(n) __attribute__((alloc_size(n)))
+#else
+ #define av_alloc_size(n)
+#endif
+
/**
* Allocate a block of \p size bytes with alignment suitable for all
* memory accesses (including vectors if available on the CPU).
* it.
* @see av_mallocz()
*/
-void *av_malloc(unsigned int size);
+void *av_malloc(unsigned int size) av_malloc_attrib av_alloc_size(1);
/**
* Allocate or reallocate a block of memory.
* reallocate or the function is used to free the memory block.
* @see av_fast_realloc()
*/
-void *av_realloc(void *ptr, unsigned int size);
+void *av_realloc(void *ptr, unsigned int size) av_alloc_size(2);
/**
* Free a memory block which has been allocated with av_malloc(z)() or
* it.
* @see av_malloc()
*/
-void *av_mallocz(unsigned int size);
+void *av_mallocz(unsigned int size) av_malloc_attrib av_alloc_size(1);
/**
* Duplicate the string \p s.
* @return Pointer to a newly allocated string containing a
* copy of \p s or NULL if it cannot be allocated.
*/
-char *av_strdup(const char *s);
+char *av_strdup(const char *s) av_malloc_attrib;
/**
* Free a memory block which has been allocated with av_malloc(z)() or