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"
46
#define EXPORT __attribute__ ((visibility ("default")))
48
#define EXPORT __declspec(dllexport)
53
/** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, celt_realloc and celt_free
54
NOTE: celt_alloc needs to CLEAR THE MEMORY */
55
#ifndef OVERRIDE_CELT_ALLOC
56
static inline void *celt_alloc (int size)
58
/* WARNING: this is not equivalent to malloc(). If you want to use malloc()
59
or your own allocator, YOU NEED TO CLEAR THE MEMORY ALLOCATED. Otherwise
60
you will experience strange bugs */
61
return calloc(size,1);
65
/** Same as celt_alloc, except that the area is only needed inside a Speex call (might cause problem with wideband though) */
66
#ifndef OVERRIDE_CELT_ALLOC_SCRATCH
67
static inline void *celt_alloc_scratch (int size)
69
/* Scratch space doesn't need to be cleared */
70
return calloc(size,1);
74
/** Speex wrapper for realloc. To do your own dynamic allocation, all you need to do is replace this function, celt_alloc and celt_free */
75
#ifndef OVERRIDE_CELT_REALLOC
76
static inline void *celt_realloc (void *ptr, int size)
78
return realloc(ptr, size);
82
/** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, celt_realloc and celt_alloc */
83
#ifndef OVERRIDE_CELT_FREE
84
static inline void celt_free (void *ptr)
90
/** Same as celt_free, except that the area is only needed inside a Speex call (might cause problem with wideband though) */
91
#ifndef OVERRIDE_CELT_FREE_SCRATCH
92
static inline void celt_free_scratch (void *ptr)
98
/** Copy n bytes of memory from src to dst. The 0* term provides compile-time type checking */
99
#ifndef OVERRIDE_CELT_COPY
100
#define CELT_COPY(dst, src, n) (memcpy((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) ))
103
/** Copy n bytes of memory from src to dst, allowing overlapping regions. The 0* term
104
provides compile-time type checking */
105
#ifndef OVERRIDE_CELT_MOVE
106
#define CELT_MOVE(dst, src, n) (memmove((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) ))
109
/** Set n bytes of memory to value of c, starting at address s */
110
#ifndef OVERRIDE_CELT_MEMSET
111
#define CELT_MEMSET(dst, c, n) (memset((dst), (c), (n)*sizeof(*(dst))))
115
#ifndef OVERRIDE_CELT_FATAL
116
static inline void _celt_fatal(const char *str, const char *file, int line)
118
fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str);
123
#ifndef OVERRIDE_CELT_WARNING
124
static inline void celt_warning(const char *str)
126
#ifndef DISABLE_WARNINGS
127
fprintf (stderr, "warning: %s\n", str);
132
#ifndef OVERRIDE_CELT_WARNING_INT
133
static inline void celt_warning_int(const char *str, int val)
135
#ifndef DISABLE_WARNINGS
136
fprintf (stderr, "warning: %s %d\n", str, val);
141
#ifndef OVERRIDE_CELT_NOTIFY
142
static inline void celt_notify(const char *str)
144
#ifndef DISABLE_NOTIFICATIONS
145
fprintf (stderr, "notification: %s\n", str);
153
#pragma GCC poison printf sprintf
154
#pragma GCC poison malloc free realloc calloc
157
#endif /* OS_SUPPORT_H */