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__ < 0x570)
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 // eMbedded Visual C++ .NET unfortunately uses _INC_NEW for both <new.h> and <new>
32 // we undefine the symbol to get the stuff in the SDK's <new>
33 # if defined (_STLP_WCE_NET) && defined (_INC_NEW)
38 /* STLport cannot replace native Std library new header if new is a macro,
39 * please define new macro after <new> header inclusion.
41 # error Cannot include native new header as new is a macro.
44 # if defined (_STLP_HAS_INCLUDE_NEXT)
47 # include _STLP_NATIVE_CPP_RUNTIME_HEADER(new)
53 #if defined (_STLP_NO_BAD_ALLOC) && !defined (_STLP_NEW_DONT_THROW_BAD_ALLOC)
54 # define _STLP_NEW_DONT_THROW_BAD_ALLOC 1
57 #if defined (_STLP_USE_EXCEPTIONS) && defined (_STLP_NEW_DONT_THROW_BAD_ALLOC)
59 # ifndef _STLP_INTERNAL_EXCEPTION
60 # include <stl/_exception.h>
65 # if defined (_STLP_NO_BAD_ALLOC)
67 # define nothrow nothrow_t()
71 * STLport own bad_alloc exception to be used if the native C++ library
72 * do not define it or when the new operator do not throw it to avoid
73 * a useless library dependency.
75 class bad_alloc
: public exception
{
77 bad_alloc () _STLP_NOTHROW_INHERENTLY
{ }
78 bad_alloc(const bad_alloc
&) _STLP_NOTHROW_INHERENTLY
{ }
79 bad_alloc
& operator=(const bad_alloc
&) _STLP_NOTHROW_INHERENTLY
{return *this;}
80 ~bad_alloc () _STLP_NOTHROW_INHERENTLY
{ }
81 const char* what() const _STLP_NOTHROW_INHERENTLY
{ return "bad alloc"; }
86 #endif /* _STLP_USE_EXCEPTIONS && (_STLP_NO_BAD_ALLOC || _STLP_NEW_DONT_THROW_BAD_ALLOC) */
88 #if defined (_STLP_USE_OWN_NAMESPACE)
92 # if !defined (_STLP_NEW_DONT_THROW_BAD_ALLOC)
93 using _STLP_VENDOR_EXCEPT_STD::bad_alloc
;
96 # if !defined (_STLP_NO_BAD_ALLOC)
97 using _STLP_VENDOR_EXCEPT_STD::nothrow_t
;
98 using _STLP_VENDOR_EXCEPT_STD::nothrow
;
99 # if defined (_STLP_GLOBAL_NEW_HANDLER)
101 using ::set_new_handler
;
103 using _STLP_VENDOR_EXCEPT_STD::new_handler
;
104 using _STLP_VENDOR_EXCEPT_STD::set_new_handler
;
106 # endif /* !_STLP_NO_BAD_ALLOC */
109 #endif /* _STLP_USE_OWN_NAMESPACE */
111 #ifndef _STLP_THROW_BAD_ALLOC
112 # if !defined (_STLP_USE_EXCEPTIONS)
113 # ifndef _STLP_INTERNAL_CSTDIO
114 # include <stl/_cstdio.h>
116 # define _STLP_THROW_BAD_ALLOC puts("out of memory\n"); exit(1)
118 # define _STLP_THROW_BAD_ALLOC _STLP_THROW(_STLP_STD::bad_alloc())
122 #if defined (_STLP_NO_NEW_NEW_HEADER) || defined (_STLP_NEW_DONT_THROW_BAD_ALLOC)
123 # define _STLP_CHECK_NULL_ALLOC(__x) void* __y = __x; if (__y == 0) { _STLP_THROW_BAD_ALLOC; } return __y
125 # define _STLP_CHECK_NULL_ALLOC(__x) return __x
128 _STLP_BEGIN_NAMESPACE
130 #if ((defined (__IBMCPP__) || defined (__OS400__) || defined (__xlC__) || defined (qTidyHeap)) && defined (_STLP_DEBUG_ALLOC))
131 inline void* _STLP_CALL
__stl_new(size_t __n
) { _STLP_CHECK_NULL_ALLOC(::operator new(__n
, __FILE__
, __LINE__
)); }
132 inline void _STLP_CALL
__stl_delete(void* __p
) { ::operator delete(__p
, __FILE__
, __LINE__
); }
134 inline void* _STLP_CALL
__stl_new(size_t __n
) { _STLP_CHECK_NULL_ALLOC(::operator new(__n
)); }
135 inline void _STLP_CALL
__stl_delete(void* __p
) { ::operator delete(__p
); }
139 #endif /* _STLP_INTERNAL_NEW */