Changeset 71dfe49


Ignore:
Timestamp:
Aug 4, 2020, 12:53:48 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
954821df
Parents:
8395152 (diff), 2ff42f4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/heap.cfa

    r8395152 r71dfe49  
    1010// Created On       : Tue Dec 19 21:58:35 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jul 27 23:16:18 2020
    13 // Update Count     : 815
     12// Last Modified On : Mon Aug  3 19:01:22 2020
     13// Update Count     : 828
    1414//
    1515
     
    222222
    223223// Bucket size must be multiple of 16.
    224 // Powers of 2 are common allocation sizes, so make powers of 2 generate the minimum required size.
     224// Smaller multiples of 16 and powers of 2 are common allocation sizes, so make them generate the minimum required bucket size.
     225// malloc(0) returns 0p, so no bucket is necessary for 0 bytes returning an address that can be freed.
    225226static const unsigned int bucketSizes[] @= {                    // different bucket sizes
    226         16, 32, 48, 64 + sizeof(HeapManager.Storage), // 4
    227         96, 112, 128 + sizeof(HeapManager.Storage), // 3
     227        16 + sizeof(HeapManager.Storage), 32 + sizeof(HeapManager.Storage), 48 + sizeof(HeapManager.Storage), 64 + sizeof(HeapManager.Storage), // 4
     228        96 + sizeof(HeapManager.Storage), 112 + sizeof(HeapManager.Storage), 128 + sizeof(HeapManager.Storage), // 3
    228229        160, 192, 224, 256 + sizeof(HeapManager.Storage), // 4
    229230        320, 384, 448, 512 + sizeof(HeapManager.Storage), // 4
     
    434435                #endif // __CFA_DEBUG__
    435436                header = realHeader( header );                                  // backup from fake to real header
     437        } else {
     438                alignment = 0;
    436439        } // if
    437440} // fakeHeader
     
    481484                        unlock( extlock );
    482485                        errno = ENOMEM;
    483                         return 0p;
     486//                      return 0p;
     487                        abort( "no memory" );
    484488                } // if
    485489                #ifdef __STATISTICS__
     
    550554
    551555                        block = (HeapManager.Storage *)extend( tsize ); // mutual exclusion on call
    552         if ( unlikely( block == 0p ) ) return 0p;
     556//      if ( unlikely( block == 0p ) ) return 0p;
    553557                #if BUCKETLOCK == SPINLOCK
    554558                } else {
     
    746750
    747751static inline void * mallocNoStats( size_t size ) {             // necessary for malloc statistics
    748         //assert( heapManager.heapBegin != 0 );
    749         if ( unlikely( heapManager.heapBegin == 0p ) ) heapManager{}; // called before memory_startup ?
     752        verify( heapManager.heapBegin != 0 );                           // called before memory_startup ?
     753  if ( size == 0 ) return 0p;                                                   // 0 BYTE ALLOCATION RETURNS NULL POINTER
     754
    750755#if __SIZEOF_POINTER__ == 8
    751756        verify( size < ((typeof(size_t))1 << 48) );
    752757#endif // __SIZEOF_POINTER__ == 8
    753         void * addr = doMalloc( size );
    754         if ( unlikely( addr == 0p ) ) errno = ENOMEM;           // POSIX
    755         return addr;
     758        return doMalloc( size );
    756759} // mallocNoStats
    757760
     
    759762static inline void * callocNoStats( size_t dim, size_t elemSize ) {
    760763        size_t size = dim * elemSize;
     764  if ( size == 0 ) return 0p;                                                   // 0 BYTE ALLOCATION RETURNS NULL POINTER
    761765        char * addr = (char *)mallocNoStats( size );
    762   if ( unlikely( addr == 0p ) ) return 0p;
    763766
    764767        HeapManager.Storage.Header * header;
    765768        HeapManager.FreeHeader * freeElem;
    766769        size_t bsize, alignment;
    767         bool mapped __attribute__(( unused )) = headers( "calloc", addr, header, freeElem, bsize, alignment );
     770        #ifndef __CFA_DEBUG__
     771        bool mapped =
     772        #endif // __CFA_DEBUG__
     773                headers( "calloc", addr, header, freeElem, bsize, alignment );
    768774        #ifndef __CFA_DEBUG__
    769775        // Mapped storage is zero filled, but in debug mode mapped memory is scrubbed in doMalloc, so it has to be reset to zero.
    770776        if ( ! mapped )
    771777        #endif // __CFA_DEBUG__
    772                 // Zero entire data space even when > than size => realloc without a new allocation and zero fill works.
    773                 // <-------00000000000000000000000000000000000000000000000000000> bsize (bucket size)
     778                // <-------0000000000000000000000000000UUUUUUUUUUUUUUUUUUUUUUUUU> bsize (bucket size) U => undefined
    774779                // `-header`-addr                      `-size
    775                 memset( addr, '\0', bsize - sizeof(HeapManager.Storage) ); // set to zeros
     780                memset( addr, '\0', size );                                             // set to zeros
    776781
    777782        header->kind.real.blockSize |= 2;                                       // mark as zero filled
     
    781786
    782787static inline void * memalignNoStats( size_t alignment, size_t size ) { // necessary for malloc statistics
     788  if ( size == 0 ) return 0p;                                                   // 0 BYTE ALLOCATION RETURNS NULL POINTER
     789
    783790        #ifdef __CFA_DEBUG__
    784791        checkAlign( alignment );                                                        // check alignment
     
    798805        // add sizeof(Storage) for fake header
    799806        char * addr = (char *)mallocNoStats( size + alignment - libAlign() + sizeof(HeapManager.Storage) );
    800   if ( unlikely( addr == 0p ) ) return addr;
    801807
    802808        // address in the block of the "next" alignment address
     
    819825static inline void * cmemalignNoStats( size_t alignment, size_t dim, size_t elemSize ) {
    820826        size_t size = dim * elemSize;
     827  if ( size == 0 ) return 0p;                                                   // 0 BYTE ALLOCATION RETURNS NULL POINTER
    821828        char * addr = (char *)memalignNoStats( alignment, size );
    822   if ( unlikely( addr == 0p ) ) return 0p;
     829
    823830        HeapManager.Storage.Header * header;
    824831        HeapManager.FreeHeader * freeElem;
     
    890897
    891898                // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
    892           if ( unlikely( size == 0 ) ) { free( oaddr ); return mallocNoStats( size ); } // special cases
     899          if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases
    893900          if ( unlikely( oaddr == 0p ) ) return mallocNoStats( size );
    894901
     
    902909          if ( oalign == 0 && size <= odsize && odsize <= size * 2 ) { // allow 50% wasted storage for smaller size
    903910                        header->kind.real.blockSize &= -2;                      // no alignment and turn off 0 fill
    904                         if ( size != odsize ) header->kind.real.size = size; // reset allocation size
     911                        header->kind.real.size = size;                          // reset allocation size
    905912                        return oaddr;
    906913                } // if
     
    908915                // change size, DO NOT preserve STICKY PROPERTIES.
    909916                free( oaddr );
    910                 void * naddr = mallocNoStats( size );                   // create new area
    911                 return naddr;
     917                return mallocNoStats( size );                                   // create new area
    912918        } // resize
    913919
     
    922928
    923929                // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
    924           if ( unlikely( size == 0 ) ) { free( oaddr ); return mallocNoStats( size ); } // special cases
     930          if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases
    925931          if ( unlikely( oaddr == 0p ) ) return mallocNoStats( size );
    926932
     
    931937
    932938                size_t odsize = dataStorage( bsize, oaddr, header ); // data storage available in bucket
    933           if ( size <= odsize && odsize <= size * 2 ) {         // allow up to 50% wasted storage in smaller size
    934                         if ( size != odsize ) header->kind.real.size = size; // reset allocation size
     939                size_t osize = header->kind.real.size;                  // old allocation size
     940                bool ozfill = (header->kind.real.blockSize & 2) != 0; // old allocation zero filled
     941          if ( unlikely( size <= odsize ) && size > odsize / 2 ) { // allow up to 50% wasted storage
     942                        header->kind.real.size = size;                          // reset allocation size
     943                        if ( unlikely( ozfill ) && size > osize ) {     // previous request zero fill and larger ?
     944                                memset( (char *)oaddr + osize, (int)'\0', size - osize ); // initialize added storage
     945                        } // if
    935946                        return oaddr;
    936947                } // if
     
    939950
    940951                void * naddr;
    941                 if ( unlikely( oalign != 0 ) ) {                                // previous request memalign?
    942                         if ( unlikely( header->kind.real.blockSize & 2 ) ) { // previous request zero fill
    943                                 naddr = cmemalignNoStats( oalign, 1, size ); // create new aligned area
    944                         } else {
    945                                 naddr = memalignNoStats( oalign, size ); // create new aligned area
     952                if ( likely( oalign == 0 ) ) {                                  // previous request memalign?
     953                        naddr = mallocNoStats( size );                          // create new area
     954                } else {
     955                        naddr = memalignNoStats( oalign, size );        // create new aligned area
     956                } // if
     957
     958                headers( "realloc", naddr, header, freeElem, bsize, oalign );
     959                memcpy( naddr, oaddr, MIN( osize, size ) );             // copy bytes
     960                free( oaddr );
     961
     962                if ( unlikely( ozfill ) ) {                                             // previous request zero fill ?
     963                        header->kind.real.blockSize |= 2;                       // mark new request as zero filled
     964                        if ( size > osize ) {                                           // previous request larger ?
     965                                memset( (char *)naddr + osize, (int)'\0', size - osize ); // initialize added storage
    946966                        } // if
    947                 } else {
    948                         if ( unlikely( header->kind.real.blockSize & 2 ) ) { // previous request zero fill
    949                                 naddr = callocNoStats( 1, size );               // create new area
    950                         } else {
    951                                 naddr = mallocNoStats( size );                  // create new area
    952                         } // if
    953                 } // if
    954           if ( unlikely( naddr == 0p ) ) return 0p;
    955 
    956                 headers( "realloc", naddr, header, freeElem, bsize, oalign );
    957                 size_t ndsize = dataStorage( bsize, naddr, header ); // data storage avilable in bucket
    958                 // To preserve prior fill, the entire bucket must be copied versus the size.
    959                 memcpy( naddr, oaddr, MIN( odsize, ndsize ) );  // copy bytes
    960                 free( oaddr );
     967                } // if
    961968                return naddr;
    962969        } // realloc
     
    10081015          if ( alignment < sizeof(void *) || ! libPow2( alignment ) ) return EINVAL; // check alignment
    10091016                * memptr = memalign( alignment, size );
    1010           if ( unlikely( * memptr == 0p ) ) return ENOMEM;
    10111017                return 0;
    10121018        } // posix_memalign
     
    12061212
    12071213        // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
    1208   if ( unlikely( size == 0 ) ) { free( oaddr ); return memalignNoStats( nalign, size ); } // special cases
     1214  if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases
    12091215  if ( unlikely( oaddr == 0p ) ) return memalignNoStats( nalign, size );
    1210 
    12111216
    12121217        if ( unlikely( nalign == 0 ) ) nalign = libAlign();     // reset alignment to minimum
     
    12351240        // change size
    12361241
    1237         void * naddr;
    1238         if ( unlikely( header->kind.real.blockSize & 2 ) ) { // previous request zero fill
    1239                 naddr = cmemalignNoStats( nalign, 1, size );    // create new aligned area
    1240         } else {
    1241                 naddr = memalignNoStats( nalign, size );                // create new aligned area
    1242         } // if
    1243 
     1242        void * naddr = memalignNoStats( nalign, size );         // create new aligned area
    12441243        free( oaddr );
    12451244        return naddr;
     
    12581257        size_t bsize, oalign = 0;
    12591258        headers( "realloc", oaddr, header, freeElem, bsize, oalign );
    1260         size_t odsize = dataStorage( bsize, oaddr, header ); // data storage available in bucket
    12611259
    12621260        if ( oalign <= nalign && (uintptr_t)oaddr % nalign == 0 ) { // <= alignment and new alignment happens to match
     
    12741272        #endif // __STATISTICS__
    12751273
     1274        size_t osize = header->kind.real.size;                  // old allocation size
     1275        bool ozfill = (header->kind.real.blockSize & 2) != 0; // old allocation zero filled
     1276
    12761277        // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
    1277   if ( unlikely( size == 0 ) ) { free( oaddr ); return memalignNoStats( nalign, size ); } // special cases
     1278  if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases
    12781279  if ( unlikely( oaddr == 0p ) ) return memalignNoStats( nalign, size );
    12791280
     
    12861287
    12871288        headers( "realloc", naddr, header, freeElem, bsize, oalign );
    1288         size_t ndsize = dataStorage( bsize, naddr, header ); // data storage available in bucket
    1289         // To preserve prior fill, the entire bucket must be copied versus the size.
    1290         memcpy( naddr, oaddr, MIN( odsize, ndsize ) );          // copy bytes
     1289        memcpy( naddr, oaddr, MIN( osize, size ) );                     // copy bytes
    12911290        free( oaddr );
     1291
     1292        if ( unlikely( ozfill ) ) {                                                     // previous request zero fill ?
     1293                header->kind.real.blockSize |= 2;                               // mark new request as zero filled
     1294                if ( size > osize ) {                                                   // previous request larger ?
     1295                        memset( (char *)naddr + osize, (int)'\0', size - osize ); // initialize added storage
     1296                } // if
     1297        } // if
    12921298        return naddr;
    12931299} // realloc
  • libcfa/src/stdlib.hfa

    r8395152 r71dfe49  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 21 07:58:05 2020
    13 // Update Count     : 475
     12// Last Modified On : Thu Jul 30 16:14:58 2020
     13// Update Count     : 490
    1414//
    1515
     
    7171        T * resize( T * ptr, size_t size ) {                            // CFA resize, eliminate return-type cast
    7272                $RE_SPECIALS( ptr, size, malloc, memalign );
    73                 return (T *)(void *)resize( (void *)ptr, size ); // CFA resize
     73                if ( _Alignof(T) <= libAlign() ) return (T *)(void *)resize( (void *)ptr, size ); // CFA resize
     74                else return (T *)(void *)resize( (void *)ptr, _Alignof(T), size ); // CFA resize
    7475        } // resize
    7576
    7677        T * realloc( T * ptr, size_t size ) {                           // CFA realloc, eliminate return-type cast
    7778                $RE_SPECIALS( ptr, size, malloc, memalign );
    78                 return (T *)(void *)realloc( (void *)ptr, size ); // C realloc
     79                if ( _Alignof(T) <= libAlign() ) return (T *)(void *)realloc( (void *)ptr, size ); // C realloc
     80                else return (T *)(void *)realloc( (void *)ptr, _Alignof(T), size ); // CFA realloc
    7981        } // realloc
    8082
     
    121123        forall( dtype S | sized(S) )
    122124        T * alloc( S ptr[], size_t dim = 1 ) {                          // singleton/array resize
    123                 size_t len = malloc_usable_size( ptr );                 // current bucket size
    124                 if ( sizeof(T) * dim > len ) {                                  // not enough space ?
    125                         T * temp = alloc( dim );                                        // new storage
    126                         free( ptr );                                                            // free old storage
    127                         return temp;
    128                 } else {
    129                         return (T *)ptr;
    130                 } // if
    131         } // alloc
    132 
    133         T * alloc( T ptr[], size_t dim, bool copy = true ) {
     125                return resize( (T *)ptr, dim * sizeof(T) );             // CFA resize
     126        } // alloc
     127
     128        T * alloc( T ptr[], size_t dim = 1, bool copy = true ) {
    134129                if ( copy ) {
    135130                        return realloc( ptr, dim * sizeof(T) );         // CFA realloc
     
    168163                        memset( (char *)nptr + osize, (int)fill, nsize - osize ); // initialize added storage
    169164                } // if
    170                 return (T *)nptr;
     165                return nptr;
    171166        } // alloc_set
    172167
     
    181176                        } // for
    182177                } // if
    183                 return (T *)nptr;
     178                return nptr;
    184179        } // alloc_align_set
    185180} // distribution
     
    195190
    196191        T * alloc_align( T * ptr, size_t align ) {                      // aligned realloc array
    197                 return (T *)(void *)realloc( (void *)ptr, align, sizeof(T) ); // CFA realloc
     192                return (T *)(void *)realloc( (void *)ptr, align, sizeof(T) ); // CFA C realloc
    198193        } // alloc_align
    199194
     
    232227                size_t osize = malloc_size( ptr );                              // current allocation
    233228                size_t nsize = dim * sizeof(T);                                 // new allocation
    234                 T * nptr = alloc_align( ptr, align, nsize );    // CFA alloc_align
     229                T * nptr = alloc_align( ptr, align, nsize );
    235230                if ( nsize > osize ) {                                                  // larger ?
    236231                        memset( (char *)nptr + osize, (int)fill, nsize - osize ); // initialize added storage
    237232                } // if
    238                 return (T *)nptr;
     233                return nptr;
    239234        } // alloc_align_set
    240235
     
    243238                size_t nsize = dim * sizeof(T);                                 // new allocation
    244239                size_t ndim = nsize / sizeof(T);                                // new dimension
    245                 T * nptr = alloc_align( ptr, align, nsize );            // CFA alloc_align
     240                T * nptr = alloc_align( ptr, align, nsize );
    246241                if ( ndim > odim ) {                                                    // larger ?
    247242                        for ( i; odim ~ ndim ) {
     
    249244                        } // for
    250245                } // if
    251                 return (T *)nptr;
     246                return nptr;
    252247        } // alloc_align_set
    253248} // distribution
  • tests/heap.cfa

    r8395152 r71dfe49  
    1010// Created On       : Tue Nov  6 17:54:56 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Nov 24 12:34:51 2019
    13 // Update Count     : 28
     12// Last Modified On : Tue Aug  4 06:36:17 2020
     13// Update Count     : 56
    1414//
    1515
     
    7575                size_t s = (i + 1) * 20;
    7676                char * area = (char *)malloc( s );
    77                 if ( area == 0p ) abort( "malloc/free out of memory" );
    7877                area[0] = '\345'; area[s - 1] = '\345';                 // fill first/last
    7978                area[malloc_usable_size( area ) - 1] = '\345';  // fill ultimate byte
     
    8483                size_t s = i + 1;                                                               // +1 to make initialization simpler
    8584                locns[i] = (char *)malloc( s );
    86                 if ( locns[i] == 0p ) abort( "malloc/free out of memory" );
    8785                locns[i][0] = '\345'; locns[i][s - 1] = '\345'; // fill first/last
    8886                locns[i][malloc_usable_size( locns[i] ) - 1] = '\345'; // fill ultimate byte
     
    10098                size_t s = i + default_mmap_start();                    // cross over point
    10199                char * area = (char *)malloc( s );
    102                 if ( area == 0p ) abort( "malloc/free out of memory" );
    103100                area[0] = '\345'; area[s - 1] = '\345';                 // fill first/last
    104101                area[malloc_usable_size( area ) - 1] = '\345';  // fill ultimate byte
     
    109106                size_t s = i + default_mmap_start();                    // cross over point
    110107                locns[i] = (char *)malloc( s );
    111                 if ( locns[i] == 0p ) abort( "malloc/free out of memory" );
    112108                locns[i][0] = '\345'; locns[i][s - 1] = '\345'; // fill first/last
    113109                locns[i][malloc_usable_size( locns[i] ) - 1] = '\345'; // fill ultimate byte
     
    125121                size_t s = (i + 1) * 20;
    126122                char * area = (char *)calloc( 5, s );
    127                 if ( area == 0p ) abort( "calloc/free out of memory" );
    128123                if ( area[0] != '\0' || area[s - 1] != '\0' ||
    129                          area[malloc_usable_size( area ) - 1] != '\0' ||
     124                         area[malloc_size( area ) - 1] != '\0' ||
    130125                         ! malloc_zero_fill( area ) ) abort( "calloc/free corrupt storage1" );
    131126                area[0] = '\345'; area[s - 1] = '\345';                 // fill first/last
     
    137132                size_t s = i + 1;
    138133                locns[i] = (char *)calloc( 5, s );
    139                 if ( locns[i] == 0p ) abort( "calloc/free out of memory" );
    140134                if ( locns[i][0] != '\0' || locns[i][s - 1] != '\0' ||
    141                          locns[i][malloc_usable_size( locns[i] ) - 1] != '\0' ||
     135                         locns[i][malloc_size( locns[i] ) - 1] != '\0' ||
    142136                         ! malloc_zero_fill( locns[i] ) ) abort( "calloc/free corrupt storage2" );
    143137                locns[i][0] = '\345'; locns[i][s - 1] = '\345'; // fill first/last
     
    156150                size_t s = i + default_mmap_start();                    // cross over point
    157151                char * area = (char *)calloc( 1, s );
    158                 if ( area == 0p ) abort( "calloc/free out of memory" );
    159152                if ( area[0] != '\0' || area[s - 1] != '\0' ) abort( "calloc/free corrupt storage4.1" );
    160                 if ( area[malloc_usable_size( area ) - 1] != '\0' ) abort( "calloc/free corrupt storage4.2" );
     153                if ( area[malloc_size( area ) - 1] != '\0' ) abort( "calloc/free corrupt storage4.2" );
    161154                if ( ! malloc_zero_fill( area ) ) abort( "calloc/free corrupt storage4.3" );
    162155                area[0] = '\345'; area[s - 1] = '\345';                 // fill first/last
     
    168161                size_t s = i + default_mmap_start();                    // cross over point
    169162                locns[i] = (char *)calloc( 1, s );
    170                 if ( locns[i] == 0p ) abort( "calloc/free out of memory" );
    171163                if ( locns[i][0] != '\0' || locns[i][s - 1] != '\0' ||
    172                          locns[i][malloc_usable_size( locns[i] ) - 1] != '\0' ||
     164                         locns[i][malloc_size( locns[i] ) - 1] != '\0' ||
    173165                         ! malloc_zero_fill( locns[i] ) ) abort( "calloc/free corrupt storage5" );
    174166                locns[i][0] = '\345'; locns[i][s - 1] = '\345'; // fill first/last
     
    188180                for ( s; 1 ~ NoOfAllocs ) {                                             // allocation of size 0 can return null
    189181                        char * area = (char *)memalign( a, s );
    190                         if ( area == 0p ) abort( "memalign/free out of memory" );
    191182                        //sout | i | area;
    192183                        if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment
     
    206197                        size_t s = i + default_mmap_start();            // cross over point
    207198                        char * area = (char *)memalign( a, s );
    208                         if ( area == 0p ) abort( "memalign/free out of memory" );
    209199                        //sout | i | area;
    210200                        if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment
     
    222212                // initial N byte allocation
    223213                char * area = (char *)calloc( 5, i );
    224                 if ( area == 0p ) abort( "calloc/realloc/free out of memory" );
    225214                if ( area[0] != '\0' || area[i - 1] != '\0' ||
    226                          area[malloc_usable_size( area ) - 1] != '\0' ||
     215                         area[malloc_size( area ) - 1] != '\0' ||
    227216                         ! malloc_zero_fill( area ) ) abort( "calloc/realloc/free corrupt storage1" );
    228217
     
    230219                for ( s; i ~ 256 * 1024 ~ 26 ) {                                // start at initial memory request
    231220                        area = (char *)realloc( area, s );                      // attempt to reuse storage
    232                         if ( area == 0p ) abort( "calloc/realloc/free out of memory" );
    233221                        if ( area[0] != '\0' || area[s - 1] != '\0' ||
    234                                  area[malloc_usable_size( area ) - 1] != '\0' ||
     222                                 area[malloc_size( area ) - 1] != '\0' ||
    235223                                 ! malloc_zero_fill( area ) ) abort( "calloc/realloc/free corrupt storage2" );
    236224                } // for
     
    244232                size_t s = i + default_mmap_start();                    // cross over point
    245233                char * area = (char *)calloc( 1, s );
    246                 if ( area == 0p ) abort( "calloc/realloc/free out of memory" );
     234//              if ( area == 0p ) abort( "calloc/realloc/free out of memory" );
    247235                if ( area[0] != '\0' || area[s - 1] != '\0' ||
    248                          area[malloc_usable_size( area ) - 1] != '\0' ||
    249                          ! malloc_zero_fill( area ) ) abort( "calloc/realloc/free corrupt storage1" );
     236                         area[malloc_size( area ) - 1] != '\0' ||
     237                         ! malloc_zero_fill( area ) ) //abort( "calloc/realloc/free corrupt storage3" );
     238                        printf( "C %zd %d %d %d %d\n", s, area[0] != '\0', area[s - 1] != '\0', area[malloc_size( area ) - 1] != '\0', ! malloc_zero_fill( area ) );
    250239
    251240                // Do not start this loop index at 0 because realloc of 0 bytes frees the storage.
    252241                for ( r; i ~ 256 * 1024 ~ 26 ) {                                // start at initial memory request
    253242                        area = (char *)realloc( area, r );                      // attempt to reuse storage
    254                         if ( area == 0p ) abort( "calloc/realloc/free out of memory" );
     243//                      if ( area == 0p ) abort( "calloc/realloc/free out of memory" );
    255244                        if ( area[0] != '\0' || area[r - 1] != '\0' ||
    256                                  area[malloc_usable_size( area ) - 1] != '\0' ||
    257                                  ! malloc_zero_fill( area ) ) abort( "calloc/realloc/free corrupt storage2" );
     245                                 area[malloc_size( area ) - 1] != '\0' ||
     246                                 ! malloc_zero_fill( area ) ) abort( "calloc/realloc/free corrupt storage4" );
    258247                } // for
    259248                free( area );
     
    266255                // initial N byte allocation
    267256                char * area = (char *)memalign( a, amount );    // aligned N-byte allocation
    268                 if ( area == 0p ) abort( "memalign/realloc/free out of memory" ); // no storage ?
     257//              if ( area == 0p ) abort( "memalign/realloc/free out of memory" ); // no storage ?
    269258                //sout | alignments[a] | area;
    270259                if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment
     
    277266                        if ( area[0] != '\345' || area[s - 2] != '\345' ) abort( "memalign/realloc/free corrupt storage" );
    278267                        area = (char *)realloc( area, s );                      // attempt to reuse storage
    279                         if ( area == 0p ) abort( "memalign/realloc/free out of memory" ); // no storage ?
    280268                        //sout | i | area;
    281269                        if ( (size_t)area % a != 0 ) {                          // check for initial alignment
     
    293281                for ( s; 1 ~ limit ) {                                                  // allocation of size 0 can return null
    294282                        char * area = (char *)cmemalign( a, 1, s );
    295                         if ( area == 0p ) abort( "cmemalign/free out of memory" );
    296283                        //sout | i | area;
    297284                        if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment
     
    299286                        } // if
    300287                        if ( area[0] != '\0' || area[s - 1] != '\0' ||
    301                                  area[malloc_usable_size( area ) - 1] != '\0' ||
     288                                 area[malloc_size( area ) - 1] != '\0' ||
    302289                                 ! malloc_zero_fill( area ) ) abort( "cmemalign/free corrupt storage" );
    303290                        area[0] = '\345'; area[s - 1] = '\345';         // fill first/last byte
     
    312299                // initial N byte allocation
    313300                char * area = (char *)cmemalign( a, 1, amount ); // aligned N-byte allocation
    314                 if ( area == 0p ) abort( "cmemalign/realloc/free out of memory" ); // no storage ?
    315301                //sout | alignments[a] | area;
    316302                if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment
     
    318304                } // if
    319305                if ( area[0] != '\0' || area[amount - 1] != '\0' ||
    320                          area[malloc_usable_size( area ) - 1] != '\0' ||
     306                         area[malloc_size( area ) - 1] != '\0' ||
    321307                         ! malloc_zero_fill( area ) ) abort( "cmemalign/realloc/free corrupt storage1" );
    322308                area[0] = '\345'; area[amount - 2] = '\345';    // fill first/penultimate byte
     
    326312                        if ( area[0] != '\345' || area[s - 2] != '\345' ) abort( "cmemalign/realloc/free corrupt storage2" );
    327313                        area = (char *)realloc( area, s );                      // attempt to reuse storage
    328                         if ( area == 0p ) abort( "cmemalign/realloc/free out of memory" ); // no storage ?
    329314                        //sout | i | area;
    330315                        if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment
    331316                                abort( "cmemalign/realloc/free bad alignment %p", area );
    332317                        } // if
    333                         if ( area[s - 1] != '\0' || area[s - 1] != '\0' ||
    334                                  area[malloc_usable_size( area ) - 1] != '\0' ||
     318                        if ( area[0] != '\345' || area[s - 1] != '\0' ||
     319                                 area[malloc_size( area ) - 1] != '\0' ||
    335320                                 ! malloc_zero_fill( area ) ) abort( "cmemalign/realloc/free corrupt storage3" );
    336321                        area[s - 1] = '\345';                                           // fill last byte
     
    345330                // initial N byte allocation
    346331                char * area = (char *)memalign( a, amount );    // aligned N-byte allocation
    347                 if ( area == 0p ) abort( "memalign/realloc with align/free out of memory" ); // no storage ?
    348332                //sout | alignments[a] | area | endl;
    349333                if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment
     
    356340                        if ( area[0] != '\345' || area[s - 2] != '\345' ) abort( "memalign/realloc/free corrupt storage" );
    357341                        area = (char *)realloc( area, a * 2, s );       // attempt to reuse storage
    358                         if ( area == 0p ) abort( "memalign/realloc with align/free out of memory" ); // no storage ?
    359342                        //sout | i | area | endl;
    360343                        if ( (size_t)area % a * 2 != 0 ) {                      // check for initial alignment
     
    371354        for ( size_t a = libAlign() + libAlign(); a <= limit; a += a ) { // generate powers of 2
    372355                // initial N byte allocation
    373                 char *area = (char *)cmemalign( a, 1, amount ); // aligned N-byte allocation
    374                 if ( area == 0p ) abort( "cmemalign/realloc with align/free out of memory" ); // no storage ?
     356                char * area = (char *)cmemalign( a, 1, amount ); // aligned N-byte allocation
    375357                //sout | alignments[a] | area | endl;
    376358                if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment
     
    378360                } // if
    379361                if ( area[0] != '\0' || area[amount - 1] != '\0' ||
    380                          area[malloc_usable_size( area ) - 1] != '\0' ||
     362                         area[malloc_size( area ) - 1] != '\0' ||
    381363                         ! malloc_zero_fill( area ) ) abort( "cmemalign/realloc with align/free corrupt storage1" );
    382364                area[0] = '\345'; area[amount - 2] = '\345';    // fill first/penultimate byte
     
    386368                        if ( area[0] != '\345' || area[s - 2] != '\345' ) abort( "cmemalign/realloc with align/free corrupt storage2" );
    387369                        area = (char *)realloc( area, a * 2, s );       // attempt to reuse storage
    388                         if ( area == 0p ) abort( "cmemalign/realloc with align/free out of memory" ); // no storage ?
    389370                        //sout | i | area | endl;
    390371                        if ( (size_t)area % a * 2 != 0 || malloc_alignment( area ) != a * 2 ) { // check for initial alignment
    391                                 abort( "cmemalign/realloc with align/free bad alignment %p %jd %jd", area, malloc_alignment( area ), a * 2 );
     372                                abort( "cmemalign/realloc with align/free bad alignment %p %zd %zd", area, malloc_alignment( area ), a * 2 );
    392373                        } // if
    393374                        if ( area[s - 1] != '\0' || area[s - 1] != '\0' ||
    394                                  area[malloc_usable_size( area ) - 1] != '\0' ||
     375                                 area[malloc_size( area ) - 1] != '\0' ||
    395376                                 ! malloc_zero_fill( area ) ) abort( "cmemalign/realloc/free corrupt storage3" );
    396377                        area[s - 1] = '\345';                                           // fill last byte
Note: See TracChangeset for help on using the changeset viewer.