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

Unified Diff: skia/ext/SkMemory_new_handler.cpp

Issue 65012: Move skia to DEPS, and put it in third_party. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 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 | « skia/config/win/stdint.h ('k') | skia/ext/SkTypeface_fake.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: skia/ext/SkMemory_new_handler.cpp
===================================================================
--- skia/ext/SkMemory_new_handler.cpp (revision 0)
+++ skia/ext/SkMemory_new_handler.cpp (revision 0)
@@ -0,0 +1,58 @@
+#include "SkTypes.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <new>
+
+// This implementation of sk_malloc_flags() and friends is identical
+// to SkMemory_malloc.c, except that it disables the CRT's new_handler
+// during malloc(), when SK_MALLOC_THROW is not set (ie., when
+// sk_malloc_flags() would not abort on NULL).
+
+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) {
+ std::new_handler old_handler;
+ if (!(flags & SK_MALLOC_THROW)) {
+ old_handler = std::set_new_handler(NULL);
+ }
+ void* p = malloc(size);
+ if (!(flags & SK_MALLOC_THROW)) {
+ std::set_new_handler(old_handler);
+ }
+ if (p == NULL) {
+ if (flags & SK_MALLOC_THROW) {
+ sk_throw();
+ }
+ }
+ return p;
+}
+
« no previous file with comments | « skia/config/win/stdint.h ('k') | skia/ext/SkTypeface_fake.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698