george@mozilla.com | cb39ee6 | 2012-08-27 19:56:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * Copyright 2012 Mozilla Foundation |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | #include "SkTypes.h" |
| 10 | |
| 11 | #include "mozilla/mozalloc.h" |
| 12 | #include "mozilla/mozalloc_abort.h" |
| 13 | #include "mozilla/mozalloc_oom.h" |
| 14 | |
djsollen | f2b340f | 2016-01-29 08:51:04 -0800 | [diff] [blame^] | 15 | void sk_abort_no_print() { |
| 16 | mozalloc_abort("Abort from sk_abort"); |
george@mozilla.com | cb39ee6 | 2012-08-27 19:56:43 +0000 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | void sk_out_of_memory(void) { |
| 20 | SkDEBUGFAIL("sk_out_of_memory"); |
| 21 | mozalloc_handle_oom(0); |
| 22 | } |
| 23 | |
| 24 | void* sk_malloc_throw(size_t size) { |
| 25 | return sk_malloc_flags(size, SK_MALLOC_THROW); |
| 26 | } |
| 27 | |
| 28 | void* sk_realloc_throw(void* addr, size_t size) { |
| 29 | return moz_xrealloc(addr, size); |
| 30 | } |
| 31 | |
| 32 | void sk_free(void* p) { |
lsalzman | b8b479b | 2015-11-23 10:30:14 -0800 | [diff] [blame] | 33 | free(p); |
george@mozilla.com | cb39ee6 | 2012-08-27 19:56:43 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | void* sk_malloc_flags(size_t size, unsigned flags) { |
lsalzman | b8b479b | 2015-11-23 10:30:14 -0800 | [diff] [blame] | 37 | return (flags & SK_MALLOC_THROW) ? moz_xmalloc(size) : malloc(size); |
george@mozilla.com | cb39ee6 | 2012-08-27 19:56:43 +0000 | [diff] [blame] | 38 | } |
mtklein@google.com | 519f967 | 2013-09-20 14:31:45 +0000 | [diff] [blame] | 39 | |
| 40 | void* sk_calloc(size_t size) { |
lsalzman | b8b479b | 2015-11-23 10:30:14 -0800 | [diff] [blame] | 41 | return calloc(size, 1); |
mtklein@google.com | 519f967 | 2013-09-20 14:31:45 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | void* sk_calloc_throw(size_t size) { |
| 45 | return moz_xcalloc(size, 1); |
| 46 | } |