Mercurial > libavutil.hg
comparison mem.h @ 482:0b8d0ec536a8 libavutil
Apply "alloc_size" attribute to av_alloc, av_realloc and av_mallocz
author | zuxy |
---|---|
date | Wed, 19 Mar 2008 07:30:34 +0000 |
parents | f4187c1c15a6 |
children | c6cd6e70780b |
comparison
equal
deleted
inserted
replaced
481:f4187c1c15a6 | 482:0b8d0ec536a8 |
---|---|
46 #define av_malloc_attrib __attribute__((__malloc__)) | 46 #define av_malloc_attrib __attribute__((__malloc__)) |
47 #else | 47 #else |
48 #define av_malloc_attrib | 48 #define av_malloc_attrib |
49 #endif | 49 #endif |
50 | 50 |
51 #if defined (__GNUC__) && (__GNU__ > 4 || __GNU__ == 4 && __GNU_MINOR__ > 1) | |
52 #define av_alloc_size(n) __attribute__((alloc_size(n))) | |
53 #else | |
54 #define av_alloc_size(n) | |
55 #endif | |
56 | |
51 /** | 57 /** |
52 * Allocate a block of \p size bytes with alignment suitable for all | 58 * Allocate a block of \p size bytes with alignment suitable for all |
53 * memory accesses (including vectors if available on the CPU). | 59 * memory accesses (including vectors if available on the CPU). |
54 * @param size Size in bytes for the memory block to be allocated. | 60 * @param size Size in bytes for the memory block to be allocated. |
55 * @return Pointer to the allocated block, NULL if it cannot allocate | 61 * @return Pointer to the allocated block, NULL if it cannot allocate |
56 * it. | 62 * it. |
57 * @see av_mallocz() | 63 * @see av_mallocz() |
58 */ | 64 */ |
59 void *av_malloc(unsigned int size) av_malloc_attrib; | 65 void *av_malloc(unsigned int size) av_malloc_attrib av_alloc_size(1); |
60 | 66 |
61 /** | 67 /** |
62 * Allocate or reallocate a block of memory. | 68 * Allocate or reallocate a block of memory. |
63 * If \p ptr is NULL and \p size > 0, allocate a new block. If \p | 69 * If \p ptr is NULL and \p size > 0, allocate a new block. If \p |
64 * size is zero, free the memory block pointed by \p ptr. | 70 * size is zero, free the memory block pointed by \p ptr. |
68 * av_malloc(z)() or av_realloc() or NULL. | 74 * av_malloc(z)() or av_realloc() or NULL. |
69 * @return Pointer to a newly reallocated block or NULL if it cannot | 75 * @return Pointer to a newly reallocated block or NULL if it cannot |
70 * reallocate or the function is used to free the memory block. | 76 * reallocate or the function is used to free the memory block. |
71 * @see av_fast_realloc() | 77 * @see av_fast_realloc() |
72 */ | 78 */ |
73 void *av_realloc(void *ptr, unsigned int size); | 79 void *av_realloc(void *ptr, unsigned int size) av_alloc_size(2); |
74 | 80 |
75 /** | 81 /** |
76 * Free a memory block which has been allocated with av_malloc(z)() or | 82 * Free a memory block which has been allocated with av_malloc(z)() or |
77 * av_realloc(). | 83 * av_realloc(). |
78 * @param ptr Pointer to the memory block which should be freed. | 84 * @param ptr Pointer to the memory block which should be freed. |
89 * @param size Size in bytes for the memory block to be allocated. | 95 * @param size Size in bytes for the memory block to be allocated. |
90 * @return Pointer to the allocated block, NULL if it cannot allocate | 96 * @return Pointer to the allocated block, NULL if it cannot allocate |
91 * it. | 97 * it. |
92 * @see av_malloc() | 98 * @see av_malloc() |
93 */ | 99 */ |
94 void *av_mallocz(unsigned int size) av_malloc_attrib; | 100 void *av_mallocz(unsigned int size) av_malloc_attrib av_alloc_size(1); |
95 | 101 |
96 /** | 102 /** |
97 * Duplicate the string \p s. | 103 * Duplicate the string \p s. |
98 * @param s String to be duplicated. | 104 * @param s String to be duplicated. |
99 * @return Pointer to a newly allocated string containing a | 105 * @return Pointer to a newly allocated string containing a |