| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkTypes.h" | 8 #include "SkTypes.h" |
| 9 | 9 |
| 10 #include <stdlib.h> | 10 #include <stdlib.h> |
| 11 | 11 |
| 12 #define SK_DEBUGFAILF(fmt, ...) \ | 12 #define SK_DEBUGFAILF(fmt, ...) \ |
| 13 SkASSERT((SkDebugf(fmt"\n", __VA_ARGS__), false)) | 13 SkASSERT((SkDebugf(fmt"\n", __VA_ARGS__), false)) |
| 14 | 14 |
| 15 static inline void sk_out_of_memory(size_t size) { | 15 static inline void sk_out_of_memory(size_t size) { |
| 16 SK_DEBUGFAILF("sk_out_of_memory (asked for " SK_SIZE_T_SPECIFIER " bytes)", | 16 SK_DEBUGFAILF("sk_out_of_memory (asked for " SK_SIZE_T_SPECIFIER " bytes)", |
| 17 size); | 17 size); |
| 18 abort(); | 18 abort(); |
| 19 } | 19 } |
| 20 | 20 |
| 21 static inline void* throw_on_failure(size_t size, void* p) { | 21 static inline void* throw_on_failure(size_t size, void* p) { |
| 22 if (size > 0 && p == nullptr) { | 22 if (size > 0 && p == nullptr) { |
| 23 // If we've got a nullptr here, the only reason we should have failed is
running out of RAM. | 23 // If we've got a nullptr here, the only reason we should have failed is
running out of RAM. |
| 24 sk_out_of_memory(size); | 24 sk_out_of_memory(size); |
| 25 } | 25 } |
| 26 return p; | 26 return p; |
| 27 } | 27 } |
| 28 | 28 |
| 29 void sk_throw() { | 29 void sk_abort_no_print() { |
| 30 SkDEBUGFAIL("sk_throw"); | |
| 31 abort(); | 30 abort(); |
| 32 } | 31 } |
| 33 | 32 |
| 34 void sk_out_of_memory(void) { | 33 void sk_out_of_memory(void) { |
| 35 SkDEBUGFAIL("sk_out_of_memory"); | 34 SkDEBUGFAIL("sk_out_of_memory"); |
| 36 abort(); | 35 abort(); |
| 37 } | 36 } |
| 38 | 37 |
| 39 void* sk_malloc_throw(size_t size) { | 38 void* sk_malloc_throw(size_t size) { |
| 40 return sk_malloc_flags(size, SK_MALLOC_THROW); | 39 return sk_malloc_flags(size, SK_MALLOC_THROW); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 59 } | 58 } |
| 60 } | 59 } |
| 61 | 60 |
| 62 void* sk_calloc(size_t size) { | 61 void* sk_calloc(size_t size) { |
| 63 return calloc(size, 1); | 62 return calloc(size, 1); |
| 64 } | 63 } |
| 65 | 64 |
| 66 void* sk_calloc_throw(size_t size) { | 65 void* sk_calloc_throw(size_t size) { |
| 67 return throw_on_failure(size, sk_calloc(size)); | 66 return throw_on_failure(size, sk_calloc(size)); |
| 68 } | 67 } |
| OLD | NEW |