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 "SkMalloc.h"
10
11#include "SkTypes.h"
12#include "mozilla/mozalloc.h"
13#include "mozilla/mozalloc_abort.h"
14#include "mozilla/mozalloc_oom.h"
15
16void sk_abort_no_print() {
17    mozalloc_abort("Abort from sk_abort");
18}
19
20void sk_out_of_memory(void) {
21    SkDEBUGFAIL("sk_out_of_memory");
22    mozalloc_handle_oom(0);
23}
24
25void sk_free(void* p) {
26    free(p);
27}
28
29void* sk_realloc_throw(void* addr, size_t size) {
30    return moz_xrealloc(addr, size);
31}
32
33void* sk_malloc_flags(size_t size, unsigned flags) {
34    if (flags & SK_MALLOC_ZERO_INITIALIZE) {
35        return (flags & SK_MALLOC_THROW) ? moz_xcalloc(size, 1) : calloc(size, 1);
36    }
37    return (flags & SK_MALLOC_THROW) ? moz_xmalloc(size) : malloc(size);
38}
39