1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/stlport/stl/debug/_debug.h Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -0,0 +1,426 @@
1.4 +/*
1.5 + *
1.6 + * Copyright (c) 1997
1.7 + * Moscow Center for SPARC Technology
1.8 + *
1.9 + * Copyright (c) 1999
1.10 + * Boris Fomitchev
1.11 + *
1.12 + * This material is provided "as is", with absolutely no warranty expressed
1.13 + * or implied. Any use is at your own risk.
1.14 + *
1.15 + * Permission to use or copy this software for any purpose is hereby granted
1.16 + * without fee, provided the above notices are retained on all copies.
1.17 + * Permission to modify the code and to distribute modified code is granted,
1.18 + * provided the above notices are retained, and a notice that the code was
1.19 + * modified is included with the above copyright notice.
1.20 + *
1.21 + */
1.22 +
1.23 +#ifndef _STLP_DEBUG_H
1.24 +# define _STLP_DEBUG_H
1.25 +
1.26 +# if defined (_STLP_ASSERTIONS) || defined (_STLP_DEBUG)
1.27 +
1.28 +#ifndef _STLP_CONFIG_H
1.29 +# include <stl/_config.h>
1.30 +#endif
1.31 +
1.32 +# if !defined (_STLP_EXTRA_OPERATORS_FOR_DEBUG) && \
1.33 + ( defined (_STLP_BASE_MATCH_BUG) || (defined (_STLP_MSVC) && _STLP_MSVC < 1100 ) )
1.34 +# define _STLP_EXTRA_OPERATORS_FOR_DEBUG
1.35 +# endif
1.36 +
1.37 +# if !defined(_STLP_FILE__)
1.38 +# define _STLP_FILE__ __FILE__
1.39 +# endif
1.40 +
1.41 +enum {
1.42 + _StlFormat_ERROR_RETURN,
1.43 + _StlFormat_ASSERTION_FAILURE,
1.44 + _StlFormat_VERBOSE_ASSERTION_FAILURE,
1.45 + _StlMsg_INVALID_ARGUMENT,
1.46 + _StlMsg_INVALID_CONTAINER,
1.47 + _StlMsg_EMPTY_CONTAINER,
1.48 + _StlMsg_ERASE_PAST_THE_END,
1.49 + _StlMsg_OUT_OF_BOUNDS,
1.50 + _StlMsg_NOT_OWNER,
1.51 + _StlMsg_INVALID_ITERATOR,
1.52 + _StlMsg_INVALID_LEFTHAND_ITERATOR,
1.53 + _StlMsg_INVALID_RIGHTHAND_ITERATOR,
1.54 + _StlMsg_DIFFERENT_OWNERS ,
1.55 + _StlMsg_NOT_DEREFERENCEABLE ,
1.56 + _StlMsg_INVALID_RANGE ,
1.57 + _StlMsg_NOT_IN_RANGE_1 ,
1.58 + _StlMsg_NOT_IN_RANGE_2 ,
1.59 + _StlMsg_INVALID_ADVANCE ,
1.60 + _StlMsg_SINGULAR_ITERATOR ,
1.61 + // debug alloc messages
1.62 + _StlMsg_DBA_DELETED_TWICE ,
1.63 + _StlMsg_DBA_NEVER_ALLOCATED ,
1.64 + _StlMsg_DBA_TYPE_MISMATCH ,
1.65 + _StlMsg_DBA_SIZE_MISMATCH ,
1.66 + _StlMsg_DBA_UNDERRUN ,
1.67 + _StlMsg_DBA_OVERRUN ,
1.68 + // auto_ptr messages
1.69 + _StlMsg_AUTO_PTR_NULL ,
1.70 + _StlMsg_UNKNOWN
1.71 + /* _StlMsg_MAX */
1.72 +};
1.73 +
1.74 +/* have to hardcode that ;() */
1.75 +# define _StlMsg_MAX 27
1.76 +
1.77 +_STLP_BEGIN_NAMESPACE
1.78 +
1.79 +// This class is unique (not inherited from exception),
1.80 +// to disallow catch in anything but (...)
1.81 +struct __stl_debug_exception {
1.82 + // no members
1.83 +};
1.84 +
1.85 +class _STLP_CLASS_DECLSPEC __owned_link;
1.86 +class _STLP_CLASS_DECLSPEC __owned_list;
1.87 +
1.88 +template <class _Dummy>
1.89 +struct __stl_debug_engine {
1.90 +
1.91 + // Basic routine to report any debug message
1.92 + // Use _STLP_DEBUG_MESSAGE to override
1.93 + static void _STLP_CALL _Message(const char * format_str, ...);
1.94 +
1.95 + // Micsellanous function to report indexed error message
1.96 + static void _STLP_CALL _IndexedError(int __ind, const char* __f, int __l);
1.97 +
1.98 + // Basic assertion report mechanism.
1.99 + // Reports failed assertion via __stl_debug_message and calls _Terminate
1.100 + // if _STLP_DEBUG_TERMINATE is specified, calls __stl_debug_terminate instead
1.101 + static void _STLP_CALL _Assert(const char* __expr, const char* __f, int __l);
1.102 +
1.103 + // The same, with additional diagnostics
1.104 + static void _STLP_CALL _VerboseAssert(const char* __expr, int __error_ind, const char* __f, int __l);
1.105 +
1.106 + // If exceptions are present, sends unique exception
1.107 + // If not, calls _STLP_ABORT() to terminate
1.108 + // Use _STLP_DEBUG_TERMINATE to override
1.109 + static void _STLP_CALL _Terminate();
1.110 +
1.111 +# ifdef _STLP_DEBUG
1.112 +
1.113 + // owned_list/link delegate non-inline functions here
1.114 +
1.115 + static bool _STLP_CALL _Check_same_owner( const __owned_link& __i1,
1.116 + const __owned_link& __i2);
1.117 + static bool _STLP_CALL _Check_same_owner_or_null( const __owned_link& __i1,
1.118 + const __owned_link& __i2);
1.119 + static bool _STLP_CALL _Check_if_owner( const __owned_list*, const __owned_link&);
1.120 +
1.121 + static void _STLP_CALL _Verify(const __owned_list*);
1.122 +
1.123 + static void _STLP_CALL _Swap_owners(__owned_list&, __owned_list& /*, bool __swap_roots */ );
1.124 +
1.125 + static void _STLP_CALL _Invalidate_all(__owned_list*);
1.126 +
1.127 + static void _STLP_CALL _Stamp_all(__owned_list*, __owned_list*);
1.128 +
1.129 + static void _STLP_CALL _M_detach(__owned_list*, __owned_link*);
1.130 +
1.131 + static void _STLP_CALL _M_attach(__owned_list*, __owned_link*);
1.132 +
1.133 + // accessor : check and get pointer to the container
1.134 + static void* _STLP_CALL _Get_container_ptr(const __owned_link*);
1.135 +# endif /* _STLP_DEBUG */
1.136 +
1.137 + // debug messages and formats
1.138 + _STLP_STATIC_MEMBER_DECLSPEC static const char* _Message_table[_StlMsg_MAX];
1.139 +};
1.140 +
1.141 +
1.142 +# if defined (_STLP_USE_TEMPLATE_EXPORT)
1.143 +_STLP_EXPORT_TEMPLATE struct _STLP_CLASS_DECLSPEC __stl_debug_engine<bool>;
1.144 +# endif /* _STLP_USE_TEMPLATE_EXPORT */
1.145 +
1.146 +typedef __stl_debug_engine<bool> __stl_debugger;
1.147 +
1.148 +_STLP_END_NAMESPACE
1.149 +
1.150 +# ifndef _STLP_ASSERT
1.151 +# define _STLP_ASSERT(expr) \
1.152 + if (!(expr)) {STLPORT::__stl_debugger::_Assert( # expr, _STLP_FILE__, __LINE__);}
1.153 +# endif
1.154 +
1.155 +# endif /* _STLP_ASSERTIONS || _STLP_DEBUG */
1.156 +
1.157 +
1.158 +// this section is for _STLP_DEBUG only
1.159 +#if defined ( _STLP_DEBUG )
1.160 +
1.161 +# ifndef _STLP_VERBOSE_ASSERT
1.162 +// fbp : new form not requiring ";"
1.163 +# define _STLP_VERBOSE_ASSERT(expr,__diag_num) \
1.164 + if (!(expr)) { STLPORT::__stl_debugger::_VerboseAssert\
1.165 + ( # expr, __diag_num, _STLP_FILE__, __LINE__ ); \
1.166 + }
1.167 +# endif
1.168 +
1.169 +# define _STLP_DEBUG_CHECK(expr) _STLP_ASSERT(expr)
1.170 +# define _STLP_DEBUG_DO(expr) expr;
1.171 +
1.172 +# ifndef _STLP_VERBOSE_RETURN
1.173 +# define _STLP_VERBOSE_RETURN(__expr,__diag_num) if (!(__expr)) { \
1.174 + __stl_debugger::_IndexedError(__diag_num, __FILE__ , __LINE__); \
1.175 + return false; }
1.176 +# endif
1.177 +
1.178 +# ifndef _STLP_VERBOSE_RETURN_0
1.179 +# define _STLP_VERBOSE_RETURN_0(__expr,__diag_num) if (!(__expr)) { \
1.180 + __stl_debugger::_IndexedError(__diag_num, __FILE__ , __LINE__); \
1.181 + return 0; }
1.182 +# endif
1.183 +
1.184 +#if ! defined (_STLP_INTERNAL_THREADS_H)
1.185 +# include <stl/_threads.h>
1.186 +#endif
1.187 +
1.188 +#ifndef _STLP_INTERNAL_ITERATOR_BASE_H
1.189 +# include <stl/_iterator_base.h>
1.190 +#endif
1.191 +
1.192 +_STLP_BEGIN_NAMESPACE
1.193 +
1.194 +//=============================================================
1.195 +template <class _Iterator>
1.196 +inline bool _STLP_CALL __valid_range(const _Iterator& __i1 ,const _Iterator& __i2,
1.197 + const random_access_iterator_tag&) {
1.198 + return (__i1< __i2) || (__i1 == __i2);
1.199 +}
1.200 +
1.201 +template <class _Iterator>
1.202 +inline bool _STLP_CALL __valid_range(const _Iterator& __i1 ,const _Iterator& __i2,
1.203 + const bidirectional_iterator_tag&) {
1.204 + // check if comparable
1.205 + bool __dummy(__i1==__i2);
1.206 + return (__dummy==__dummy);
1.207 +}
1.208 +
1.209 +template <class _Iterator>
1.210 +inline bool _STLP_CALL __valid_range(const _Iterator& __i1 ,const _Iterator& __i2, const forward_iterator_tag&) {
1.211 + // check if comparable
1.212 + bool __dummy(__i1==__i2);
1.213 + return (__dummy==__dummy);
1.214 +}
1.215 +
1.216 +template <class _Iterator>
1.217 +inline bool _STLP_CALL __valid_range(const _Iterator&,const _Iterator&, const input_iterator_tag&) {
1.218 + return true;
1.219 +}
1.220 +
1.221 +template <class _Iterator>
1.222 +inline bool _STLP_CALL __valid_range(const _Iterator&,const _Iterator&, const output_iterator_tag&) {
1.223 + return true;
1.224 +}
1.225 +
1.226 +template <class _Iterator>
1.227 +inline bool _STLP_CALL __valid_range(const _Iterator& __i1, const _Iterator& __i2) {
1.228 + return __valid_range(__i1,__i2,_STLP_ITERATOR_CATEGORY(__i1, _Iterator));
1.229 +}
1.230 +
1.231 +// Note : that means in range [i1, i2].
1.232 +template <class _Iterator>
1.233 +inline bool _STLP_CALL __in_range(const _Iterator& _It, const _Iterator& __i1,
1.234 + const _Iterator& __i2) {
1.235 + return __valid_range(__i1,_It,_STLP_ITERATOR_CATEGORY(__i1, _Iterator)) &&
1.236 + __valid_range(_It,__i2,_STLP_ITERATOR_CATEGORY(_It, _Iterator));
1.237 +}
1.238 +
1.239 +template <class _Iterator>
1.240 +inline bool _STLP_CALL __in_range(const _Iterator& __first, const _Iterator& __last,
1.241 + const _Iterator& __start, const _Iterator& __finish) {
1.242 + return __valid_range(__first,__last,_STLP_ITERATOR_CATEGORY(__first, _Iterator)) &&
1.243 + __valid_range(__start,__first,_STLP_ITERATOR_CATEGORY(__first, _Iterator)) &&
1.244 + __valid_range(__last,__finish,_STLP_ITERATOR_CATEGORY(__last, _Iterator));
1.245 +}
1.246 +
1.247 +//==========================================================
1.248 +
1.249 +
1.250 +class _STLP_CLASS_DECLSPEC __owned_link {
1.251 +public:
1.252 +
1.253 + __owned_link() : _M_owner(0) {}
1.254 + __owned_link(const __owned_list* __c) : _M_owner(0), _M_next(0) {
1.255 + __stl_debugger::_M_attach(__CONST_CAST(__owned_list*,__c), this);
1.256 + }
1.257 + __owned_link(const __owned_link& __rhs): _M_owner(0) {
1.258 + __stl_debugger::_M_attach(__CONST_CAST(__owned_list*,__rhs._M_owner), this);
1.259 + }
1.260 + __owned_link& operator=(const __owned_link& __rhs) {
1.261 + __owned_list* __new_owner = __CONST_CAST(__owned_list*,__rhs._M_owner);
1.262 + __owned_list* __old_owner = _M_owner;
1.263 + if ( __old_owner != __new_owner ) {
1.264 + __stl_debugger::_M_detach(__old_owner, this);
1.265 + __stl_debugger::_M_attach(__new_owner, this);
1.266 + }
1.267 + return *this;
1.268 + }
1.269 + ~__owned_link() {
1.270 + __stl_debugger::_M_detach(_M_owner, this);
1.271 + _Invalidate();
1.272 + }
1.273 +
1.274 + const __owned_list* _Owner() const {
1.275 + return _M_owner;
1.276 + }
1.277 + __owned_list* _Owner() {
1.278 + return _M_owner;
1.279 + }
1.280 + void _Set_owner(const __owned_list* __o) {
1.281 + _M_owner= __CONST_CAST(__owned_list*,__o);
1.282 + }
1.283 + bool _Valid() const {
1.284 + return _M_owner !=0;
1.285 + }
1.286 +
1.287 + void _Invalidate() { _M_owner=0; _M_next = 0; }
1.288 + void _Link_to_self() { _M_next= 0; }
1.289 +
1.290 + __owned_link* _Next() { return _M_next; }
1.291 + const __owned_link* _Next() const { return _M_next; }
1.292 +
1.293 +public:
1.294 + __owned_list* _M_owner;
1.295 + __owned_link* _M_next;
1.296 +};
1.297 +
1.298 +
1.299 +class _STLP_CLASS_DECLSPEC __owned_list {
1.300 +public:
1.301 + __owned_list(const void* __o) {
1.302 + // fprintf(stderr, "__owned_list(): %p\n",(void*)this);
1.303 + _M_node._M_owner = __CONST_CAST(__owned_list*, __REINTERPRET_CAST(const __owned_list*,__o));
1.304 + _M_node._M_next=0;
1.305 + }
1.306 + ~__owned_list() {
1.307 + // fprintf(stderr, "~__owned_list(): %p\n",(void*)this);
1.308 + _Invalidate_all();
1.309 + // that prevents detach
1.310 + _M_node._Invalidate();
1.311 + }
1.312 + const void* _Owner() const {
1.313 + return (const void*)_M_node._M_owner;
1.314 + }
1.315 + void* _Owner() {
1.316 + return (void*)_M_node._M_owner;
1.317 + }
1.318 + bool _Valid() const {
1.319 + return _M_node._M_owner!=0;
1.320 + }
1.321 + void _Invalidate() { _M_node._M_owner=0; }
1.322 +
1.323 + __owned_link* _First() { return _M_node._Next(); }
1.324 + __owned_link* _Last() { return 0 ; }
1.325 +
1.326 + const __owned_link* _First() const { return (__owned_link*)_M_node._M_next; }
1.327 + const __owned_link* _Last() const { return 0 ;}
1.328 +
1.329 + void _Verify() const {
1.330 + __stl_debugger::_Verify(this);
1.331 + }
1.332 +
1.333 + void _Swap_owners(__owned_list& __y) {
1.334 + __stl_debugger::_Swap_owners(*this, __y);
1.335 + }
1.336 +
1.337 + void _Invalidate_all() {
1.338 + __stl_debugger::_Invalidate_all(this);
1.339 + }
1.340 +
1.341 + mutable __owned_link _M_node;
1.342 + mutable _STLP_mutex _M_lock;
1.343 +
1.344 +private:
1.345 + // should never be called, should be left undefined,
1.346 + // but some compilers complain about it ;(
1.347 + __owned_list(const __owned_list&){}
1.348 + void operator=(const __owned_list&) {}
1.349 +
1.350 + friend class __owned_link;
1.351 + friend struct __stl_debug_engine<bool>;
1.352 +};
1.353 +
1.354 +
1.355 +//==========================================================
1.356 +
1.357 +// forward declaratioins
1.358 +
1.359 +template <class _Iterator>
1.360 +bool _STLP_CALL __check_range(const _Iterator&, const _Iterator&);
1.361 +template <class _Iterator>
1.362 +bool _STLP_CALL __check_range(const _Iterator&,
1.363 + const _Iterator&, const _Iterator&);
1.364 +template <class _Iterator>
1.365 +bool _STLP_CALL __check_range(const _Iterator&, const _Iterator& ,
1.366 + const _Iterator&, const _Iterator& );
1.367 +
1.368 +template <class _Iterator>
1.369 +void _STLP_CALL __invalidate_range(const __owned_list* __base,
1.370 + const _Iterator& __first,
1.371 + const _Iterator& __last);
1.372 +
1.373 +template <class _Iterator>
1.374 +void _STLP_CALL __invalidate_iterator(const __owned_list* __base,
1.375 + const _Iterator& __it);
1.376 +
1.377 +//============================================================
1.378 +
1.379 +inline bool _STLP_CALL
1.380 +__check_same_owner( const __owned_link& __i1, const __owned_link& __i2) {
1.381 + return __stl_debugger::_Check_same_owner(__i1,__i2);
1.382 +}
1.383 +inline bool _STLP_CALL
1.384 +__check_same_owner_or_null( const __owned_link& __i1, const __owned_link& __i2) {
1.385 + return __stl_debugger::_Check_same_owner_or_null(__i1,__i2);
1.386 +}
1.387 +
1.388 +template <class _Iterator>
1.389 +inline bool _STLP_CALL __check_if_owner( const __owned_list* __owner,
1.390 + const _Iterator& __it) {
1.391 + return __stl_debugger::_Check_if_owner(__owner, (const __owned_link&)__it);
1.392 +}
1.393 +
1.394 +_STLP_END_NAMESPACE
1.395 +
1.396 +# endif /* _STLP_DEBUG */
1.397 +
1.398 +#if defined ( _STLP_ASSERTIONS )
1.399 +
1.400 +# ifndef _STLP_ASSERT_MSG_TRAILER
1.401 +# define _STLP_ASSERT_MSG_TRAILER
1.402 +# endif
1.403 +
1.404 +// dwa 12/30/98 - if _STLP_DEBUG_MESSAGE is defined, the user can supply own definition.
1.405 +# if !defined( _STLP_DEBUG_MESSAGE )
1.406 +# define __stl_debug_message __stl_debugger::_Message
1.407 +# else
1.408 + extern void __stl_debug_message(const char * format_str, ...);
1.409 +# endif
1.410 +
1.411 +// fbp: if _STLP_DEBUG_TERMINATE is defined, the user can supply own definition.
1.412 +# if !defined( _STLP_DEBUG_TERMINATE )
1.413 +# define __stl_debug_terminate __stl_debugger::_Terminate
1.414 +# else
1.415 + extern void __stl_debug_terminate(void);
1.416 +# endif
1.417 +
1.418 +#endif
1.419 +
1.420 +# if !defined (_STLP_LINK_TIME_INSTANTIATION)
1.421 +# include <stl/debug/_debug.c>
1.422 +# endif
1.423 +
1.424 +#endif /* DEBUG_H */
1.425 +
1.426 +// Local Variables:
1.427 +// mode:C++
1.428 +// End:
1.429 +