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 sk_abort_no_print()16void sk_abort_no_print() { 17 mozalloc_abort("Abort from sk_abort"); 18 } 19 sk_out_of_memory(void)20void sk_out_of_memory(void) { 21 SkDEBUGFAIL("sk_out_of_memory"); 22 mozalloc_handle_oom(0); 23 } 24 sk_free(void * p)25void sk_free(void* p) { 26 free(p); 27 } 28 sk_realloc_throw(void * addr,size_t size)29void* sk_realloc_throw(void* addr, size_t size) { 30 return moz_xrealloc(addr, size); 31 } 32 sk_malloc_flags(size_t size,unsigned flags)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