williamr@2
|
1 |
/*
|
williamr@2
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
|
williamr@2
|
3 |
|
williamr@2
|
4 |
* Redistribution and use in source and binary forms, with or without
|
williamr@2
|
5 |
* modification, are permitted provided that the following conditions are met:
|
williamr@2
|
6 |
|
williamr@2
|
7 |
* Redistributions of source code must retain the above copyright notice, this
|
williamr@2
|
8 |
* list of conditions and the following disclaimer.
|
williamr@2
|
9 |
* Redistributions in binary form must reproduce the above copyright notice,
|
williamr@2
|
10 |
* this list of conditions and the following disclaimer in the documentation
|
williamr@2
|
11 |
* and/or other materials provided with the distribution.
|
williamr@2
|
12 |
* Neither the name of Nokia Corporation nor the names of its contributors
|
williamr@2
|
13 |
* may be used to endorse or promote products derived from this software
|
williamr@2
|
14 |
* without specific prior written permission.
|
williamr@2
|
15 |
|
williamr@2
|
16 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
williamr@2
|
17 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
williamr@2
|
18 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
williamr@2
|
19 |
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
williamr@2
|
20 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
williamr@2
|
21 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
williamr@2
|
22 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
williamr@2
|
23 |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
williamr@2
|
24 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
williamr@2
|
25 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
williamr@2
|
26 |
*
|
williamr@2
|
27 |
* Description:
|
williamr@2
|
28 |
*
|
williamr@2
|
29 |
*/
|
williamr@2
|
30 |
|
williamr@2
|
31 |
#ifndef _STLP_NEW_H_HEADER
|
williamr@2
|
32 |
# define _STLP_NEW_H_HEADER
|
williamr@2
|
33 |
|
williamr@2
|
34 |
# ifdef _STLP_NO_BAD_ALLOC
|
williamr@2
|
35 |
# ifndef _STLP_NEW_DONT_THROW
|
williamr@2
|
36 |
# define _STLP_NEW_DONT_THROW 1
|
williamr@2
|
37 |
# endif /* _STLP_NEW_DONT_THROW */
|
williamr@2
|
38 |
|
williamr@2
|
39 |
# include <exception>
|
williamr@2
|
40 |
|
williamr@2
|
41 |
|
williamr@2
|
42 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
43 |
|
williamr@2
|
44 |
#if defined(__SYMBIAN32__) && defined( __WINSCW__)
|
williamr@2
|
45 |
// already defined symcpp.h included from rvct2_2.h
|
williamr@2
|
46 |
struct nothrow_t {};
|
williamr@2
|
47 |
#endif
|
williamr@2
|
48 |
|
williamr@2
|
49 |
|
williamr@2
|
50 |
# ifdef _STLP_OWN_IOSTREAMS
|
williamr@2
|
51 |
#ifdef __ARMCC__
|
williamr@2
|
52 |
extern _STLP_DECLSPEC const nothrow_t nothrow;
|
williamr@2
|
53 |
#else
|
williamr@2
|
54 |
extern IMPORT_C const nothrow_t& GetNoThrowObj();
|
williamr@2
|
55 |
#define nothrow GetNoThrowObj()
|
williamr@2
|
56 |
#endif
|
williamr@2
|
57 |
# else
|
williamr@2
|
58 |
# define nothrow nothrow_t()
|
williamr@2
|
59 |
# endif
|
williamr@2
|
60 |
#ifndef _STLP_EXCEPTION_BASE
|
williamr@2
|
61 |
# define _STLP_EXCEPTION_BASE exception
|
williamr@2
|
62 |
#endif
|
williamr@2
|
63 |
|
williamr@2
|
64 |
class bad_alloc : public _STLP_EXCEPTION_BASE {
|
williamr@2
|
65 |
public:
|
williamr@2
|
66 |
bad_alloc () _STLP_NOTHROW_INHERENTLY { }
|
williamr@2
|
67 |
bad_alloc(const bad_alloc&) _STLP_NOTHROW_INHERENTLY { }
|
williamr@2
|
68 |
bad_alloc& operator=(const bad_alloc&) _STLP_NOTHROW_INHERENTLY {return *this;}
|
williamr@2
|
69 |
~bad_alloc () _STLP_NOTHROW_INHERENTLY { }
|
williamr@2
|
70 |
const char* what() const _STLP_NOTHROW_INHERENTLY { return "bad alloc"; }
|
williamr@2
|
71 |
};
|
williamr@2
|
72 |
|
williamr@2
|
73 |
_STLP_END_NAMESPACE
|
williamr@2
|
74 |
|
williamr@2
|
75 |
#endif /* _STLP_NO_BAD_ALLOC */
|
williamr@2
|
76 |
|
williamr@2
|
77 |
#if defined (_STLP_WINCE)
|
williamr@2
|
78 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
79 |
|
williamr@2
|
80 |
inline void* _STLP_CALL __stl_new(size_t __n) {
|
williamr@2
|
81 |
return ::malloc(__n);
|
williamr@2
|
82 |
}
|
williamr@2
|
83 |
|
williamr@2
|
84 |
inline void _STLP_CALL __stl_delete(void* __p) {
|
williamr@2
|
85 |
free(__p);
|
williamr@2
|
86 |
}
|
williamr@2
|
87 |
|
williamr@2
|
88 |
#ifndef __cdecl
|
williamr@2
|
89 |
# define __cdecl
|
williamr@2
|
90 |
#endif
|
williamr@2
|
91 |
|
williamr@2
|
92 |
_STLP_END_NAMESPACE
|
williamr@2
|
93 |
|
williamr@2
|
94 |
#else /* _STLP_WINCE */
|
williamr@2
|
95 |
|
williamr@2
|
96 |
#include <new>
|
williamr@2
|
97 |
|
williamr@2
|
98 |
# ifndef _STLP_NO_BAD_ALLOC
|
williamr@2
|
99 |
# ifdef _STLP_USE_OWN_NAMESPACE
|
williamr@2
|
100 |
|
williamr@2
|
101 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
102 |
using _STLP_VENDOR_EXCEPT_STD::bad_alloc;
|
williamr@2
|
103 |
using _STLP_VENDOR_EXCEPT_STD::nothrow_t;
|
williamr@2
|
104 |
using _STLP_VENDOR_EXCEPT_STD::nothrow;
|
williamr@2
|
105 |
|
williamr@2
|
106 |
# if defined (_STLP_GLOBAL_NEW_HANDLER)
|
williamr@2
|
107 |
using ::new_handler;
|
williamr@2
|
108 |
using ::set_new_handler;
|
williamr@2
|
109 |
# else
|
williamr@2
|
110 |
using _STLP_VENDOR_EXCEPT_STD::new_handler;
|
williamr@2
|
111 |
using _STLP_VENDOR_EXCEPT_STD::set_new_handler;
|
williamr@2
|
112 |
# endif
|
williamr@2
|
113 |
|
williamr@2
|
114 |
_STLP_END_NAMESPACE
|
williamr@2
|
115 |
|
williamr@2
|
116 |
# endif /* _STLP_OWN_NAMESPACE */
|
williamr@2
|
117 |
|
williamr@2
|
118 |
# endif /* _STLP_NO_BAD_ALLOC */
|
williamr@2
|
119 |
|
williamr@2
|
120 |
# if defined (_STLP_NO_NEW_NEW_HEADER) || defined (_STLP_NEW_DONT_THROW) || defined (__SYMBIAN32__) \
|
williamr@2
|
121 |
|| defined (__WINS__) && ! defined (_STLP_CHECK_NULL_ALLOC)
|
williamr@2
|
122 |
# define _STLP_CHECK_NULL_ALLOC(__x) void* __y = __x;if (__y == 0){_STLP_THROW(bad_alloc());}return __y
|
williamr@2
|
123 |
# if defined (__SYMBIAN32__)
|
williamr@2
|
124 |
//# define _STLP_NEW operator new
|
williamr@2
|
125 |
#define _STLP_NEW ::malloc
|
williamr@2
|
126 |
#endif
|
williamr@2
|
127 |
/*
|
williamr@2
|
128 |
# elif defined (__SYMBIAN32__) || defined (__WINS__)
|
williamr@2
|
129 |
# ifndef _STLP_USE_TRAP_LEAVE
|
williamr@2
|
130 |
# define _STLP_CHECK_NULL_ALLOC(__x) void* __y = __x;if (__y == 0){abort();}return __y
|
williamr@2
|
131 |
# else
|
williamr@2
|
132 |
# define _STLP_NEW(x) :: operator new (x, ELeave)
|
williamr@2
|
133 |
# define _STLP_CHECK_NULL_ALLOC(__x) return __x
|
williamr@2
|
134 |
# endif
|
williamr@2
|
135 |
*/
|
williamr@2
|
136 |
# else
|
williamr@2
|
137 |
# define _STLP_CHECK_NULL_ALLOC(__x) return __x
|
williamr@2
|
138 |
# endif
|
williamr@2
|
139 |
|
williamr@2
|
140 |
#ifndef _STLP_NEW
|
williamr@2
|
141 |
# define _STLP_NEW ::operator new
|
williamr@2
|
142 |
#endif
|
williamr@2
|
143 |
# define _STLP_PLACEMENT_NEW ::new
|
williamr@2
|
144 |
|
williamr@2
|
145 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
146 |
|
williamr@2
|
147 |
#ifdef __SYMBIAN32__
|
williamr@2
|
148 |
|
williamr@2
|
149 |
typedef void(*new_handler)();
|
williamr@2
|
150 |
|
williamr@2
|
151 |
_STLP_DECLSPEC new_handler set_new_handler(new_handler pnew) throw();
|
williamr@2
|
152 |
|
williamr@2
|
153 |
#endif
|
williamr@2
|
154 |
|
williamr@2
|
155 |
#if (( defined(__IBMCPP__)|| defined(__OS400__) || defined (__xlC__) || defined (qTidyHeap)) && defined(__DEBUG_ALLOC__) )
|
williamr@2
|
156 |
inline void* _STLP_CALL __stl_new(size_t __n) { _STLP_CHECK_NULL_ALLOC(_STLP_NEW(__n, __FILE__, __LINE__)); }
|
williamr@2
|
157 |
inline void _STLP_CALL __stl_delete(void* __p) { ::operator delete(__p, __FILE__, __LINE__); }
|
williamr@2
|
158 |
#else
|
williamr@2
|
159 |
inline void* _STLP_CALL __stl_new(size_t __n) { return ::operator new(__n); }
|
williamr@2
|
160 |
inline void _STLP_CALL __stl_delete(void* __p) { ::operator delete(__p); }
|
williamr@2
|
161 |
#endif
|
williamr@2
|
162 |
_STLP_END_NAMESPACE
|
williamr@2
|
163 |
|
williamr@2
|
164 |
|
williamr@2
|
165 |
# endif /* _STLP_WINCE */
|
williamr@2
|
166 |
|
williamr@2
|
167 |
#if defined(__SYMBIAN32__) && !defined(__GCCE__)
|
williamr@2
|
168 |
_STLP_DECLSPEC void *operator new(unsigned int aSize);
|
williamr@2
|
169 |
|
williamr@2
|
170 |
_STLP_DECLSPEC void *operator new[](unsigned int aSize);
|
williamr@2
|
171 |
#endif
|
williamr@2
|
172 |
|
williamr@2
|
173 |
_STLP_DECLSPEC void operator delete(void* aPtr) throw();
|
williamr@2
|
174 |
|
williamr@2
|
175 |
_STLP_DECLSPEC void operator delete[](void* aPtr) throw();
|
williamr@2
|
176 |
|
williamr@2
|
177 |
_STLP_DECLSPEC void* operator new(unsigned int aSize, const std::nothrow_t& /*aNoThrow*/) throw();
|
williamr@2
|
178 |
|
williamr@2
|
179 |
_STLP_DECLSPEC void* operator new[](unsigned int aSize, const std::nothrow_t& aNoThrow) throw();
|
williamr@2
|
180 |
|
williamr@2
|
181 |
_STLP_DECLSPEC void operator delete(void* aPtr, const std::nothrow_t& /*aNoThrow*/) throw();
|
williamr@2
|
182 |
|
williamr@2
|
183 |
_STLP_DECLSPEC void operator delete[](void* aPtr, const std::nothrow_t& /*aNoThrow*/) throw();
|
williamr@2
|
184 |
|
williamr@2
|
185 |
|
williamr@2
|
186 |
// placement delete
|
williamr@2
|
187 |
#ifndef __PLACEMENT_VEC_NEW_INLINE
|
williamr@2
|
188 |
#define __PLACEMENT_VEC_NEW_INLINE
|
williamr@2
|
189 |
inline void* operator new[](unsigned int /*aSize*/, void* aBase) throw()
|
williamr@2
|
190 |
{return aBase;}
|
williamr@2
|
191 |
inline void operator delete[](void* /*aPtr*/, void* /*aBase*/) throw()
|
williamr@2
|
192 |
{
|
williamr@2
|
193 |
|
williamr@2
|
194 |
}
|
williamr@2
|
195 |
#endif
|
williamr@2
|
196 |
|
williamr@2
|
197 |
#ifndef __PLACEMENT_NEW_INLINE
|
williamr@2
|
198 |
#define __PLACEMENT_NEW_INLINE
|
williamr@2
|
199 |
inline void* operator new(unsigned int /*aSize*/, void* aBase) throw()
|
williamr@2
|
200 |
{return aBase;}
|
williamr@2
|
201 |
|
williamr@2
|
202 |
// Global placement operator delete
|
williamr@2
|
203 |
inline void operator delete(void* /*aPtr*/, void* /*aBase*/) throw()
|
williamr@2
|
204 |
{}
|
williamr@2
|
205 |
#endif //__PLACEMENT_NEW_INLINE
|
williamr@2
|
206 |
|
williamr@2
|
207 |
|
williamr@2
|
208 |
#endif /* _STLP_NEW_H_HEADER */
|