blob: 35b94de4ce47cd40b85125fda79b29937c8b2385 [file] [log] [blame]
george@mozilla.comcb39ee62012-08-27 19:56:43 +00001/*
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 Derbyb549cc32017-03-27 13:35:15 -04009#include "SkMalloc.h"
george@mozilla.comcb39ee62012-08-27 19:56:43 +000010
Herb Derbyd7b34a52017-03-20 11:19:23 -040011#include "SkTypes.h"
george@mozilla.comcb39ee62012-08-27 19:56:43 +000012#include "mozilla/mozalloc.h"
13#include "mozilla/mozalloc_abort.h"
14#include "mozilla/mozalloc_oom.h"
15
djsollenf2b340f2016-01-29 08:51:04 -080016void sk_abort_no_print() {
17 mozalloc_abort("Abort from sk_abort");
george@mozilla.comcb39ee62012-08-27 19:56:43 +000018}
19
20void sk_out_of_memory(void) {
21 SkDEBUGFAIL("sk_out_of_memory");
22 mozalloc_handle_oom(0);
23}
24
Mike Reed8dc8dbc2018-01-05 11:20:10 -050025void sk_free(void* p) {
26 free(p);
george@mozilla.comcb39ee62012-08-27 19:56:43 +000027}
28
29void* sk_realloc_throw(void* addr, size_t size) {
30 return moz_xrealloc(addr, size);
31}
32
Mike Reed8dc8dbc2018-01-05 11:20:10 -050033void* sk_malloc_flags(size_t size, unsigned flags) {
Mike Reed8dc8dbc2018-01-05 11:20:10 -050034 if (flags & SK_MALLOC_ZERO_INITIALIZE) {
35 return (flags & SK_MALLOC_THROW) ? moz_xcalloc(size, 1) : calloc(size, 1);
36 }
Mike Reed8dc8dbc2018-01-05 11:20:10 -050037 return (flags & SK_MALLOC_THROW) ? moz_xmalloc(size) : malloc(size);
george@mozilla.comcb39ee62012-08-27 19:56:43 +000038}