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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « skia/config/win/stdint.h ('k') | skia/ext/SkTypeface_fake.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #include "SkTypes.h"
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <new>
5
6 // This implementation of sk_malloc_flags() and friends is identical
7 // to SkMemory_malloc.c, except that it disables the CRT's new_handler
8 // during malloc(), when SK_MALLOC_THROW is not set (ie., when
9 // sk_malloc_flags() would not abort on NULL).
10
11 void sk_throw() {
12 SkASSERT(!"sk_throw");
13 abort();
14 }
15
16 void sk_out_of_memory(void) {
17 SkASSERT(!"sk_out_of_memory");
18 abort();
19 }
20
21 void* sk_malloc_throw(size_t size) {
22 return sk_malloc_flags(size, SK_MALLOC_THROW);
23 }
24
25 void* sk_realloc_throw(void* addr, size_t size) {
26 void* p = realloc(addr, size);
27 if (size == 0) {
28 return p;
29 }
30 if (p == NULL) {
31 sk_throw();
32 }
33 return p;
34 }
35
36 void sk_free(void* p) {
37 if (p) {
38 free(p);
39 }
40 }
41
42 void* sk_malloc_flags(size_t size, unsigned flags) {
43 std::new_handler old_handler;
44 if (!(flags & SK_MALLOC_THROW)) {
45 old_handler = std::set_new_handler(NULL);
46 }
47 void* p = malloc(size);
48 if (!(flags & SK_MALLOC_THROW)) {
49 std::set_new_handler(old_handler);
50 }
51 if (p == NULL) {
52 if (flags & SK_MALLOC_THROW) {
53 sk_throw();
54 }
55 }
56 return p;
57 }
58
OLDNEW
« 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