Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
4 * Moscow Center for SPARC Technology
9 * This material is provided "as is", with absolutely no warranty expressed
10 * or implied. Any use is at your own risk.
12 * Permission to use or copy this software for any purpose is hereby granted
13 * without fee, provided the above notices are retained on all copies.
14 * Permission to modify the code and to distribute modified code is granted,
15 * provided the above notices are retained, and a notice that the code was
16 * modified is included with the above copyright notice.
21 # define _STLP_DEBUG_H
23 # if defined (_STLP_ASSERTIONS) || defined (_STLP_DEBUG)
25 #ifndef _STLP_CONFIG_H
26 # include <stl/_config.h>
29 # if !defined (_STLP_EXTRA_OPERATORS_FOR_DEBUG) && \
30 ( defined (_STLP_BASE_MATCH_BUG) || (defined (_STLP_MSVC) && _STLP_MSVC < 1100 ) )
31 # define _STLP_EXTRA_OPERATORS_FOR_DEBUG
34 # if !defined(_STLP_FILE__)
35 # define _STLP_FILE__ __FILE__
39 _StlFormat_ERROR_RETURN,
40 _StlFormat_ASSERTION_FAILURE,
41 _StlFormat_VERBOSE_ASSERTION_FAILURE,
42 _StlMsg_INVALID_ARGUMENT,
43 _StlMsg_INVALID_CONTAINER,
44 _StlMsg_EMPTY_CONTAINER,
45 _StlMsg_ERASE_PAST_THE_END,
46 _StlMsg_OUT_OF_BOUNDS,
48 _StlMsg_INVALID_ITERATOR,
49 _StlMsg_INVALID_LEFTHAND_ITERATOR,
50 _StlMsg_INVALID_RIGHTHAND_ITERATOR,
51 _StlMsg_DIFFERENT_OWNERS ,
52 _StlMsg_NOT_DEREFERENCEABLE ,
53 _StlMsg_INVALID_RANGE ,
54 _StlMsg_NOT_IN_RANGE_1 ,
55 _StlMsg_NOT_IN_RANGE_2 ,
56 _StlMsg_INVALID_ADVANCE ,
57 _StlMsg_SINGULAR_ITERATOR ,
58 // debug alloc messages
59 _StlMsg_DBA_DELETED_TWICE ,
60 _StlMsg_DBA_NEVER_ALLOCATED ,
61 _StlMsg_DBA_TYPE_MISMATCH ,
62 _StlMsg_DBA_SIZE_MISMATCH ,
63 _StlMsg_DBA_UNDERRUN ,
66 _StlMsg_AUTO_PTR_NULL ,
71 /* have to hardcode that ;() */
72 # define _StlMsg_MAX 27
76 // This class is unique (not inherited from exception),
77 // to disallow catch in anything but (...)
78 struct __stl_debug_exception {
82 class _STLP_CLASS_DECLSPEC __owned_link;
83 class _STLP_CLASS_DECLSPEC __owned_list;
85 template <class _Dummy>
86 struct __stl_debug_engine {
88 // Basic routine to report any debug message
89 // Use _STLP_DEBUG_MESSAGE to override
90 static void _STLP_CALL _Message(const char * format_str, ...);
92 // Micsellanous function to report indexed error message
93 static void _STLP_CALL _IndexedError(int __ind, const char* __f, int __l);
95 // Basic assertion report mechanism.
96 // Reports failed assertion via __stl_debug_message and calls _Terminate
97 // if _STLP_DEBUG_TERMINATE is specified, calls __stl_debug_terminate instead
98 static void _STLP_CALL _Assert(const char* __expr, const char* __f, int __l);
100 // The same, with additional diagnostics
101 static void _STLP_CALL _VerboseAssert(const char* __expr, int __error_ind, const char* __f, int __l);
103 // If exceptions are present, sends unique exception
104 // If not, calls _STLP_ABORT() to terminate
105 // Use _STLP_DEBUG_TERMINATE to override
106 static void _STLP_CALL _Terminate();
110 // owned_list/link delegate non-inline functions here
112 static bool _STLP_CALL _Check_same_owner( const __owned_link& __i1,
113 const __owned_link& __i2);
114 static bool _STLP_CALL _Check_same_owner_or_null( const __owned_link& __i1,
115 const __owned_link& __i2);
116 static bool _STLP_CALL _Check_if_owner( const __owned_list*, const __owned_link&);
118 static void _STLP_CALL _Verify(const __owned_list*);
120 static void _STLP_CALL _Swap_owners(__owned_list&, __owned_list& /*, bool __swap_roots */ );
122 static void _STLP_CALL _Invalidate_all(__owned_list*);
124 static void _STLP_CALL _Stamp_all(__owned_list*, __owned_list*);
126 static void _STLP_CALL _M_detach(__owned_list*, __owned_link*);
128 static void _STLP_CALL _M_attach(__owned_list*, __owned_link*);
130 // accessor : check and get pointer to the container
131 static void* _STLP_CALL _Get_container_ptr(const __owned_link*);
132 # endif /* _STLP_DEBUG */
134 // debug messages and formats
135 _STLP_STATIC_MEMBER_DECLSPEC static const char* _Message_table[_StlMsg_MAX];
139 # if defined (_STLP_USE_TEMPLATE_EXPORT)
140 _STLP_EXPORT_TEMPLATE struct _STLP_CLASS_DECLSPEC __stl_debug_engine<bool>;
141 # endif /* _STLP_USE_TEMPLATE_EXPORT */
143 typedef __stl_debug_engine<bool> __stl_debugger;
147 # ifndef _STLP_ASSERT
148 # define _STLP_ASSERT(expr) \
149 if (!(expr)) {STLPORT::__stl_debugger::_Assert( # expr, _STLP_FILE__, __LINE__);}
152 # endif /* _STLP_ASSERTIONS || _STLP_DEBUG */
155 // this section is for _STLP_DEBUG only
156 #if defined ( _STLP_DEBUG )
158 # ifndef _STLP_VERBOSE_ASSERT
159 // fbp : new form not requiring ";"
160 # define _STLP_VERBOSE_ASSERT(expr,__diag_num) \
161 if (!(expr)) { STLPORT::__stl_debugger::_VerboseAssert\
162 ( # expr, __diag_num, _STLP_FILE__, __LINE__ ); \
166 # define _STLP_DEBUG_CHECK(expr) _STLP_ASSERT(expr)
167 # define _STLP_DEBUG_DO(expr) expr;
169 # ifndef _STLP_VERBOSE_RETURN
170 # define _STLP_VERBOSE_RETURN(__expr,__diag_num) if (!(__expr)) { \
171 __stl_debugger::_IndexedError(__diag_num, __FILE__ , __LINE__); \
175 # ifndef _STLP_VERBOSE_RETURN_0
176 # define _STLP_VERBOSE_RETURN_0(__expr,__diag_num) if (!(__expr)) { \
177 __stl_debugger::_IndexedError(__diag_num, __FILE__ , __LINE__); \
181 #if ! defined (_STLP_INTERNAL_THREADS_H)
182 # include <stl/_threads.h>
185 #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
186 # include <stl/_iterator_base.h>
189 _STLP_BEGIN_NAMESPACE
191 //=============================================================
192 template <class _Iterator>
193 inline bool _STLP_CALL __valid_range(const _Iterator& __i1 ,const _Iterator& __i2,
194 const random_access_iterator_tag&) {
195 return (__i1< __i2) || (__i1 == __i2);
198 template <class _Iterator>
199 inline bool _STLP_CALL __valid_range(const _Iterator& __i1 ,const _Iterator& __i2,
200 const bidirectional_iterator_tag&) {
201 // check if comparable
202 bool __dummy(__i1==__i2);
203 return (__dummy==__dummy);
206 template <class _Iterator>
207 inline bool _STLP_CALL __valid_range(const _Iterator& __i1 ,const _Iterator& __i2, const forward_iterator_tag&) {
208 // check if comparable
209 bool __dummy(__i1==__i2);
210 return (__dummy==__dummy);
213 template <class _Iterator>
214 inline bool _STLP_CALL __valid_range(const _Iterator&,const _Iterator&, const input_iterator_tag&) {
218 template <class _Iterator>
219 inline bool _STLP_CALL __valid_range(const _Iterator&,const _Iterator&, const output_iterator_tag&) {
223 template <class _Iterator>
224 inline bool _STLP_CALL __valid_range(const _Iterator& __i1, const _Iterator& __i2) {
225 return __valid_range(__i1,__i2,_STLP_ITERATOR_CATEGORY(__i1, _Iterator));
228 // Note : that means in range [i1, i2].
229 template <class _Iterator>
230 inline bool _STLP_CALL __in_range(const _Iterator& _It, const _Iterator& __i1,
231 const _Iterator& __i2) {
232 return __valid_range(__i1,_It,_STLP_ITERATOR_CATEGORY(__i1, _Iterator)) &&
233 __valid_range(_It,__i2,_STLP_ITERATOR_CATEGORY(_It, _Iterator));
236 template <class _Iterator>
237 inline bool _STLP_CALL __in_range(const _Iterator& __first, const _Iterator& __last,
238 const _Iterator& __start, const _Iterator& __finish) {
239 return __valid_range(__first,__last,_STLP_ITERATOR_CATEGORY(__first, _Iterator)) &&
240 __valid_range(__start,__first,_STLP_ITERATOR_CATEGORY(__first, _Iterator)) &&
241 __valid_range(__last,__finish,_STLP_ITERATOR_CATEGORY(__last, _Iterator));
244 //==========================================================
247 class _STLP_CLASS_DECLSPEC __owned_link {
250 __owned_link() : _M_owner(0) {}
251 __owned_link(const __owned_list* __c) : _M_owner(0), _M_next(0) {
252 __stl_debugger::_M_attach(__CONST_CAST(__owned_list*,__c), this);
254 __owned_link(const __owned_link& __rhs): _M_owner(0) {
255 __stl_debugger::_M_attach(__CONST_CAST(__owned_list*,__rhs._M_owner), this);
257 __owned_link& operator=(const __owned_link& __rhs) {
258 __owned_list* __new_owner = __CONST_CAST(__owned_list*,__rhs._M_owner);
259 __owned_list* __old_owner = _M_owner;
260 if ( __old_owner != __new_owner ) {
261 __stl_debugger::_M_detach(__old_owner, this);
262 __stl_debugger::_M_attach(__new_owner, this);
267 __stl_debugger::_M_detach(_M_owner, this);
271 const __owned_list* _Owner() const {
274 __owned_list* _Owner() {
277 void _Set_owner(const __owned_list* __o) {
278 _M_owner= __CONST_CAST(__owned_list*,__o);
280 bool _Valid() const {
284 void _Invalidate() { _M_owner=0; _M_next = 0; }
285 void _Link_to_self() { _M_next= 0; }
287 __owned_link* _Next() { return _M_next; }
288 const __owned_link* _Next() const { return _M_next; }
291 __owned_list* _M_owner;
292 __owned_link* _M_next;
296 class _STLP_CLASS_DECLSPEC __owned_list {
298 __owned_list(const void* __o) {
299 // fprintf(stderr, "__owned_list(): %p\n",(void*)this);
300 _M_node._M_owner = __CONST_CAST(__owned_list*, __REINTERPRET_CAST(const __owned_list*,__o));
304 // fprintf(stderr, "~__owned_list(): %p\n",(void*)this);
306 // that prevents detach
307 _M_node._Invalidate();
309 const void* _Owner() const {
310 return (const void*)_M_node._M_owner;
313 return (void*)_M_node._M_owner;
315 bool _Valid() const {
316 return _M_node._M_owner!=0;
318 void _Invalidate() { _M_node._M_owner=0; }
320 __owned_link* _First() { return _M_node._Next(); }
321 __owned_link* _Last() { return 0 ; }
323 const __owned_link* _First() const { return (__owned_link*)_M_node._M_next; }
324 const __owned_link* _Last() const { return 0 ;}
326 void _Verify() const {
327 __stl_debugger::_Verify(this);
330 void _Swap_owners(__owned_list& __y) {
331 __stl_debugger::_Swap_owners(*this, __y);
334 void _Invalidate_all() {
335 __stl_debugger::_Invalidate_all(this);
338 mutable __owned_link _M_node;
339 mutable _STLP_mutex _M_lock;
342 // should never be called, should be left undefined,
343 // but some compilers complain about it ;(
344 __owned_list(const __owned_list&){}
345 void operator=(const __owned_list&) {}
347 friend class __owned_link;
348 friend struct __stl_debug_engine<bool>;
352 //==========================================================
354 // forward declaratioins
356 template <class _Iterator>
357 bool _STLP_CALL __check_range(const _Iterator&, const _Iterator&);
358 template <class _Iterator>
359 bool _STLP_CALL __check_range(const _Iterator&,
360 const _Iterator&, const _Iterator&);
361 template <class _Iterator>
362 bool _STLP_CALL __check_range(const _Iterator&, const _Iterator& ,
363 const _Iterator&, const _Iterator& );
365 template <class _Iterator>
366 void _STLP_CALL __invalidate_range(const __owned_list* __base,
367 const _Iterator& __first,
368 const _Iterator& __last);
370 template <class _Iterator>
371 void _STLP_CALL __invalidate_iterator(const __owned_list* __base,
372 const _Iterator& __it);
374 //============================================================
376 inline bool _STLP_CALL
377 __check_same_owner( const __owned_link& __i1, const __owned_link& __i2) {
378 return __stl_debugger::_Check_same_owner(__i1,__i2);
380 inline bool _STLP_CALL
381 __check_same_owner_or_null( const __owned_link& __i1, const __owned_link& __i2) {
382 return __stl_debugger::_Check_same_owner_or_null(__i1,__i2);
385 template <class _Iterator>
386 inline bool _STLP_CALL __check_if_owner( const __owned_list* __owner,
387 const _Iterator& __it) {
388 return __stl_debugger::_Check_if_owner(__owner, (const __owned_link&)__it);
393 # endif /* _STLP_DEBUG */
395 #if defined ( _STLP_ASSERTIONS )
397 # ifndef _STLP_ASSERT_MSG_TRAILER
398 # define _STLP_ASSERT_MSG_TRAILER
401 // dwa 12/30/98 - if _STLP_DEBUG_MESSAGE is defined, the user can supply own definition.
402 # if !defined( _STLP_DEBUG_MESSAGE )
403 # define __stl_debug_message __stl_debugger::_Message
405 extern void __stl_debug_message(const char * format_str, ...);
408 // fbp: if _STLP_DEBUG_TERMINATE is defined, the user can supply own definition.
409 # if !defined( _STLP_DEBUG_TERMINATE )
410 # define __stl_debug_terminate __stl_debugger::_Terminate
412 extern void __stl_debug_terminate(void);
417 # if !defined (_STLP_LINK_TIME_INSTANTIATION)
418 # include <stl/debug/_debug.c>