1 /* Copyright (C) 2007 Jean-Marc Valin
4 This is the (tiny) OS abstraction layer. Aside from math.h, this is the
5 only place where system headers are allowed.
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are
11 1. Redistributions of source code must retain the above copyright notice,
12 this list of conditions and the following disclaimer.
14 2. Redistributions in binary form must reproduce the above copyright
15 notice, this list of conditions and the following disclaimer in the
16 documentation and/or other materials provided with the distribution.
18 3. The name of the author may not be used to endorse or promote products
19 derived from this software without specific prior written permission.
21 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
25 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 POSSIBILITY OF SUCH DAMAGE.
38 # include "custom_support.h"
45 /** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, celt_realloc and celt_free
46 NOTE: celt_alloc needs to CLEAR THE MEMORY */
47 #ifndef OVERRIDE_CELT_ALLOC
48 static inline void *celt_alloc (int size)
50 /* WARNING: this is not equivalent to malloc(). If you want to use malloc()
51 or your own allocator, YOU NEED TO CLEAR THE MEMORY ALLOCATED. Otherwise
52 you will experience strange bugs */
53 return calloc(size,1);
57 /** Same as celt_alloc, except that the area is only needed inside a Speex call (might cause problem with wideband though) */
58 #ifndef OVERRIDE_CELT_ALLOC_SCRATCH
59 static inline void *celt_alloc_scratch (int size)
61 /* Scratch space doesn't need to be cleared */
62 return calloc(size,1);
66 /** Speex wrapper for realloc. To do your own dynamic allocation, all you need to do is replace this function, celt_alloc and celt_free */
67 #ifndef OVERRIDE_CELT_REALLOC
68 static inline void *celt_realloc (void *ptr, int size)
70 return realloc(ptr, size);
74 /** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, celt_realloc and celt_alloc */
75 #ifndef OVERRIDE_CELT_FREE
76 static inline void celt_free (void *ptr)
82 /** Same as celt_free, except that the area is only needed inside a Speex call (might cause problem with wideband though) */
83 #ifndef OVERRIDE_CELT_FREE_SCRATCH
84 static inline void celt_free_scratch (void *ptr)
90 /** Copy n bytes of memory from src to dst. The 0* term provides compile-time type checking */
91 #ifndef OVERRIDE_CELT_COPY
92 #define CELT_COPY(dst, src, n) (memcpy((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) ))
95 /** Copy n bytes of memory from src to dst, allowing overlapping regions. The 0* term
96 provides compile-time type checking */
97 #ifndef OVERRIDE_CELT_MOVE
98 #define CELT_MOVE(dst, src, n) (memmove((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) ))
101 /** Set n bytes of memory to value of c, starting at address s */
102 #ifndef OVERRIDE_CELT_MEMSET
103 #define CELT_MEMSET(dst, c, n) (memset((dst), (c), (n)*sizeof(*(dst))))
107 #ifndef OVERRIDE_CELT_FATAL
108 static inline void _celt_fatal(const char *str, const char *file, int line)
110 fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str);
115 #ifndef OVERRIDE_CELT_WARNING
116 static inline void celt_warning(const char *str)
118 #ifndef DISABLE_WARNINGS
119 fprintf (stderr, "warning: %s\n", str);
124 #ifndef OVERRIDE_CELT_WARNING_INT
125 static inline void celt_warning_int(const char *str, int val)
127 #ifndef DISABLE_WARNINGS
128 fprintf (stderr, "warning: %s %d\n", str, val);
133 #ifndef OVERRIDE_CELT_NOTIFY
134 static inline void celt_notify(const char *str)
136 #ifndef DISABLE_NOTIFICATIONS
137 fprintf (stderr, "notification: %s\n", str);
145 #pragma GCC poison printf sprintf
146 #pragma GCC poison malloc free realloc calloc
149 #endif /* OS_SUPPORT_H */