1cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com/*
2cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com * Copyright 2011 Google Inc.
3cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com * Copyright 2012 Mozilla Foundation
4cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com *
5cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com * Use of this source code is governed by a BSD-style license that can be
6cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com * found in the LICENSE file.
7cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com */
8cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com
9cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com#include "SkTypes.h"
10cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com
11cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com#include "mozilla/mozalloc.h"
12cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com#include "mozilla/mozalloc_abort.h"
13cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com#include "mozilla/mozalloc_oom.h"
14cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com
15f2b340fc885ad2a12d2d73974eff9c8f4c94192cdjsollenvoid sk_abort_no_print() {
16f2b340fc885ad2a12d2d73974eff9c8f4c94192cdjsollen    mozalloc_abort("Abort from sk_abort");
17cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com}
18cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com
19cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.comvoid sk_out_of_memory(void) {
20cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com    SkDEBUGFAIL("sk_out_of_memory");
21cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com    mozalloc_handle_oom(0);
22cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com}
23cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com
24cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.comvoid* sk_malloc_throw(size_t size) {
25cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com    return sk_malloc_flags(size, SK_MALLOC_THROW);
26cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com}
27cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com
28cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.comvoid* sk_realloc_throw(void* addr, size_t size) {
29cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com    return moz_xrealloc(addr, size);
30cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com}
31cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com
32cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.comvoid sk_free(void* p) {
33b8b479b29d24f45a25dca74752ff6ed653e60ba9lsalzman    free(p);
34cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com}
35cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com
36cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.comvoid* sk_malloc_flags(size_t size, unsigned flags) {
37b8b479b29d24f45a25dca74752ff6ed653e60ba9lsalzman    return (flags & SK_MALLOC_THROW) ? moz_xmalloc(size) : malloc(size);
38cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com}
39519f9677a41239808f41a7c13ef1f6e05eb1ed50mtklein@google.com
40519f9677a41239808f41a7c13ef1f6e05eb1ed50mtklein@google.comvoid* sk_calloc(size_t size) {
41b8b479b29d24f45a25dca74752ff6ed653e60ba9lsalzman    return calloc(size, 1);
42519f9677a41239808f41a7c13ef1f6e05eb1ed50mtklein@google.com}
43519f9677a41239808f41a7c13ef1f6e05eb1ed50mtklein@google.com
44519f9677a41239808f41a7c13ef1f6e05eb1ed50mtklein@google.comvoid* sk_calloc_throw(size_t size) {
45519f9677a41239808f41a7c13ef1f6e05eb1ed50mtklein@google.com    return moz_xcalloc(size, 1);
46519f9677a41239808f41a7c13ef1f6e05eb1ed50mtklein@google.com}
47