Changeset c86f587


Ignore:
Timestamp:
Sep 2, 2020, 8:36:50 AM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
f67b983
Parents:
4557bcf7
Message:

fix bugs in resize and realloc with alignment

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/heap.cfa

    r4557bcf7 rc86f587  
    1010// Created On       : Tue Dec 19 21:58:35 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 24 20:29:24 2020
    13 // Update Count     : 926
     12// Last Modified On : Tue Sep  1 21:58:36 2020
     13// Update Count     : 927
    1414//
    1515
     
    12181218        #endif // __STATISTICS__
    12191219
    1220         // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
    1221   if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases
    1222   if ( unlikely( oaddr == 0p ) ) {
    1223                 #ifdef __STATISTICS__
    1224                 __atomic_add_fetch( &resize_storage, size, __ATOMIC_SEQ_CST );
    1225                 #endif // __STATISTICS__
    1226                 return memalignNoStats( nalign, size );
    1227         } // if
    1228 
    12291220        if ( unlikely( nalign < libAlign() ) ) nalign = libAlign(); // reset alignment to minimum
    12301221        #ifdef __CFA_DEBUG__
     
    12321223                checkAlign( nalign );                                                   // check alignment
    12331224        #endif // __CFA_DEBUG__
     1225
     1226        // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
     1227  if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases
     1228  if ( unlikely( oaddr == 0p ) ) {
     1229                #ifdef __STATISTICS__
     1230                __atomic_add_fetch( &resize_storage, size, __ATOMIC_SEQ_CST );
     1231                #endif // __STATISTICS__
     1232                return memalignNoStats( nalign, size );
     1233        } // if
    12341234
    12351235        HeapManager.Storage.Header * header;
     
    12671267        #endif // __CFA_DEBUG__
    12681268
     1269        // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
     1270  if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases
     1271  if ( unlikely( oaddr == 0p ) ) {
     1272                #ifdef __STATISTICS__
     1273                __atomic_add_fetch( &realloc_calls, 1, __ATOMIC_SEQ_CST );
     1274                __atomic_add_fetch( &realloc_storage, size, __ATOMIC_SEQ_CST );
     1275                #endif // __STATISTICS__
     1276                return memalignNoStats( nalign, size );
     1277        } // if
     1278
    12691279        HeapManager.Storage.Header * header;
    12701280        HeapManager.FreeHeader * freeElem;
     
    12861296        #endif // __STATISTICS__
    12871297
    1288         // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
    1289   if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases
    1290   if ( unlikely( oaddr == 0p ) ) return memalignNoStats( nalign, size );
    1291 
    12921298        size_t osize = header->kind.real.size;                          // old allocation size
    12931299        bool ozfill = (header->kind.real.blockSize & 2) != 0; // old allocation zero filled
Note: See TracChangeset for help on using the changeset viewer.