Changes in / [64aeca0:58fe85a]


Ignore:
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/heap.cfa

    r64aeca0 r58fe85a  
    1010// Created On       : Tue Dec 19 21:58:35 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jan 10 11:20:49 2021
    13 // Update Count     : 1031
     12// Last Modified On : Wed Dec 16 12:28:25 2020
     13// Update Count     : 1023
    1414//
    1515
     
    262262#ifdef __STATISTICS__
    263263// Heap statistics counters.
    264 static unsigned int malloc_zero_calls, malloc_calls;
     264static unsigned int malloc_calls;
    265265static unsigned long long int malloc_storage;
    266 static unsigned int aalloc_zero_calls, aalloc_calls;
     266static unsigned int aalloc_calls;
    267267static unsigned long long int aalloc_storage;
    268 static unsigned int calloc_zero_calls, calloc_calls;
     268static unsigned int calloc_calls;
    269269static unsigned long long int calloc_storage;
    270 static unsigned int memalign_zero_calls, memalign_calls;
     270static unsigned int memalign_calls;
    271271static unsigned long long int memalign_storage;
    272 static unsigned int amemalign_zero_calls, amemalign_calls;
     272static unsigned int amemalign_calls;
    273273static unsigned long long int amemalign_storage;
    274 static unsigned int cmemalign_zero_calls, cmemalign_calls;
     274static unsigned int cmemalign_calls;
    275275static unsigned long long int cmemalign_storage;
    276 static unsigned int resize_zero_calls, resize_calls;
     276static unsigned int resize_calls;
    277277static unsigned long long int resize_storage;
    278 static unsigned int realloc_zero_calls, realloc_calls;
     278static unsigned int realloc_calls;
    279279static unsigned long long int realloc_storage;
    280 static unsigned int free_zero_calls, free_calls;
     280static unsigned int free_calls;
    281281static unsigned long long int free_storage;
    282282static unsigned int mmap_calls;
     
    287287static unsigned long long int sbrk_storage;
    288288// Statistics file descriptor (changed by malloc_stats_fd).
    289 static int stats_fd = STDERR_FILENO;                                    // default stderr
     289static int stat_fd = STDERR_FILENO;                                             // default stderr
    290290
    291291// Use "write" because streams may be shutdown when calls are made.
     
    293293        char helpText[1024];
    294294        __cfaabi_bits_print_buffer( STDERR_FILENO, helpText, sizeof(helpText),
    295                                                                 "\nHeap statistics:\n"
    296                                                                 "  malloc    0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
    297                                                                 "  aalloc    0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
    298                                                                 "  calloc    0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
    299                                                                 "  memalign  0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
    300                                                                 "  amemalign 0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
    301                                                                 "  cmemalign 0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
    302                                                                 "  resize    0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
    303                                                                 "  realloc   0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
    304                                                                 "  free      0-calls %'u; >0-calls %'u; storage %'llu bytes\n"
    305                                                                 "  mmap      calls %'u; storage %'llu bytes\n"
    306                                                                 "  munmap    calls %'u; storage %'llu bytes\n"
    307                                                                 "  sbrk      calls %'u; storage %'llu bytes\n",
    308                                                                 malloc_zero_calls, malloc_calls, malloc_storage,
    309                                                                 aalloc_zero_calls, aalloc_calls, aalloc_storage,
    310                                                                 calloc_zero_calls, calloc_calls, calloc_storage,
    311                                                                 memalign_zero_calls, memalign_calls, memalign_storage,
    312                                                                 amemalign_zero_calls, amemalign_calls, amemalign_storage,
    313                                                                 cmemalign_zero_calls, cmemalign_calls, cmemalign_storage,
    314                                                                 resize_zero_calls, resize_calls, resize_storage,
    315                                                                 realloc_zero_calls, realloc_calls, realloc_storage,
    316                                                                 free_zero_calls, free_calls, free_storage,
    317                                                                 mmap_calls, mmap_storage,
    318                                                                 munmap_calls, munmap_storage,
    319                                                                 sbrk_calls, sbrk_storage
     295                                                                        "\nHeap statistics:\n"
     296                                                                        "  malloc: calls %u / storage %llu\n"
     297                                                                        "  aalloc: calls %u / storage %llu\n"
     298                                                                        "  calloc: calls %u / storage %llu\n"
     299                                                                        "  memalign: calls %u / storage %llu\n"
     300                                                                        "  amemalign: calls %u / storage %llu\n"
     301                                                                        "  cmemalign: calls %u / storage %llu\n"
     302                                                                        "  resize: calls %u / storage %llu\n"
     303                                                                        "  realloc: calls %u / storage %llu\n"
     304                                                                        "  free: calls %u / storage %llu\n"
     305                                                                        "  mmap: calls %u / storage %llu\n"
     306                                                                        "  munmap: calls %u / storage %llu\n"
     307                                                                        "  sbrk: calls %u / storage %llu\n",
     308                                                                        malloc_calls, malloc_storage,
     309                                                                        aalloc_calls, aalloc_storage,
     310                                                                        calloc_calls, calloc_storage,
     311                                                                        memalign_calls, memalign_storage,
     312                                                                        amemalign_calls, amemalign_storage,
     313                                                                        cmemalign_calls, cmemalign_storage,
     314                                                                        resize_calls, resize_storage,
     315                                                                        realloc_calls, realloc_storage,
     316                                                                        free_calls, free_storage,
     317                                                                        mmap_calls, mmap_storage,
     318                                                                        munmap_calls, munmap_storage,
     319                                                                        sbrk_calls, sbrk_storage
    320320                );
    321321} // printStats
     
    328328                                                "<sizes>\n"
    329329                                                "</sizes>\n"
    330                                                 "<total type=\"malloc\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
    331                                                 "<total type=\"aalloc\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
    332                                                 "<total type=\"calloc\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
    333                                                 "<total type=\"memalign\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
    334                                                 "<total type=\"amemalign\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
    335                                                 "<total type=\"cmemalign\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
    336                                                 "<total type=\"resize\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
    337                                                 "<total type=\"realloc\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
    338                                                 "<total type=\"free\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n"
    339                                                 "<total type=\"mmap\" count=\"%'u;\" size=\"%'llu\"/> bytes\n"
    340                                                 "<total type=\"munmap\" count=\"%'u;\" size=\"%'llu\"/> bytes\n"
    341                                                 "<total type=\"sbrk\" count=\"%'u;\" size=\"%'llu\"/> bytes\n"
     330                                                "<total type=\"malloc\" count=\"%u\" size=\"%llu\"/>\n"
     331                                                "<total type=\"aalloc\" count=\"%u\" size=\"%llu\"/>\n"
     332                                                "<total type=\"calloc\" count=\"%u\" size=\"%llu\"/>\n"
     333                                                "<total type=\"memalign\" count=\"%u\" size=\"%llu\"/>\n"
     334                                                "<total type=\"amemalign\" count=\"%u\" size=\"%llu\"/>\n"
     335                                                "<total type=\"cmemalign\" count=\"%u\" size=\"%llu\"/>\n"
     336                                                "<total type=\"resize\" count=\"%u\" size=\"%llu\"/>\n"
     337                                                "<total type=\"realloc\" count=\"%u\" size=\"%llu\"/>\n"
     338                                                "<total type=\"free\" count=\"%u\" size=\"%llu\"/>\n"
     339                                                "<total type=\"mmap\" count=\"%u\" size=\"%llu\"/>\n"
     340                                                "<total type=\"munmap\" count=\"%u\" size=\"%llu\"/>\n"
     341                                                "<total type=\"sbrk\" count=\"%u\" size=\"%llu\"/>\n"
    342342                                                "</malloc>",
    343                                                 malloc_zero_calls, malloc_calls, malloc_storage,
    344                                                 aalloc_zero_calls, aalloc_calls, aalloc_storage,
    345                                                 calloc_zero_calls, calloc_calls, calloc_storage,
    346                                                 memalign_zero_calls, memalign_calls, memalign_storage,
    347                                                 amemalign_zero_calls, amemalign_calls, amemalign_storage,
    348                                                 cmemalign_zero_calls, cmemalign_calls, cmemalign_storage,
    349                                                 resize_zero_calls, resize_calls, resize_storage,
    350                                                 realloc_zero_calls, realloc_calls, realloc_storage,
    351                                                 free_zero_calls, free_calls, free_storage,
     343                                                malloc_calls, malloc_storage,
     344                                                aalloc_calls, aalloc_storage,
     345                                                calloc_calls, calloc_storage,
     346                                                memalign_calls, memalign_storage,
     347                                                amemalign_calls, amemalign_storage,
     348                                                cmemalign_calls, cmemalign_storage,
     349                                                resize_calls, resize_storage,
     350                                                realloc_calls, realloc_storage,
     351                                                free_calls, free_storage,
    352352                                                mmap_calls, mmap_storage,
    353353                                                munmap_calls, munmap_storage,
     
    466466} // headers
    467467
    468 // #ifdef __CFA_DEBUG__
    469 // #if __SIZEOF_POINTER__ == 4
    470 // #define MASK 0xdeadbeef
    471 // #else
    472 // #define MASK 0xdeadbeefdeadbeef
    473 // #endif
    474 // #define STRIDE size_t
    475 
    476 // static void * Memset( void * addr, STRIDE size ) {           // debug only
    477 //      if ( size % sizeof(STRIDE) != 0 ) abort( "Memset() : internal error, size %zd not multiple of %zd.", size, sizeof(STRIDE) );
    478 //      if ( (STRIDE)addr % sizeof(STRIDE) != 0 ) abort( "Memset() : internal error, addr %p not multiple of %zd.", addr, sizeof(STRIDE) );
    479 
    480 //      STRIDE * end = (STRIDE *)addr + size / sizeof(STRIDE);
    481 //      for ( STRIDE * p = (STRIDE *)addr; p < end; p += 1 ) *p = MASK;
    482 //      return addr;
    483 // } // Memset
    484 // #endif // __CFA_DEBUG__
     468#ifdef __CFA_DEBUG__
     469#if __SIZEOF_POINTER__ == 4
     470#define MASK 0xdeadbeef
     471#else
     472#define MASK 0xdeadbeefdeadbeef
     473#endif
     474#define STRIDE size_t
     475
     476static void * Memset( void * addr, STRIDE size ) {              // debug only
     477        if ( size % sizeof(STRIDE) != 0 ) abort( "Memset() : internal error, size %zd not multiple of %zd.", size, sizeof(STRIDE) );
     478        if ( (STRIDE)addr % sizeof(STRIDE) != 0 ) abort( "Memset() : internal error, addr %p not multiple of %zd.", addr, sizeof(STRIDE) );
     479
     480        STRIDE * end = (STRIDE *)addr + size / sizeof(STRIDE);
     481        for ( STRIDE * p = (STRIDE *)addr; p < end; p += 1 ) *p = MASK;
     482        return addr;
     483} // Memset
     484#endif // __CFA_DEBUG__
    485485
    486486
     
    498498                        unlock( extlock );
    499499                        __cfaabi_bits_print_nolock( STDERR_FILENO, NO_MEMORY_MSG, size );
    500                         _exit( EXIT_FAILURE );                                          // give up
    501                 } // if
    502                 // Make storage executable for thunks.
     500                        _exit( EXIT_FAILURE );
     501                } // if
    503502                if ( mprotect( (char *)heapEnd + heapRemaining, increase, __map_prot ) ) {
    504503                        unlock( extlock );
     
    771770
    772771
     772static inline void * callocNoStats( size_t dim, size_t elemSize ) {
     773        size_t size = dim * elemSize;
     774  if ( unlikely( size ) == 0 ) return 0p;                               // 0 BYTE ALLOCATION RETURNS NULL POINTER
     775        char * addr = (char *)mallocNoStats( size );
     776
     777        HeapManager.Storage.Header * header;
     778        HeapManager.FreeHeader * freeElem;
     779        size_t bsize, alignment;
     780        #ifndef __CFA_DEBUG__
     781        bool mapped =
     782        #endif // __CFA_DEBUG__
     783                headers( "calloc", addr, header, freeElem, bsize, alignment );
     784        #ifndef __CFA_DEBUG__
     785
     786        // Mapped storage is zero filled, but in debug mode mapped memory is scrubbed in doMalloc, so it has to be reset to zero.
     787        if ( ! mapped )
     788        #endif // __CFA_DEBUG__
     789                // <-------0000000000000000000000000000UUUUUUUUUUUUUUUUUUUUUUUUU> bsize (bucket size) U => undefined
     790                // `-header`-addr                      `-size
     791                memset( addr, '\0', size );                                             // set to zeros
     792
     793        header->kind.real.blockSize |= 2;                                       // mark as zero filled
     794        return addr;
     795} // callocNoStats
     796
     797
    773798static inline void * memalignNoStats( size_t alignment, size_t size ) {
    774799  if ( unlikely( size ) == 0 ) return 0p;                               // 0 BYTE ALLOCATION RETURNS NULL POINTER
     
    809834
    810835
     836static inline void * cmemalignNoStats( size_t alignment, size_t dim, size_t elemSize ) {
     837        size_t size = dim * elemSize;
     838  if ( unlikely( size ) == 0 ) return 0p;                               // 0 BYTE ALLOCATION RETURNS NULL POINTER
     839        char * addr = (char *)memalignNoStats( alignment, size );
     840
     841        HeapManager.Storage.Header * header;
     842        HeapManager.FreeHeader * freeElem;
     843        size_t bsize;
     844        #ifndef __CFA_DEBUG__
     845        bool mapped =
     846        #endif // __CFA_DEBUG__
     847                headers( "cmemalign", addr, header, freeElem, bsize, alignment );
     848
     849        // Mapped storage is zero filled, but in debug mode mapped memory is scrubbed in doMalloc, so it has to be reset to zero.
     850        #ifndef __CFA_DEBUG__
     851        if ( ! mapped )
     852        #endif // __CFA_DEBUG__
     853                // <-------0000000000000000000000000000UUUUUUUUUUUUUUUUUUUUUUUUU> bsize (bucket size) U => undefined
     854                // `-header`-addr                      `-size
     855                memset( addr, '\0', size );                                             // set to zeros
     856
     857        header->kind.real.blockSize |= 2;                                       // mark as zero filled
     858        return addr;
     859} // cmemalignNoStats
     860
     861
    811862extern "C" {
    812863        // Allocates size bytes and returns a pointer to the allocated memory.  The contents are undefined. If size is 0,
     
    814865        void * malloc( size_t size ) {
    815866                #ifdef __STATISTICS__
    816                 if ( likely( size > 0 ) ) {
    817                         __atomic_add_fetch( &malloc_calls, 1, __ATOMIC_SEQ_CST );
    818                         __atomic_add_fetch( &malloc_storage, size, __ATOMIC_SEQ_CST );
    819                 } else {
    820                         __atomic_add_fetch( &malloc_zero_calls, 1, __ATOMIC_SEQ_CST );
    821                 } // if
     867                __atomic_add_fetch( &malloc_calls, 1, __ATOMIC_SEQ_CST );
     868                __atomic_add_fetch( &malloc_storage, size, __ATOMIC_SEQ_CST );
    822869                #endif // __STATISTICS__
    823870
     
    830877                size_t size = dim * elemSize;
    831878                #ifdef __STATISTICS__
    832                 if ( likely( size > 0 ) ) {
    833                         __atomic_add_fetch( &aalloc_calls, 1, __ATOMIC_SEQ_CST );
    834                         __atomic_add_fetch( &aalloc_storage, size, __ATOMIC_SEQ_CST );
    835                 } else {
    836                         __atomic_add_fetch( &aalloc_zero_calls, 1, __ATOMIC_SEQ_CST );
    837                 } // if
     879                __atomic_add_fetch( &aalloc_calls, 1, __ATOMIC_SEQ_CST );
     880                __atomic_add_fetch( &aalloc_storage, size, __ATOMIC_SEQ_CST );
    838881                #endif // __STATISTICS__
    839882
     
    844887        // Same as aalloc() with memory set to zero.
    845888        void * calloc( size_t dim, size_t elemSize ) {
    846                 size_t size = dim * elemSize;
    847           if ( unlikely( size ) == 0 ) {                        // 0 BYTE ALLOCATION RETURNS NULL POINTER
    848                         #ifdef __STATISTICS__
    849                         __atomic_add_fetch( &calloc_zero_calls, 1, __ATOMIC_SEQ_CST );
    850                         #endif // __STATISTICS__
    851                         return 0p;
    852                 } // if
    853889                #ifdef __STATISTICS__
    854890                __atomic_add_fetch( &calloc_calls, 1, __ATOMIC_SEQ_CST );
     
    856892                #endif // __STATISTICS__
    857893
    858                 char * addr = (char *)mallocNoStats( size );
    859 
    860                 HeapManager.Storage.Header * header;
    861                 HeapManager.FreeHeader * freeElem;
    862                 size_t bsize, alignment;
    863 
    864                 #ifndef __CFA_DEBUG__
    865                 bool mapped =
    866                         #endif // __CFA_DEBUG__
    867                         headers( "calloc", addr, header, freeElem, bsize, alignment );
    868 
    869                 #ifndef __CFA_DEBUG__
    870                 // Mapped storage is zero filled, but in debug mode mapped memory is scrubbed in doMalloc, so it has to be reset to zero.
    871                 if ( ! mapped )
    872                 #endif // __CFA_DEBUG__
    873                         // <-------0000000000000000000000000000UUUUUUUUUUUUUUUUUUUUUUUUU> bsize (bucket size) U => undefined
    874                         // `-header`-addr                      `-size
    875                         memset( addr, '\0', size );                                     // set to zeros
    876 
    877                 header->kind.real.blockSize |= 2;                               // mark as zero filled
    878                 return addr;
     894                return callocNoStats( dim, elemSize );
    879895        } // calloc
    880896
     
    885901        // call to malloc(), alloc(), calloc() or realloc(). If the area pointed to was moved, a free(oaddr) is done.
    886902        void * resize( void * oaddr, size_t size ) {
     903                #ifdef __STATISTICS__
     904                __atomic_add_fetch( &resize_calls, 1, __ATOMIC_SEQ_CST );
     905                #endif // __STATISTICS__
     906
    887907                // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
    888           if ( unlikely( size == 0 ) ) {                                        // special cases
    889                         #ifdef __STATISTICS__
    890                         __atomic_add_fetch( &resize_zero_calls, 1, __ATOMIC_SEQ_CST );
    891                         #endif // __STATISTICS__
    892                         free( oaddr );
    893                         return 0p;
    894                 } // if
    895                 #ifdef __STATISTICS__
    896                 __atomic_add_fetch( &resize_calls, 1, __ATOMIC_SEQ_CST );
    897                 #endif // __STATISTICS__
    898 
     908          if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases
    899909          if ( unlikely( oaddr == 0p ) ) {
    900910                        #ifdef __STATISTICS__
     
    908918                size_t bsize, oalign;
    909919                headers( "resize", oaddr, header, freeElem, bsize, oalign );
    910 
    911920                size_t odsize = dataStorage( bsize, oaddr, header ); // data storage available in bucket
     921
    912922                // same size, DO NOT preserve STICKY PROPERTIES.
    913923                if ( oalign == libAlign() && size <= odsize && odsize <= size * 2 ) { // allow 50% wasted storage for smaller size
     
    930940        // the old and new sizes.
    931941        void * realloc( void * oaddr, size_t size ) {
     942                #ifdef __STATISTICS__
     943                __atomic_add_fetch( &realloc_calls, 1, __ATOMIC_SEQ_CST );
     944                #endif // __STATISTICS__
     945
    932946                // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
    933           if ( unlikely( size == 0 ) ) {                                        // special cases
    934                         #ifdef __STATISTICS__
    935                         __atomic_add_fetch( &realloc_zero_calls, 1, __ATOMIC_SEQ_CST );
    936                         #endif // __STATISTICS__
    937                         free( oaddr );
    938                         return 0p;
    939                 } // if
    940                 #ifdef __STATISTICS__
    941                 __atomic_add_fetch( &realloc_calls, 1, __ATOMIC_SEQ_CST );
    942                 #endif // __STATISTICS__
    943 
     947          if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases
    944948          if ( unlikely( oaddr == 0p ) ) {
    945949                        #ifdef __STATISTICS__
     
    995999        void * memalign( size_t alignment, size_t size ) {
    9961000                #ifdef __STATISTICS__
    997                 if ( likely( size > 0 ) ) {
    998                         __atomic_add_fetch( &memalign_calls, 1, __ATOMIC_SEQ_CST );
    999                         __atomic_add_fetch( &memalign_storage, size, __ATOMIC_SEQ_CST );
    1000                 } else {
    1001                         __atomic_add_fetch( &memalign_zero_calls, 1, __ATOMIC_SEQ_CST );
    1002                 } // if
     1001                __atomic_add_fetch( &memalign_calls, 1, __ATOMIC_SEQ_CST );
     1002                __atomic_add_fetch( &memalign_storage, size, __ATOMIC_SEQ_CST );
    10031003                #endif // __STATISTICS__
    10041004
     
    10111011                size_t size = dim * elemSize;
    10121012                #ifdef __STATISTICS__
    1013                 if ( likely( size > 0 ) ) {
    1014                         __atomic_add_fetch( &cmemalign_calls, 1, __ATOMIC_SEQ_CST );
    1015                         __atomic_add_fetch( &cmemalign_storage, size, __ATOMIC_SEQ_CST );
    1016                 } else {
    1017                         __atomic_add_fetch( &cmemalign_zero_calls, 1, __ATOMIC_SEQ_CST );
    1018                 } // if
     1013                __atomic_add_fetch( &cmemalign_calls, 1, __ATOMIC_SEQ_CST );
     1014                __atomic_add_fetch( &cmemalign_storage, size, __ATOMIC_SEQ_CST );
    10191015                #endif // __STATISTICS__
    10201016
     
    10251021        // Same as calloc() with memory alignment.
    10261022        void * cmemalign( size_t alignment, size_t dim, size_t elemSize ) {
    1027                 size_t size = dim * elemSize;
    1028           if ( unlikely( size ) == 0 ) {                                        // 0 BYTE ALLOCATION RETURNS NULL POINTER
    1029                         #ifdef __STATISTICS__
    1030                         __atomic_add_fetch( &cmemalign_zero_calls, 1, __ATOMIC_SEQ_CST );
    1031                         #endif // __STATISTICS__
    1032                         return 0p;
    1033                 } // if
    10341023                #ifdef __STATISTICS__
    10351024                __atomic_add_fetch( &cmemalign_calls, 1, __ATOMIC_SEQ_CST );
     
    10371026                #endif // __STATISTICS__
    10381027
    1039                 char * addr = (char *)memalignNoStats( alignment, size );
    1040 
    1041                 HeapManager.Storage.Header * header;
    1042                 HeapManager.FreeHeader * freeElem;
    1043                 size_t bsize;
    1044 
    1045                 #ifndef __CFA_DEBUG__
    1046                 bool mapped =
    1047                         #endif // __CFA_DEBUG__
    1048                         headers( "cmemalign", addr, header, freeElem, bsize, alignment );
    1049 
    1050                 // Mapped storage is zero filled, but in debug mode mapped memory is scrubbed in doMalloc, so it has to be reset to zero.
    1051                 #ifndef __CFA_DEBUG__
    1052                 if ( ! mapped )
    1053                 #endif // __CFA_DEBUG__
    1054                         // <-------0000000000000000000000000000UUUUUUUUUUUUUUUUUUUUUUUUU> bsize (bucket size) U => undefined
    1055                         // `-header`-addr                      `-size
    1056                         memset( addr, '\0', size );                                     // set to zeros
    1057 
    1058                 header->kind.real.blockSize |= 2;                               // mark as zero filled
    1059                 return addr;
     1028                return cmemalignNoStats( alignment, dim, elemSize );
    10601029        } // cmemalign
    10611030
     
    10961065        // 0p, no operation is performed.
    10971066        void free( void * addr ) {
     1067                #ifdef __STATISTICS__
     1068                __atomic_add_fetch( &free_calls, 1, __ATOMIC_SEQ_CST );
     1069                #endif // __STATISTICS__
     1070
    10981071          if ( unlikely( addr == 0p ) ) {                                       // special case
    1099                         #ifdef __STATISTICS__
    1100                         __atomic_add_fetch( &free_zero_calls, 1, __ATOMIC_SEQ_CST );
    1101                         #endif // __STATISTICS__
    1102 
    11031072                        // #ifdef __CFA_DEBUG__
    11041073                        // if ( traceHeap() ) {
     
    12131182        int malloc_stats_fd( int fd __attribute__(( unused )) ) {
    12141183                #ifdef __STATISTICS__
    1215                 int temp = stats_fd;
    1216                 stats_fd = fd;
     1184                int temp = stat_fd;
     1185                stat_fd = fd;
    12171186                return temp;
    12181187                #else
     
    12451214        // The string is printed on the file stream stream.  The exported string includes information about all arenas (see
    12461215        // malloc).
    1247         int malloc_info( int options, FILE * stream __attribute__(( unused )) ) {
     1216        int malloc_info( int options, FILE * stream ) {
    12481217          if ( options != 0 ) { errno = EINVAL; return -1; }
    12491218                #ifdef __STATISTICS__
     
    12741243// Must have CFA linkage to overload with C linkage realloc.
    12751244void * resize( void * oaddr, size_t nalign, size_t size ) {
    1276         // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
    1277   if ( unlikely( size == 0 ) ) {                                                // special cases
    1278                 #ifdef __STATISTICS__
    1279                 __atomic_add_fetch( &resize_zero_calls, 1, __ATOMIC_SEQ_CST );
    1280                 #endif // __STATISTICS__
    1281                 free( oaddr );
    1282                 return 0p;
    1283         } // if
     1245        #ifdef __STATISTICS__
     1246        __atomic_add_fetch( &resize_calls, 1, __ATOMIC_SEQ_CST );
     1247        #endif // __STATISTICS__
    12841248
    12851249        if ( unlikely( nalign < libAlign() ) ) nalign = libAlign(); // reset alignment to minimum
    12861250        #ifdef __CFA_DEBUG__
    1287         else checkAlign( nalign );                                                      // check alignment
     1251        else
     1252                checkAlign( nalign );                                                   // check alignment
    12881253        #endif // __CFA_DEBUG__
    12891254
     1255        // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
     1256  if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases
    12901257  if ( unlikely( oaddr == 0p ) ) {
    12911258                #ifdef __STATISTICS__
    1292                 __atomic_add_fetch( &resize_calls, 1, __ATOMIC_SEQ_CST );
    12931259                __atomic_add_fetch( &resize_storage, size, __ATOMIC_SEQ_CST );
    12941260                #endif // __STATISTICS__
     
    13361302
    13371303void * realloc( void * oaddr, size_t nalign, size_t size ) {
    1338         // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
    1339   if ( unlikely( size == 0 ) ) {                                                // special cases
    1340                 #ifdef __STATISTICS__
    1341                 __atomic_add_fetch( &realloc_zero_calls, 1, __ATOMIC_SEQ_CST );
    1342                 #endif // __STATISTICS__
    1343                 free( oaddr );
    1344                 return 0p;
    1345         } // if
    1346 
    13471304        if ( unlikely( nalign < libAlign() ) ) nalign = libAlign(); // reset alignment to minimum
    13481305        #ifdef __CFA_DEBUG__
    1349         else checkAlign( nalign );                                                      // check alignment
     1306        else
     1307                checkAlign( nalign );                                                   // check alignment
    13501308        #endif // __CFA_DEBUG__
    13511309
     1310        // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.
     1311  if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases
    13521312  if ( unlikely( oaddr == 0p ) ) {
    13531313                #ifdef __STATISTICS__
  • libcfa/src/startup.cfa

    r64aeca0 r58fe85a  
    1010// Created On       : Tue Jul 24 16:21:57 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jan  9 23:18:23 2021
    13 // Update Count     : 34
     12// Last Modified On : Tue Feb  4 13:03:18 2020
     13// Update Count     : 30
    1414//
    1515
    16 #include <time.h>                                                                               // tzset
    17 #include <locale.h>                                                                             // setlocale
    18 #include <stdlib.h>                                                                             // getenv
     16#include <time.h>                // tzset
     17#include <locale.h>        // setlocale
    1918#include "startup.hfa"
    2019
     
    2322    void __cfaabi_appready_startup( void ) {
    2423                tzset();                                                                                // initialize time global variables
    25                 setlocale( LC_NUMERIC, getenv("LANG") );
     24                setlocale(LC_NUMERIC, "");
    2625                #ifdef __CFA_DEBUG__
    2726                extern void heapAppStart();
  • src/Parser/ParseNode.h

    r64aeca0 r58fe85a  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jan  3 18:23:01 2021
    13 // Update Count     : 896
     12// Last Modified On : Sat Oct 24 03:53:54 2020
     13// Update Count     : 895
    1414//
    1515
     
    3939struct DeclarationNode;
    4040class DeclarationWithType;
     41class ExpressionNode;
    4142class Initializer;
    42 class ExpressionNode;
    4343struct StatementNode;
    4444
  • src/Parser/parser.yy

    r64aeca0 r58fe85a  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jan 10 17:41:00 2021
    13 // Update Count     : 4625
     12// Last Modified On : Sat Oct 24 08:21:14 2020
     13// Update Count     : 4624
    1414//
    1515
     
    329329%type<en> conditional_expression                constant_expression                     assignment_expression           assignment_expression_opt
    330330%type<en> comma_expression                              comma_expression_opt
    331 %type<en> argument_expression_list_opt  argument_expression                     default_initializer_opt
     331%type<en> argument_expression_list_opt  argument_expression                     default_initialize_opt
    332332%type<ifctl> if_control_expression
    333333%type<fctl> for_control_expression              for_control_expression_list
     
    424424%type<decl> sue_declaration_specifier sue_declaration_specifier_nobody sue_type_specifier sue_type_specifier_nobody
    425425
    426 %type<tclass> type_class new_type_class
     426%type<tclass> type_class
    427427%type<decl> type_declarator type_declarator_name type_declaring_list
    428428
     
    22232223        ;
    22242224
    2225 cfa_parameter_ellipsis_list_opt:                                                // CFA, abstract + real
     2225cfa_parameter_ellipsis_list_opt:                                                        // CFA, abstract + real
    22262226        // empty
    22272227                { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); }
     
    22802280cfa_parameter_declaration:                                                              // CFA, new & old style parameter declaration
    22812281        parameter_declaration
    2282         | cfa_identifier_parameter_declarator_no_tuple identifier_or_type_name default_initializer_opt
     2282        | cfa_identifier_parameter_declarator_no_tuple identifier_or_type_name default_initialize_opt
    22832283                { $$ = $1->addName( $2 ); }
    2284         | cfa_abstract_tuple identifier_or_type_name default_initializer_opt
     2284        | cfa_abstract_tuple identifier_or_type_name default_initialize_opt
    22852285                // To obtain LR(1), these rules must be duplicated here (see cfa_abstract_declarator).
    22862286                { $$ = $1->addName( $2 ); }
    2287         | type_qualifier_list cfa_abstract_tuple identifier_or_type_name default_initializer_opt
     2287        | type_qualifier_list cfa_abstract_tuple identifier_or_type_name default_initialize_opt
    22882288                { $$ = $2->addName( $3 )->addQualifiers( $1 ); }
    22892289        | cfa_function_specifier
     
    23022302parameter_declaration:
    23032303                // No SUE declaration in parameter list.
    2304         declaration_specifier_nobody identifier_parameter_declarator default_initializer_opt
     2304        declaration_specifier_nobody identifier_parameter_declarator default_initialize_opt
    23052305                { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
    2306         | declaration_specifier_nobody type_parameter_redeclarator default_initializer_opt
     2306        | declaration_specifier_nobody type_parameter_redeclarator default_initialize_opt
    23072307                { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
    23082308        ;
    23092309
    23102310abstract_parameter_declaration:
    2311         declaration_specifier_nobody default_initializer_opt
     2311        declaration_specifier_nobody default_initialize_opt
    23122312                { $$ = $1->addInitializer( $2 ? new InitializerNode( $2 ) : nullptr ); }
    2313         | declaration_specifier_nobody abstract_parameter_declarator default_initializer_opt
     2313        | declaration_specifier_nobody abstract_parameter_declarator default_initialize_opt
    23142314                { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
    23152315        ;
     
    24412441        type_class identifier_or_type_name
    24422442                { typedefTable.addToScope( *$2, TYPEDEFname, "9" ); }
    2443           type_initializer_opt assertion_list_opt
     2443        type_initializer_opt assertion_list_opt
    24442444                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
    2445         | identifier_or_type_name new_type_class
    2446                 { typedefTable.addToScope( *$1, TYPEDEFname, "9" ); }
    2447           type_initializer_opt assertion_list_opt
    2448                 { $$ = DeclarationNode::newTypeParam( $2, $1 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
    2449         | '[' identifier_or_type_name ']'
    2450                 { typedefTable.addToScope( *$2, TYPEDEFname, "9" ); }
    2451         // | type_specifier identifier_parameter_declarator
     2445        | type_specifier identifier_parameter_declarator
    24522446        | assertion_list
    24532447                { $$ = DeclarationNode::newTypeParam( TypeDecl::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); }
    2454         ;
    2455 
    2456 new_type_class:                                                                                 // CFA
    2457         // empty
    2458                 { $$ = TypeDecl::Otype; }
    2459         | '&'
    2460                 { $$ = TypeDecl::Dtype; }
    2461         | '*'
    2462                 { $$ = TypeDecl::Dtype; }
    2463         | ELLIPSIS
    2464                 { $$ = TypeDecl::Ttype; }
    24652448        ;
    24662449
     
    34933476        ;
    34943477
    3495 default_initializer_opt:
     3478default_initialize_opt:
    34963479        // empty
    34973480                { $$ = nullptr; }
Note: See TracChangeset for help on using the changeset viewer.