OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stdio.h> | 5 #include <stdio.h> |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 #include <new> | 7 #include <new> |
8 | 8 |
| 9 #include "base/process_util.h" |
| 10 |
9 #include "third_party/skia/include/core/SkTypes.h" | 11 #include "third_party/skia/include/core/SkTypes.h" |
10 #include "third_party/skia/include/core/SkThread.h" | 12 #include "third_party/skia/include/core/SkThread.h" |
11 | 13 |
12 // This implementation of sk_malloc_flags() and friends is identical | 14 // This implementation of sk_malloc_flags() and friends is identical |
13 // to SkMemory_malloc.c, except that it disables the CRT's new_handler | 15 // to SkMemory_malloc.c, except that it disables the CRT's new_handler |
14 // during malloc(), when SK_MALLOC_THROW is not set (ie., when | 16 // during malloc(), when SK_MALLOC_THROW is not set (ie., when |
15 // sk_malloc_flags() would not abort on NULL). | 17 // sk_malloc_flags() would not abort on NULL). |
16 | 18 |
17 SK_DECLARE_STATIC_MUTEX(gSkNewHandlerMutex); | 19 SK_DECLARE_STATIC_MUTEX(gSkNewHandlerMutex); |
18 | 20 |
(...skipping 28 matching lines...) Expand all Loading... |
47 } | 49 } |
48 } | 50 } |
49 | 51 |
50 void* sk_malloc_flags(size_t size, unsigned flags) { | 52 void* sk_malloc_flags(size_t size, unsigned flags) { |
51 void* p; | 53 void* p; |
52 #if defined(ANDROID) | 54 #if defined(ANDROID) |
53 // Android doesn't have std::set_new_handler. | 55 // Android doesn't have std::set_new_handler. |
54 p = malloc(size); | 56 p = malloc(size); |
55 #else | 57 #else |
56 if (!(flags & SK_MALLOC_THROW)) { | 58 if (!(flags & SK_MALLOC_THROW)) { |
| 59 #if defined(OS_MACOSX) |
| 60 p = base::UncheckedMalloc(size); |
| 61 #else |
57 SkAutoMutexAcquire lock(gSkNewHandlerMutex); | 62 SkAutoMutexAcquire lock(gSkNewHandlerMutex); |
58 std::new_handler old_handler = std::set_new_handler(NULL); | 63 std::new_handler old_handler = std::set_new_handler(NULL); |
59 p = malloc(size); | 64 p = malloc(size); |
60 std::set_new_handler(old_handler); | 65 std::set_new_handler(old_handler); |
| 66 #endif |
61 } else { | 67 } else { |
62 p = malloc(size); | 68 p = malloc(size); |
63 } | 69 } |
64 #endif | 70 #endif |
65 if (p == NULL) { | 71 if (p == NULL) { |
66 if (flags & SK_MALLOC_THROW) { | 72 if (flags & SK_MALLOC_THROW) { |
67 sk_throw(); | 73 sk_throw(); |
68 } | 74 } |
69 } | 75 } |
70 return p; | 76 return p; |
71 } | 77 } |
OLD | NEW |