| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <config.h> | 5 #include <config.h> |
| 6 | 6 |
| 7 // When defined, different heap allocators can be used via an environment | 7 // When defined, different heap allocators can be used via an environment |
| 8 // variable set before running the program. This may reduce the amount | 8 // variable set before running the program. This may reduce the amount |
| 9 // of inlining that we get with malloc/free/etc. Disabling makes it | 9 // of inlining that we get with malloc/free/etc. Disabling makes it |
| 10 // so that only tcmalloc can be used. | 10 // so that only tcmalloc can be used. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 throw std::bad_alloc(); | 81 throw std::bad_alloc(); |
| 82 } | 82 } |
| 83 // Otherwise, try the new_handler. If it returns, retry the | 83 // Otherwise, try the new_handler. If it returns, retry the |
| 84 // allocation. If it throws std::bad_alloc, fail the allocation. | 84 // allocation. If it throws std::bad_alloc, fail the allocation. |
| 85 // if it throws something else, don't interfere. | 85 // if it throws something else, don't interfere. |
| 86 try { | 86 try { |
| 87 (*nh)(); | 87 (*nh)(); |
| 88 } catch (const std::bad_alloc&) { | 88 } catch (const std::bad_alloc&) { |
| 89 if (!nothrow) | 89 if (!nothrow) |
| 90 throw; | 90 throw; |
| 91 return p; | 91 return true; |
| 92 } | 92 } |
| 93 #endif // (defined(__GNUC__) && !defined(__EXCEPTIONS)) || (defined(_HAS_EXCEPT
IONS) && !_HAS_EXCEPTIONS) | 93 #endif // (defined(__GNUC__) && !defined(__EXCEPTIONS)) || (defined(_HAS_EXCEPT
IONS) && !_HAS_EXCEPTIONS) |
| 94 } | 94 } |
| 95 | 95 |
| 96 void* malloc(size_t size) __THROW { | 96 void* malloc(size_t size) __THROW { |
| 97 void* ptr; | 97 void* ptr; |
| 98 for (;;) { | 98 for (;;) { |
| 99 #ifdef ENABLE_DYNAMIC_ALLOCATOR_SWITCHING | 99 #ifdef ENABLE_DYNAMIC_ALLOCATOR_SWITCHING |
| 100 switch (allocator) { | 100 switch (allocator) { |
| 101 case JEMALLOC: | 101 case JEMALLOC: |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 // to test whether the CRT has been initialized. Once we've ripped out | 257 // to test whether the CRT has been initialized. Once we've ripped out |
| 258 // the allocators from libcmt, we need to provide this definition so that | 258 // the allocators from libcmt, we need to provide this definition so that |
| 259 // the rest of the CRT is still usable. | 259 // the rest of the CRT is still usable. |
| 260 extern "C" void* _crtheap = reinterpret_cast<void*>(1); | 260 extern "C" void* _crtheap = reinterpret_cast<void*>(1); |
| 261 | 261 |
| 262 #endif // WIN32 | 262 #endif // WIN32 |
| 263 | 263 |
| 264 #include "generic_allocators.cc" | 264 #include "generic_allocators.cc" |
| 265 | 265 |
| 266 } // extern C | 266 } // extern C |
| OLD | NEW |