~vericalcroft/ubuntu/quantal/celt/added-misc-depends

« back to all changes in this revision

Viewing changes to libcelt/os_support.h

  • Committer: Bazaar Package Importer
  • Author(s): Ron Lee
  • Date: 2008-04-05 03:07:18 UTC
  • Revision ID: james.westby@ubuntu.com-20080405030718-qayahnc495gy25ng
Tags: upstream-0.3.0
ImportĀ upstreamĀ versionĀ 0.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2007 Jean-Marc Valin
 
2
      
 
3
   File: os_support.h
 
4
   This is the (tiny) OS abstraction layer. Aside from math.h, this is the
 
5
   only place where system headers are allowed.
 
6
 
 
7
   Redistribution and use in source and binary forms, with or without
 
8
   modification, are permitted provided that the following conditions are
 
9
   met:
 
10
 
 
11
   1. Redistributions of source code must retain the above copyright notice,
 
12
   this list of conditions and the following disclaimer.
 
13
 
 
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.
 
17
 
 
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.
 
20
 
 
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.
 
32
*/
 
33
 
 
34
#ifndef OS_SUPPORT_H
 
35
#define OS_SUPPORT_H
 
36
 
 
37
#ifdef CUSTOM_SUPPORT
 
38
#  include "custom_support.h"
 
39
#endif
 
40
 
 
41
#include <string.h>
 
42
#include <stdio.h>
 
43
#include <stdlib.h>
 
44
 
 
45
#ifdef __GNUC__
 
46
#define EXPORT __attribute__ ((visibility ("default")))
 
47
#elif defined(WIN32)
 
48
#define EXPORT __declspec(dllexport)
 
49
#else
 
50
#define EXPORT
 
51
#endif
 
52
 
 
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)
 
57
{
 
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);
 
62
}
 
63
#endif
 
64
 
 
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)
 
68
{
 
69
   /* Scratch space doesn't need to be cleared */
 
70
   return calloc(size,1);
 
71
}
 
72
#endif
 
73
 
 
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)
 
77
{
 
78
   return realloc(ptr, size);
 
79
}
 
80
#endif
 
81
 
 
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)
 
85
{
 
86
   free(ptr);
 
87
}
 
88
#endif
 
89
 
 
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)
 
93
{
 
94
   free(ptr);
 
95
}
 
96
#endif
 
97
 
 
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)) ))
 
101
#endif
 
102
 
 
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)) ))
 
107
#endif
 
108
 
 
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))))
 
112
#endif
 
113
 
 
114
 
 
115
#ifndef OVERRIDE_CELT_FATAL
 
116
static inline void _celt_fatal(const char *str, const char *file, int line)
 
117
{
 
118
   fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str);
 
119
   abort();
 
120
}
 
121
#endif
 
122
 
 
123
#ifndef OVERRIDE_CELT_WARNING
 
124
static inline void celt_warning(const char *str)
 
125
{
 
126
#ifndef DISABLE_WARNINGS
 
127
   fprintf (stderr, "warning: %s\n", str);
 
128
#endif
 
129
}
 
130
#endif
 
131
 
 
132
#ifndef OVERRIDE_CELT_WARNING_INT
 
133
static inline void celt_warning_int(const char *str, int val)
 
134
{
 
135
#ifndef DISABLE_WARNINGS
 
136
   fprintf (stderr, "warning: %s %d\n", str, val);
 
137
#endif
 
138
}
 
139
#endif
 
140
 
 
141
#ifndef OVERRIDE_CELT_NOTIFY
 
142
static inline void celt_notify(const char *str)
 
143
{
 
144
#ifndef DISABLE_NOTIFICATIONS
 
145
   fprintf (stderr, "notification: %s\n", str);
 
146
#endif
 
147
}
 
148
#endif
 
149
 
 
150
 
 
151
 
 
152
#ifdef __GNUC__
 
153
#pragma GCC poison printf sprintf
 
154
#pragma GCC poison malloc free realloc calloc
 
155
#endif
 
156
 
 
157
#endif /* OS_SUPPORT_H */
 
158