Ignore:
Timestamp:
Sep 1, 2020, 8:05:48 PM (3 years ago)
Author:
m3zulfiq <m3zulfiq@…>
Branches:
arm-eh, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
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)

File:
1 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                }
Note: See TracChangeset for help on using the changeset viewer.