Changeset 3d02803


Ignore:
Timestamp:
Sep 24, 2025, 6:31:58 PM (4 months ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
master
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'

Files:
1 deleted
3 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
  • tests/.expect/alloc.txt

    r78bc398 r3d02803  
    767642 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5,
    777742 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5, 42 42.5,
     78ctor
     79ctor
     80ctor
     81ctor
     82ctor
     83ctor
     84ctor
     85ctor
     86ctor
     87ctor
     88ctor
     89ctor
     90ctor
     91ctor
     92ctor
     93dtor
     94dtor
     95dtor
     96dtor
     97dtor
     98dtor
     99dtor
     100dtor
     101dtor
     102dtor
     103dtor
     104dtor
     105dtor
     106dtor
     107dtor
    78108
    79109pointer arithmetic 0
  • tests/alloc.cfa

    r78bc398 r3d02803  
    1010// Created On       : Wed Feb  3 07:56:22 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Apr 23 14:04:11 2024
    13 // Update Count     : 492
     12// Last Modified On : Wed Sep 24 18:21:09 2025
     13// Update Count     : 493
    1414//
    1515
     
    362362        assert( const_count == 2 + 2 * dim && dest_count == 2 + 2 * dim); // assertion for testing
    363363
     364        struct Empty {};
     365        void ?{}( Empty & ) { sout | "ctor"; }
     366        void ^?{}( Empty & ) { sout | "dtor"; }
     367        Empty * ea1 = anew( 5 );
     368        Empty * ea2 = anew( 5 );
     369        Empty * ea3 = anew( 5 );
     370        adelete( ea1, ea2, ea3 );
     371
    364372        // extras
    365373        sout | nl;
Note: See TracChangeset for help on using the changeset viewer.