OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SkTypes.h" | 8 #include "SkTypes.h" |
9 #include <stdio.h> | 9 #include <stdio.h> |
10 #include <stdlib.h> | 10 #include <stdlib.h> |
11 | 11 |
12 #ifdef SK_DEBUG | |
13 #define SK_DEBUGFAILF(message, ...) \ | |
mtklein
2014/07/10 15:03:40
Can we put this in SkTypes as
#define SK_DEBUGFAI
hal.canary
2014/07/10 15:15:11
Done.
Mike Reed: please note that this touches i
| |
14 do { \ | |
15 SkNO_RETURN_HINT(); \ | |
16 SkDebugf("%s:%d: fail:" message "]\n", \ | |
17 __FILE__, __LINE__, __VA_ARGS__); \ | |
18 SK_CRASH(); \ | |
19 } while(0) | |
20 #else | |
21 #define SK_DEBUGFAILF(message, ...) | |
22 #endif | |
23 | |
24 static inline void sk_out_of_memory(size_t size) { | |
25 SK_DEBUGFAILF("sk_out_of_memory [0x%lx]", static_cast<unsigned long>(size)); | |
mtklein
2014/07/10 15:03:40
Let's be explicit this is a byte size, and perhaps
hal.canary
2014/07/10 15:15:11
Done.
| |
26 abort(); | |
27 } | |
28 | |
12 static inline void* throw_on_failure(size_t size, void* p) { | 29 static inline void* throw_on_failure(size_t size, void* p) { |
13 if (size > 0 && p == NULL) { | 30 if (size > 0 && p == NULL) { |
14 // If we've got a NULL here, the only reason we should have failed is ru nning out of RAM. | 31 // If we've got a NULL here, the only reason we should have failed is ru nning out of RAM. |
15 sk_out_of_memory(); | 32 sk_out_of_memory(size); |
16 } | 33 } |
17 return p; | 34 return p; |
18 } | 35 } |
19 | 36 |
20 void sk_throw() { | 37 void sk_throw() { |
21 SkDEBUGFAIL("sk_throw"); | 38 SkDEBUGFAIL("sk_throw"); |
22 abort(); | 39 abort(); |
23 } | 40 } |
24 | 41 |
25 void sk_out_of_memory(void) { | 42 void sk_out_of_memory(void) { |
(...skipping 24 matching lines...) Expand all Loading... | |
50 } | 67 } |
51 } | 68 } |
52 | 69 |
53 void* sk_calloc(size_t size) { | 70 void* sk_calloc(size_t size) { |
54 return calloc(size, 1); | 71 return calloc(size, 1); |
55 } | 72 } |
56 | 73 |
57 void* sk_calloc_throw(size_t size) { | 74 void* sk_calloc_throw(size_t size) { |
58 return throw_on_failure(size, sk_calloc(size)); | 75 return throw_on_failure(size, sk_calloc(size)); |
59 } | 76 } |
OLD | NEW |