diff options
author | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2009-05-04 19:24:56 +0000 |
---|---|---|
committer | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2009-05-04 19:24:56 +0000 |
commit | 7a561082645315215949fb7ad9c80c883ffd89ad (patch) | |
tree | 689c8ada7754d1247a08b4f7a6d89926bf922410 /src | |
parent | a6260ff5696e3ae45f295463eaeada2cd75a8b85 (diff) |
add simple port of memory APIs, to be used as a template for other platforms
that may want to add new_handler logic or other hooks.
git-svn-id: http://skia.googlecode.com/svn/trunk@167 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r-- | src/ports/SkMemory_malloc.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/ports/SkMemory_malloc.cpp b/src/ports/SkMemory_malloc.cpp new file mode 100644 index 0000000000..b10ef7000b --- /dev/null +++ b/src/ports/SkMemory_malloc.cpp @@ -0,0 +1,45 @@ +#include "SkTypes.h" +#include <stdio.h> +#include <stdlib.h> + +void sk_throw() { + SkASSERT(!"sk_throw"); + abort(); +} + +void sk_out_of_memory(void) { + SkASSERT(!"sk_out_of_memory"); + abort(); +} + +void* sk_malloc_throw(size_t size) { + return sk_malloc_flags(size, SK_MALLOC_THROW); +} + +void* sk_realloc_throw(void* addr, size_t size) { + void* p = realloc(addr, size); + if (size == 0) { + return p; + } + if (p == NULL) { + sk_throw(); + } + return p; +} + +void sk_free(void* p) { + if (p) { + free(p); + } +} + +void* sk_malloc_flags(size_t size, unsigned flags) { + void* p = malloc(size); + if (p == NULL) { + if (flags & SK_MALLOC_THROW) { + sk_throw(); + } + } + return p; +} + |