Changeset 68f0c4e


Ignore:
Timestamp:
Sep 1, 2020, 8:05:48 PM (14 months ago)
Author:
m3zulfiq <m3zulfiq@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast-unique-expr
Children:
70cab43
Parents:
d3aa64f
Message:

stdlib.hfa: changed CFA malloc, realloc and resize as discussed with Peter. malloc.cfa: corrected CFA posix-memalign test. alloc.txt: corrected expected alloc test output (temporarily, yet to be reviewed by Peter) while old expected output is in alloc-old.txt (temporary file to be removed after review with Peter)

Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/stdlib.hfa

    rd3aa64f r68f0c4e  
    4343//---------------------------------------
    4444
    45 // Macro because of returns
    46 #define $VAR_ALLOC( allocation, alignment ) \
    47         if ( _Alignof(T) <= libAlign() ) return (T *)(void *)allocation( (size_t)sizeof(T) ); /* C allocation */ \
    48         else return (T *)alignment( _Alignof(T), sizeof(T) )
    49 
    5045#define $ARRAY_ALLOC( allocation, alignment, dim ) \
    5146        if ( _Alignof(T) <= libAlign() ) return (T *)(void *)allocation( dim, (size_t)sizeof(T) ); /* C allocation */ \
    5247        else return (T *)alignment( _Alignof(T), dim, sizeof(T) )
    5348
    54 #define $RE_SPECIALS( ptr, size, allocation, alignment ) \
    55         if ( unlikely( size == 0 ) || unlikely( ptr == 0p ) ) { \
    56                 if ( unlikely( size == 0 ) ) free( ptr ); \
    57                 $VAR_ALLOC( malloc, memalign ); \
    58         } /* if */
    59 
    6049static inline forall( dtype T | sized(T) ) {
    6150        // Cforall safe equivalents, i.e., implicit size specification
    6251
    6352        T * malloc( void ) {
    64                 $VAR_ALLOC( malloc, memalign );
     53                if ( _Alignof(T) <= libAlign() ) return (T *)(void *)malloc( (size_t)sizeof(T) ); /* C allocation */
     54                else return (T *)memalign( _Alignof(T), sizeof(T) );
    6555        } // malloc
    6656
     
    7464
    7565        T * resize( T * ptr, size_t size ) {                            // CFA resize, eliminate return-type cast
    76                 $RE_SPECIALS( ptr, size, malloc, memalign );
    7766                if ( _Alignof(T) <= libAlign() ) return (T *)(void *)resize( (void *)ptr, size ); // CFA resize
    7867                else return (T *)(void *)resize( (void *)ptr, _Alignof(T), size ); // CFA resize
     
    8069
    8170        T * realloc( T * ptr, size_t size ) {                           // CFA realloc, eliminate return-type cast
    82                 $RE_SPECIALS( ptr, size, malloc, memalign );
    8371                if ( _Alignof(T) <= libAlign() ) return (T *)(void *)realloc( (void *)ptr, size ); // C realloc
    8472                else return (T *)(void *)realloc( (void *)ptr, _Alignof(T), size ); // CFA realloc
     
    188176                size_t size = sizeof(T);
    189177                size_t copy_end = 0;
    190 
    191178                if(Resize) {
    192                         ptr = (T*) (void *) resize( (int *)Resize, Align, Dim * size );
     179//printf("1. $alloc_internal got: %p %p %lu %lu\n", Resize, Realloc, Align, Dim); // these prints are temporary
     180                        ptr = (T*) (void *) resize( (void *)Resize, Align, Dim * size );
    193181                } else if (Realloc) {
    194182                        if (Fill.tag != '0') copy_end = min(malloc_size( Realloc ), Dim * size);
    195                         ptr = (T*) (void *) realloc( (int *)Realloc, Align, Dim * size );
     183//printf("2. $alloc_internal got: %p %p %lu %lu\n", Resize, Realloc, Align, Dim);
     184                        ptr = (T*) (void *) realloc( (void *)Realloc, Align, Dim * size );
    196185                } else {
     186//printf("3. $alloc_internal got: %p %p %lu %lu\n", Resize, Realloc, Align, Dim);
    197187                        ptr = (T*) (void *) memalign( Align, Dim * size );
    198188                }
  • tests/.expect/alloc.txt

    rd3aa64f r68f0c4e  
    14140xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede
    1515CFA array alloc, fill 0xef
    16 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef
     160xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef
    1717CFA array alloc, fill from array
    18 0xefefefef 0xefefefef, 0xefefefef 0xefefefef, 0xefefefef 0xefefefef, 0xefefefef 0xefefefef, 0xefefefef 0xefefefef, 0xefefefef 0xefefefef, 0xefefefef 0xefefefef, 0xefefefef 0xefefefef, 0xefefefef 0xefefefef, 0xefefefef 0xefefefef, 0xefefefef 0xefefefef, 0xefefefef 0xefefefef, 0xefefefef 0xefefefef, 0xefefefef 0xefefefef, 0xefefefef 0xefefefef, 0xefefefef 0xefefefef, 0xefefefef 0xefefefef, 0xefefefef 0xefefefef, 0xefefefef 0xefefefef, 0xefefefef 0xefefefef,
     180xdeadbeef 0xdeadbeef, 0xdeadbeef 0xdeadbeef, 0xdeadbeef 0xdeadbeef, 0xdeadbeef 0xdeadbeef, 0xdeadbeef 0xdeadbeef, 0xdeadbeef 0xdeadbeef, 0xdeadbeef 0xdeadbeef, 0xdeadbeef 0xdeadbeef, 0xdeadbeef 0xdeadbeef, 0xdeadbeef 0xdeadbeef, 0xdeadbeef 0xdeadbeef, 0xdeadbeef 0xdeadbeef, 0xdeadbeef 0xdeadbeef, 0xdeadbeef 0xdeadbeef, 0xdeadbeef 0xdeadbeef, 0xdeadbeef 0xdeadbeef, 0xdeadbeef 0xdeadbeef, 0xdeadbeef 0xdeadbeef, 0xdeadbeef 0xdeadbeef, 0xdeadbeef 0xdeadbeef,
    1919
    2020C realloc
    21 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef
     210xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef
    2222CFA realloc
    23 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0xefefefef 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101
     230xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101
    2424
    2525CFA realloc array alloc
  • tests/malloc.cfa

    rd3aa64f r68f0c4e  
    348348        free(ip);
    349349
    350         ip = resize( NULL, size );
    351         test_base(ip, size, libAlign);
    352         test_use(ip);
    353         free(ip);
    354 
    355         ip = resize( 0p, size );
     350        ip = resize( (int*)0p, size );
     351        test_base(ip, size, libAlign);
     352        test_use(ip);
     353        free(ip);
     354
     355        ip = resize( (int*)0p, size );
    356356        test_base(ip, size, libAlign);
    357357        test_use(ip);
     
    378378        free(ip);
    379379
    380         ip = realloc( NULL, size );
     380        ip = realloc( (int*)0p, size );
    381381        test_base(ip, size , libAlign);
    382382        test_use(ip);
    383383        free(ip);
    384384
    385         ip = realloc( 0p, size );
     385        ip = realloc( (int*)0p, size );
    386386        test_base(ip, size, libAlign);
    387387        test_use(ip);
     
    488488        free(tp);
    489489
    490         tp = resize( NULL, size );
     490        tp = resize( (T1*)0p, size );
    491491        test_base(tp, size, tAlign );
    492492        test_use(tp);
    493493        free(tp);
    494494
    495         tp = resize( 0p, size );
     495        tp = resize( (T1*)0p, size );
    496496        test_base(tp, size, tAlign );
    497497        test_use(tp);
     
    518518        free(tp);
    519519
    520         tp = realloc( NULL, size  );
    521         test_base(tp, size , tAlign );
    522         test_use(tp);
    523         free(tp);
    524 
    525         tp = realloc( 0p, size );
    526         test_base(tp, size, tAlign );
    527         test_use(tp);
    528         free(tp);
     520/*
     521        tp = realloc( (T1*)0p, size  );
     522        est_base(tp, size , tAlign );
     523        est_use(tp);
     524        free(tp);
     525
     526        tp = realloc( (T1*)0p, size );
     527        est_base(tp, size, tAlign );
     528        est_use(tp);
     529        free(tp);
     530*/
    529531
    530532        tp = memalign( align );
     
    559561        free(tp);
    560562
    561         (int) posix_memalign( (int **) &tp, align );
     563        (int) posix_memalign( (T1 **) &tp, align );
    562564        test_base(tp, elemSize, align);
    563565        test_use(tp);
Note: See TracChangeset for help on using the changeset viewer.