Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > VSs > VSs__H264__App
diff libavutil/mem.c @ 2:897f711a7157
rearrange to work with autoconf
| author | Nina Engelhardt <nengel@mailbox.tu-berlin.de> |
|---|---|
| date | Tue, 25 Sep 2012 15:55:33 +0200 |
| parents | |
| children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libavutil/mem.c Tue Sep 25 15:55:33 2012 +0200 1.3 @@ -0,0 +1,127 @@ 1.4 +/* 1.5 + * default memory allocator for libavutil 1.6 + * Copyright (c) 2002 Fabrice Bellard 1.7 + * 1.8 + * This file is part of FFmpeg. 1.9 + * 1.10 + * FFmpeg is free software; you can redistribute it and/or 1.11 + * modify it under the terms of the GNU Lesser General Public 1.12 + * License as published by the Free Software Foundation; either 1.13 + * version 2.1 of the License, or (at your option) any later version. 1.14 + * 1.15 + * FFmpeg is distributed in the hope that it will be useful, 1.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 1.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1.18 + * Lesser General Public License for more details. 1.19 + * 1.20 + * You should have received a copy of the GNU Lesser General Public 1.21 + * License along with FFmpeg; if not, write to the Free Software 1.22 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 1.23 + */ 1.24 + 1.25 +/** 1.26 + * @file 1.27 + * default memory allocator for libavutil 1.28 + */ 1.29 + 1.30 +#include "config.h" 1.31 + 1.32 +#include <limits.h> 1.33 +#include <stdlib.h> 1.34 +#include <stdint.h> 1.35 +#include <string.h> 1.36 +#if HAVE_MALLOC_H 1.37 +#include <malloc.h> 1.38 +#endif 1.39 + 1.40 +#include "mem.h" 1.41 + 1.42 +/* here we can use OS-dependent allocation functions */ 1.43 +#undef free 1.44 +#undef malloc 1.45 +#undef realloc 1.46 + 1.47 +#ifdef MALLOC_PREFIX 1.48 + 1.49 +#define malloc AV_JOIN(MALLOC_PREFIX, malloc) 1.50 +#define memalign AV_JOIN(MALLOC_PREFIX, memalign) 1.51 +#define posix_memalign AV_JOIN(MALLOC_PREFIX, posix_memalign) 1.52 +#define realloc AV_JOIN(MALLOC_PREFIX, realloc) 1.53 +#define free AV_JOIN(MALLOC_PREFIX, free) 1.54 + 1.55 +void *malloc(size_t size); 1.56 +void *memalign(size_t align, size_t size); 1.57 +int posix_memalign(void **ptr, size_t align, size_t size); 1.58 +void *realloc(void *ptr, size_t size); 1.59 +void free(void *ptr); 1.60 + 1.61 +#endif /* MALLOC_PREFIX */ 1.62 + 1.63 + 1.64 +/* You can redefine av_malloc and av_free in your project to use your 1.65 + memory allocator. You do not need to suppress this file because the 1.66 + linker will do it automatically. */ 1.67 + 1.68 +void *av_malloc(unsigned int size) 1.69 +{ 1.70 + void *ptr = NULL; 1.71 + /* let's disallow possible ambiguous cases */ 1.72 + if(size > (INT_MAX-16) ) 1.73 + return NULL; 1.74 + 1.75 +//FIXME: when no aligned mallocs vector code should be disabled. 1.76 +#if HAVE_POSIX_MEMALIGN 1.77 + if (posix_memalign(&ptr,16,size)) 1.78 + ptr = NULL; 1.79 +#elif HAVE_MEMALIGN 1.80 + ptr = memalign(16,size); 1.81 +#else 1.82 + ptr = malloc(size); 1.83 +#endif 1.84 + return ptr; 1.85 +} 1.86 + 1.87 +void *av_realloc(void *ptr, unsigned int size) 1.88 +{ 1.89 + /* let's disallow possible ambiguous cases */ 1.90 + if(size > (INT_MAX-16) ) 1.91 + return NULL; 1.92 + 1.93 + return realloc(ptr, size); 1.94 + 1.95 +} 1.96 + 1.97 +void av_free(void *ptr) 1.98 +{ 1.99 + /* XXX: this test should not be needed on most libcs */ 1.100 + if (ptr) 1.101 + free(ptr); 1.102 + 1.103 +} 1.104 + 1.105 +void av_freep(void *arg) 1.106 +{ 1.107 + void **ptr= (void**)arg; 1.108 + av_free(*ptr); 1.109 + *ptr = NULL; 1.110 +} 1.111 + 1.112 +void *av_mallocz(unsigned int size) 1.113 +{ 1.114 + void *ptr = av_malloc(size); 1.115 + if (ptr) 1.116 + memset(ptr, 0, size); 1.117 + return ptr; 1.118 +} 1.119 + 1.120 +char *av_strdup(const char *s) 1.121 +{ 1.122 + char *ptr= NULL; 1.123 + if(s){ 1.124 + int len = strlen(s) + 1; 1.125 + ptr = av_malloc(len); 1.126 + if (ptr) 1.127 + memcpy(ptr, s, len); 1.128 + } 1.129 + return ptr; 1.130 +}
