annotate mem.c @ 860:536c2e94defa libavutil

Add av_stristr() function This is a case-insensitive version of strstr().
author mru
date Sat, 06 Mar 2010 19:41:22 +0000
parents 14e19b1c0cd5
children 0795a743bda1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
82
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
1 /*
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
2 * default memory allocator for libavutil
613
ed203c477511 cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 603
diff changeset
3 * Copyright (c) 2002 Fabrice Bellard
82
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
4 *
116
d76a36742464 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 113
diff changeset
5 * This file is part of FFmpeg.
d76a36742464 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 113
diff changeset
6 *
d76a36742464 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 113
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
82
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
116
d76a36742464 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 113
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
82
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
11 *
116
d76a36742464 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 113
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
82
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
15 * Lesser General Public License for more details.
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
16 *
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
116
d76a36742464 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 113
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
82
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
20 */
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
21
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
22 /**
642
70bdd5501662 Use full internal pathname in doxygen @file directives.
diego
parents: 633
diff changeset
23 * @file libavutil/mem.c
633
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 629
diff changeset
24 * default memory allocator for libavutil
82
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
25 */
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
26
618
e0bf946f7d23 Directly #include a bunch of indirectly #included headers.
diego
parents: 613
diff changeset
27 #include "config.h"
82
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
28
618
e0bf946f7d23 Directly #include a bunch of indirectly #included headers.
diego
parents: 613
diff changeset
29 #include <limits.h>
597
b4abc96d1610 Use posix_memalign() if available.
ramiro
parents: 509
diff changeset
30 #include <stdlib.h>
618
e0bf946f7d23 Directly #include a bunch of indirectly #included headers.
diego
parents: 613
diff changeset
31 #include <string.h>
603
880c6441f56a Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 597
diff changeset
32 #if HAVE_MALLOC_H
82
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
33 #include <malloc.h>
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
34 #endif
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
35
824
14e19b1c0cd5 Add --malloc-prefix to apply a prefix to malloc, free etc
mru
parents: 667
diff changeset
36 #include "avutil.h"
628
51e8796fe8fc C files should #include the header files of the same name.
diego
parents: 621
diff changeset
37 #include "mem.h"
51e8796fe8fc C files should #include the header files of the same name.
diego
parents: 621
diff changeset
38
633
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 629
diff changeset
39 /* here we can use OS-dependent allocation functions */
629
097c9438d7f4 10l: Add #undefs for system free/malloc/realloc, which must be used here.
diego
parents: 628
diff changeset
40 #undef free
097c9438d7f4 10l: Add #undefs for system free/malloc/realloc, which must be used here.
diego
parents: 628
diff changeset
41 #undef malloc
097c9438d7f4 10l: Add #undefs for system free/malloc/realloc, which must be used here.
diego
parents: 628
diff changeset
42 #undef realloc
097c9438d7f4 10l: Add #undefs for system free/malloc/realloc, which must be used here.
diego
parents: 628
diff changeset
43
824
14e19b1c0cd5 Add --malloc-prefix to apply a prefix to malloc, free etc
mru
parents: 667
diff changeset
44 #ifdef MALLOC_PREFIX
14e19b1c0cd5 Add --malloc-prefix to apply a prefix to malloc, free etc
mru
parents: 667
diff changeset
45
14e19b1c0cd5 Add --malloc-prefix to apply a prefix to malloc, free etc
mru
parents: 667
diff changeset
46 #define malloc AV_JOIN(MALLOC_PREFIX, malloc)
14e19b1c0cd5 Add --malloc-prefix to apply a prefix to malloc, free etc
mru
parents: 667
diff changeset
47 #define memalign AV_JOIN(MALLOC_PREFIX, memalign)
14e19b1c0cd5 Add --malloc-prefix to apply a prefix to malloc, free etc
mru
parents: 667
diff changeset
48 #define posix_memalign AV_JOIN(MALLOC_PREFIX, posix_memalign)
14e19b1c0cd5 Add --malloc-prefix to apply a prefix to malloc, free etc
mru
parents: 667
diff changeset
49 #define realloc AV_JOIN(MALLOC_PREFIX, realloc)
14e19b1c0cd5 Add --malloc-prefix to apply a prefix to malloc, free etc
mru
parents: 667
diff changeset
50 #define free AV_JOIN(MALLOC_PREFIX, free)
14e19b1c0cd5 Add --malloc-prefix to apply a prefix to malloc, free etc
mru
parents: 667
diff changeset
51
14e19b1c0cd5 Add --malloc-prefix to apply a prefix to malloc, free etc
mru
parents: 667
diff changeset
52 void *malloc(size_t size);
14e19b1c0cd5 Add --malloc-prefix to apply a prefix to malloc, free etc
mru
parents: 667
diff changeset
53 void *memalign(size_t align, size_t size);
14e19b1c0cd5 Add --malloc-prefix to apply a prefix to malloc, free etc
mru
parents: 667
diff changeset
54 int posix_memalign(void **ptr, size_t align, size_t size);
14e19b1c0cd5 Add --malloc-prefix to apply a prefix to malloc, free etc
mru
parents: 667
diff changeset
55 void *realloc(void *ptr, size_t size);
14e19b1c0cd5 Add --malloc-prefix to apply a prefix to malloc, free etc
mru
parents: 667
diff changeset
56 void free(void *ptr);
14e19b1c0cd5 Add --malloc-prefix to apply a prefix to malloc, free etc
mru
parents: 667
diff changeset
57
14e19b1c0cd5 Add --malloc-prefix to apply a prefix to malloc, free etc
mru
parents: 667
diff changeset
58 #endif /* MALLOC_PREFIX */
14e19b1c0cd5 Add --malloc-prefix to apply a prefix to malloc, free etc
mru
parents: 667
diff changeset
59
633
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 629
diff changeset
60 /* You can redefine av_malloc and av_free in your project to use your
82
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
61 memory allocator. You do not need to suppress this file because the
633
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 629
diff changeset
62 linker will do it automatically. */
82
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
63
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
64 void *av_malloc(unsigned int size)
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
65 {
597
b4abc96d1610 Use posix_memalign() if available.
ramiro
parents: 509
diff changeset
66 void *ptr = NULL;
603
880c6441f56a Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 597
diff changeset
67 #if CONFIG_MEMALIGN_HACK
82
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
68 long diff;
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
69 #endif
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
70
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
71 /* let's disallow possible ambiguous cases */
96
7d343463873b revert aligned realloc() changesm this should be identical to r5784
michael
parents: 95
diff changeset
72 if(size > (INT_MAX-16) )
82
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
73 return NULL;
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
74
603
880c6441f56a Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 597
diff changeset
75 #if CONFIG_MEMALIGN_HACK
82
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
76 ptr = malloc(size+16);
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
77 if(!ptr)
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
78 return ptr;
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
79 diff= ((-(long)ptr - 1)&15) + 1;
451
c2e1ba46b27c Avoid void*-arithmetic.
benoit
parents: 281
diff changeset
80 ptr = (char*)ptr + diff;
82
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
81 ((char*)ptr)[-1]= diff;
603
880c6441f56a Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 597
diff changeset
82 #elif HAVE_POSIX_MEMALIGN
667
998344532d61 Check return value of posix_memalign and explicitly set pointer to NULL if it
diego
parents: 642
diff changeset
83 if (posix_memalign(&ptr,16,size))
998344532d61 Check return value of posix_memalign and explicitly set pointer to NULL if it
diego
parents: 642
diff changeset
84 ptr = NULL;
603
880c6441f56a Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 597
diff changeset
85 #elif HAVE_MEMALIGN
82
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
86 ptr = memalign(16,size);
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
87 /* Why 64?
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
88 Indeed, we should align it:
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
89 on 4 for 386
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
90 on 16 for 486
633
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 629
diff changeset
91 on 32 for 586, PPro - K6-III
82
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
92 on 64 for K7 (maybe for P3 too).
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
93 Because L1 and L2 caches are aligned on those values.
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
94 But I don't want to code such logic here!
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
95 */
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
96 /* Why 16?
466
f4fd038fcb58 misc spelling fixes
diego
parents: 451
diff changeset
97 Because some CPUs need alignment, for example SSE2 on P4, & most RISC CPUs
82
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
98 it will just trigger an exception and the unaligned load will be done in the
633
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 629
diff changeset
99 exception handler or it will just segfault (SSE2 on P4).
467
4472cc562ee9 typo fixes
diego
parents: 466
diff changeset
100 Why not larger? Because I did not see a difference in benchmarks ...
82
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
101 */
633
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 629
diff changeset
102 /* benchmarks with P3
82
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
103 memalign(64)+1 3071,3051,3032
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
104 memalign(64)+2 3051,3032,3041
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
105 memalign(64)+4 2911,2896,2915
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
106 memalign(64)+8 2545,2554,2550
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
107 memalign(64)+16 2543,2572,2563
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
108 memalign(64)+32 2546,2545,2571
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
109 memalign(64)+64 2570,2533,2558
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
110
633
8c48a1b999a3 spelling/grammar/consistency review part I
diego
parents: 629
diff changeset
111 BTW, malloc seems to do 8-byte alignment by default here.
82
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
112 */
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
113 #else
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
114 ptr = malloc(size);
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
115 #endif
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
116 return ptr;
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
117 }
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
118
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
119 void *av_realloc(void *ptr, unsigned int size)
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
120 {
603
880c6441f56a Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 597
diff changeset
121 #if CONFIG_MEMALIGN_HACK
96
7d343463873b revert aligned realloc() changesm this should be identical to r5784
michael
parents: 95
diff changeset
122 int diff;
7d343463873b revert aligned realloc() changesm this should be identical to r5784
michael
parents: 95
diff changeset
123 #endif
82
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
124
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
125 /* let's disallow possible ambiguous cases */
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
126 if(size > (INT_MAX-16) )
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
127 return NULL;
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
128
603
880c6441f56a Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 597
diff changeset
129 #if CONFIG_MEMALIGN_HACK
96
7d343463873b revert aligned realloc() changesm this should be identical to r5784
michael
parents: 95
diff changeset
130 //FIXME this isn't aligned correctly, though it probably isn't needed
7d343463873b revert aligned realloc() changesm this should be identical to r5784
michael
parents: 95
diff changeset
131 if(!ptr) return av_malloc(size);
7d343463873b revert aligned realloc() changesm this should be identical to r5784
michael
parents: 95
diff changeset
132 diff= ((char*)ptr)[-1];
451
c2e1ba46b27c Avoid void*-arithmetic.
benoit
parents: 281
diff changeset
133 return (char*)realloc((char*)ptr - diff, size + diff) + diff;
96
7d343463873b revert aligned realloc() changesm this should be identical to r5784
michael
parents: 95
diff changeset
134 #else
7d343463873b revert aligned realloc() changesm this should be identical to r5784
michael
parents: 95
diff changeset
135 return realloc(ptr, size);
82
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
136 #endif
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
137 }
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
138
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
139 void av_free(void *ptr)
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
140 {
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
141 /* XXX: this test should not be needed on most libcs */
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
142 if (ptr)
603
880c6441f56a Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 597
diff changeset
143 #if CONFIG_MEMALIGN_HACK
451
c2e1ba46b27c Avoid void*-arithmetic.
benoit
parents: 281
diff changeset
144 free((char*)ptr - ((char*)ptr)[-1]);
82
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
145 #else
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
146 free(ptr);
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
147 #endif
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
148 }
8fb151c4d4c7 Move av_malloc(), av_realloc(), and av_free() from libavcodec to libavutil
lucabe
parents:
diff changeset
149
113
8fc54918226e move memory functions from avcodec to avutil
lu_zero
parents: 96
diff changeset
150 void av_freep(void *arg)
8fc54918226e move memory functions from avcodec to avutil
lu_zero
parents: 96
diff changeset
151 {
8fc54918226e move memory functions from avcodec to avutil
lu_zero
parents: 96
diff changeset
152 void **ptr= (void**)arg;
8fc54918226e move memory functions from avcodec to avutil
lu_zero
parents: 96
diff changeset
153 av_free(*ptr);
8fc54918226e move memory functions from avcodec to avutil
lu_zero
parents: 96
diff changeset
154 *ptr = NULL;
8fc54918226e move memory functions from avcodec to avutil
lu_zero
parents: 96
diff changeset
155 }
8fc54918226e move memory functions from avcodec to avutil
lu_zero
parents: 96
diff changeset
156
8fc54918226e move memory functions from avcodec to avutil
lu_zero
parents: 96
diff changeset
157 void *av_mallocz(unsigned int size)
8fc54918226e move memory functions from avcodec to avutil
lu_zero
parents: 96
diff changeset
158 {
488
cb7f0f00760e Merge declaration and initialization.
michael
parents: 467
diff changeset
159 void *ptr = av_malloc(size);
113
8fc54918226e move memory functions from avcodec to avutil
lu_zero
parents: 96
diff changeset
160 if (ptr)
8fc54918226e move memory functions from avcodec to avutil
lu_zero
parents: 96
diff changeset
161 memset(ptr, 0, size);
8fc54918226e move memory functions from avcodec to avutil
lu_zero
parents: 96
diff changeset
162 return ptr;
8fc54918226e move memory functions from avcodec to avutil
lu_zero
parents: 96
diff changeset
163 }
8fc54918226e move memory functions from avcodec to avutil
lu_zero
parents: 96
diff changeset
164
8fc54918226e move memory functions from avcodec to avutil
lu_zero
parents: 96
diff changeset
165 char *av_strdup(const char *s)
8fc54918226e move memory functions from avcodec to avutil
lu_zero
parents: 96
diff changeset
166 {
508
9409d2db661c make av_strdup(NULL) return NULL
michael
parents: 489
diff changeset
167 char *ptr= NULL;
9409d2db661c make av_strdup(NULL) return NULL
michael
parents: 489
diff changeset
168 if(s){
509
michael
parents: 508
diff changeset
169 int len = strlen(s) + 1;
michael
parents: 508
diff changeset
170 ptr = av_malloc(len);
michael
parents: 508
diff changeset
171 if (ptr)
michael
parents: 508
diff changeset
172 memcpy(ptr, s, len);
508
9409d2db661c make av_strdup(NULL) return NULL
michael
parents: 489
diff changeset
173 }
113
8fc54918226e move memory functions from avcodec to avutil
lu_zero
parents: 96
diff changeset
174 return ptr;
8fc54918226e move memory functions from avcodec to avutil
lu_zero
parents: 96
diff changeset
175 }
8fc54918226e move memory functions from avcodec to avutil
lu_zero
parents: 96
diff changeset
176