Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(445)

Unified Diff: skia/ext/SkMemory_new_handler.cpp

Issue 220273002: Use cross-platform base::UncheckedMalloc for skia (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typos Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/process/memory.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: skia/ext/SkMemory_new_handler.cpp
diff --git a/skia/ext/SkMemory_new_handler.cpp b/skia/ext/SkMemory_new_handler.cpp
index a142f2994e2fac6bb4ab1d43736a52ab867f4b35..0b0c4d8dd354f2c7d8134ca4879bffb782f09e88 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_ANDROID)
+ void* result;
+ // It's the responsibility of the caller to check the return value.
+ bool success ALLOW_UNUSED = base::UncheckedMalloc(size, &result);
Nico 2014/04/01 21:05:02 Why ALLOW_UNUSED?
Nico 2014/04/01 21:06:19 (i.e. I think you want ignore_result() here. also
+ 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_ANDROID)
+ void* result;
+ // It's the responsibility of the caller to check the return value.
+ bool success ALLOW_UNUSED = base::UncheckedCalloc(size, 1, &result);
+ return result;
#else
SkAutoMutexAcquire lock(gSkNewHandlerMutex);
std::new_handler old_handler = std::set_new_handler(NULL);
« no previous file with comments | « base/process/memory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698