Changeset 3d02803 for libcfa/src


Ignore:
Timestamp:
Sep 24, 2025, 6:31:58 PM (5 months ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
master, stuck-waitfor-destruct
Children:
843bce5
Parents:
78bc398 (diff), 1911f37 (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 remote-tracking branch 'refs/remotes/origin/master'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/stdlib.cfa

    r78bc398 r3d02803  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Apr 21 16:17:22 2024
    13 // Update Count     : 700
     12// Last Modified On : Wed Sep 24 18:14:20 2025
     13// Update Count     : 760
    1414//
    1515
     
    3333forall( T & | sized(T), Parms ... | { void ?{}( T &, Parms ); } )
    3434T * anew( size_t dim, Parms p ) {
    35         T * arr = alloc( dim );
     35        T * arr;
     36        if ( sizeof( T ) == 0 ) {                                                       // empty element size ?
     37                arr = (T *)(size_t *)alloc();                                   // create fake array
     38                *((size_t *)arr) = dim;                                                 // remember dimension
     39        } else arr = alloc( dim );
    3640        for ( i; dim ) {
    3741                (arr[i]){ p };                                                                  // run constructor
     
    4246forall( T & | sized(T) | { void ^?{}( T & ); } )
    4347void adelete( T arr[] ) {
    44         if ( arr ) {                                                                            // ignore null
    45                 size_t dim = malloc_size( arr ) / sizeof( T );
    46                 for ( i; 0 -~= dim - 1 ) {                                              // reverse allocation order, must be unsigned
    47                         ^(arr[i]){};                                                            // run destructor
    48                 } // for
    49                 free( arr );
    50         } // if
     48  if ( arr == 0p ) return;                                                              // 0p ? special case
     49        size_t dim = sizeof( T ) == 0 ? (size_t)(*(size_t *)arr) : malloc_size( arr ) / sizeof( T ); // compute dimension
     50        for ( i; 0 -~= dim - 1 ) {                                                      // reverse allocation order, must be signed
     51                ^(arr[i]){};                                                                    // run destructor
     52        } // for
     53        if ( sizeof( T ) == 0 ) free( (size_t *)arr ); else free( arr );
    5154} // adelete
    5255
    5356forall( T & | sized(T) | { void ^?{}( T & ); }, List ... | { void adelete( List ); } )
    5457void adelete( T arr[], List rest ) {
    55         if ( arr ) {                                                                            // ignore null
    56                 size_t dim = malloc_size( arr ) / sizeof( T );
    57                 for ( i; 0 -~= dim - 1 ) {                                              // reverse allocation order, must be unsigned
    58                         ^(arr[i]){};                                                            // run destructor
    59                 } // for
    60                 free( arr );
    61         } // if
     58        adelete( arr );
    6259        adelete( rest );
    6360} // adelete
     
    6865
    6966bool checkif( const char s[], int (* kind)( int ) ) {
    70         for () {
    71                 if ( *s == '\0' ) return true;
    72                 if ( ! kind( *s ) ) return false;
     67        for () {                                                                                        // at least 1 character '\0'
     68          if ( *s == '\0' ) return true;
     69          if ( ! kind( *s ) ) return false;
    7370                s += 1;
    7471        } // for
     
    7673
    7774bool checkif( const char s[], int (* kind)( int, locale_t ), locale_t locale ) {
    78         for () {
    79                 if ( *s == '\0' ) return true;
    80                 if ( ! kind( *s, locale ) ) return false;
     75        for () {                                                                                        // at least 1 character '\0'
     76          if ( *s == '\0' ) return true;
     77          if ( ! kind( *s, locale ) ) return false;
    8178                s += 1;
    8279        } // for
Note: See TracChangeset for help on using the changeset viewer.