Changeset 3740656 in mainline
- Timestamp:
- 2018-07-05T21:41:17Z (6 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)
- Location:
- uspace/lib/cpp
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/include/exception
ra1aecb1 r3740656 39 39 exception(const exception&) = default; 40 40 exception& operator=(const exception&) noexcept; 41 virtual const char *what() const;41 virtual const char* what() const; 42 42 virtual ~exception() = default; 43 43 }; -
uspace/lib/cpp/include/new
ra1aecb1 r3740656 41 41 bad_alloc(const bad_alloc&); 42 42 bad_alloc& operator=(const bad_alloc&) = default; 43 virtual const char *what() const override;43 virtual const char* what() const override; 44 44 virtual ~bad_alloc() = default; 45 45 }; 46 47 using new_handler = void (*)();48 46 49 47 struct nothrow_t {}; 50 48 extern const nothrow_t nothrow; 51 49 50 using new_handler = void (*)(); 51 52 new_handler set_new_handler(new_handler); 53 new_handler get_new_handler() noexcept; 54 52 55 } 53 56 54 void *operator new(std::size_t); 57 void* operator new(std::size_t); 58 void* operator new(std::size_t, const std::nothrow_t&) noexcept; 59 void* operator new[](std::size_t); 60 void* operator new[](std::size_t, const std::nothrow_t&) noexcept; 55 61 56 void operator delete(void *); 62 void operator delete(void* ); 63 void operator delete[](void* ); 57 64 58 65 #endif -
uspace/lib/cpp/src/exception.cpp
ra1aecb1 r3740656 30 30 namespace std 31 31 { 32 const char *exception::what() const32 const char* exception::what() const 33 33 { 34 34 return "std::exception"; -
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.