memory.cc (299143) | memory.cc (299144) |
---|---|
1/* 2 * Copyright 2010-2011 PathScale, Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * 7 * 1. Redistributions of source code must retain the above copyright notice, 8 * this list of conditions and the following disclaimer. --- 57 unchanged lines hidden (view full) --- 66 __attribute__((weak)) 67 new_handler get_new_handler(void) 68 { 69 return ATOMIC_LOAD(&new_handl); 70 } 71} 72 73 | 1/* 2 * Copyright 2010-2011 PathScale, Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * 7 * 1. Redistributions of source code must retain the above copyright notice, 8 * this list of conditions and the following disclaimer. --- 57 unchanged lines hidden (view full) --- 66 __attribute__((weak)) 67 new_handler get_new_handler(void) 68 { 69 return ATOMIC_LOAD(&new_handl); 70 } 71} 72 73 |
74#if __cplusplus < 201103L 75#define NOEXCEPT throw() 76#define BADALLOC throw(std::bad_alloc) 77#else 78#define NOEXCEPT noexcept 79#define BADALLOC 80#endif 81 82 |
|
74__attribute__((weak)) | 83__attribute__((weak)) |
75void* operator new(size_t size) | 84void* operator new(size_t size) BADALLOC |
76{ 77 if (0 == size) 78 { 79 size = 1; 80 } 81 void * mem = malloc(size); 82 while (0 == mem) 83 { --- 8 unchanged lines hidden (view full) --- 92 } 93 mem = malloc(size); 94 } 95 96 return mem; 97} 98 99__attribute__((weak)) | 85{ 86 if (0 == size) 87 { 88 size = 1; 89 } 90 void * mem = malloc(size); 91 while (0 == mem) 92 { --- 8 unchanged lines hidden (view full) --- 101 } 102 mem = malloc(size); 103 } 104 105 return mem; 106} 107 108__attribute__((weak)) |
100void* operator new(size_t size, const std::nothrow_t &) throw() | 109void* operator new(size_t size, const std::nothrow_t &) NOEXCEPT |
101{ 102 try { 103 return :: operator new(size); 104 } catch (...) { 105 // nothrow operator new should return NULL in case of 106 // std::bad_alloc exception in new handler 107 return NULL; 108 } 109} 110 111 112__attribute__((weak)) | 110{ 111 try { 112 return :: operator new(size); 113 } catch (...) { 114 // nothrow operator new should return NULL in case of 115 // std::bad_alloc exception in new handler 116 return NULL; 117 } 118} 119 120 121__attribute__((weak)) |
113void operator delete(void * ptr) 114#if __cplusplus < 201000L 115throw() 116#endif | 122void operator delete(void * ptr) NOEXCEPT |
117{ 118 free(ptr); 119} 120 121 122__attribute__((weak)) | 123{ 124 free(ptr); 125} 126 127 128__attribute__((weak)) |
123void * operator new[](size_t size) 124#if __cplusplus < 201000L 125throw(std::bad_alloc) 126#endif | 129void * operator new[](size_t size) BADALLOC |
127{ 128 return ::operator new(size); 129} 130 131 132__attribute__((weak)) | 130{ 131 return ::operator new(size); 132} 133 134 135__attribute__((weak)) |
133void * operator new[](size_t size, const std::nothrow_t &) throw() | 136void * operator new[](size_t size, const std::nothrow_t &) NOEXCEPT |
134{ 135 try { 136 return ::operator new[](size); 137 } catch (...) { 138 // nothrow operator new should return NULL in case of 139 // std::bad_alloc exception in new handler 140 return NULL; 141 } 142} 143 144 145__attribute__((weak)) | 137{ 138 try { 139 return ::operator new[](size); 140 } catch (...) { 141 // nothrow operator new should return NULL in case of 142 // std::bad_alloc exception in new handler 143 return NULL; 144 } 145} 146 147 148__attribute__((weak)) |
146void operator delete[](void * ptr) 147#if __cplusplus < 201000L 148throw() 149#endif | 149void operator delete[](void * ptr) NOEXCEPT |
150{ 151 ::operator delete(ptr); 152} 153 154 | 150{ 151 ::operator delete(ptr); 152} 153 154 |