| OLD | NEW |
| 1 /* libs/corecg/SkMemory_stdlib.cpp | 1 /* libs/corecg/SkMemory_stdlib.cpp |
| 2 ** | 2 ** |
| 3 ** Copyright 2006, The Android Open Source Project | 3 ** Copyright 2006, The Android Open Source Project |
| 4 ** | 4 ** |
| 5 ** Licensed under the Apache License, Version 2.0 (the "License"); | 5 ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 ** you may not use this file except in compliance with the License. | 6 ** you may not use this file except in compliance with the License. |
| 7 ** You may obtain a copy of the License at | 7 ** You may obtain a copy of the License at |
| 8 ** | 8 ** |
| 9 ** http://www.apache.org/licenses/LICENSE-2.0 | 9 ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 ** | 10 ** |
| 11 ** Unless required by applicable law or agreed to in writing, software | 11 ** Unless required by applicable law or agreed to in writing, software |
| 12 ** distributed under the License is distributed on an "AS IS" BASIS, | 12 ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 ** See the License for the specific language governing permissions and | 14 ** See the License for the specific language governing permissions and |
| 15 ** limitations under the License. | 15 ** limitations under the License. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 #include "SkTypes.h" | 18 #include "SkTypes.h" |
| 19 #include <stdio.h> | 19 #include <stdio.h> |
| 20 #include <stdlib.h> | 20 #include <stdlib.h> |
| 21 | 21 |
| 22 #ifdef SK_DEBUG | 22 #ifdef SK_DEBUG |
| 23 #define SK_TAG_BLOCKS | 23 #define SK_TAG_BLOCKS |
| 24 // #define SK_TRACK_ALLOC // enable to see a printf for every alloc/free | 24 // #define SK_TRACK_ALLOC // enable to see a printf for every alloc/free |
| 25 // #define SK_CHECK_TAGS // enable to double-check debugging link list | 25 // #define SK_CHECK_TAGS // enable to double-check debugging link list |
| 26 #endif | 26 #endif |
| 27 | 27 |
| 28 static bool g_sk_malloc_will_throw = true; |
| 29 |
| 28 #ifdef SK_TAG_BLOCKS | 30 #ifdef SK_TAG_BLOCKS |
| 29 | 31 |
| 30 #include "SkThread.h" | 32 #include "SkThread.h" |
| 31 | 33 |
| 32 // size this (as a multiple of 4) so that the total offset to the internal data | 34 // size this (as a multiple of 4) so that the total offset to the internal data |
| 33 // is at least a multiple of 8 (since some clients of our malloc may require | 35 // is at least a multiple of 8 (since some clients of our malloc may require |
| 34 // that. | 36 // that. |
| 35 static const char kBlockHeaderTag[] = { 's', 'k', 'i', 'a', '1', '2', '3', '4' }
; | 37 static const char kBlockHeaderTag[] = { 's', 'k', 'i', 'a', '1', '2', '3', '4' }
; |
| 36 static const char kBlockTrailerTag[] = { 'a', 'i', 'k', 's' }; | 38 static const char kBlockTrailerTag[] = { 'a', 'i', 'k', 's' }; |
| 37 #define kByteFill 0xCD | 39 #define kByteFill 0xCD |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 } | 252 } |
| 251 | 253 |
| 252 void* sk_malloc_flags(size_t size, unsigned flags) | 254 void* sk_malloc_flags(size_t size, unsigned flags) |
| 253 { | 255 { |
| 254 ValidateHeap(); | 256 ValidateHeap(); |
| 255 #ifdef SK_TAG_BLOCKS | 257 #ifdef SK_TAG_BLOCKS |
| 256 size_t realSize = size; | 258 size_t realSize = size; |
| 257 size += sizeof(SkBlockHeader); | 259 size += sizeof(SkBlockHeader); |
| 258 #endif | 260 #endif |
| 259 | 261 |
| 262 if (!(flags & SK_MALLOC_THROW)) { |
| 263 g_sk_malloc_will_throw = false; |
| 264 } |
| 260 void* p = malloc(size); | 265 void* p = malloc(size); |
| 266 if (!(flags & SK_MALLOC_THROW)) { |
| 267 g_sk_malloc_will_throw = true; |
| 268 } |
| 261 if (p == NULL) | 269 if (p == NULL) |
| 262 { | 270 { |
| 263 if (flags & SK_MALLOC_THROW) | 271 if (flags & SK_MALLOC_THROW) |
| 264 sk_throw(); | 272 sk_throw(); |
| 265 } | 273 } |
| 266 #ifdef SK_TAG_BLOCKS | 274 #ifdef SK_TAG_BLOCKS |
| 267 else | 275 else |
| 268 { | 276 { |
| 269 SkBlockHeader* header = (SkBlockHeader*) p; | 277 SkBlockHeader* header = (SkBlockHeader*) p; |
| 270 p = header->add(realSize); | 278 p = header->add(realSize); |
| 271 memset(p, kByteFill, realSize); | 279 memset(p, kByteFill, realSize); |
| 272 #ifdef SK_TRACK_ALLOC | 280 #ifdef SK_TRACK_ALLOC |
| 273 printf("sk_malloc_flags %p size=%zd\n", p, realSize); | 281 printf("sk_malloc_flags %p size=%zd\n", p, realSize); |
| 274 #endif | 282 #endif |
| 275 } | 283 } |
| 276 #endif | 284 #endif |
| 277 ValidateHeap(); | 285 ValidateHeap(); |
| 278 return p; | 286 return p; |
| 279 } | 287 } |
| 280 | 288 |
| 289 bool sk_malloc_will_throw() |
| 290 { |
| 291 return g_sk_malloc_will_throw; |
| 292 } |
| OLD | NEW |