2010-05-12 03:42:16 +08:00
|
|
|
// -*- C++ -*-
|
|
|
|
//===----------------------------- new ------------------------------------===//
|
|
|
|
//
|
2010-05-12 05:36:01 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
2010-05-12 03:42:16 +08:00
|
|
|
//
|
2010-11-17 06:09:02 +08:00
|
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
// Source Licenses. See LICENSE.TXT for details.
|
2010-05-12 03:42:16 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_NEW
|
|
|
|
#define _LIBCPP_NEW
|
|
|
|
|
|
|
|
/*
|
|
|
|
new synopsis
|
|
|
|
|
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
|
|
|
|
class bad_alloc
|
|
|
|
: public exception
|
|
|
|
{
|
|
|
|
public:
|
2011-05-27 02:23:59 +08:00
|
|
|
bad_alloc() noexcept;
|
|
|
|
bad_alloc(const bad_alloc&) noexcept;
|
|
|
|
bad_alloc& operator=(const bad_alloc&) noexcept;
|
|
|
|
virtual const char* what() const noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2013-09-11 09:38:42 +08:00
|
|
|
class bad_array_length : public bad_alloc // C++14
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bad_array_length() noexcept;
|
|
|
|
};
|
|
|
|
|
|
|
|
class bad_array_new_length : public bad_alloc
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bad_array_new_length() noexcept;
|
|
|
|
};
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
struct nothrow_t {};
|
|
|
|
extern const nothrow_t nothrow;
|
|
|
|
typedef void (*new_handler)();
|
2011-05-27 02:23:59 +08:00
|
|
|
new_handler set_new_handler(new_handler new_p) noexcept;
|
|
|
|
new_handler get_new_handler() noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
} // std
|
|
|
|
|
2011-05-27 02:23:59 +08:00
|
|
|
void* operator new(std::size_t size); // replaceable
|
|
|
|
void* operator new(std::size_t size, const std::nothrow_t&) noexcept; // replaceable
|
|
|
|
void operator delete(void* ptr) noexcept; // replaceable
|
2015-02-15 13:18:55 +08:00
|
|
|
void operator delete(void* ptr, std::size_t size) noexcept; // replaceable, C++14
|
2011-05-27 02:23:59 +08:00
|
|
|
void operator delete(void* ptr, const std::nothrow_t&) noexcept; // replaceable
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-05-27 02:23:59 +08:00
|
|
|
void* operator new[](std::size_t size); // replaceable
|
|
|
|
void* operator new[](std::size_t size, const std::nothrow_t&) noexcept; // replaceable
|
|
|
|
void operator delete[](void* ptr) noexcept; // replaceable
|
2015-02-15 13:18:55 +08:00
|
|
|
void operator delete[](void* ptr, std::size_t size) noexcept; // replaceable, C++14
|
2011-05-27 02:23:59 +08:00
|
|
|
void operator delete[](void* ptr, const std::nothrow_t&) noexcept; // replaceable
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-05-27 02:23:59 +08:00
|
|
|
void* operator new (std::size_t size, void* ptr) noexcept;
|
|
|
|
void* operator new[](std::size_t size, void* ptr) noexcept;
|
|
|
|
void operator delete (void* ptr, void*) noexcept;
|
|
|
|
void operator delete[](void* ptr, void*) noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <__config>
|
|
|
|
#include <exception>
|
|
|
|
#include <cstddef>
|
|
|
|
|
2015-02-14 06:15:32 +08:00
|
|
|
#include <__undef___deallocate>
|
|
|
|
|
2011-10-18 04:05:10 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2010-05-12 03:42:16 +08:00
|
|
|
#pragma GCC system_header
|
2011-10-18 04:05:10 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
namespace std // purposefully not using versioning namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
class _LIBCPP_EXCEPTION_ABI bad_alloc
|
|
|
|
: public exception
|
|
|
|
{
|
|
|
|
public:
|
2011-05-27 02:23:59 +08:00
|
|
|
bad_alloc() _NOEXCEPT;
|
|
|
|
virtual ~bad_alloc() _NOEXCEPT;
|
|
|
|
virtual const char* what() const _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class _LIBCPP_EXCEPTION_ABI bad_array_new_length
|
|
|
|
: public bad_alloc
|
|
|
|
{
|
|
|
|
public:
|
2011-05-27 02:23:59 +08:00
|
|
|
bad_array_new_length() _NOEXCEPT;
|
|
|
|
virtual ~bad_array_new_length() _NOEXCEPT;
|
|
|
|
virtual const char* what() const _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2013-09-11 09:38:42 +08:00
|
|
|
#if defined(_LIBCPP_BUILDING_NEW) || (_LIBCPP_STD_VER > 11)
|
2013-11-08 01:15:51 +08:00
|
|
|
|
2013-09-11 09:38:42 +08:00
|
|
|
class _LIBCPP_EXCEPTION_ABI bad_array_length
|
|
|
|
: public bad_alloc
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bad_array_length() _NOEXCEPT;
|
|
|
|
virtual ~bad_array_length() _NOEXCEPT;
|
|
|
|
virtual const char* what() const _NOEXCEPT;
|
|
|
|
};
|
2013-11-08 01:15:51 +08:00
|
|
|
|
|
|
|
#define _LIBCPP_BAD_ARRAY_LENGTH_DEFINED
|
|
|
|
|
|
|
|
#endif // defined(_LIBCPP_BUILDING_NEW) || (_LIBCPP_STD_VER > 11)
|
2013-09-11 09:38:42 +08:00
|
|
|
|
2013-08-13 02:38:34 +08:00
|
|
|
_LIBCPP_FUNC_VIS void __throw_bad_alloc(); // not in C++ spec
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2013-03-07 07:30:19 +08:00
|
|
|
struct _LIBCPP_TYPE_VIS nothrow_t {};
|
|
|
|
extern _LIBCPP_FUNC_VIS const nothrow_t nothrow;
|
2010-05-12 03:42:16 +08:00
|
|
|
typedef void (*new_handler)();
|
2013-03-07 07:30:19 +08:00
|
|
|
_LIBCPP_FUNC_VIS new_handler set_new_handler(new_handler) _NOEXCEPT;
|
|
|
|
_LIBCPP_FUNC_VIS new_handler get_new_handler() _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
} // std
|
|
|
|
|
2013-08-13 02:38:34 +08:00
|
|
|
#if defined(_WIN32) && !defined(cxx_EXPORTS)
|
|
|
|
# define _LIBCPP_NEW_DELETE_VIS _LIBCPP_FUNC_VIS_ONLY
|
|
|
|
#else
|
|
|
|
# define _LIBCPP_NEW_DELETE_VIS _LIBCPP_FUNC_VIS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
_LIBCPP_NEW_DELETE_VIS void* operator new(std::size_t __sz)
|
2011-05-27 02:23:59 +08:00
|
|
|
#if !__has_feature(cxx_noexcept)
|
|
|
|
throw(std::bad_alloc)
|
|
|
|
#endif
|
|
|
|
;
|
2013-08-13 02:38:34 +08:00
|
|
|
_LIBCPP_NEW_DELETE_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
|
|
|
|
_LIBCPP_NEW_DELETE_VIS void operator delete(void* __p) _NOEXCEPT;
|
|
|
|
_LIBCPP_NEW_DELETE_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT;
|
2015-05-19 10:03:22 +08:00
|
|
|
#if defined(_LIBCPP_BUILDING_NEW) || _LIBCPP_STD_VER >= 14 || \
|
|
|
|
(defined(__cpp_sized_deallocation) && __cpp_sized_deallocation >= 201309)
|
2015-02-20 14:13:05 +08:00
|
|
|
_LIBCPP_NEW_DELETE_VIS void operator delete(void* __p, std::size_t __sz) _NOEXCEPT;
|
|
|
|
#endif
|
2011-05-27 02:23:59 +08:00
|
|
|
|
2013-08-13 02:38:34 +08:00
|
|
|
_LIBCPP_NEW_DELETE_VIS void* operator new[](std::size_t __sz)
|
2011-05-27 02:23:59 +08:00
|
|
|
#if !__has_feature(cxx_noexcept)
|
|
|
|
throw(std::bad_alloc)
|
|
|
|
#endif
|
|
|
|
;
|
2013-08-13 02:38:34 +08:00
|
|
|
_LIBCPP_NEW_DELETE_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
|
|
|
|
_LIBCPP_NEW_DELETE_VIS void operator delete[](void* __p) _NOEXCEPT;
|
|
|
|
_LIBCPP_NEW_DELETE_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT;
|
2015-05-19 10:03:22 +08:00
|
|
|
#if defined(_LIBCPP_BUILDING_NEW) || _LIBCPP_STD_VER >= 14 || \
|
|
|
|
(defined(__cpp_sized_deallocation) && __cpp_sized_deallocation >= 201309)
|
2015-02-20 14:13:05 +08:00
|
|
|
_LIBCPP_NEW_DELETE_VIS void operator delete[](void* __p, std::size_t __sz) _NOEXCEPT;
|
|
|
|
#endif
|
2013-08-13 02:38:34 +08:00
|
|
|
|
2013-10-05 06:09:00 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY void* operator new (std::size_t, void* __p) _NOEXCEPT {return __p;}
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY void* operator new[](std::size_t, void* __p) _NOEXCEPT {return __p;}
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY void operator delete (void*, void*) _NOEXCEPT {}
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY void operator delete[](void*, void*) _NOEXCEPT {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2014-06-05 03:54:15 +08:00
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY void *__allocate(size_t __size) {
|
|
|
|
#ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE
|
|
|
|
return ::operator new(__size);
|
|
|
|
#else
|
|
|
|
return __builtin_operator_new(__size);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY void __deallocate(void *__ptr) {
|
|
|
|
#ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE
|
|
|
|
::operator delete(__ptr);
|
|
|
|
#else
|
|
|
|
__builtin_operator_delete(__ptr);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
#endif // _LIBCPP_NEW
|