Changeset 4e08a54 for libcfa/src


Ignore:
Timestamp:
Apr 19, 2024, 12:01:34 PM (8 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
b9b6efb
Parents:
da87eaf (diff), 02c80cdc (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

Location:
libcfa/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/collections/string.cfa

    rda87eaf r4e08a54  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb  7 21:17:06 2024
    13 // Update Count     : 259
     12// Last Modified On : Mon Apr 15 21:56:28 2024
     13// Update Count     : 260
    1414//
    1515
     
    198198        cstr[len] = '\0';                                                                       // terminate
    199199        _Ostream_Manip(const char *) cf @= { cstr, f.wd, f.pc, f.base, {f.all} };
    200         os | cf | nonl;
    201         return os;
     200        return os | cf | nonl;
    202201} // ?|?
    203202
  • libcfa/src/collections/string_res.cfa

    rda87eaf r4e08a54  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Feb 10 17:47:22 2024
    13 // Update Count     : 83
     12// Last Modified On : Mon Apr 15 21:56:27 2024
     13// Update Count     : 85
    1414//
    1515
     
    200200ofstream & ?|?(ofstream & out, const string_res & s) {
    201201        // CFA string is NOT null terminated, so print exactly lnth characters in a minimum width of 0.
    202         out | wd( 0, s.Handle.lnth, s.Handle.s ) | nonl;
    203         return out;
     202        return out | wd( 0, s.Handle.lnth, s.Handle.s ) | nonl;
    204203}
    205204
  • libcfa/src/stdlib.hfa

    rda87eaf r4e08a54  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Apr 12 07:39:15 2024
    13 // Update Count     : 812
     12// Last Modified On : Fri Apr 19 09:47:55 2024
     13// Update Count     : 826
    1414//
    1515
     
    4747
    4848static inline forall( T & | sized(T) ) {
    49         // CFA safe equivalents, i.e., implicit size specification
     49        // CFA safe equivalents, i.e., implicit size specification, eliminate return-type cast
    5050
    5151        T * malloc( void ) {
     
    6464        } // calloc
    6565
    66         T * resize( T * ptr, size_t size ) {                            // CFA resize, eliminate return-type cast
    67                 if ( _Alignof(T) <= libAlign() ) return (T *)resize( (void *)ptr, size ); // CFA resize
     66        T * resize( T * ptr, size_t size ) {
     67                if ( _Alignof(T) <= libAlign() ) return (T *)resize( (void *)ptr, size ); // C resize
    6868                else return (T *)resize( (void *)ptr, _Alignof(T), size ); // CFA resize
    6969        } // resize
    7070
    71         T * realloc( T * ptr, size_t size ) {                           // CFA realloc, eliminate return-type cast
     71        T * resize( T * ptr, size_t alignment, size_t size ) {
     72                return (T *)resize( (void *)ptr, alignment, size ); // CFA resize
     73        } // resize
     74
     75        T * realloc( T * ptr, size_t size ) {                           // CFA realloc
    7276                if ( _Alignof(T) <= libAlign() ) return (T *)realloc( (void *)ptr, size ); // C realloc
    7377                else return (T *)realloc( (void *)ptr, _Alignof(T), size ); // CFA realloc
    7478        } // realloc
    7579
     80        T * realloc( T * ptr, size_t alignment, size_t size ) {
     81                return (T *)realloc( (void *)ptr, alignment, size ); // CFA realloc
     82        } // realloc
     83
     84        T * reallocarray( T * ptr, size_t dim ) {                       // CFA reallocarray
     85                if ( _Alignof(T) <= libAlign() ) return (T *)reallocarray( (void *)ptr, dim, sizeof(T) ); // C reallocarray
     86                else return (T *)reallocarray( (void *)ptr, _Alignof(T), dim ); // CFA reallocarray
     87        } // realloc
     88
     89        T * reallocarray( T * ptr, size_t alignment, size_t dim ) {
     90                return (T *)reallocarray( (void *)ptr, alignment, dim ); // CFA reallocarray
     91        } // realloc
     92
    7693        T * memalign( size_t align ) {
    7794                return (T *)memalign( align, sizeof(T) );               // C memalign
     
    8299        } // amemalign
    83100
    84         T * cmemalign( size_t align, size_t dim  ) {
     101        T * cmemalign( size_t align, size_t dim ) {
    85102                return (T *)cmemalign( align, dim, sizeof(T) ); // CFA cmemalign
    86103        } // cmemalign
     
    159176static inline T_resize ?`resize( void * a )     { return (T_resize){a}; }
    160177
    161 extern "C" ssize_t write(int fd, const void *buf, size_t count);
    162178static inline forall( T & | sized(T) ) {
    163         S_fill(T) ?`fill ( T t ) {
     179        S_fill(T) ?`fill( T t ) {
    164180                S_fill(T) ret = { 't' };
    165181                size_t size = sizeof(T);
     
    170186                return ret;
    171187        }
    172         S_fill(T) ?`fill ( zero_t ) = void; // FIX ME: remove this once ticket 214 is resolved
    173         S_fill(T) ?`fill ( T * a ) { return (S_fill(T)){ 'T', '0', 0, a }; } // FIX ME: remove this once ticket 214 is resolved
    174         S_fill(T) ?`fill ( char c ) { return (S_fill(T)){ 'c', c };     }
    175         S_fill(T) ?`fill ( T a[], size_t nmemb ) { return (S_fill(T)){ 'a', '0', nmemb * sizeof(T), a }; }
     188        S_fill(T) ?`fill( zero_t ) = void; // FIX ME: remove this once ticket 214 is resolved
     189        S_fill(T) ?`fill( T * a ) { return (S_fill(T)){ 'T', '0', 0, a }; } // FIX ME: remove this once ticket 214 is resolved
     190        S_fill(T) ?`fill( char c ) { return (S_fill(T)){ 'c', c };      }
     191        S_fill(T) ?`fill( T a[], size_t nmemb ) { return (S_fill(T)){ 'a', '0', nmemb * sizeof(T), a }; }
    176192
    177193        S_realloc(T) ?`realloc ( T * a ) { return (S_realloc(T)){a}; }
     
    210226        } // alloc_internal$
    211227
    212         forall( TT... | { T * alloc_internal$( void *, T *, size_t, size_t, S_fill(T), TT ); } ) {
    213                 T * alloc_internal$( void *, T *, size_t Align, size_t Dim, S_fill(T) Fill, T_resize Resize, TT rest ) {
     228        forall( List ... | { T * alloc_internal$( void *, T *, size_t, size_t, S_fill(T), List ); } ) {
     229                T * alloc_internal$( void *, T *, size_t Align, size_t Dim, S_fill(T) Fill, T_resize Resize, List rest ) {
    214230                return alloc_internal$( Resize, (T*)0p, Align, Dim, Fill, rest);
    215231                }
    216232
    217                 T * alloc_internal$( void *, T *, size_t Align, size_t Dim, S_fill(T) Fill, S_realloc(T) Realloc, TT rest ) {
     233                T * alloc_internal$( void *, T *, size_t Align, size_t Dim, S_fill(T) Fill, S_realloc(T) Realloc, List rest ) {
    218234                return alloc_internal$( (void*)0p, Realloc, Align, Dim, Fill, rest);
    219235                }
    220236
    221                 T * alloc_internal$( void * Resize, T * Realloc, size_t, size_t Dim, S_fill(T) Fill, T_align Align, TT rest ) {
     237                T * alloc_internal$( void * Resize, T * Realloc, size_t, size_t Dim, S_fill(T) Fill, T_align Align, List rest ) {
    222238                return alloc_internal$( Resize, Realloc, Align, Dim, Fill, rest);
    223239                }
    224240
    225                 T * alloc_internal$( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T), S_fill(T) Fill, TT rest ) {
     241                T * alloc_internal$( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T), S_fill(T) Fill, List rest ) {
    226242                return alloc_internal$( Resize, Realloc, Align, Dim, Fill, rest );
    227243                }
    228244
    229             T * alloc( TT all ) {
     245            T * alloc( List all ) {
    230246                return alloc_internal$( (void*)0p, (T*)0p, (_Alignof(T) > libAlign() ? _Alignof(T) : libAlign()), (size_t)1, (S_fill(T)){'0'}, all );
    231247            }
    232248
    233             T * alloc( size_t dim, TT all ) {
     249            T * alloc( size_t dim, List all ) {
    234250                return alloc_internal$( (void*)0p, (T*)0p, (_Alignof(T) > libAlign() ? _Alignof(T) : libAlign()), dim, (S_fill(T)){'0'}, all );
    235251            }
    236         } // distribution TT
     252        } // distribution List
    237253} // distribution T
    238254
     
    258274
    259275// CFA deallocation for multiple objects
    260 static inline forall( T & )                                                     // FIX ME, problems with 0p in list
     276static inline forall( T & )
    261277void free( T * ptr ) {
    262278        free( (void *)ptr );                                                            // C free
    263279} // free
    264 static inline forall( T &, TT... | { void free( TT ); } )
    265 void free( T * ptr, TT rest ) {
     280static inline forall( T &, List ... | { void free( List ); } )
     281void free( T * ptr, List rest ) {
    266282        free( ptr );
    267283        free( rest );
     
    269285
    270286// CFA allocation/deallocation and constructor/destructor, non-array types
    271 static inline forall( T & | sized(T), TT... | { void ?{}( T &, TT ); } )
    272 T * new( TT p ) {
     287static inline forall( T & | sized(T), Parms ... | { void ?{}( T &, Parms ); } )
     288T * new( Parms p ) {
    273289        return &(*(T *)malloc()){ p };                                          // run constructor
    274290} // new
     
    282298        free( ptr );                                                                            // always call free
    283299} // delete
    284 static inline forall( T &, TT... | { void ^?{}( T & ); void delete( TT ); } )
    285 void delete( T * ptr, TT rest ) {
     300static inline forall( T &, List ... | { void ^?{}( T & ); void delete( List ); } )
     301void delete( T * ptr, List rest ) {
    286302        delete( ptr );
    287303        delete( rest );
     
    289305
    290306// CFA allocation/deallocation and constructor/destructor, array types
    291 forall( T & | sized(T), TT... | { void ?{}( T &, TT ); } ) T * anew( size_t dim, TT p );
     307forall( T & | sized(T), Parms ... | { void ?{}( T &, Parms ); } ) T * anew( size_t dim, Parms p );
    292308forall( T & | sized(T) | { void ^?{}( T & ); } ) void adelete( T arr[] );
    293 forall( T & | sized(T) | { void ^?{}( T & ); }, TT... | { void adelete( TT ); } ) void adelete( T arr[], TT rest );
     309forall( T & | sized(T) | { void ^?{}( T & ); }, List ... | { void adelete( List ); } ) void adelete( T arr[], List rest );
     310
    294311//---------------------------------------
    295312
  • libcfa/src/time.hfa

    rda87eaf r4e08a54  
    1010// Created On       : Wed Mar 14 23:18:57 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Oct  8 09:07:48 2022
    13 // Update Count     : 668
     12// Last Modified On : Thu Apr 18 12:07:21 2024
     13// Update Count     : 670
    1414//
    1515
     
    8484        Duration ?`m( int64_t min ) { return (Duration)@{ min * (60LL * TIMEGRAN) }; }
    8585        Duration ?`m( double min ) { return (Duration)@{ min * (60LL * TIMEGRAN) }; }
    86         Duration ?`h( int64_t hours ) { return (Duration)@{ hours * (60LL * 60LL * TIMEGRAN) }; }
    87         Duration ?`h( double hours ) { return (Duration)@{ hours * (60LL * 60LL * TIMEGRAN) }; }
    88         Duration ?`d( int64_t days ) { return (Duration)@{ days * (24LL * 60LL * 60LL * TIMEGRAN) }; }
    89         Duration ?`d( double days ) { return (Duration)@{ days * (24LL * 60LL * 60LL * TIMEGRAN) }; }
    90         Duration ?`w( int64_t weeks ) { return (Duration)@{ weeks * (7LL * 24LL * 60LL * 60LL * TIMEGRAN) }; }
    91         Duration ?`w( double weeks ) { return (Duration)@{ weeks * (7LL * 24LL * 60LL * 60LL * TIMEGRAN) }; }
     86        Duration ?`h( int64_t hour ) { return (Duration)@{ hour * (60LL * 60LL * TIMEGRAN) }; }
     87        Duration ?`h( double hour ) { return (Duration)@{ hour * (60LL * 60LL * TIMEGRAN) }; }
     88        Duration ?`d( int64_t day ) { return (Duration)@{ day * (24LL * 60LL * 60LL * TIMEGRAN) }; }
     89        Duration ?`d( double day ) { return (Duration)@{ day * (24LL * 60LL * 60LL * TIMEGRAN) }; }
     90        Duration ?`w( int64_t week ) { return (Duration)@{ week * (7LL * 24LL * 60LL * 60LL * TIMEGRAN) }; }
     91        Duration ?`w( double week ) { return (Duration)@{ week * (7LL * 24LL * 60LL * 60LL * TIMEGRAN) }; }
    9292
    9393        int64_t ?`ns( Duration dur ) { return dur.tn; }
Note: See TracChangeset for help on using the changeset viewer.