Show
Ignore:
Timestamp:
08/13/08 13:49:09 (5 months ago)
Author:
odole
Message:

merge with webkit revision 35706

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/BAL/OWBAL/Concretizations/Memory/WK/BCFastMallocWK.cpp

    r427 r436  
    151151 
    152152namespace WTF { 
    153 void *fastZeroedMalloc(size_t n)  
     153 
     154void* fastZeroedMalloc(size_t n)  
    154155{ 
    155     void *result = fastMalloc(n); 
     156    void* result = fastMalloc(n); 
     157    memset(result, 0, n); 
     158    return result; 
     159
     160     
     161void* tryFastZeroedMalloc(size_t n)  
     162
     163    void* result = tryFastMalloc(n); 
    156164    if (!result) 
    157165        return 0; 
    158166    memset(result, 0, n); 
    159 #ifndef WTF_CHANGES 
    160     MallocHook::InvokeNewHook(result, n); 
    161 #endif 
    162167    return result; 
    163168} 
    164      
    165 } 
     169 
     170} // namespace WTF 
    166171 
    167172#if FORCE_SYSTEM_MALLOC 
     
    174179namespace WTF { 
    175180     
    176 void *fastMalloc(size_t n)  
     181void* tryFastMalloc(size_t n)  
    177182{ 
    178183    ASSERT(!isForbidden()); 
     
    180185} 
    181186 
    182 void *fastCalloc(size_t n_elements, size_t element_size) 
     187void* fastMalloc(size_t n)  
     188
     189    ASSERT(!isForbidden()); 
     190    void* result = malloc(n); 
     191    if (!result) 
     192        abort(); 
     193    return result; 
     194
     195 
     196void* tryFastCalloc(size_t n_elements, size_t element_size) 
    183197{ 
    184198    ASSERT(!isForbidden()); 
    185199    return calloc(n_elements, element_size); 
     200} 
     201 
     202void* 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; 
    186209} 
    187210 
     
    192215} 
    193216 
    194 void *fastRealloc(void* p, size_t n) 
     217void* tryFastRealloc(void* p, size_t n) 
    195218{ 
    196219    ASSERT(!isForbidden()); 
    197220    return realloc(p, n); 
     221} 
     222 
     223void* fastRealloc(void* p, size_t n) 
     224{ 
     225    ASSERT(!isForbidden()); 
     226    void* result = realloc(p, n); 
     227    if (!result) 
     228        abort(); 
     229    return result; 
    198230} 
    199231 
     
    29622994} 
    29632995 
     2996#ifdef WTF_CHANGES 
     2997template <bool abortOnFailure> 
     2998#endif 
    29642999static ALWAYS_INLINE void* do_malloc(size_t size) { 
    29653000  void* ret = NULL; 
     
    29913026    ret = CheckedMallocResult(heap->Allocate(size)); 
    29923027  } 
    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  } 
    29943036  return ret; 
    29953037} 
     
    31553197#ifndef WTF_CHANGES 
    31563198extern "C"  
     3199#else 
     3200#define do_malloc do_malloc<abortOnFailure> 
     3201 
     3202template <bool abortOnFailure> 
     3203void* malloc(size_t); 
     3204 
     3205void* fastMalloc(size_t size) 
     3206{ 
     3207    return malloc<true>(size); 
     3208} 
     3209 
     3210void* tryFastMalloc(size_t size) 
     3211{ 
     3212    return malloc<false>(size); 
     3213} 
     3214 
     3215template <bool abortOnFailure> 
     3216ALWAYS_INLINE 
    31573217#endif 
    31583218void* malloc(size_t size) { 
     
    31763236#ifndef WTF_CHANGES 
    31773237extern "C"  
     3238#else 
     3239template <bool abortOnFailure> 
     3240void* calloc(size_t, size_t); 
     3241 
     3242void* fastCalloc(size_t n, size_t elem_size) 
     3243{ 
     3244    return calloc<true>(n, elem_size); 
     3245} 
     3246 
     3247void* tryFastCalloc(size_t n, size_t elem_size) 
     3248{ 
     3249    return calloc<false>(n, elem_size); 
     3250} 
     3251 
     3252template <bool abortOnFailure> 
     3253ALWAYS_INLINE 
    31783254#endif 
    31793255void* calloc(size_t n, size_t elem_size) { 
     
    32063282#ifndef WTF_CHANGES 
    32073283extern "C"  
     3284#else 
     3285template <bool abortOnFailure> 
     3286void* realloc(void*, size_t); 
     3287 
     3288void* fastRealloc(void* old_ptr, size_t new_size) 
     3289{ 
     3290    return realloc<true>(old_ptr, new_size); 
     3291} 
     3292 
     3293void* tryFastRealloc(void* old_ptr, size_t new_size) 
     3294{ 
     3295    return realloc<false>(old_ptr, new_size); 
     3296} 
     3297 
     3298template <bool abortOnFailure> 
     3299ALWAYS_INLINE 
    32083300#endif 
    32093301void* realloc(void* old_ptr, size_t new_size) { 
     
    32653357} 
    32663358 
    3267 #ifndef WTF_CHANGES 
     3359#ifdef WTF_CHANGES 
     3360#undef do_malloc 
     3361#else 
    32683362 
    32693363static SpinLock set_new_handler_lock = SPINLOCK_INITIALIZER;