epoc32/include/stdapis/stlportv5/stl/_new.h
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
     1.1 --- a/epoc32/include/stdapis/stlportv5/stl/_new.h	Wed Mar 31 12:27:01 2010 +0100
     1.2 +++ b/epoc32/include/stdapis/stlportv5/stl/_new.h	Wed Mar 31 12:33:34 2010 +0100
     1.3 @@ -1,67 +1,89 @@
     1.4  /*
     1.5 -* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
     1.6 + * Copyright (c) 1999
     1.7 + * Boris Fomitchev
     1.8 + *
     1.9 + * This material is provided "as is", with absolutely no warranty expressed
    1.10 + * or implied. Any use is at your own risk.
    1.11 + *
    1.12 + * Permission to use or copy this software for any purpose is hereby granted
    1.13 + * without fee, provided the above notices are retained on all copies.
    1.14 + * Permission to modify the code and to distribute modified code is granted,
    1.15 + * provided the above notices are retained, and a notice that the code was
    1.16 + * modified is included with the above copyright notice.
    1.17 + *
    1.18 + */
    1.19  
    1.20 -* Redistribution and use in source and binary forms, with or without 
    1.21 -* modification, are permitted provided that the following conditions are met:
    1.22 +#ifndef _STLP_INTERNAL_NEW
    1.23 +#define _STLP_INTERNAL_NEW
    1.24  
    1.25 -* Redistributions of source code must retain the above copyright notice, this 
    1.26 -* list of conditions and the following disclaimer.
    1.27 -* Redistributions in binary form must reproduce the above copyright notice, 
    1.28 -* this list of conditions and the following disclaimer in the documentation 
    1.29 -* and/or other materials provided with the distribution.
    1.30 -* Neither the name of Nokia Corporation nor the names of its contributors 
    1.31 -* may be used to endorse or promote products derived from this software 
    1.32 -* without specific prior written permission.
    1.33 +#ifndef _STLP_INTERNAL_CSTDDEF
    1.34 +// size_t
    1.35 +#  include <stl/_cstddef.h>
    1.36 +#endif
    1.37  
    1.38 -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
    1.39 -* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
    1.40 -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
    1.41 -* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 
    1.42 -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
    1.43 -* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
    1.44 -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
    1.45 -* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
    1.46 -* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    1.47 -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.48 -*
    1.49 -* Description:
    1.50 -*
    1.51 -*/
    1.52 +#if defined (__BORLANDC__) && (__BORLANDC__ < 0x580)
    1.53 +// new.h uses ::malloc ;(
    1.54 +#  include _STLP_NATIVE_CPP_C_HEADER(cstdlib)
    1.55 +using _STLP_VENDOR_CSTD::malloc;
    1.56 +#endif
    1.57  
    1.58 -#ifndef _STLP_NEW_H_HEADER
    1.59 -# define _STLP_NEW_H_HEADER
    1.60 +#if !defined (_STLP_NO_NEW_NEW_HEADER)
    1.61 +#  if defined (_STLP_BROKEN_BAD_ALLOC_CLASS)
    1.62 +#    define bad_alloc _STLP_NULLIFIED_BROKEN_BAD_ALLOC_CLASS
    1.63 +#    define nothrow_t _STLP_NULLIFIED_BROKEN_BAD_NOTHROW_T_CLASS
    1.64 +#    define nothrow _STLP_NULLIFIED_BROKEN_BAD_NOTHROW
    1.65 +#  endif
    1.66  
    1.67 -# ifdef _STLP_NO_BAD_ALLOC
    1.68 -# ifndef _STLP_NEW_DONT_THROW
    1.69 -#   define _STLP_NEW_DONT_THROW 1
    1.70 -# endif /* _STLP_NEW_DONT_THROW */
    1.71 +// eMbedded Visual C++ .NET unfortunately uses _INC_NEW for both <new.h> and <new>
    1.72 +// we undefine the symbol to get the stuff in the SDK's <new>
    1.73 +#  if defined (_STLP_WCE_NET) && defined (_INC_NEW)
    1.74 +#    undef _INC_NEW
    1.75 +#  endif
    1.76  
    1.77 -#  include <exception>
    1.78 +#  if defined (new)
    1.79 +/* STLport cannot replace native Std library new header if new is a macro,
    1.80 + * please define new macro after <new> header inclusion.
    1.81 + */
    1.82 +#    error Cannot include native new header as new is a macro.
    1.83 +#  endif
    1.84  
    1.85 +#  include _STLP_NATIVE_CPP_RUNTIME_HEADER(new)
    1.86 +
    1.87 +#  if defined (_STLP_BROKEN_BAD_ALLOC_CLASS)
    1.88 +#    undef bad_alloc
    1.89 +#    undef nothrow_t
    1.90 +#    undef nothrow
    1.91 +#    undef _STLP_NULLIFIED_BROKEN_BAD_ALLOC_CLASS
    1.92 +#    undef _STLP_NULLIFIED_BROKEN_BAD_NOTHROW_T_CLASS
    1.93 +#    undef _STLP_NULLIFIED_BROKEN_BAD_NOTHROW
    1.94 +#  endif
    1.95 +#else
    1.96 +#  include <new.h>
    1.97 +#endif
    1.98 +
    1.99 +#if defined (_STLP_NO_BAD_ALLOC) && !defined (_STLP_NEW_DONT_THROW_BAD_ALLOC)
   1.100 +#  define _STLP_NEW_DONT_THROW_BAD_ALLOC 1
   1.101 +#endif
   1.102 +
   1.103 +#if defined (_STLP_USE_EXCEPTIONS) && defined (_STLP_NEW_DONT_THROW_BAD_ALLOC)
   1.104 +
   1.105 +#  ifndef _STLP_INTERNAL_EXCEPTION
   1.106 +#    include <stl/_exception.h>
   1.107 +#  endif
   1.108  
   1.109  _STLP_BEGIN_NAMESPACE
   1.110  
   1.111 -#if defined(__SYMBIAN32__) && defined( __WINSCW__)
   1.112 -// already defined symcpp.h included from rvct2_2.h
   1.113 +#  if defined (_STLP_NO_BAD_ALLOC)
   1.114  struct nothrow_t {};
   1.115 -#endif
   1.116 +#    define nothrow nothrow_t()
   1.117 +#  endif
   1.118  
   1.119 -
   1.120 -# ifdef _STLP_OWN_IOSTREAMS
   1.121 -#ifdef __ARMCC__
   1.122 -extern _STLP_DECLSPEC const nothrow_t nothrow;
   1.123 -#else
   1.124 -extern IMPORT_C const nothrow_t& GetNoThrowObj();
   1.125 -#define nothrow GetNoThrowObj()
   1.126 -#endif
   1.127 -# else
   1.128 -#  define nothrow nothrow_t()
   1.129 -# endif
   1.130 -#ifndef _STLP_EXCEPTION_BASE
   1.131 -#  define _STLP_EXCEPTION_BASE exception
   1.132 -#endif
   1.133 -
   1.134 -class bad_alloc : public _STLP_EXCEPTION_BASE { 
   1.135 +/*
   1.136 + * STLport own bad_alloc exception to be used if the native C++ library
   1.137 + * do not define it or when the new operator do not throw it to avoid
   1.138 + * a useless library dependency.
   1.139 + */
   1.140 +class bad_alloc : public exception {
   1.141  public:
   1.142    bad_alloc () _STLP_NOTHROW_INHERENTLY { }
   1.143    bad_alloc(const bad_alloc&) _STLP_NOTHROW_INHERENTLY { }
   1.144 @@ -72,137 +94,68 @@
   1.145  
   1.146  _STLP_END_NAMESPACE
   1.147  
   1.148 -#endif /* _STLP_NO_BAD_ALLOC */
   1.149 +#endif /* _STLP_USE_EXCEPTIONS && (_STLP_NO_BAD_ALLOC || _STLP_NEW_DONT_THROW_BAD_ALLOC) */
   1.150  
   1.151 -#if defined (_STLP_WINCE)
   1.152 +#if defined (_STLP_RTTI_BUG)
   1.153  _STLP_BEGIN_NAMESPACE
   1.154  
   1.155 -inline void* _STLP_CALL __stl_new(size_t __n) {
   1.156 -  return ::malloc(__n);
   1.157 -}
   1.158 +inline void* _STLP_CALL __stl_new(size_t __n)
   1.159 +{ return ::malloc(__n); }
   1.160  
   1.161 -inline void _STLP_CALL __stl_delete(void* __p) {
   1.162 -  free(__p);
   1.163 -}
   1.164 -
   1.165 -#ifndef __cdecl
   1.166 -# define __cdecl
   1.167 -#endif
   1.168 -
   1.169 +inline void _STLP_CALL __stl_delete(void* __p)
   1.170 +{ ::free(__p); }
   1.171  _STLP_END_NAMESPACE
   1.172  
   1.173 -#else /* _STLP_WINCE */
   1.174 +#else /* _STLP_RTTI_BUG */
   1.175  
   1.176 -#include <new>
   1.177 -
   1.178 -# ifndef _STLP_NO_BAD_ALLOC
   1.179 -#  ifdef _STLP_USE_OWN_NAMESPACE
   1.180 -
   1.181 -    _STLP_BEGIN_NAMESPACE
   1.182 -    using _STLP_VENDOR_EXCEPT_STD::bad_alloc;
   1.183 -    using _STLP_VENDOR_EXCEPT_STD::nothrow_t;
   1.184 -    using _STLP_VENDOR_EXCEPT_STD::nothrow;
   1.185 -
   1.186 -#  if defined (_STLP_GLOBAL_NEW_HANDLER)
   1.187 -    using ::new_handler;
   1.188 -    using ::set_new_handler;
   1.189 -#  else
   1.190 -    using _STLP_VENDOR_EXCEPT_STD::new_handler;
   1.191 -    using _STLP_VENDOR_EXCEPT_STD::set_new_handler;
   1.192 -#  endif
   1.193 -    
   1.194 -    _STLP_END_NAMESPACE
   1.195 -
   1.196 -#  endif /* _STLP_OWN_NAMESPACE */
   1.197 -
   1.198 -# endif /* _STLP_NO_BAD_ALLOC */
   1.199 -
   1.200 -# if defined (_STLP_NO_NEW_NEW_HEADER) || defined (_STLP_NEW_DONT_THROW) || defined (__SYMBIAN32__) \
   1.201 -                    || defined (__WINS__) && ! defined (_STLP_CHECK_NULL_ALLOC)
   1.202 -#  define _STLP_CHECK_NULL_ALLOC(__x) void* __y = __x;if (__y == 0){_STLP_THROW(bad_alloc());}return __y
   1.203 -# if defined (__SYMBIAN32__)
   1.204 -//# define _STLP_NEW operator new
   1.205 -#define _STLP_NEW  ::malloc
   1.206 -#endif
   1.207 -/*
   1.208 -# elif defined (__SYMBIAN32__) || defined (__WINS__)
   1.209 -#  ifndef _STLP_USE_TRAP_LEAVE
   1.210 -#   define _STLP_CHECK_NULL_ALLOC(__x) void* __y = __x;if (__y == 0){abort();}return __y
   1.211 -#  else
   1.212 -#   define _STLP_NEW(x) :: operator new (x, ELeave) 
   1.213 -#   define _STLP_CHECK_NULL_ALLOC(__x) return __x
   1.214 -#  endif
   1.215 -*/
   1.216 -# else
   1.217 -#  define _STLP_CHECK_NULL_ALLOC(__x) return __x
   1.218 -# endif
   1.219 -
   1.220 -#ifndef _STLP_NEW
   1.221 -# define _STLP_NEW ::operator new
   1.222 -#endif
   1.223 -# define _STLP_PLACEMENT_NEW ::new
   1.224 +#  if defined (_STLP_USE_OWN_NAMESPACE)
   1.225  
   1.226  _STLP_BEGIN_NAMESPACE
   1.227  
   1.228 -#ifdef __SYMBIAN32__
   1.229 +#    if !defined (_STLP_NEW_DONT_THROW_BAD_ALLOC)
   1.230 +using _STLP_VENDOR_EXCEPT_STD::bad_alloc;
   1.231 +#    endif
   1.232  
   1.233 -typedef void(*new_handler)();
   1.234 +#    if !defined (_STLP_NO_BAD_ALLOC)
   1.235 +using _STLP_VENDOR_EXCEPT_STD::nothrow_t;
   1.236 +using _STLP_VENDOR_EXCEPT_STD::nothrow;
   1.237 +#      if defined (_STLP_GLOBAL_NEW_HANDLER)
   1.238 +using ::new_handler;
   1.239 +using ::set_new_handler;
   1.240 +#      else
   1.241 +using _STLP_VENDOR_EXCEPT_STD::new_handler;
   1.242 +using _STLP_VENDOR_EXCEPT_STD::set_new_handler;
   1.243 +#      endif
   1.244 +#    endif /* !_STLP_NO_BAD_ALLOC */
   1.245  
   1.246 -_STLP_DECLSPEC new_handler set_new_handler(new_handler pnew) throw();
   1.247 +_STLP_END_NAMESPACE
   1.248 +#  endif /* _STLP_USE_OWN_NAMESPACE */
   1.249  
   1.250 -#endif
   1.251 +#  if defined (_STLP_USE_EXCEPTIONS) && \
   1.252 +     (defined (_STLP_NO_NEW_NEW_HEADER) || defined (_STLP_NEW_DONT_THROW_BAD_ALLOC))
   1.253 +#    define _STLP_CHECK_NULL_ALLOC(__x) void* __y = __x; if (__y == 0) { _STLP_THROW(_STLP_STD::bad_alloc()); } return __y
   1.254 +#  else
   1.255 +#    define _STLP_CHECK_NULL_ALLOC(__x) return __x
   1.256 +#  endif
   1.257  
   1.258 -#if (( defined(__IBMCPP__)|| defined(__OS400__) || defined (__xlC__) || defined (qTidyHeap)) && defined(__DEBUG_ALLOC__) )
   1.259 -inline void*  _STLP_CALL __stl_new(size_t __n) {  _STLP_CHECK_NULL_ALLOC(_STLP_NEW(__n, __FILE__, __LINE__)); }
   1.260 -inline void _STLP_CALL __stl_delete(void* __p) { ::operator delete(__p, __FILE__, __LINE__); }
   1.261 -#else
   1.262 -inline void*  _STLP_CALL __stl_new(size_t __n)   { return ::operator new(__n); }
   1.263 -inline void   _STLP_CALL __stl_delete(void* __p) { ::operator delete(__p); }
   1.264 -#endif
   1.265 +_STLP_BEGIN_NAMESPACE
   1.266 +
   1.267 +#  if ((defined (__IBMCPP__) || defined (__OS400__) || defined (__xlC__) || defined (qTidyHeap)) && defined (__DEBUG_ALLOC__))
   1.268 +inline void* _STLP_CALL __stl_new(size_t __n)   { _STLP_CHECK_NULL_ALLOC(::operator _STLP_NEW(__n, __FILE__, __LINE__)); }
   1.269 +inline void  _STLP_CALL __stl_delete(void* __p) { ::operator delete(__p, __FILE__, __LINE__); }
   1.270 +#  else
   1.271 +inline void* _STLP_CALL __stl_new(size_t __n)   { _STLP_CHECK_NULL_ALLOC(::operator _STLP_NEW(__n)); }
   1.272 +inline void  _STLP_CALL __stl_delete(void* __p) { ::operator delete(__p); }
   1.273 +#  endif
   1.274  _STLP_END_NAMESPACE
   1.275  
   1.276 +#endif /* _STLP_RTTI_BUG */
   1.277  
   1.278 -# endif /* _STLP_WINCE */
   1.279 +#endif /* _STLP_INTERNAL_NEW */
   1.280  
   1.281 -#if defined(__SYMBIAN32__) && !defined(__GCCE__)
   1.282 -_STLP_DECLSPEC void *operator new(unsigned int aSize);
   1.283  
   1.284 -_STLP_DECLSPEC void *operator new[](unsigned int aSize);
   1.285 -#endif
   1.286 -
   1.287 -_STLP_DECLSPEC void operator delete(void* aPtr) throw();
   1.288 -
   1.289 -_STLP_DECLSPEC void operator delete[](void* aPtr) throw();
   1.290 -
   1.291 -_STLP_DECLSPEC void* operator new(unsigned int aSize, const std::nothrow_t& /*aNoThrow*/) throw();
   1.292 -
   1.293 -_STLP_DECLSPEC void* operator new[](unsigned int aSize, const std::nothrow_t& aNoThrow) throw();
   1.294 -
   1.295 -_STLP_DECLSPEC void operator delete(void* aPtr, const std::nothrow_t& /*aNoThrow*/) throw();
   1.296 -
   1.297 -_STLP_DECLSPEC void operator delete[](void* aPtr, const std::nothrow_t& /*aNoThrow*/) throw();
   1.298 -
   1.299 -
   1.300 -// placement delete
   1.301 -#ifndef __PLACEMENT_VEC_NEW_INLINE
   1.302 -#define __PLACEMENT_VEC_NEW_INLINE
   1.303 -inline void* operator new[](unsigned int /*aSize*/, void* aBase) throw()
   1.304 -	{return aBase;}
   1.305 -inline void operator delete[](void* /*aPtr*/, void* /*aBase*/) throw()
   1.306 -    {
   1.307 -    
   1.308 -    }
   1.309 -#endif
   1.310 -
   1.311 -#ifndef __PLACEMENT_NEW_INLINE
   1.312 -#define __PLACEMENT_NEW_INLINE
   1.313 -inline void* operator new(unsigned int /*aSize*/, void* aBase) throw()
   1.314 -	{return aBase;}
   1.315 -
   1.316 -// Global placement operator delete
   1.317 -inline void operator delete(void* /*aPtr*/, void* /*aBase*/) throw()
   1.318 -	{}
   1.319 -#endif //__PLACEMENT_NEW_INLINE
   1.320 -
   1.321 -
   1.322 -#endif /* _STLP_NEW_H_HEADER */
   1.323 +/*
   1.324 + * Local Variables:
   1.325 + * mode:C++
   1.326 + * End:
   1.327 + */