1 2 /* 3 * Copyright 2011 Google Inc. 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 #include "SkTypes.h" 9 #include <stdio.h> 10 #include <stdlib.h> 11 sk_throw()12void sk_throw() { 13 SkDEBUGFAIL("sk_throw"); 14 abort(); 15 } 16 sk_out_of_memory(void)17void sk_out_of_memory(void) { 18 SkDEBUGFAIL("sk_out_of_memory"); 19 abort(); 20 } 21 sk_malloc_throw(size_t size)22void* sk_malloc_throw(size_t size) { 23 return sk_malloc_flags(size, SK_MALLOC_THROW); 24 } 25 sk_realloc_throw(void * addr,size_t size)26void* sk_realloc_throw(void* addr, size_t size) { 27 void* p = realloc(addr, size); 28 if (size == 0) { 29 return p; 30 } 31 if (p == NULL) { 32 sk_throw(); 33 } 34 return p; 35 } 36 sk_free(void * p)37void sk_free(void* p) { 38 if (p) { 39 free(p); 40 } 41 } 42 sk_malloc_flags(size_t size,unsigned flags)43void* sk_malloc_flags(size_t size, unsigned flags) { 44 void* p = malloc(size); 45 if (p == NULL) { 46 if (flags & SK_MALLOC_THROW) { 47 sk_throw(); 48 } 49 } 50 return p; 51 } 52 53