Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > VSs > VSs__H264__App
comparison 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 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:42ed195b74d2 |
|---|---|
| 1 /* | |
| 2 * default memory allocator for libavutil | |
| 3 * Copyright (c) 2002 Fabrice Bellard | |
| 4 * | |
| 5 * This file is part of FFmpeg. | |
| 6 * | |
| 7 * FFmpeg is free software; you can redistribute it and/or | |
| 8 * modify it under the terms of the GNU Lesser General Public | |
| 9 * License as published by the Free Software Foundation; either | |
| 10 * version 2.1 of the License, or (at your option) any later version. | |
| 11 * | |
| 12 * FFmpeg is distributed in the hope that it will be useful, | |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 15 * Lesser General Public License for more details. | |
| 16 * | |
| 17 * You should have received a copy of the GNU Lesser General Public | |
| 18 * License along with FFmpeg; if not, write to the Free Software | |
| 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 */ | |
| 21 | |
| 22 /** | |
| 23 * @file | |
| 24 * default memory allocator for libavutil | |
| 25 */ | |
| 26 | |
| 27 #include "config.h" | |
| 28 | |
| 29 #include <limits.h> | |
| 30 #include <stdlib.h> | |
| 31 #include <stdint.h> | |
| 32 #include <string.h> | |
| 33 #if HAVE_MALLOC_H | |
| 34 #include <malloc.h> | |
| 35 #endif | |
| 36 | |
| 37 #include "mem.h" | |
| 38 | |
| 39 /* here we can use OS-dependent allocation functions */ | |
| 40 #undef free | |
| 41 #undef malloc | |
| 42 #undef realloc | |
| 43 | |
| 44 #ifdef MALLOC_PREFIX | |
| 45 | |
| 46 #define malloc AV_JOIN(MALLOC_PREFIX, malloc) | |
| 47 #define memalign AV_JOIN(MALLOC_PREFIX, memalign) | |
| 48 #define posix_memalign AV_JOIN(MALLOC_PREFIX, posix_memalign) | |
| 49 #define realloc AV_JOIN(MALLOC_PREFIX, realloc) | |
| 50 #define free AV_JOIN(MALLOC_PREFIX, free) | |
| 51 | |
| 52 void *malloc(size_t size); | |
| 53 void *memalign(size_t align, size_t size); | |
| 54 int posix_memalign(void **ptr, size_t align, size_t size); | |
| 55 void *realloc(void *ptr, size_t size); | |
| 56 void free(void *ptr); | |
| 57 | |
| 58 #endif /* MALLOC_PREFIX */ | |
| 59 | |
| 60 | |
| 61 /* You can redefine av_malloc and av_free in your project to use your | |
| 62 memory allocator. You do not need to suppress this file because the | |
| 63 linker will do it automatically. */ | |
| 64 | |
| 65 void *av_malloc(unsigned int size) | |
| 66 { | |
| 67 void *ptr = NULL; | |
| 68 /* let's disallow possible ambiguous cases */ | |
| 69 if(size > (INT_MAX-16) ) | |
| 70 return NULL; | |
| 71 | |
| 72 //FIXME: when no aligned mallocs vector code should be disabled. | |
| 73 #if HAVE_POSIX_MEMALIGN | |
| 74 if (posix_memalign(&ptr,16,size)) | |
| 75 ptr = NULL; | |
| 76 #elif HAVE_MEMALIGN | |
| 77 ptr = memalign(16,size); | |
| 78 #else | |
| 79 ptr = malloc(size); | |
| 80 #endif | |
| 81 return ptr; | |
| 82 } | |
| 83 | |
| 84 void *av_realloc(void *ptr, unsigned int size) | |
| 85 { | |
| 86 /* let's disallow possible ambiguous cases */ | |
| 87 if(size > (INT_MAX-16) ) | |
| 88 return NULL; | |
| 89 | |
| 90 return realloc(ptr, size); | |
| 91 | |
| 92 } | |
| 93 | |
| 94 void av_free(void *ptr) | |
| 95 { | |
| 96 /* XXX: this test should not be needed on most libcs */ | |
| 97 if (ptr) | |
| 98 free(ptr); | |
| 99 | |
| 100 } | |
| 101 | |
| 102 void av_freep(void *arg) | |
| 103 { | |
| 104 void **ptr= (void**)arg; | |
| 105 av_free(*ptr); | |
| 106 *ptr = NULL; | |
| 107 } | |
| 108 | |
| 109 void *av_mallocz(unsigned int size) | |
| 110 { | |
| 111 void *ptr = av_malloc(size); | |
| 112 if (ptr) | |
| 113 memset(ptr, 0, size); | |
| 114 return ptr; | |
| 115 } | |
| 116 | |
| 117 char *av_strdup(const char *s) | |
| 118 { | |
| 119 char *ptr= NULL; | |
| 120 if(s){ | |
| 121 int len = strlen(s) + 1; | |
| 122 ptr = av_malloc(len); | |
| 123 if (ptr) | |
| 124 memcpy(ptr, s, len); | |
| 125 } | |
| 126 return ptr; | |
| 127 } |
