14684ddb6SLionel Sambuc// -*- C++ -*- 24684ddb6SLionel Sambuc//===----------------------------- new ------------------------------------===// 34684ddb6SLionel Sambuc// 44684ddb6SLionel Sambuc// The LLVM Compiler Infrastructure 54684ddb6SLionel Sambuc// 64684ddb6SLionel Sambuc// This file is dual licensed under the MIT and the University of Illinois Open 74684ddb6SLionel Sambuc// Source Licenses. See LICENSE.TXT for details. 84684ddb6SLionel Sambuc// 94684ddb6SLionel Sambuc//===----------------------------------------------------------------------===// 104684ddb6SLionel Sambuc 114684ddb6SLionel Sambuc#ifndef _LIBCPP_NEW 124684ddb6SLionel Sambuc#define _LIBCPP_NEW 134684ddb6SLionel Sambuc 144684ddb6SLionel Sambuc/* 154684ddb6SLionel Sambuc new synopsis 164684ddb6SLionel Sambuc 174684ddb6SLionel Sambucnamespace std 184684ddb6SLionel Sambuc{ 194684ddb6SLionel Sambuc 204684ddb6SLionel Sambucclass bad_alloc 214684ddb6SLionel Sambuc : public exception 224684ddb6SLionel Sambuc{ 234684ddb6SLionel Sambucpublic: 244684ddb6SLionel Sambuc bad_alloc() noexcept; 254684ddb6SLionel Sambuc bad_alloc(const bad_alloc&) noexcept; 264684ddb6SLionel Sambuc bad_alloc& operator=(const bad_alloc&) noexcept; 274684ddb6SLionel Sambuc virtual const char* what() const noexcept; 284684ddb6SLionel Sambuc}; 294684ddb6SLionel Sambuc 304684ddb6SLionel Sambucclass bad_array_length : public bad_alloc // C++14 314684ddb6SLionel Sambuc{ 324684ddb6SLionel Sambucpublic: 334684ddb6SLionel Sambuc bad_array_length() noexcept; 344684ddb6SLionel Sambuc}; 354684ddb6SLionel Sambuc 364684ddb6SLionel Sambucclass bad_array_new_length : public bad_alloc 374684ddb6SLionel Sambuc{ 384684ddb6SLionel Sambucpublic: 394684ddb6SLionel Sambuc bad_array_new_length() noexcept; 404684ddb6SLionel Sambuc}; 414684ddb6SLionel Sambuc 424684ddb6SLionel Sambucstruct nothrow_t {}; 434684ddb6SLionel Sambucextern const nothrow_t nothrow; 444684ddb6SLionel Sambuctypedef void (*new_handler)(); 454684ddb6SLionel Sambucnew_handler set_new_handler(new_handler new_p) noexcept; 464684ddb6SLionel Sambucnew_handler get_new_handler() noexcept; 474684ddb6SLionel Sambuc 484684ddb6SLionel Sambuc} // std 494684ddb6SLionel Sambuc 504684ddb6SLionel Sambucvoid* operator new(std::size_t size); // replaceable 514684ddb6SLionel Sambucvoid* operator new(std::size_t size, const std::nothrow_t&) noexcept; // replaceable 524684ddb6SLionel Sambucvoid operator delete(void* ptr) noexcept; // replaceable 53*0a6a1f1dSLionel Sambucvoid operator delete(void* ptr, std::size_t size) noexcept; // replaceable, C++14 544684ddb6SLionel Sambucvoid operator delete(void* ptr, const std::nothrow_t&) noexcept; // replaceable 554684ddb6SLionel Sambuc 564684ddb6SLionel Sambucvoid* operator new[](std::size_t size); // replaceable 574684ddb6SLionel Sambucvoid* operator new[](std::size_t size, const std::nothrow_t&) noexcept; // replaceable 584684ddb6SLionel Sambucvoid operator delete[](void* ptr) noexcept; // replaceable 59*0a6a1f1dSLionel Sambucvoid operator delete[](void* ptr, std::size_t size) noexcept; // replaceable, C++14 604684ddb6SLionel Sambucvoid operator delete[](void* ptr, const std::nothrow_t&) noexcept; // replaceable 614684ddb6SLionel Sambuc 624684ddb6SLionel Sambucvoid* operator new (std::size_t size, void* ptr) noexcept; 634684ddb6SLionel Sambucvoid* operator new[](std::size_t size, void* ptr) noexcept; 644684ddb6SLionel Sambucvoid operator delete (void* ptr, void*) noexcept; 654684ddb6SLionel Sambucvoid operator delete[](void* ptr, void*) noexcept; 664684ddb6SLionel Sambuc 674684ddb6SLionel Sambuc*/ 684684ddb6SLionel Sambuc 694684ddb6SLionel Sambuc#include <__config> 704684ddb6SLionel Sambuc#include <exception> 714684ddb6SLionel Sambuc#include <cstddef> 724684ddb6SLionel Sambuc 73*0a6a1f1dSLionel Sambuc#include <__undef___deallocate> 74*0a6a1f1dSLionel Sambuc 754684ddb6SLionel Sambuc#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 764684ddb6SLionel Sambuc#pragma GCC system_header 774684ddb6SLionel Sambuc#endif 784684ddb6SLionel Sambuc 794684ddb6SLionel Sambucnamespace std // purposefully not using versioning namespace 804684ddb6SLionel Sambuc{ 814684ddb6SLionel Sambuc 824684ddb6SLionel Sambucclass _LIBCPP_EXCEPTION_ABI bad_alloc 834684ddb6SLionel Sambuc : public exception 844684ddb6SLionel Sambuc{ 854684ddb6SLionel Sambucpublic: 864684ddb6SLionel Sambuc bad_alloc() _NOEXCEPT; 874684ddb6SLionel Sambuc virtual ~bad_alloc() _NOEXCEPT; 884684ddb6SLionel Sambuc virtual const char* what() const _NOEXCEPT; 894684ddb6SLionel Sambuc}; 904684ddb6SLionel Sambuc 914684ddb6SLionel Sambucclass _LIBCPP_EXCEPTION_ABI bad_array_new_length 924684ddb6SLionel Sambuc : public bad_alloc 934684ddb6SLionel Sambuc{ 944684ddb6SLionel Sambucpublic: 954684ddb6SLionel Sambuc bad_array_new_length() _NOEXCEPT; 964684ddb6SLionel Sambuc virtual ~bad_array_new_length() _NOEXCEPT; 974684ddb6SLionel Sambuc virtual const char* what() const _NOEXCEPT; 984684ddb6SLionel Sambuc}; 994684ddb6SLionel Sambuc 1004684ddb6SLionel Sambuc#if defined(_LIBCPP_BUILDING_NEW) || (_LIBCPP_STD_VER > 11) 1014684ddb6SLionel Sambuc 1024684ddb6SLionel Sambucclass _LIBCPP_EXCEPTION_ABI bad_array_length 1034684ddb6SLionel Sambuc : public bad_alloc 1044684ddb6SLionel Sambuc{ 1054684ddb6SLionel Sambucpublic: 1064684ddb6SLionel Sambuc bad_array_length() _NOEXCEPT; 1074684ddb6SLionel Sambuc virtual ~bad_array_length() _NOEXCEPT; 1084684ddb6SLionel Sambuc virtual const char* what() const _NOEXCEPT; 1094684ddb6SLionel Sambuc}; 1104684ddb6SLionel Sambuc 1114684ddb6SLionel Sambuc#define _LIBCPP_BAD_ARRAY_LENGTH_DEFINED 1124684ddb6SLionel Sambuc 1134684ddb6SLionel Sambuc#endif // defined(_LIBCPP_BUILDING_NEW) || (_LIBCPP_STD_VER > 11) 1144684ddb6SLionel Sambuc 1154684ddb6SLionel Sambuc_LIBCPP_FUNC_VIS void __throw_bad_alloc(); // not in C++ spec 1164684ddb6SLionel Sambuc 1174684ddb6SLionel Sambucstruct _LIBCPP_TYPE_VIS nothrow_t {}; 1184684ddb6SLionel Sambucextern _LIBCPP_FUNC_VIS const nothrow_t nothrow; 1194684ddb6SLionel Sambuctypedef void (*new_handler)(); 1204684ddb6SLionel Sambuc_LIBCPP_FUNC_VIS new_handler set_new_handler(new_handler) _NOEXCEPT; 1214684ddb6SLionel Sambuc_LIBCPP_FUNC_VIS new_handler get_new_handler() _NOEXCEPT; 1224684ddb6SLionel Sambuc 1234684ddb6SLionel Sambuc} // std 1244684ddb6SLionel Sambuc 1254684ddb6SLionel Sambuc#if defined(_WIN32) && !defined(cxx_EXPORTS) 1264684ddb6SLionel Sambuc# define _LIBCPP_NEW_DELETE_VIS _LIBCPP_FUNC_VIS_ONLY 1274684ddb6SLionel Sambuc#else 1284684ddb6SLionel Sambuc# define _LIBCPP_NEW_DELETE_VIS _LIBCPP_FUNC_VIS 1294684ddb6SLionel Sambuc#endif 1304684ddb6SLionel Sambuc 1314684ddb6SLionel Sambuc_LIBCPP_NEW_DELETE_VIS void* operator new(std::size_t __sz) 1324684ddb6SLionel Sambuc#if !__has_feature(cxx_noexcept) 1334684ddb6SLionel Sambuc throw(std::bad_alloc) 1344684ddb6SLionel Sambuc#endif 1354684ddb6SLionel Sambuc; 1364684ddb6SLionel Sambuc_LIBCPP_NEW_DELETE_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS; 1374684ddb6SLionel Sambuc_LIBCPP_NEW_DELETE_VIS void operator delete(void* __p) _NOEXCEPT; 1384684ddb6SLionel Sambuc_LIBCPP_NEW_DELETE_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT; 139*0a6a1f1dSLionel Sambuc#if defined(_LIBCPP_BUILDING_NEW) || _LIBCPP_STD_VER >= 14 || \ 140*0a6a1f1dSLionel Sambuc (defined(__cpp_sized_deallocation) && __cpp_sized_deallocation >= 201309) 141*0a6a1f1dSLionel Sambuc_LIBCPP_NEW_DELETE_VIS void operator delete(void* __p, std::size_t __sz) _NOEXCEPT; 142*0a6a1f1dSLionel Sambuc#endif 1434684ddb6SLionel Sambuc 1444684ddb6SLionel Sambuc_LIBCPP_NEW_DELETE_VIS void* operator new[](std::size_t __sz) 1454684ddb6SLionel Sambuc#if !__has_feature(cxx_noexcept) 1464684ddb6SLionel Sambuc throw(std::bad_alloc) 1474684ddb6SLionel Sambuc#endif 1484684ddb6SLionel Sambuc; 1494684ddb6SLionel Sambuc_LIBCPP_NEW_DELETE_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS; 1504684ddb6SLionel Sambuc_LIBCPP_NEW_DELETE_VIS void operator delete[](void* __p) _NOEXCEPT; 1514684ddb6SLionel Sambuc_LIBCPP_NEW_DELETE_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT; 152*0a6a1f1dSLionel Sambuc#if defined(_LIBCPP_BUILDING_NEW) || _LIBCPP_STD_VER >= 14 || \ 153*0a6a1f1dSLionel Sambuc (defined(__cpp_sized_deallocation) && __cpp_sized_deallocation >= 201309) 154*0a6a1f1dSLionel Sambuc_LIBCPP_NEW_DELETE_VIS void operator delete[](void* __p, std::size_t __sz) _NOEXCEPT; 155*0a6a1f1dSLionel Sambuc#endif 1564684ddb6SLionel Sambuc 1574684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY void* operator new (std::size_t, void* __p) _NOEXCEPT {return __p;} 1584684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY void* operator new[](std::size_t, void* __p) _NOEXCEPT {return __p;} 1594684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY void operator delete (void*, void*) _NOEXCEPT {} 1604684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY void operator delete[](void*, void*) _NOEXCEPT {} 1614684ddb6SLionel Sambuc 162*0a6a1f1dSLionel Sambuc_LIBCPP_BEGIN_NAMESPACE_STD 163*0a6a1f1dSLionel Sambuc 164*0a6a1f1dSLionel Sambucinline _LIBCPP_INLINE_VISIBILITY void *__allocate(size_t __size) { 165*0a6a1f1dSLionel Sambuc#ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE 166*0a6a1f1dSLionel Sambuc return ::operator new(__size); 167*0a6a1f1dSLionel Sambuc#else 168*0a6a1f1dSLionel Sambuc return __builtin_operator_new(__size); 169*0a6a1f1dSLionel Sambuc#endif 170*0a6a1f1dSLionel Sambuc} 171*0a6a1f1dSLionel Sambuc 172*0a6a1f1dSLionel Sambucinline _LIBCPP_INLINE_VISIBILITY void __deallocate(void *__ptr) { 173*0a6a1f1dSLionel Sambuc#ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE 174*0a6a1f1dSLionel Sambuc ::operator delete(__ptr); 175*0a6a1f1dSLionel Sambuc#else 176*0a6a1f1dSLionel Sambuc __builtin_operator_delete(__ptr); 177*0a6a1f1dSLionel Sambuc#endif 178*0a6a1f1dSLionel Sambuc} 179*0a6a1f1dSLionel Sambuc 180*0a6a1f1dSLionel Sambuc_LIBCPP_END_NAMESPACE_STD 181*0a6a1f1dSLionel Sambuc 1824684ddb6SLionel Sambuc#endif // _LIBCPP_NEW 183