Changeset 4803a901


Ignore:
Timestamp:
Dec 12, 2020, 2:04:53 PM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
aac5dfd, b4aa1ab
Parents:
2dda05d
Message:

support freeing ("free") multiple objects using ttype

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/stdlib.hfa

    r2dda05d r4803a901  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec  8 18:27:22 2020
    13 // Update Count     : 524
     12// Last Modified On : Sat Dec 12 13:52:34 2020
     13// Update Count     : 536
    1414//
    1515
     
    4949
    5050static inline forall( dtype T | sized(T) ) {
    51         // Cforall safe equivalents, i.e., implicit size specification
     51        // CFA safe equivalents, i.e., implicit size specification
    5252
    5353        T * malloc( void ) {
     
    234234
    235235static inline forall( dtype T | sized(T) ) {
    236         // Cforall safe initialization/copy, i.e., implicit size specification, non-array types
     236        // CFA safe initialization/copy, i.e., implicit size specification, non-array types
    237237        T * memset( T * dest, char fill ) {
    238238                return (T *)memset( dest, fill, sizeof(T) );
     
    243243        } // memcpy
    244244
    245         // Cforall safe initialization/copy, i.e., implicit size specification, array types
     245        // CFA safe initialization/copy, i.e., implicit size specification, array types
    246246        T * amemset( T dest[], char fill, size_t dim ) {
    247247                return (T *)(void *)memset( dest, fill, dim * sizeof(T) ); // C memset
     
    253253} // distribution
    254254
    255 // Cforall deallocation for multiple objects
     255// CFA deallocation for multiple objects
     256static inline forall( dtype T )                                                 // FIX ME, problems with 0p in list
     257void free( T * ptr ) {
     258        free( (void *)ptr );                                                            // C free
     259} // free
    256260static inline forall( dtype T, ttype TT | { void free( TT ); } )
    257 void free( T * addr, TT rest ) {
    258         free( ( void *)addr );                                                          // use C free
     261void free( T * ptr, TT rest ) {
     262        free( ptr );
    259263        free( rest );
    260264} // free
    261265
    262 // Cforall allocation/deallocation and constructor/destructor, non-array types
     266// CFA allocation/deallocation and constructor/destructor, non-array types
    263267static inline forall( dtype T | sized(T), ttype TT | { void ?{}( T &, TT ); } )
    264268T * new( TT p ) {
     
    272276                ^(*ptr){};                                                                              // run destructor
    273277        } // if
    274         free( ptr );
     278        free( ptr );                                                                            // always call free
    275279} // delete
    276 
    277280static inline forall( dtype T, ttype TT | { void ^?{}( T & ); void delete( TT ); } )
    278281void delete( T * ptr, TT rest ) {
     
    281284} // delete
    282285
    283 // Cforall allocation/deallocation and constructor/destructor, array types
     286// CFA allocation/deallocation and constructor/destructor, array types
    284287forall( dtype T | sized(T), ttype TT | { void ?{}( T &, TT ); } ) T * anew( size_t dim, TT p );
    285288forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void adelete( T arr[] );
Note: See TracChangeset for help on using the changeset viewer.