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

Side by Side Diff: src/core/SkVarAlloc.cpp

Issue 1551673002: remove use of malloc.h (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkVarAlloc.h" 8 #include "SkVarAlloc.h"
9 9
10 // We use non-standard malloc diagnostic methods to make sure our allocations ar e sized well.
11 #if defined(SK_BUILD_FOR_MAC)
12 #include <malloc/malloc.h>
13 #elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN32)
14 #include <malloc.h>
15 #endif
16
17 struct SkVarAlloc::Block { 10 struct SkVarAlloc::Block {
18 Block* prev; 11 Block* prev;
19 char* data() { return (char*)(this + 1); } 12 char* data() { return (char*)(this + 1); }
20 13
21 static Block* Alloc(Block* prev, size_t size) { 14 static Block* Alloc(Block* prev, size_t size) {
22 SkASSERT(size >= sizeof(Block)); 15 SkASSERT(size >= sizeof(Block));
23 Block* b = (Block*)sk_malloc_throw(size); 16 Block* b = (Block*)sk_malloc_throw(size);
24 b->prev = prev; 17 b->prev = prev;
25 return b; 18 return b;
26 } 19 }
(...skipping 26 matching lines...) Expand all
53 SkASSERT(SkIsAlignPtr(bytes)); 46 SkASSERT(SkIsAlignPtr(bytes));
54 47
55 size_t alloc = 1<<fLgSize++; 48 size_t alloc = 1<<fLgSize++;
56 while (alloc < bytes + sizeof(Block)) { 49 while (alloc < bytes + sizeof(Block)) {
57 alloc *= 2; 50 alloc *= 2;
58 } 51 }
59 fBytesAllocated += alloc; 52 fBytesAllocated += alloc;
60 fBlock = Block::Alloc(fBlock, alloc); 53 fBlock = Block::Alloc(fBlock, alloc);
61 fByte = fBlock->data(); 54 fByte = fBlock->data();
62 fRemaining = alloc - sizeof(Block); 55 fRemaining = alloc - sizeof(Block);
63
64 #if defined(SK_BUILD_FOR_MAC)
65 SkASSERT(alloc == malloc_good_size(alloc));
66 #elif defined(SK_BUILD_FOR_UNIX) && !defined(__UCLIBC__)
67 // TODO(mtklein): tune so we can assert something like this
68 //SkASSERT(alloc == malloc_usable_size(fBlock));
69 #endif
70 } 56 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698