diff options
author | b.kelemen@samsung.com <b.kelemen@samsung.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-04 03:27:03 +0000 |
---|---|---|
committer | b.kelemen@samsung.com <b.kelemen@samsung.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-04 03:27:03 +0000 |
commit | 150e913b6583a26c87d3fc9f992f4b4da95e8433 (patch) | |
tree | aefcc1d4edbba60e50eff122a1aafbd1b309fcb2 /skia | |
parent | 2fb91f200ea577377754f86859ddc96eb3471b86 (diff) | |
download | chromium_src-150e913b6583a26c87d3fc9f992f4b4da95e8433.zip chromium_src-150e913b6583a26c87d3fc9f992f4b4da95e8433.tar.gz chromium_src-150e913b6583a26c87d3fc9f992f4b4da95e8433.tar.bz2 |
Use cross-platform base::UncheckedMalloc for skia
UncheckedMalloc/UncheckedCalloc is now implemented for Linux as well so we can use it.
BUG=73751
Review URL: https://codereview.chromium.org/220273002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@261643 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r-- | skia/ext/SkMemory_new_handler.cpp | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/skia/ext/SkMemory_new_handler.cpp b/skia/ext/SkMemory_new_handler.cpp index a142f29..015521f 100644 --- a/skia/ext/SkMemory_new_handler.cpp +++ b/skia/ext/SkMemory_new_handler.cpp @@ -50,13 +50,15 @@ void* sk_malloc_throw(size_t size) { return throw_on_failure(size, malloc(size)); } -// Platform specific ways to try really hard to get a malloc that won't crash on failure. static void* sk_malloc_nothrow(size_t size) { -#if defined(ANDROID) - // Android doesn't have std::set_new_handler, so we just call malloc. - return malloc(size); -#elif defined(OS_MACOSX) && !defined(OS_IOS) - return base::UncheckedMalloc(size); + // TODO(b.kelemen): we should always use UncheckedMalloc but currently it + // doesn't work as intended everywhere. +#if defined(LIBC_GLIBC) || defined(USE_TCMALLOC) || \ + (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_ANDROID) + void* result; + // It's the responsibility of the caller to check the return value. + ignore_result(base::UncheckedMalloc(size, &result)); + return result; #else // This is not really thread safe. It only won't collide with itself, but we're totally // unprotected from races with other code that calls set_new_handler. @@ -79,12 +81,15 @@ void* sk_calloc_throw(size_t size) { return throw_on_failure(size, calloc(size, 1)); } -// Jump through the same hoops as sk_malloc_nothrow to avoid a crash, but for calloc. void* sk_calloc(size_t size) { -#if defined(ANDROID) - return calloc(size, 1); -#elif defined(OS_MACOSX) && !defined(OS_IOS) - return base::UncheckedCalloc(size, 1); + // TODO(b.kelemen): we should always use UncheckedCalloc but currently it + // doesn't work as intended everywhere. +#if defined(LIBC_GLIBC) || defined(USE_TCMALLOC) || \ + (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_ANDROID) + void* result; + // It's the responsibility of the caller to check the return value. + ignore_result(base::UncheckedCalloc(size, 1, &result)); + return result; #else SkAutoMutexAcquire lock(gSkNewHandlerMutex); std::new_handler old_handler = std::set_new_handler(NULL); |