williamr@2
|
1 |
/*
|
williamr@2
|
2 |
* © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
|
williamr@2
|
3 |
*
|
williamr@2
|
4 |
* Copyright (c) 1997
|
williamr@2
|
5 |
* Moscow Center for SPARC Technology
|
williamr@2
|
6 |
*
|
williamr@2
|
7 |
* Copyright (c) 1999
|
williamr@2
|
8 |
* Boris Fomitchev
|
williamr@2
|
9 |
*
|
williamr@2
|
10 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@2
|
11 |
* or implied. Any use is at your own risk.
|
williamr@2
|
12 |
*
|
williamr@2
|
13 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@2
|
14 |
* without fee, provided the above notices are retained on all copies.
|
williamr@2
|
15 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@2
|
16 |
* provided the above notices are retained, and a notice that the code was
|
williamr@2
|
17 |
* modified is included with the above copyright notice.
|
williamr@2
|
18 |
*
|
williamr@2
|
19 |
*/
|
williamr@2
|
20 |
|
williamr@2
|
21 |
# ifndef _STLP_DEBUG_C
|
williamr@2
|
22 |
# define _STLP_DEBUG_C
|
williamr@2
|
23 |
|
williamr@2
|
24 |
#if defined ( _STLP_DEBUG )
|
williamr@2
|
25 |
|
williamr@2
|
26 |
# ifdef _STLP_THREADS
|
williamr@2
|
27 |
# ifndef _STLP_NEED_MUTABLE
|
williamr@2
|
28 |
# define _STLP_ACQUIRE_LOCK(_Lock) _Lock._M_acquire_lock();
|
williamr@2
|
29 |
# define _STLP_RELEASE_LOCK(_Lock) _Lock._M_release_lock();
|
williamr@2
|
30 |
# else
|
williamr@2
|
31 |
# define _STLP_ACQUIRE_LOCK(_Lock) ((_STLP_mutex&)_Lock)._M_acquire_lock();
|
williamr@2
|
32 |
# define _STLP_RELEASE_LOCK(_Lock) ((_STLP_mutex&)_Lock)._M_release_lock();
|
williamr@2
|
33 |
# endif /* _STLP_NEED_MUTABLE */
|
williamr@2
|
34 |
# else
|
williamr@2
|
35 |
# define _STLP_ACQUIRE_LOCK(_Lock)
|
williamr@2
|
36 |
# define _STLP_RELEASE_LOCK(_Lock)
|
williamr@2
|
37 |
# endif /* _STLP_THREADS */
|
williamr@2
|
38 |
|
williamr@2
|
39 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
40 |
|
williamr@2
|
41 |
//==========================================================
|
williamr@2
|
42 |
// global non-inline functions
|
williamr@2
|
43 |
//==========================================================
|
williamr@2
|
44 |
|
williamr@2
|
45 |
// [ i1, i2)
|
williamr@2
|
46 |
template <class _Iterator>
|
williamr@2
|
47 |
inline bool _STLP_CALL
|
williamr@2
|
48 |
__in_range_aux(const _Iterator& __it, const _Iterator& __first,
|
williamr@2
|
49 |
const _Iterator& __last, const random_access_iterator_tag &) {
|
williamr@2
|
50 |
return ( __it >= __first &&
|
williamr@2
|
51 |
__it < __last);
|
williamr@2
|
52 |
}
|
williamr@2
|
53 |
|
williamr@2
|
54 |
template <class _Iterator1, class _Iterator>
|
williamr@2
|
55 |
# if defined (_STLP_MSVC) && (_STLP_MSVC >= 1100)
|
williamr@2
|
56 |
inline bool _STLP_CALL __in_range_aux(_Iterator1 __it, const _Iterator& __first,
|
williamr@2
|
57 |
# else
|
williamr@2
|
58 |
inline bool _STLP_CALL __in_range_aux(const _Iterator1& __it, const _Iterator& __first,
|
williamr@2
|
59 |
# endif
|
williamr@2
|
60 |
const _Iterator& __last, const forward_iterator_tag &) {
|
williamr@2
|
61 |
_Iterator1 __i(__first);
|
williamr@2
|
62 |
for (; __i != __last && __i != __it; ++__i);
|
williamr@2
|
63 |
return (__i!=__last);
|
williamr@2
|
64 |
}
|
williamr@2
|
65 |
|
williamr@2
|
66 |
# if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
|
williamr@2
|
67 |
template <class _Iterator1, class _Iterator>
|
williamr@2
|
68 |
inline bool _STLP_CALL
|
williamr@2
|
69 |
__in_range_aux(const _Iterator1& __it, const _Iterator& __first,
|
williamr@2
|
70 |
const _Iterator& __last, const bidirectional_iterator_tag &) {
|
williamr@2
|
71 |
_Iterator1 __i(__first);
|
williamr@2
|
72 |
for (; __i != __last && __i != __it; ++__i);
|
williamr@2
|
73 |
return (__i !=__last);
|
williamr@2
|
74 |
}
|
williamr@2
|
75 |
# endif
|
williamr@2
|
76 |
|
williamr@2
|
77 |
template <class _Iterator>
|
williamr@2
|
78 |
bool _STLP_CALL __check_range(const _Iterator& __first, const _Iterator& __last) {
|
williamr@2
|
79 |
_STLP_VERBOSE_RETURN(__valid_range(__first,__last), _StlMsg_INVALID_RANGE )
|
williamr@2
|
80 |
return true;
|
williamr@2
|
81 |
}
|
williamr@2
|
82 |
|
williamr@2
|
83 |
template <class _Iterator>
|
williamr@2
|
84 |
bool _STLP_CALL __check_range(const _Iterator& __it,
|
williamr@2
|
85 |
const _Iterator& __start, const _Iterator& __finish) {
|
williamr@2
|
86 |
_STLP_VERBOSE_RETURN(__in_range(__it,__start, __finish),
|
williamr@2
|
87 |
_StlMsg_NOT_IN_RANGE_1)
|
williamr@2
|
88 |
return true;
|
williamr@2
|
89 |
}
|
williamr@2
|
90 |
|
williamr@2
|
91 |
template <class _Iterator>
|
williamr@2
|
92 |
bool _STLP_CALL __check_range(const _Iterator& __first, const _Iterator& __last,
|
williamr@2
|
93 |
const _Iterator& __start, const _Iterator& __finish) {
|
williamr@2
|
94 |
_STLP_VERBOSE_RETURN(__in_range(__first, __last, __start, __finish),
|
williamr@2
|
95 |
_StlMsg_NOT_IN_RANGE_2)
|
williamr@2
|
96 |
return true;
|
williamr@2
|
97 |
}
|
williamr@2
|
98 |
|
williamr@2
|
99 |
//===============================================================
|
williamr@2
|
100 |
|
williamr@2
|
101 |
template <class _Iterator>
|
williamr@2
|
102 |
void _STLP_CALL __invalidate_range(const __owned_list* __base,
|
williamr@2
|
103 |
const _Iterator& __first,
|
williamr@2
|
104 |
const _Iterator& __last)
|
williamr@2
|
105 |
{
|
williamr@2
|
106 |
typedef _Iterator* _Safe_iterator_ptr;
|
williamr@2
|
107 |
typedef __owned_link _L_type;
|
williamr@2
|
108 |
_STLP_ACQUIRE_LOCK(__base->_M_lock)
|
williamr@2
|
109 |
_L_type* __pos;
|
williamr@2
|
110 |
_L_type* __prev;
|
williamr@2
|
111 |
|
williamr@2
|
112 |
for (__prev = (_L_type*)&__base->_M_node, __pos= (_L_type*)__prev->_M_next;
|
williamr@2
|
113 |
__pos!=0;) {
|
williamr@2
|
114 |
if ((!(&__first == (_Iterator*)__pos || &__last == (_Iterator*)__pos))
|
williamr@2
|
115 |
&& __in_range_aux(
|
williamr@2
|
116 |
((_Iterator*)__pos)->_M_iterator,
|
williamr@2
|
117 |
__first._M_iterator,
|
williamr@2
|
118 |
__last._M_iterator,
|
williamr@2
|
119 |
_STLP_ITERATOR_CATEGORY(__first, _Iterator))) {
|
williamr@2
|
120 |
__pos->_M_owner = 0;
|
williamr@2
|
121 |
__pos = (_L_type*) (__prev->_M_next = __pos->_M_next);
|
williamr@2
|
122 |
}
|
williamr@2
|
123 |
else {
|
williamr@2
|
124 |
__prev = __pos;
|
williamr@2
|
125 |
__pos=(_L_type*)__pos->_M_next;
|
williamr@2
|
126 |
}
|
williamr@2
|
127 |
}
|
williamr@2
|
128 |
_STLP_RELEASE_LOCK(__base->_M_lock)
|
williamr@2
|
129 |
}
|
williamr@2
|
130 |
|
williamr@2
|
131 |
template <class _Iterator>
|
williamr@2
|
132 |
void _STLP_CALL __invalidate_iterator(const __owned_list* __base,
|
williamr@2
|
133 |
const _Iterator& __it)
|
williamr@2
|
134 |
{
|
williamr@2
|
135 |
typedef __owned_link _L_type;
|
williamr@2
|
136 |
_L_type* __position, *__prev;
|
williamr@2
|
137 |
_STLP_ACQUIRE_LOCK(__base->_M_lock)
|
williamr@2
|
138 |
for (__prev = (_L_type*)&__base->_M_node, __position = (_L_type*)__prev->_M_next;
|
williamr@2
|
139 |
__position!= 0;) {
|
williamr@2
|
140 |
// this requires safe iterators to be derived from __owned_link
|
williamr@2
|
141 |
if ((__position != (_L_type*)&__it) && ((_Iterator*)__position)->_M_iterator ==__it._M_iterator) {
|
williamr@2
|
142 |
__position->_M_owner = 0;
|
williamr@2
|
143 |
__position = (_L_type*) (__prev->_M_next = __position->_M_next);
|
williamr@2
|
144 |
}
|
williamr@2
|
145 |
else {
|
williamr@2
|
146 |
__prev = __position;
|
williamr@2
|
147 |
__position=(_L_type*)__position->_M_next;
|
williamr@2
|
148 |
}
|
williamr@2
|
149 |
}
|
williamr@2
|
150 |
_STLP_RELEASE_LOCK(__base->_M_lock)
|
williamr@2
|
151 |
}
|
williamr@2
|
152 |
|
williamr@2
|
153 |
_STLP_END_NAMESPACE
|
williamr@2
|
154 |
|
williamr@2
|
155 |
# endif /* _STLP_DEBUG */
|
williamr@2
|
156 |
|
williamr@2
|
157 |
# if defined (_STLP_EXPOSE_GLOBALS_IMPLEMENTATION)
|
williamr@2
|
158 |
|
williamr@2
|
159 |
// dwa 12/26/99 -- for abort
|
williamr@2
|
160 |
# if defined (_STLP_USE_NEW_C_HEADERS)
|
williamr@2
|
161 |
# include <cstdlib>
|
williamr@2
|
162 |
# else
|
williamr@2
|
163 |
# include <stdlib.h>
|
williamr@2
|
164 |
# endif
|
williamr@2
|
165 |
|
williamr@2
|
166 |
# if defined (_STLP_WIN32)
|
williamr@2
|
167 |
# include <stl/_threads.h>
|
williamr@2
|
168 |
# endif
|
williamr@2
|
169 |
|
williamr@2
|
170 |
//==========================================================
|
williamr@2
|
171 |
// .c section
|
williamr@2
|
172 |
// owned_list non-inline methods and global functions
|
williamr@2
|
173 |
//==========================================================
|
williamr@2
|
174 |
|
williamr@2
|
175 |
#if defined ( _STLP_ASSERTIONS )
|
williamr@2
|
176 |
|
williamr@2
|
177 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
178 |
|
williamr@2
|
179 |
# ifndef _STLP_STRING_LITERAL
|
williamr@2
|
180 |
# define _STLP_STRING_LITERAL(__x) __x
|
williamr@2
|
181 |
# endif
|
williamr@2
|
182 |
|
williamr@2
|
183 |
# ifdef _STLP_WINCE
|
williamr@2
|
184 |
# define _STLP_PERCENT_S "%hs"
|
williamr@2
|
185 |
# else
|
williamr@2
|
186 |
# define _STLP_PERCENT_S "%s"
|
williamr@2
|
187 |
# endif
|
williamr@2
|
188 |
|
williamr@2
|
189 |
# define _STLP_MESSAGE_TABLE_BODY = { \
|
williamr@2
|
190 |
_STLP_STRING_LITERAL("\n" _STLP_PERCENT_S "(%d): STL error: %s\n"), \
|
williamr@2
|
191 |
_STLP_STRING_LITERAL(_STLP_PERCENT_S "(%d): STL assertion failure : " _STLP_PERCENT_S "\n" _STLP_ASSERT_MSG_TRAILER), \
|
williamr@2
|
192 |
_STLP_STRING_LITERAL("\n" _STLP_PERCENT_S "(%d): STL error : " _STLP_PERCENT_S "\n" _STLP_PERCENT_S "(%d): STL assertion failure: " _STLP_PERCENT_S " \n" _STLP_ASSERT_MSG_TRAILER), \
|
williamr@2
|
193 |
_STLP_STRING_LITERAL("Invalid argument to operation (see operation documentation)"), \
|
williamr@2
|
194 |
_STLP_STRING_LITERAL("Taking an iterator out of destroyed (or otherwise corrupted) container"), \
|
williamr@2
|
195 |
_STLP_STRING_LITERAL("Trying to extract an object out from empty container"),\
|
williamr@2
|
196 |
_STLP_STRING_LITERAL("Past-the-end iterator could not be erased"), \
|
williamr@2
|
197 |
_STLP_STRING_LITERAL("Index out of bounds"), \
|
williamr@2
|
198 |
_STLP_STRING_LITERAL("Container doesn't own the iterator"), \
|
williamr@2
|
199 |
_STLP_STRING_LITERAL("Uninitialized or invalidated (by mutating operation) iterator used"), \
|
williamr@2
|
200 |
_STLP_STRING_LITERAL("Uninitialized or invalidated (by mutating operation) lefthand iterator in expression"), \
|
williamr@2
|
201 |
_STLP_STRING_LITERAL("Uninitialized or invalidated (by mutating operation) righthand iterator in expression"), \
|
williamr@2
|
202 |
_STLP_STRING_LITERAL("Iterators used in expression are from different owners"), \
|
williamr@2
|
203 |
_STLP_STRING_LITERAL("Iterator could not be dereferenced (past-the-end ?)"), \
|
williamr@2
|
204 |
_STLP_STRING_LITERAL("Range [first,last) is invalid"), \
|
williamr@2
|
205 |
_STLP_STRING_LITERAL("Iterator is not in range [first,last)"), \
|
williamr@2
|
206 |
_STLP_STRING_LITERAL("Range [first,last) is not in range [start,finish)"), \
|
williamr@2
|
207 |
_STLP_STRING_LITERAL("The advance would produce invalid iterator"), \
|
williamr@2
|
208 |
_STLP_STRING_LITERAL("Iterator is singular (advanced beyond the bounds ?)"), \
|
williamr@2
|
209 |
_STLP_STRING_LITERAL("Memory block deallocated twice"), \
|
williamr@2
|
210 |
_STLP_STRING_LITERAL("Deallocating a block that was never allocated"), \
|
williamr@2
|
211 |
_STLP_STRING_LITERAL("Deallocating a memory block allocated for another type"), \
|
williamr@2
|
212 |
_STLP_STRING_LITERAL("Size of block passed to deallocate() doesn't match block size"), \
|
williamr@2
|
213 |
_STLP_STRING_LITERAL("Pointer underrun - safety margin at front of memory block overwritten"), \
|
williamr@2
|
214 |
_STLP_STRING_LITERAL("Pointer overrrun - safety margin at back of memory block overwritten"), \
|
williamr@2
|
215 |
_STLP_STRING_LITERAL("Attempt to dereference null pointer returned by auto_ptr::get()"), \
|
williamr@2
|
216 |
_STLP_STRING_LITERAL("Unknown problem") \
|
williamr@2
|
217 |
}
|
williamr@2
|
218 |
|
williamr@2
|
219 |
# if ( _STLP_STATIC_TEMPLATE_DATA > 0 )
|
williamr@2
|
220 |
#ifdef __SYMBIAN32__
|
williamr@2
|
221 |
template <class _Dummy>
|
williamr@2
|
222 |
const char* __stl_debug_engine<_Dummy>::_Message_table[_StlMsg_MAX];// _STLP_MESSAGE_TABLE_BODY;
|
williamr@2
|
223 |
#else
|
williamr@2
|
224 |
template <class _Dummy>
|
williamr@2
|
225 |
const char* __stl_debug_engine<_Dummy>::_Message_table[_StlMsg_MAX] _STLP_MESSAGE_TABLE_BODY;
|
williamr@2
|
226 |
#endif
|
williamr@2
|
227 |
|
williamr@2
|
228 |
# else
|
williamr@2
|
229 |
__DECLARE_INSTANCE(const char*, __stl_debug_engine<bool>::_Message_table[_StlMsg_MAX],
|
williamr@2
|
230 |
_STLP_MESSAGE_TABLE_BODY);
|
williamr@2
|
231 |
|
williamr@2
|
232 |
# endif
|
williamr@2
|
233 |
|
williamr@2
|
234 |
# undef _STLP_STRING_LITERAL
|
williamr@2
|
235 |
# undef _STLP_PERCENT_S
|
williamr@2
|
236 |
_STLP_END_NAMESPACE
|
williamr@2
|
237 |
|
williamr@2
|
238 |
// abort()
|
williamr@2
|
239 |
# include <cstdlib>
|
williamr@2
|
240 |
|
williamr@2
|
241 |
# if !defined( _STLP_DEBUG_MESSAGE )
|
williamr@2
|
242 |
|
williamr@2
|
243 |
# include <cstdarg>
|
williamr@2
|
244 |
# include <cstdio>
|
williamr@2
|
245 |
|
williamr@2
|
246 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
247 |
|
williamr@2
|
248 |
template <class _Dummy>
|
williamr@2
|
249 |
void _STLP_CALL
|
williamr@2
|
250 |
__stl_debug_engine<_Dummy>::_Message(const char * __format_str, ...)
|
williamr@2
|
251 |
{
|
williamr@2
|
252 |
STLPORT_CSTD::va_list __args;
|
williamr@2
|
253 |
va_start( __args, __format_str );
|
williamr@2
|
254 |
|
williamr@2
|
255 |
# if defined (_STLP_WINCE)
|
williamr@2
|
256 |
TCHAR __buffer[512];
|
williamr@2
|
257 |
int _convert = strlen(__format_str) + 1;
|
williamr@2
|
258 |
LPWSTR _lpw = (LPWSTR)alloca(_convert*sizeof(wchar_t));
|
williamr@2
|
259 |
_lpw[0] = '\0';
|
williamr@2
|
260 |
MultiByteToWideChar(GetACP(), 0, __format_str, -1, _lpw, _convert);
|
williamr@2
|
261 |
wvsprintf(__buffer, _lpw, __args);
|
williamr@2
|
262 |
// wvsprintf(__buffer, __format_str, __args);
|
williamr@2
|
263 |
_STLP_WINCE_TRACE(__buffer);
|
williamr@2
|
264 |
# elif defined (_STLP_WIN32) && ( defined(_STLP_MSVC) || defined (__ICL) || defined (__BORLANDC__)) && ! defined (__WINS__)
|
williamr@2
|
265 |
char __buffer [4096];
|
williamr@2
|
266 |
_vsnprintf(__buffer, sizeof(__buffer) / sizeof(char),
|
williamr@2
|
267 |
__format_str, __args);
|
williamr@2
|
268 |
OutputDebugStringA(__buffer);
|
williamr@2
|
269 |
# elif defined (__amigaos__)
|
williamr@2
|
270 |
STLPORT_CSTD::vfprintf(stderr, __format_str, (char *)__args);
|
williamr@2
|
271 |
# else
|
williamr@2
|
272 |
STLPORT_CSTD::vfprintf(stderr, __format_str, __args);
|
williamr@2
|
273 |
# endif /* WINCE */
|
williamr@2
|
274 |
|
williamr@2
|
275 |
# ifdef _STLP_DEBUG_MESSAGE_POST
|
williamr@2
|
276 |
_STLP_DEBUG_MESSAGE_POST
|
williamr@2
|
277 |
# endif
|
williamr@2
|
278 |
|
williamr@2
|
279 |
va_end(__args);
|
williamr@2
|
280 |
|
williamr@2
|
281 |
}
|
williamr@2
|
282 |
|
williamr@2
|
283 |
_STLP_END_NAMESPACE
|
williamr@2
|
284 |
|
williamr@2
|
285 |
# endif /* _STLP_DEBUG_MESSAGE */
|
williamr@2
|
286 |
|
williamr@2
|
287 |
|
williamr@2
|
288 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
289 |
|
williamr@2
|
290 |
|
williamr@2
|
291 |
template <class _Dummy>
|
williamr@2
|
292 |
void _STLP_CALL
|
williamr@2
|
293 |
__stl_debug_engine<_Dummy>::_IndexedError(int __error_ind, const char* __f, int __l)
|
williamr@2
|
294 |
{
|
williamr@2
|
295 |
__stl_debug_message(_Message_table[_StlFormat_ERROR_RETURN],
|
williamr@2
|
296 |
__f, __l, _Message_table[__error_ind]);
|
williamr@2
|
297 |
}
|
williamr@2
|
298 |
|
williamr@2
|
299 |
template <class _Dummy>
|
williamr@2
|
300 |
void _STLP_CALL
|
williamr@2
|
301 |
__stl_debug_engine<_Dummy>::_VerboseAssert(const char* __expr, int __error_ind, const char* __f, int __l)
|
williamr@2
|
302 |
{
|
williamr@2
|
303 |
__stl_debug_message(_Message_table[_StlFormat_VERBOSE_ASSERTION_FAILURE],
|
williamr@2
|
304 |
__f, __l, _Message_table[__error_ind], __f, __l, __expr);
|
williamr@2
|
305 |
__stl_debug_terminate();
|
williamr@2
|
306 |
}
|
williamr@2
|
307 |
|
williamr@2
|
308 |
template <class _Dummy>
|
williamr@2
|
309 |
void _STLP_CALL
|
williamr@2
|
310 |
__stl_debug_engine<_Dummy>::_Assert(const char* __expr, const char* __f, int __l)
|
williamr@2
|
311 |
{
|
williamr@2
|
312 |
__stl_debug_message(_Message_table[_StlFormat_ASSERTION_FAILURE],__f, __l, __expr);
|
williamr@2
|
313 |
__stl_debug_terminate();
|
williamr@2
|
314 |
}
|
williamr@2
|
315 |
|
williamr@2
|
316 |
// if exceptions are present, sends unique exception
|
williamr@2
|
317 |
// if not, calls abort() to terminate
|
williamr@2
|
318 |
template <class _Dummy>
|
williamr@2
|
319 |
void _STLP_CALL
|
williamr@2
|
320 |
__stl_debug_engine<_Dummy>::_Terminate()
|
williamr@2
|
321 |
{
|
williamr@2
|
322 |
# ifdef _STLP_USE_NAMESPACES
|
williamr@2
|
323 |
using namespace _STLP_STD;
|
williamr@2
|
324 |
# endif
|
williamr@2
|
325 |
# if defined (_STLP_USE_EXCEPTIONS) && ! defined (_STLP_NO_DEBUG_EXCEPTIONS)
|
williamr@2
|
326 |
throw __stl_debug_exception();
|
williamr@2
|
327 |
# else
|
williamr@2
|
328 |
_STLP_ABORT();
|
williamr@2
|
329 |
# endif
|
williamr@2
|
330 |
}
|
williamr@2
|
331 |
|
williamr@2
|
332 |
_STLP_END_NAMESPACE
|
williamr@2
|
333 |
|
williamr@2
|
334 |
# endif /* _STLP_ASSERTIONS */
|
williamr@2
|
335 |
|
williamr@2
|
336 |
#ifdef _STLP_DEBUG
|
williamr@2
|
337 |
|
williamr@2
|
338 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
339 |
|
williamr@2
|
340 |
//==========================================================
|
williamr@2
|
341 |
// owned_list non-inline methods
|
williamr@2
|
342 |
//==========================================================
|
williamr@2
|
343 |
|
williamr@2
|
344 |
template <class _Dummy>
|
williamr@2
|
345 |
void _STLP_CALL
|
williamr@2
|
346 |
__stl_debug_engine<_Dummy>::_Invalidate_all(__owned_list* __l) {
|
williamr@2
|
347 |
_STLP_ACQUIRE_LOCK(__l->_M_lock);
|
williamr@2
|
348 |
_Stamp_all(__l, 0);
|
williamr@2
|
349 |
__l->_M_node._M_next =0;
|
williamr@2
|
350 |
_STLP_RELEASE_LOCK(__l->_M_lock);
|
williamr@2
|
351 |
}
|
williamr@2
|
352 |
|
williamr@2
|
353 |
// boris : this is unasafe routine; should be used from within critical section only !
|
williamr@2
|
354 |
template <class _Dummy>
|
williamr@2
|
355 |
void _STLP_CALL
|
williamr@2
|
356 |
__stl_debug_engine<_Dummy>::_Stamp_all(__owned_list* __l, __owned_list* __o) {
|
williamr@2
|
357 |
// crucial
|
williamr@2
|
358 |
if (__l->_M_node._M_owner) {
|
williamr@2
|
359 |
for (__owned_link* __position = (__owned_link*)__l->_M_node._M_next;
|
williamr@2
|
360 |
__position != 0; __position= (__owned_link*)__position->_M_next) {
|
williamr@2
|
361 |
_STLP_ASSERT(__position->_Owner()== __l)
|
williamr@2
|
362 |
__position->_M_owner=__o;
|
williamr@2
|
363 |
}
|
williamr@2
|
364 |
}
|
williamr@2
|
365 |
}
|
williamr@2
|
366 |
|
williamr@2
|
367 |
template <class _Dummy>
|
williamr@2
|
368 |
void _STLP_CALL
|
williamr@2
|
369 |
__stl_debug_engine<_Dummy>::_Verify(const __owned_list* __l) {
|
williamr@2
|
370 |
_STLP_ACQUIRE_LOCK(__l->_M_lock);
|
williamr@2
|
371 |
if (__l) {
|
williamr@2
|
372 |
_STLP_ASSERT(__l->_M_node._Owner() != 0)
|
williamr@2
|
373 |
for (__owned_link* __position = (__owned_link*)__l->_M_node._M_next;
|
williamr@2
|
374 |
__position != 0; __position= (__owned_link*)__position->_M_next) {
|
williamr@2
|
375 |
_STLP_ASSERT(__position->_Owner()== __l)
|
williamr@2
|
376 |
}
|
williamr@2
|
377 |
}
|
williamr@2
|
378 |
_STLP_RELEASE_LOCK(__l->_M_lock);
|
williamr@2
|
379 |
}
|
williamr@2
|
380 |
|
williamr@2
|
381 |
template <class _Dummy>
|
williamr@2
|
382 |
void _STLP_CALL
|
williamr@2
|
383 |
__stl_debug_engine<_Dummy>::_Swap_owners(__owned_list& __x, __owned_list& __y) {
|
williamr@2
|
384 |
|
williamr@2
|
385 |
// according to the standard : --no swap() function invalidates any references,
|
williamr@2
|
386 |
// pointers, or iterators referring to the elements of the containers being swapped.
|
williamr@2
|
387 |
|
williamr@2
|
388 |
__owned_link* __tmp;
|
williamr@2
|
389 |
|
williamr@2
|
390 |
// boris : there is a deadlock potential situation here if we lock two containers sequentially.
|
williamr@2
|
391 |
// As user is supposed to provide its own synchronization around swap() ( it is unsafe to do any container/iterator access
|
williamr@2
|
392 |
// in parallel with swap()), we just do not use any locking at all -- that behaviour is closer to non-debug version
|
williamr@2
|
393 |
|
williamr@2
|
394 |
__tmp = __x._M_node._M_next;
|
williamr@2
|
395 |
|
williamr@2
|
396 |
_Stamp_all(&__x, &__y);
|
williamr@2
|
397 |
_Stamp_all(&__y, &__x);
|
williamr@2
|
398 |
|
williamr@2
|
399 |
__x._M_node._M_next = __y._M_node._M_next;
|
williamr@2
|
400 |
__y._M_node._M_next = __tmp;
|
williamr@2
|
401 |
|
williamr@2
|
402 |
}
|
williamr@2
|
403 |
|
williamr@2
|
404 |
template <class _Dummy>
|
williamr@2
|
405 |
void _STLP_CALL
|
williamr@2
|
406 |
__stl_debug_engine<_Dummy>::_M_detach(__owned_list* __l, __owned_link* __c_node) {
|
williamr@2
|
407 |
if (__l != 0) {
|
williamr@2
|
408 |
|
williamr@2
|
409 |
_STLP_VERBOSE_ASSERT(__l->_Owner()!=0, _StlMsg_INVALID_CONTAINER)
|
williamr@2
|
410 |
|
williamr@2
|
411 |
_STLP_ACQUIRE_LOCK(__l->_M_lock)
|
williamr@2
|
412 |
// boris : re-test the condition in case someone else already deleted us
|
williamr@2
|
413 |
if(__c_node->_M_owner != 0) {
|
williamr@2
|
414 |
__owned_link* __prev, *__next;
|
williamr@2
|
415 |
|
williamr@2
|
416 |
for (__prev = &__l->_M_node; (__next = __prev->_M_next) != __c_node;
|
williamr@2
|
417 |
__prev = __next) {
|
williamr@2
|
418 |
_STLP_ASSERT(__next && __next->_Owner() == __l)
|
williamr@2
|
419 |
}
|
williamr@2
|
420 |
|
williamr@2
|
421 |
__prev->_M_next = __c_node->_M_next;
|
williamr@2
|
422 |
__c_node->_M_owner=0;
|
williamr@2
|
423 |
}
|
williamr@2
|
424 |
_STLP_RELEASE_LOCK(__l->_M_lock)
|
williamr@2
|
425 |
}
|
williamr@2
|
426 |
}
|
williamr@2
|
427 |
|
williamr@2
|
428 |
template <class _Dummy>
|
williamr@2
|
429 |
void _STLP_CALL
|
williamr@2
|
430 |
__stl_debug_engine<_Dummy>::_M_attach(__owned_list* __l, __owned_link* __c_node) {
|
williamr@2
|
431 |
if (__l ==0) {
|
williamr@2
|
432 |
(__c_node)->_M_owner = 0;
|
williamr@2
|
433 |
} else {
|
williamr@2
|
434 |
_STLP_VERBOSE_ASSERT(__l->_Owner()!=0, _StlMsg_INVALID_CONTAINER)
|
williamr@2
|
435 |
_STLP_ACQUIRE_LOCK(__l->_M_lock)
|
williamr@2
|
436 |
__c_node->_M_owner = __l;
|
williamr@2
|
437 |
__c_node->_M_next = __l->_M_node._M_next;
|
williamr@2
|
438 |
__l->_M_node._M_next = __c_node;
|
williamr@2
|
439 |
_STLP_RELEASE_LOCK(__l->_M_lock)
|
williamr@2
|
440 |
}
|
williamr@2
|
441 |
}
|
williamr@2
|
442 |
|
williamr@2
|
443 |
|
williamr@2
|
444 |
template <class _Dummy>
|
williamr@2
|
445 |
void* _STLP_CALL
|
williamr@2
|
446 |
__stl_debug_engine<_Dummy>::_Get_container_ptr(const __owned_link* __l) {
|
williamr@2
|
447 |
const __owned_list* __owner = __l->_Owner();
|
williamr@2
|
448 |
_STLP_VERBOSE_RETURN_0(__owner != 0, _StlMsg_INVALID_ITERATOR)
|
williamr@2
|
449 |
void* __ret = __CONST_CAST(void*,__owner->_Owner());
|
williamr@2
|
450 |
_STLP_VERBOSE_RETURN_0(__ret !=0, _StlMsg_INVALID_CONTAINER)
|
williamr@2
|
451 |
return __ret;
|
williamr@2
|
452 |
}
|
williamr@2
|
453 |
|
williamr@2
|
454 |
template <class _Dummy>
|
williamr@2
|
455 |
bool _STLP_CALL
|
williamr@2
|
456 |
__stl_debug_engine<_Dummy>::_Check_same_owner( const __owned_link& __i1,
|
williamr@2
|
457 |
const __owned_link& __i2)
|
williamr@2
|
458 |
{
|
williamr@2
|
459 |
_STLP_VERBOSE_RETURN(__i1._Valid(), _StlMsg_INVALID_LEFTHAND_ITERATOR)
|
williamr@2
|
460 |
_STLP_VERBOSE_RETURN(__i2._Valid(), _StlMsg_INVALID_RIGHTHAND_ITERATOR)
|
williamr@2
|
461 |
_STLP_VERBOSE_RETURN((__i1._Owner()==__i2._Owner()), _StlMsg_DIFFERENT_OWNERS)
|
williamr@2
|
462 |
return true;
|
williamr@2
|
463 |
}
|
williamr@2
|
464 |
|
williamr@2
|
465 |
template <class _Dummy>
|
williamr@2
|
466 |
bool _STLP_CALL
|
williamr@2
|
467 |
__stl_debug_engine<_Dummy>::_Check_same_owner_or_null( const __owned_link& __i1,
|
williamr@2
|
468 |
const __owned_link& __i2)
|
williamr@2
|
469 |
{
|
williamr@2
|
470 |
_STLP_VERBOSE_RETURN(__i1._Owner()==__i2._Owner(), _StlMsg_DIFFERENT_OWNERS)
|
williamr@2
|
471 |
return true;
|
williamr@2
|
472 |
}
|
williamr@2
|
473 |
|
williamr@2
|
474 |
template <class _Dummy>
|
williamr@2
|
475 |
bool _STLP_CALL
|
williamr@2
|
476 |
__stl_debug_engine<_Dummy>::_Check_if_owner( const __owned_list * __l, const __owned_link& __it)
|
williamr@2
|
477 |
{
|
williamr@2
|
478 |
const __owned_list* __owner_ptr = __it._Owner();
|
williamr@2
|
479 |
_STLP_VERBOSE_RETURN(__owner_ptr!=0, _StlMsg_INVALID_ITERATOR)
|
williamr@2
|
480 |
_STLP_VERBOSE_RETURN(__l==__owner_ptr, _StlMsg_NOT_OWNER)
|
williamr@2
|
481 |
return true;
|
williamr@2
|
482 |
}
|
williamr@2
|
483 |
|
williamr@2
|
484 |
|
williamr@2
|
485 |
_STLP_END_NAMESPACE
|
williamr@2
|
486 |
|
williamr@2
|
487 |
#endif /* _STLP_DEBUG */
|
williamr@2
|
488 |
|
williamr@2
|
489 |
#endif /* if defined (EXPOSE_GLOBALS_IMPLEMENTATION) */
|
williamr@2
|
490 |
|
williamr@2
|
491 |
#endif /* header guard */
|
williamr@2
|
492 |
|
williamr@2
|
493 |
// Local Variables:
|
williamr@2
|
494 |
// mode:C++
|
williamr@2
|
495 |
// End:
|
williamr@2
|
496 |
|