summaryrefslogtreecommitdiff
path: root/apps/codecs/libFLAC/memory.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libFLAC/memory.c')
-rw-r--r--apps/codecs/libFLAC/memory.c189
1 files changed, 0 insertions, 189 deletions
diff --git a/apps/codecs/libFLAC/memory.c b/apps/codecs/libFLAC/memory.c
deleted file mode 100644
index d93ace693e..0000000000
--- a/apps/codecs/libFLAC/memory.c
+++ /dev/null
@@ -1,189 +0,0 @@
1/* libFLAC - Free Lossless Audio Codec library
2 * Copyright (C) 2001,2002,2003,2004,2005 Josh Coalson
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * - Neither the name of the Xiph.org Foundation nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#include "global.h" /* for malloc() */
33#include "private/memory.h"
34#include "FLAC/assert.h"
35
36#ifdef HAVE_CONFIG_H
37#include <config.h>
38#endif
39
40void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
41{
42 void *x;
43
44 FLAC__ASSERT(0 != aligned_address);
45
46#ifdef FLAC__ALIGN_MALLOC_DATA
47 /* align on 32-byte (256-bit) boundary */
48 x = malloc(bytes+31);
49 *aligned_address = (void*)(((unsigned)x + 31) & -32);
50#else
51 x = malloc(bytes);
52 *aligned_address = x;
53#endif
54 return x;
55}
56
57FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer)
58{
59 FLAC__int32 *pu; /* unaligned pointer */
60 union { /* union needed to comply with C99 pointer aliasing rules */
61 FLAC__int32 *pa; /* aligned pointer */
62 void *pv; /* aligned pointer alias */
63 } u;
64
65 FLAC__ASSERT(elements > 0);
66 FLAC__ASSERT(0 != unaligned_pointer);
67 FLAC__ASSERT(0 != aligned_pointer);
68 FLAC__ASSERT(unaligned_pointer != aligned_pointer);
69
70 pu = (FLAC__int32*)FLAC__memory_alloc_aligned(sizeof(FLAC__int32) * elements, &u.pv);
71 if(0 == pu) {
72 return false;
73 }
74 else {
75 if(*unaligned_pointer != 0)
76 free(*unaligned_pointer);
77 *unaligned_pointer = pu;
78 *aligned_pointer = u.pa;
79 return true;
80 }
81}
82
83FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer)
84{
85 FLAC__uint32 *pu; /* unaligned pointer */
86 union { /* union needed to comply with C99 pointer aliasing rules */
87 FLAC__uint32 *pa; /* aligned pointer */
88 void *pv; /* aligned pointer alias */
89 } u;
90
91 FLAC__ASSERT(elements > 0);
92 FLAC__ASSERT(0 != unaligned_pointer);
93 FLAC__ASSERT(0 != aligned_pointer);
94 FLAC__ASSERT(unaligned_pointer != aligned_pointer);
95
96 pu = (FLAC__uint32*)FLAC__memory_alloc_aligned(sizeof(FLAC__uint32) * elements, &u.pv);
97 if(0 == pu) {
98 return false;
99 }
100 else {
101 if(*unaligned_pointer != 0)
102 free(*unaligned_pointer);
103 *unaligned_pointer = pu;
104 *aligned_pointer = u.pa;
105 return true;
106 }
107}
108
109FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer)
110{
111 FLAC__uint64 *pu; /* unaligned pointer */
112 union { /* union needed to comply with C99 pointer aliasing rules */
113 FLAC__uint64 *pa; /* aligned pointer */
114 void *pv; /* aligned pointer alias */
115 } u;
116
117 FLAC__ASSERT(elements > 0);
118 FLAC__ASSERT(0 != unaligned_pointer);
119 FLAC__ASSERT(0 != aligned_pointer);
120 FLAC__ASSERT(unaligned_pointer != aligned_pointer);
121
122 pu = (FLAC__uint64*)FLAC__memory_alloc_aligned(sizeof(FLAC__uint64) * elements, &u.pv);
123 if(0 == pu) {
124 return false;
125 }
126 else {
127 if(*unaligned_pointer != 0)
128 free(*unaligned_pointer);
129 *unaligned_pointer = pu;
130 *aligned_pointer = u.pa;
131 return true;
132 }
133}
134
135FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer)
136{
137 unsigned *pu; /* unaligned pointer */
138 union { /* union needed to comply with C99 pointer aliasing rules */
139 unsigned *pa; /* aligned pointer */
140 void *pv; /* aligned pointer alias */
141 } u;
142
143 FLAC__ASSERT(elements > 0);
144 FLAC__ASSERT(0 != unaligned_pointer);
145 FLAC__ASSERT(0 != aligned_pointer);
146 FLAC__ASSERT(unaligned_pointer != aligned_pointer);
147
148 pu = (unsigned*)FLAC__memory_alloc_aligned(sizeof(unsigned) * elements, &u.pv);
149 if(0 == pu) {
150 return false;
151 }
152 else {
153 if(*unaligned_pointer != 0)
154 free(*unaligned_pointer);
155 *unaligned_pointer = pu;
156 *aligned_pointer = u.pa;
157 return true;
158 }
159}
160
161#ifndef FLAC__INTEGER_ONLY_LIBRARY
162
163FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer)
164{
165 FLAC__real *pu; /* unaligned pointer */
166 union { /* union needed to comply with C99 pointer aliasing rules */
167 FLAC__real *pa; /* aligned pointer */
168 void *pv; /* aligned pointer alias */
169 } u;
170
171 FLAC__ASSERT(elements > 0);
172 FLAC__ASSERT(0 != unaligned_pointer);
173 FLAC__ASSERT(0 != aligned_pointer);
174 FLAC__ASSERT(unaligned_pointer != aligned_pointer);
175
176 pu = (FLAC__real*)FLAC__memory_alloc_aligned(sizeof(FLAC__real) * elements, &u.pv);
177 if(0 == pu) {
178 return false;
179 }
180 else {
181 if(*unaligned_pointer != 0)
182 free(*unaligned_pointer);
183 *unaligned_pointer = pu;
184 *aligned_pointer = u.pa;
185 return true;
186 }
187}
188
189#endif