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 | |
Herb Derby | b549cc3 | 2017-03-27 13:35:15 -0400 | [diff] [blame] | 9 | #include "SkMalloc.h" |
george@mozilla.com | cb39ee6 | 2012-08-27 19:56:43 +0000 | [diff] [blame] | 10 | |
Herb Derby | d7b34a5 | 2017-03-20 11:19:23 -0400 | [diff] [blame] | 11 | #include "SkTypes.h" |
george@mozilla.com | cb39ee6 | 2012-08-27 19:56:43 +0000 | [diff] [blame] | 12 | #include "mozilla/mozalloc.h" |
| 13 | #include "mozilla/mozalloc_abort.h" |
| 14 | #include "mozilla/mozalloc_oom.h" |
| 15 | |
djsollen | f2b340f | 2016-01-29 08:51:04 -0800 | [diff] [blame] | 16 | void sk_abort_no_print() { |
| 17 | mozalloc_abort("Abort from sk_abort"); |
george@mozilla.com | cb39ee6 | 2012-08-27 19:56:43 +0000 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | void sk_out_of_memory(void) { |
| 21 | SkDEBUGFAIL("sk_out_of_memory"); |
| 22 | mozalloc_handle_oom(0); |
| 23 | } |
| 24 | |
Mike Reed | 8dc8dbc | 2018-01-05 11:20:10 -0500 | [diff] [blame] | 25 | void sk_free(void* p) { |
| 26 | free(p); |
george@mozilla.com | cb39ee6 | 2012-08-27 19:56:43 +0000 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | void* sk_realloc_throw(void* addr, size_t size) { |
| 30 | return moz_xrealloc(addr, size); |
| 31 | } |
| 32 | |
Mike Reed | 8dc8dbc | 2018-01-05 11:20:10 -0500 | [diff] [blame] | 33 | void* sk_malloc_flags(size_t size, unsigned flags) { |
Mike Reed | 8dc8dbc | 2018-01-05 11:20:10 -0500 | [diff] [blame] | 34 | if (flags & SK_MALLOC_ZERO_INITIALIZE) { |
| 35 | return (flags & SK_MALLOC_THROW) ? moz_xcalloc(size, 1) : calloc(size, 1); |
| 36 | } |
Mike Reed | 8dc8dbc | 2018-01-05 11:20:10 -0500 | [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 | } |