Changes in / [0300979:a95c117]


Ignore:
Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/heap.c

    r0300979 ra95c117  
    1010// Created On       : Tue Dec 19 21:58:35 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 26 22:28:23 2018
    13 // Update Count     : 449
     12// Last Modified On : Wed Jul 25 16:42:02 2018
     13// Update Count     : 438
    1414//
    1515
     
    111111//      return temp;
    112112// } // prtHeapTermOff
    113 
    114 
    115 #ifdef __CFA_DEBUG__
    116 static unsigned int allocfree;                                                  // running total of allocations minus frees
    117 static unsigned int appStart;                                                   // storage allocation when application starts
    118 
    119 static void checkUnfreed() {
    120         unsigned int total = allocfree - appStart;
    121     if ( total != 0 ) {
    122                 // DO NOT USE STREAMS AS THEY MAY BE UNAVAILABLE AT THIS POINT.
    123                 // char helpText[512];
    124                 // int len = snprintf( helpText, 512, "CFA warning (UNIX pid:%ld) : program terminating with %u(0x%x) bytes of storage allocated but not freed.\n"
    125                 //                                      "Possible cause is unfreed storage allocated by the program or system/library routines called from the program.\n",
    126                 //                                      (long int)getpid(), total, total ); // always print the UNIX pid
    127                 // __cfaabi_dbg_bits_write( helpText, len );
    128     } // if
    129 } // checkUnfreed
    130 
    131 extern "C" {
    132 void heapAppStart() {                                                                   // called by __cfaabi_appready_startup
    133         appStart = allocfree;
    134 } // heapAppStart
    135 
    136 void heapAppStop() {                                                                    // called by __cfaabi_appready_startdown
    137         checkUnfreed();
    138 } // heapAppStop
    139 } // extern "C"
    140 #endif // __CFA_DEBUG__
    141113
    142114
     
    167139static int mmapFd = -1;                                                                 // fake or actual fd for anonymous file
    168140
     141static unsigned int allocfree;                                                  // running total of allocations minus frees
     142static unsigned int appStart;                                                   // storage allocation when application starts
     143
     144static void checkUnfreed() {
     145        #ifdef __CFA_DEBUG__
     146        unsigned int total = allocfree - appStart;
     147    if ( total != 0 ) {
     148                // DO NOT USE STREAMS AS THEY MAY BE UNAVAILABLE AT THIS POINT.
     149                // char helpText[512];
     150                // int len = snprintf( helpText, 512, "CFA warning (UNIX pid:%ld) : program terminating with %u(0x%x) bytes of storage allocated but not freed.\n"
     151                //                                      "Possible cause is unfreed storage allocated by the program or system/library routines called from the program.\n",
     152                //                                      (long int)getpid(), total, total ); // always print the UNIX pid
     153                // __cfaabi_dbg_bits_write( helpText, len );
     154    } // if
     155        #endif // __CFA_DEBUG__
     156} // checkUnfreed
     157
     158#ifdef __CFA_DEBUG__
     159extern "C" {
     160void heapAppStart() {                                                                   // called by __cfaabi_appready_startup
     161        appStart = allocfree;
     162} // heapAppStart
     163
     164void heapAppStop() {                                                                    // called by __cfaabi_appready_startdown
     165        checkUnfreed();
     166} // heapAppStop
     167} // extern "C"
     168#endif // __CFA_DEBUG__
     169
    169170
    170171struct HeapManager {
     
    177178                                        union {
    178179                                                struct {                                                // 32-bit word => 64-bit header, 64-bit word => 128-bit header
    179                                                         #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ && __SIZEOF_POINTER__ == 4
     180                                                        #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ && __U_WORDSIZE__ == 32
    180181                                                        uint32_t padding;                       // unused, force home/blocksize to overlay alignment in fake header
    181                                                         #endif // __ORDER_BIG_ENDIAN__ && __U_WORDSIZE__ == 32
     182                                                        #endif // __U_WORDSIZE__ == 32 && __U_WORDSIZE__ == 32
    182183
    183184                                                        union {
     
    190191                                                        };
    191192
    192                                                         #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ && __SIZEOF_POINTER__ == 4
     193                                                        #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ && __U_WORDSIZE__ == 32
    193194                                                        uint32_t padding;                       // unused, force home/blocksize to overlay alignment in fake header
    194                                                         #endif // __ORDER_LITTLE_ENDIAN__ && __U_WORDSIZE__ == 32
     195                                                        #endif // __U_WORDSIZE__ == 32 && __U_WORDSIZE__ == 32
    195196
    196197                                                };
     
    203204                                        #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
    204205                                        uint32_t alignment;                                     // low-order bits of home/blockSize used for tricks
    205                                         #endif // __ORDER_LITTLE_ENDIAN__
     206                                        #endif // __BYTE_ORDER__
    206207
    207208                                        uint32_t offset;
     
    209210                                        #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
    210211                                        uint32_t alignment;                                     // low-order bits of home/blockSize used for tricks
    211                                         #endif // __ORDER_BIG_ENDIAN__
     212                                        #endif // __BYTE_ORDER__
    212213                                } fake;
    213214                        } kind;
     
    304305        #endif // __CFA_DEBUG__
    305306
    306         assert( heapManager.heapBegin == 0 );
    307307        heapManager{};
    308308} // memory_startup
     
    672672
    673673static inline void * malloc2( size_t size ) {                   // necessary for malloc statistics
    674         assert( heapManager.heapBegin != 0 );
     674    assert( heapManager.heapBegin != 0 ) ;                              // heap started
    675675    void * area = doMalloc( size );
    676676    if ( unlikely( area == 0 ) ) errno = ENOMEM;                // POSIX
  • src/libcfa/stdlib

    r0300979 ra95c117  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 27 07:21:36 2018
    13 // Update Count     : 345
     12// Last Modified On : Mon Jul 23 07:44:47 2018
     13// Update Count     : 341
    1414//
    1515
     
    1919extern "C" {
    2020        void * memalign( size_t align, size_t size );           // malloc.h
    21         void * memset( void * dest, int fill, size_t size ); // string.h
     21        void * memset( void * dest, int c, size_t size );       // string.h
    2222        void * memcpy( void * dest, const void * src, size_t size ); // string.h
    2323    void * cmemalign( size_t alignment, size_t noOfElems, size_t elemSize ); // CFA
     
    127127        // data, non-array types
    128128
    129         T * memset( T * dest, char fill ) {
    130                 return (T *)memset( dest, fill, sizeof(T) );
     129        T * memset( T * dest, char c ) {
     130                return (T *)memset( dest, c, sizeof(T) );
    131131        } // memset
    132132
     
    139139        // data, array types
    140140
    141         T * amemset( T dest[], char fill, size_t dim ) {
    142                 return (T *)(void *)memset( dest, fill, dim * sizeof(T) ); // C memset
    143         } // amemset
    144 
    145         T * amemcpy( T dest[], const T src[], size_t dim ) {
     141        T * memset( T dest[], size_t dim, char c ) {
     142                return (T *)(void *)memset( dest, c, dim * sizeof(T) ); // C memset
     143        } // memset
     144
     145        T * memcpy( T dest[], const T src[], size_t dim ) {
    146146                return (T *)(void *)memcpy( dest, src, dim * sizeof(T) ); // C memcpy
    147         } // amemcpy
     147        } // memcpy
    148148} // distribution
    149149
     
    203203        E * bsearchu( E key, const E * vals, size_t dim );
    204204        size_t bsearchu( E key, const E * vals, size_t dim );
     205
     206        void qsort( E * vals, size_t dim );
    205207} // distribution
    206208
     
    212214        E * bsearchu( K key, const E * vals, size_t dim );
    213215        size_t bsearchu( K key, const E * vals, size_t dim );
    214 } // distribution
    215 
    216 forall( otype E | { int ?<?( E, E ); } ) {
    217         void qsort( E * vals, size_t dim );
    218216} // distribution
    219217
  • src/tests/.expect/alloc.txt

    r0300979 ra95c117  
    4949CFA array memset
    50500xffffffff -nan, 0xffffffff -nan, 0xffffffff -nan, 0xffffffff -nan, 0xffffffff -nan, 0xffffffff -nan, 0xffffffff -nan, 0xffffffff -nan, 0xffffffff -nan, 0xffffffff -nan,
    51 CFA array memcpy
     51CFA memcpy
    52520xffffffff -nan, 0xffffffff -nan, 0xffffffff -nan, 0xffffffff -nan, 0xffffffff -nan, 0xffffffff -nan, 0xffffffff -nan, 0xffffffff -nan, 0xffffffff -nan, 0xffffffff -nan,
    5353
  • src/tests/alloc.c

    r0300979 ra95c117  
    1010// Created On       : Wed Feb  3 07:56:22 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 26 20:58:05 2018
    13 // Update Count     : 334
     12// Last Modified On : Wed Jul 25 09:09:43 2018
     13// Update Count     : 331
    1414//
    1515
     
    219219        printf( "\n" );
    220220
    221         amemset( sta, fill, dim );                                                      // CFA array memset, type safe
     221        memset( sta, dim, fill );                           // CFA array memset, type safe
    222222        printf( "CFA array memset\n" );
    223223        for ( int i = 0; i < dim; i += 1 ) { printf( "%#x %a, ", sta[i].x, sta[i].y ); }
    224224        printf( "\n" );
    225225
    226         amemcpy( sta1, sta, dim );                                                      // CFA array memcpy, type safe
    227         printf( "CFA array memcpy\n" );
     226        memcpy( sta1, sta, dim );                           // CFA array memcpy, type safe
     227        printf( "CFA memcpy\n" );
    228228        for ( int i = 0; i < dim; i += 1 ) { printf( "%#x %a, ", sta1[i].x, sta1[i].y ); }
    229229        printf( "\n" );
Note: See TracChangeset for help on using the changeset viewer.