5 * This material is provided "as is", with absolutely no warranty expressed
6 * or implied. Any use is at your own risk.
8 * Permission to use or copy this software for any purpose is hereby granted
9 * without fee, provided the above notices are retained on all copies.
10 * Permission to modify the code and to distribute modified code is granted,
11 * provided the above notices are retained, and a notice that the code was
12 * modified is included with the above copyright notice.
16 #ifndef _STLP_INTERNAL_NEW
17 #define _STLP_INTERNAL_NEW
19 #ifndef _STLP_INTERNAL_CSTDDEF
21 # include <stl/_cstddef.h>
24 #if defined (__BORLANDC__) && (__BORLANDC__ < 0x580)
25 // new.h uses ::malloc ;(
26 # include _STLP_NATIVE_CPP_C_HEADER(cstdlib)
27 using _STLP_VENDOR_CSTD::malloc;
30 #if !defined (_STLP_NO_NEW_NEW_HEADER)
31 # if defined (_STLP_BROKEN_BAD_ALLOC_CLASS)
32 # define bad_alloc _STLP_NULLIFIED_BROKEN_BAD_ALLOC_CLASS
33 # define nothrow_t _STLP_NULLIFIED_BROKEN_BAD_NOTHROW_T_CLASS
34 # define nothrow _STLP_NULLIFIED_BROKEN_BAD_NOTHROW
37 // eMbedded Visual C++ .NET unfortunately uses _INC_NEW for both <new.h> and <new>
38 // we undefine the symbol to get the stuff in the SDK's <new>
39 # if defined (_STLP_WCE_NET) && defined (_INC_NEW)
44 /* STLport cannot replace native Std library new header if new is a macro,
45 * please define new macro after <new> header inclusion.
47 # error Cannot include native new header as new is a macro.
50 # include _STLP_NATIVE_CPP_RUNTIME_HEADER(new)
52 # if defined (_STLP_BROKEN_BAD_ALLOC_CLASS)
56 # undef _STLP_NULLIFIED_BROKEN_BAD_ALLOC_CLASS
57 # undef _STLP_NULLIFIED_BROKEN_BAD_NOTHROW_T_CLASS
58 # undef _STLP_NULLIFIED_BROKEN_BAD_NOTHROW
64 #if defined (_STLP_NO_BAD_ALLOC) && !defined (_STLP_NEW_DONT_THROW_BAD_ALLOC)
65 # define _STLP_NEW_DONT_THROW_BAD_ALLOC 1
68 #if defined (_STLP_USE_EXCEPTIONS) && defined (_STLP_NEW_DONT_THROW_BAD_ALLOC)
70 # ifndef _STLP_INTERNAL_EXCEPTION
71 # include <stl/_exception.h>
76 # if defined (_STLP_NO_BAD_ALLOC)
78 # define nothrow nothrow_t()
82 * STLport own bad_alloc exception to be used if the native C++ library
83 * do not define it or when the new operator do not throw it to avoid
84 * a useless library dependency.
86 class bad_alloc : public exception {
88 bad_alloc () _STLP_NOTHROW_INHERENTLY { }
89 bad_alloc(const bad_alloc&) _STLP_NOTHROW_INHERENTLY { }
90 bad_alloc& operator=(const bad_alloc&) _STLP_NOTHROW_INHERENTLY {return *this;}
91 ~bad_alloc () _STLP_NOTHROW_INHERENTLY { }
92 const char* what() const _STLP_NOTHROW_INHERENTLY { return "bad alloc"; }
97 #endif /* _STLP_USE_EXCEPTIONS && (_STLP_NO_BAD_ALLOC || _STLP_NEW_DONT_THROW_BAD_ALLOC) */
99 #if defined (_STLP_RTTI_BUG)
100 _STLP_BEGIN_NAMESPACE
102 inline void* _STLP_CALL __stl_new(size_t __n)
103 { return ::malloc(__n); }
105 inline void _STLP_CALL __stl_delete(void* __p)
109 #else /* _STLP_RTTI_BUG */
111 # if defined (_STLP_USE_OWN_NAMESPACE)
113 _STLP_BEGIN_NAMESPACE
115 # if !defined (_STLP_NEW_DONT_THROW_BAD_ALLOC)
116 using _STLP_VENDOR_EXCEPT_STD::bad_alloc;
119 # if !defined (_STLP_NO_BAD_ALLOC)
120 using _STLP_VENDOR_EXCEPT_STD::nothrow_t;
121 using _STLP_VENDOR_EXCEPT_STD::nothrow;
122 # if defined (_STLP_GLOBAL_NEW_HANDLER)
124 using ::set_new_handler;
126 using _STLP_VENDOR_EXCEPT_STD::new_handler;
127 using _STLP_VENDOR_EXCEPT_STD::set_new_handler;
129 # endif /* !_STLP_NO_BAD_ALLOC */
132 # endif /* _STLP_USE_OWN_NAMESPACE */
134 # if defined (_STLP_USE_EXCEPTIONS) && \
135 (defined (_STLP_NO_NEW_NEW_HEADER) || defined (_STLP_NEW_DONT_THROW_BAD_ALLOC))
136 # define _STLP_CHECK_NULL_ALLOC(__x) void* __y = __x; if (__y == 0) { _STLP_THROW(_STLP_STD::bad_alloc()); } return __y
138 # define _STLP_CHECK_NULL_ALLOC(__x) return __x
141 _STLP_BEGIN_NAMESPACE
143 # if ((defined (__IBMCPP__) || defined (__OS400__) || defined (__xlC__) || defined (qTidyHeap)) && defined (__DEBUG_ALLOC__))
144 inline void* _STLP_CALL __stl_new(size_t __n) { _STLP_CHECK_NULL_ALLOC(::operator _STLP_NEW(__n, __FILE__, __LINE__)); }
145 inline void _STLP_CALL __stl_delete(void* __p) { ::operator delete(__p, __FILE__, __LINE__); }
147 inline void* _STLP_CALL __stl_new(size_t __n) { _STLP_CHECK_NULL_ALLOC(::operator _STLP_NEW(__n)); }
148 inline void _STLP_CALL __stl_delete(void* __p) { ::operator delete(__p); }
152 #endif /* _STLP_RTTI_BUG */
154 #endif /* _STLP_INTERNAL_NEW */