Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/stdlib.hfa

    r94429f8 r55acc3a  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov 12 08:12:08 2020
    13 // Update Count     : 515
     12// Last Modified On : Tue Sep  1 20:32:34 2020
     13// Update Count     : 505
    1414//
    1515
    1616#pragma once
    1717
    18 #include "bits/defs.hfa"                                                                // OPTIONAL_THREAD
    19 #include "bits/align.hfa"                                                               // libAlign
     18#include "bits/defs.hfa"
     19#include "bits/align.hfa"
    2020
    2121#include <stdlib.h>                                                                             // *alloc, strto*, ato*
     
    107107} // distribution
    108108
     109static inline forall( ttype TT | { void free( TT ); } ) {
     110        // T* does not take void* and vice-versa
     111
     112        void free( void * addr, TT rest ) {
     113                free( addr );
     114                free( rest );
     115        } // free
     116
     117        forall( dtype T | sized(T) )
     118        void free( T * addr, TT rest ) {
     119                free( addr );
     120                free( rest );
     121        } // free
     122} // distribution
     123
    109124/*
    110125        FIX ME : fix alloc interface after Ticker Number 214 is resolved, define and add union to S_fill. Then, modify postfix-fill functions to support T * with nmemb, char, and T object of any size. Finally, change alloc_internal.
     
    114129                forall( dtype T | sized(T) ) {
    115130                        union  U_fill           { char c; T * a; T t; };
    116                         struct S_fill           { char tag; U_fill(T) fill; };
     131                        struct S_fill           { char tag; char c; size_t size; T * at; char t[50]; };
    117132                        struct S_realloc        { inline T *; };
    118133                }
     
    162177static inline T_align   ?`align   ( size_t a )  { return (T_align){a}; }
    163178static inline T_resize  ?`resize  ( void * a )  { return (T_resize){a}; }
    164 
    165179static inline forall( dtype T | sized(T) ) {
     180
    166181        S_fill(T) ?`fill ( T t ) {
    167182                S_fill(T) ret = { 't' };
     
    235250
    236251        } // distribution TT
     252
    237253} // distribution T
    238254
     
    246262                return (T *)memcpy( dest, src, sizeof(T) );
    247263        } // memcpy
    248 
     264} // distribution
     265
     266static inline forall( dtype T | sized(T) ) {
    249267        // Cforall safe initialization/copy, i.e., implicit size specification, array types
    250268        T * amemset( T dest[], char fill, size_t dim ) {
     
    257275} // distribution
    258276
    259 // Cforall deallocation for multiple objects
    260 static inline forall( dtype T, ttype TT | { void free( TT ); } )
    261 void free( T * addr, TT rest ) {
    262         free( addr );
    263         free( rest );
    264 } // free
    265 
    266277// Cforall allocation/deallocation and constructor/destructor, non-array types
    267 static inline forall( dtype T | sized(T), ttype TT | { void ?{}( T &, TT ); } )
    268 T * new( TT p ) {
    269         return &(*malloc()){ p };                                                       // run constructor
    270 } // new
    271 
    272 static inline forall( dtype T | { void ^?{}( T & ); } )
    273 void delete( T * ptr ) {
    274         if ( ptr ) {                                                                            // ignore null
    275                 ^(*ptr){};                                                                              // run destructor
    276                 free( ptr );
    277         } // if
    278 } // delete
    279 
    280 static inline forall( dtype T, ttype TT | { void ^?{}( T & ); void delete( TT ); } )
    281 void delete( T * ptr, TT rest ) {
    282         delete( ptr );
    283         delete( rest );
    284 } // delete
     278forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * new( Params p );
     279forall( dtype T | { void ^?{}( T & ); } ) void delete( T * ptr );
     280forall( dtype T, ttype Params | { void ^?{}( T & ); void delete( Params ); } ) void delete( T * ptr, Params rest );
    285281
    286282// Cforall allocation/deallocation and constructor/destructor, array types
    287 forall( dtype T | sized(T), ttype TT | { void ?{}( T &, TT ); } ) T * anew( size_t dim, TT p );
     283forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * anew( size_t dim, Params p );
    288284forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void adelete( T arr[] );
    289 forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype TT | { void adelete( TT ); } ) void adelete( T arr[], TT rest );
     285forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype Params | { void adelete( Params ); } ) void adelete( T arr[], Params rest );
    290286
    291287//---------------------------------------
     
    383379//---------------------------------------
    384380
    385 extern bool threading_enabled( void ) OPTIONAL_THREAD;
     381extern bool threading_enabled(void) OPTIONAL_THREAD;
    386382
    387383// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.