Miam-Player  0.8.0
A nice music player
mem.h
Go to the documentation of this file.
1 /*
2  * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
27 #ifndef AVUTIL_MEM_H
28 #define AVUTIL_MEM_H
29 
30 #include <limits.h>
31 #include <stdint.h>
32 
33 #include "attributes.h"
34 #include "error.h"
35 #include "avutil.h"
36 
90 #if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1110 || defined(__SUNPRO_C)
91  #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
92  #define DECLARE_ASM_CONST(n,t,v) const t __attribute__ ((aligned (n))) v
93 #elif defined(__TI_COMPILER_VERSION__)
94  #define DECLARE_ALIGNED(n,t,v) \
95  AV_PRAGMA(DATA_ALIGN(v,n)) \
96  t __attribute__((aligned(n))) v
97  #define DECLARE_ASM_CONST(n,t,v) \
98  AV_PRAGMA(DATA_ALIGN(v,n)) \
99  static const t __attribute__((aligned(n))) v
100 #elif defined(__GNUC__)
101  #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
102  #define DECLARE_ASM_CONST(n,t,v) static const t av_used __attribute__ ((aligned (n))) v
103 #elif defined(_MSC_VER)
104  #define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v
105  #define DECLARE_ASM_CONST(n,t,v) __declspec(align(n)) static const t v
106 #else
107  #define DECLARE_ALIGNED(n,t,v) t v
108  #define DECLARE_ASM_CONST(n,t,v) static const t v
109 #endif
110 
131 #if AV_GCC_VERSION_AT_LEAST(3,1)
132  #define av_malloc_attrib __attribute__((__malloc__))
133 #else
134  #define av_malloc_attrib
135 #endif
136 
152 #if AV_GCC_VERSION_AT_LEAST(4,3)
153  #define av_alloc_size(...) __attribute__((alloc_size(__VA_ARGS__)))
154 #else
155  #define av_alloc_size(...)
156 #endif
157 
183 
194 
206 av_alloc_size(1, 2) static inline void *av_malloc_array(size_t nmemb, size_t size)
207 {
208  if (!size || nmemb >= INT_MAX / size)
209  return NULL;
210  return av_malloc(nmemb * size);
211 }
212 
226 av_alloc_size(1, 2) static inline void *av_mallocz_array(size_t nmemb, size_t size)
227 {
228  if (!size || nmemb >= INT_MAX / size)
229  return NULL;
230  return av_mallocz(nmemb * size);
231 }
232 
238 void *av_calloc(size_t nmemb, size_t size) av_malloc_attrib;
239 
260 void *av_realloc(void *ptr, size_t size) av_alloc_size(2);
261 
282 int av_reallocp(void *ptr, size_t size);
283 
299 void *av_realloc_f(void *ptr, size_t nelem, size_t elsize);
300 
319 av_alloc_size(2, 3) void *av_realloc_array(void *ptr, size_t nmemb, size_t size);
320 
338 av_alloc_size(2, 3) int av_reallocp_array(void *ptr, size_t nmemb, size_t size);
339 
372 void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size);
373 
403 void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size);
404 
423 void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size);
424 
436 void av_free(void *ptr);
437 
459 void av_freep(void *ptr);
460 
469 char *av_strdup(const char *s) av_malloc_attrib;
470 
480 char *av_strndup(const char *s, size_t len) av_malloc_attrib;
481 
490 void *av_memdup(const void *p, size_t size);
491 
503 void av_memcpy_backptr(uint8_t *dst, int back, int cnt);
504 
605 void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem);
606 
618 int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem);
619 
643 void *av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size,
644  const uint8_t *elem_data);
645 
665 static inline int av_size_mult(size_t a, size_t b, size_t *r)
666 {
667  size_t t = a * b;
668  /* Hack inspired from glibc: don't try the division if nelem and elsize
669  * are both less than sqrt(SIZE_MAX). */
670  if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b)
671  return AVERROR(EINVAL);
672  *r = t;
673  return 0;
674 }
675 
689 void av_max_alloc(size_t max);
690 
696 #endif /* AVUTIL_MEM_H */
void * av_realloc_f(void *ptr, size_t nelem, size_t elsize)
void av_max_alloc(size_t max)
#define av_malloc_attrib
Definition: mem.h:134
void * av_calloc(size_t nmemb, size_t size) av_malloc_attrib
size_t size
Definition: mem.h:207
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
av_warn_unused_result int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
void * av_malloc(size_t size) av_malloc_attrib av_alloc_size(1)
#define AVERROR(e)
Definition: error.h:43
void av_freep(void *ptr)
void * av_memdup(const void *p, size_t size)
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size)
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
av_warn_unused_result int av_reallocp(void *ptr, size_t size)
char * av_strdup(const char *s) av_malloc_attrib
void * av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size, const uint8_t *elem_data)
void * av_realloc(void *ptr, size_t size) av_alloc_size(2)
void av_free(void *ptr)
#define av_warn_unused_result
Definition: attributes.h:58
#define av_alloc_size(...)
Definition: mem.h:155
void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
size_t nmemb
Definition: mem.h:319
void * av_mallocz(size_t size) av_malloc_attrib av_alloc_size(1)
char * av_strndup(const char *s, size_t len) av_malloc_attrib