Changeset 3740656 in mainline for uspace/lib/cpp/src/new.cpp
- Timestamp:
- 2018-07-05T21:41:17Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c2c1966
- Parents:
- a1aecb1
- git-author:
- Jaroslav Jindrak <dzejrou@…> (2017-10-09 16:33:43)
- git-committer:
- Dzejrou <dzejrou@…> (2018-07-05 21:41:17)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/src/new.cpp
ra1aecb1 r3740656 31 31 namespace std 32 32 { 33 const char *bad_alloc::what() const33 const char* bad_alloc::what() const 34 34 { 35 35 return "std::bad_alloc"; … … 37 37 38 38 const nothrow_t nothrow{}; 39 40 static new_handler handler = nullptr; 41 42 new_handler set_new_handler(new_handler h) 43 { 44 auto old = handler; 45 handler = h; 46 47 return old; 48 } 49 50 new_handler get_new_handler() noexcept 51 { 52 return handler; 53 } 39 54 } 40 55 41 void *operator new(std::size_t size)56 void* operator new(std::size_t size) 42 57 { 43 // TODO: Implement usage of std::new_handler.44 58 if (size == 0) 45 59 size = 1; 46 60 47 61 void *ptr = std::malloc(size); 48 // TODO: For this we need stack unwinding support. 49 /* if (!ptr) */ 50 /* throw std::bad_alloc{}; */ 62 63 while (!ptr) 64 { 65 auto h = std::get_new_handler(); 66 if (h) 67 h(); 68 else 69 { 70 // TODO: For this we need stack unwinding support. 71 /* throw std::bad_alloc{}; */ 72 } 73 } 51 74 52 75 return ptr; 53 76 } 54 77 55 void operator delete(void *ptr) 78 void* operator new(std::size_t size, const std::nothrow_t& nt) noexcept 79 { 80 void* ptr{nullptr}; 81 82 try 83 { 84 ptr = ::operator new(size); 85 } 86 catch(...) 87 { /* DUMMY BODY */ } 88 89 return ptr; 90 } 91 92 void* operator new[](std::size_t size) 93 { 94 return ::operator new(size); 95 } 96 97 void* operator new[](std::size_t size, const std::nothrow_t& nt) noexcept 98 { 99 return ::operator new(size, nt); 100 } 101 102 void operator delete(void* ptr) 56 103 { 57 104 if (ptr) 58 105 std::free(ptr); 59 106 } 107 108 void operator delete[](void* ptr) 109 { 110 ::operator delete(ptr); 111 }
Note:
See TracChangeset
for help on using the changeset viewer.