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
15cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.comvoid sk_throw() {
16cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com    SkDEBUGFAIL("sk_throw");
17cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com    mozalloc_abort("Abort from sk_throw");
18cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com}
19cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com
20cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.comvoid sk_out_of_memory(void) {
21cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com    SkDEBUGFAIL("sk_out_of_memory");
22cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com    mozalloc_handle_oom(0);
23cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com}
24cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com
25cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.comvoid* sk_malloc_throw(size_t size) {
26cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com    return sk_malloc_flags(size, SK_MALLOC_THROW);
27cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com}
28cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com
29cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.comvoid* sk_realloc_throw(void* addr, size_t size) {
30cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com    return moz_xrealloc(addr, size);
31cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com}
32cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com
33cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.comvoid sk_free(void* p) {
34cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com    moz_free(p);
35cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com}
36cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com
37cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.comvoid* sk_malloc_flags(size_t size, unsigned flags) {
38cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com    return (flags & SK_MALLOC_THROW) ? moz_xmalloc(size) : moz_malloc(size);
39cb39ee645a32b7e15a813672ac0acfd7e8dc114bgeorge@mozilla.com}
40519f9677a41239808f41a7c13ef1f6e05eb1ed50mtklein@google.com
41519f9677a41239808f41a7c13ef1f6e05eb1ed50mtklein@google.comvoid* sk_calloc(size_t size) {
42519f9677a41239808f41a7c13ef1f6e05eb1ed50mtklein@google.com    return moz_calloc(size, 1);
43519f9677a41239808f41a7c13ef1f6e05eb1ed50mtklein@google.com}
44519f9677a41239808f41a7c13ef1f6e05eb1ed50mtklein@google.com
45519f9677a41239808f41a7c13ef1f6e05eb1ed50mtklein@google.comvoid* sk_calloc_throw(size_t size) {
46519f9677a41239808f41a7c13ef1f6e05eb1ed50mtklein@google.com    return moz_xcalloc(size, 1);
47519f9677a41239808f41a7c13ef1f6e05eb1ed50mtklein@google.com}
48