- Timestamp:
- 08/13/08 13:49:09 (5 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/BAL/OWBAL/Concretizations/Memory/WK/BCFastMallocWK.cpp
r427 r436 151 151 152 152 namespace WTF { 153 void *fastZeroedMalloc(size_t n) 153 154 void* fastZeroedMalloc(size_t n) 154 155 { 155 void *result = fastMalloc(n); 156 void* result = fastMalloc(n); 157 memset(result, 0, n); 158 return result; 159 } 160 161 void* tryFastZeroedMalloc(size_t n) 162 { 163 void* result = tryFastMalloc(n); 156 164 if (!result) 157 165 return 0; 158 166 memset(result, 0, n); 159 #ifndef WTF_CHANGES160 MallocHook::InvokeNewHook(result, n);161 #endif162 167 return result; 163 168 } 164 165 } 169 170 } // namespace WTF 166 171 167 172 #if FORCE_SYSTEM_MALLOC … … 174 179 namespace WTF { 175 180 176 void *fastMalloc(size_t n)181 void* tryFastMalloc(size_t n) 177 182 { 178 183 ASSERT(!isForbidden()); … … 180 185 } 181 186 182 void *fastCalloc(size_t n_elements, size_t element_size) 187 void* fastMalloc(size_t n) 188 { 189 ASSERT(!isForbidden()); 190 void* result = malloc(n); 191 if (!result) 192 abort(); 193 return result; 194 } 195 196 void* tryFastCalloc(size_t n_elements, size_t element_size) 183 197 { 184 198 ASSERT(!isForbidden()); 185 199 return calloc(n_elements, element_size); 200 } 201 202 void* fastCalloc(size_t n_elements, size_t element_size) 203 { 204 ASSERT(!isForbidden()); 205 void* result = calloc(n_elements, element_size); 206 if (!result) 207 abort(); 208 return result; 186 209 } 187 210 … … 192 215 } 193 216 194 void *fastRealloc(void* p, size_t n)217 void* tryFastRealloc(void* p, size_t n) 195 218 { 196 219 ASSERT(!isForbidden()); 197 220 return realloc(p, n); 221 } 222 223 void* fastRealloc(void* p, size_t n) 224 { 225 ASSERT(!isForbidden()); 226 void* result = realloc(p, n); 227 if (!result) 228 abort(); 229 return result; 198 230 } 199 231 … … 2962 2994 } 2963 2995 2996 #ifdef WTF_CHANGES 2997 template <bool abortOnFailure> 2998 #endif 2964 2999 static ALWAYS_INLINE void* do_malloc(size_t size) { 2965 3000 void* ret = NULL; … … 2991 3026 ret = CheckedMallocResult(heap->Allocate(size)); 2992 3027 } 2993 if (ret == NULL) errno = ENOMEM; 3028 if (!ret) { 3029 #ifdef WTF_CHANGES 3030 if (abortOnFailure) // This branch should be optimized out by the compiler. 3031 abort(); 3032 #else 3033 errno = ENOMEM; 3034 #endif 3035 } 2994 3036 return ret; 2995 3037 } … … 3155 3197 #ifndef WTF_CHANGES 3156 3198 extern "C" 3199 #else 3200 #define do_malloc do_malloc<abortOnFailure> 3201 3202 template <bool abortOnFailure> 3203 void* malloc(size_t); 3204 3205 void* fastMalloc(size_t size) 3206 { 3207 return malloc<true>(size); 3208 } 3209 3210 void* tryFastMalloc(size_t size) 3211 { 3212 return malloc<false>(size); 3213 } 3214 3215 template <bool abortOnFailure> 3216 ALWAYS_INLINE 3157 3217 #endif 3158 3218 void* malloc(size_t size) { … … 3176 3236 #ifndef WTF_CHANGES 3177 3237 extern "C" 3238 #else 3239 template <bool abortOnFailure> 3240 void* calloc(size_t, size_t); 3241 3242 void* fastCalloc(size_t n, size_t elem_size) 3243 { 3244 return calloc<true>(n, elem_size); 3245 } 3246 3247 void* tryFastCalloc(size_t n, size_t elem_size) 3248 { 3249 return calloc<false>(n, elem_size); 3250 } 3251 3252 template <bool abortOnFailure> 3253 ALWAYS_INLINE 3178 3254 #endif 3179 3255 void* calloc(size_t n, size_t elem_size) { … … 3206 3282 #ifndef WTF_CHANGES 3207 3283 extern "C" 3284 #else 3285 template <bool abortOnFailure> 3286 void* realloc(void*, size_t); 3287 3288 void* fastRealloc(void* old_ptr, size_t new_size) 3289 { 3290 return realloc<true>(old_ptr, new_size); 3291 } 3292 3293 void* tryFastRealloc(void* old_ptr, size_t new_size) 3294 { 3295 return realloc<false>(old_ptr, new_size); 3296 } 3297 3298 template <bool abortOnFailure> 3299 ALWAYS_INLINE 3208 3300 #endif 3209 3301 void* realloc(void* old_ptr, size_t new_size) { … … 3265 3357 } 3266 3358 3267 #ifndef WTF_CHANGES 3359 #ifdef WTF_CHANGES 3360 #undef do_malloc 3361 #else 3268 3362 3269 3363 static SpinLock set_new_handler_lock = SPINLOCK_INITIALIZER;
