Changeset ff29f08 for src/libcfa/stdlib


Ignore:
Timestamp:
May 18, 2018, 2:09:21 PM (7 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
new-env, with_gc
Children:
2472a19
Parents:
f6f0cca3 (diff), c7d8100c (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 'origin/master' into with_gc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/stdlib

    rf6f0cca3 rff29f08  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jan  2 12:21:04 2018
    13 // Update Count     : 292
     12// Last Modified On : Wed May 16 07:53:10 2018
     13// Update Count     : 300
    1414//
    1515
    1616#pragma once
    1717
    18 //#define _XOPEN_SOURCE 600                                                             // posix_memalign, *rand48
    1918#include <stdlib.h>                                                                             // strto*, *abs
    2019
     
    2827//---------------------------------------
    2928
    30 // allocation, non-array types
    31 static inline forall( dtype T | sized(T) ) T * malloc( void ) {
    32         // printf( "* malloc\n" );
    33         return (T *)(void *)malloc( (size_t)sizeof(T) );        // C malloc
    34 } // malloc
    35 
    36 // static inline forall( dtype T | sized(T) ) T & malloc( void ) {
    37 //      int & p = *(T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc
    38 //      printf( "& malloc %p\n", &p );
    39 //      return p;
    40 // //   return (T &)*(T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc
    41 // } // malloc
    42 
    43 extern "C" { void * calloc( size_t dim, size_t size ); } // default C routine
    44 static inline forall( dtype T | sized(T) ) T * calloc( size_t dim ) {
    45         //printf( "X2\n" );
    46         return (T *)(void *)calloc( dim, sizeof(T) );           // C cmalloc
    47 }
    48 
    49 extern "C" { void * realloc( void * ptr, size_t size ); } // default C routine for void *
    50 static inline forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size ) {
    51         //printf( "X3\n" );
    52         return (T *)(void *)realloc( (void *)ptr, size );
    53 }
    54 
    55 extern "C" { void * memalign( size_t align, size_t size ); } // use default C routine for void *
    56 static inline forall( dtype T | sized(T) ) T * memalign( size_t align ) {
    57         //printf( "X4\n" );
    58         return (T *)memalign( align, sizeof(T) );
    59 } // memalign
    60 
    61 static inline forall( dtype T | sized(T) ) T * aligned_alloc( size_t align ) {
    62         //printf( "X5\n" );
    63         return (T *)memalign( align, sizeof(T) );
    64 } // aligned_alloc
    65 
    66 extern "C" { int posix_memalign( void ** ptr, size_t align, size_t size ); } // use default C routine for void *
    67 static inline forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t align ) {
    68         //printf( "X6\n" );
    69         return posix_memalign( (void **)ptr, align, sizeof(T) );
    70 } // posix_memalign
    71 
    72 
    73 extern "C" { void * memset( void * dest, int c, size_t size ); } // use default C routine for void *
    74 
    75 static inline forall( dtype T | sized(T) ) T * alloc( void ) {
    76         //printf( "X7\n" );
    77         return (T *)(void *)malloc( (size_t)sizeof(T) );        // C malloc
    78 } // alloc
    79 static inline forall( dtype T | sized(T) ) T * alloc( char fill ) {
    80         //printf( "X8\n" );
    81         T * ptr = (T *)(void *)malloc( (size_t)sizeof(T) );     // C malloc
    82     return (T *)memset( ptr, (int)fill, sizeof(T) );    // initial with fill value
    83 } // alloc
    84 
    85 static inline forall( dtype T | sized(T) ) T * alloc( size_t dim ) {
    86         //printf( "X9\n" );
    87         return (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc
    88 } // alloc
    89 static inline forall( dtype T | sized(T) ) T * alloc( size_t dim, char fill ) {
    90         //printf( "X10\n" );
    91         T * ptr = (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc
    92     return (T *)memset( ptr, (int)fill, dim * sizeof(T) );
    93 } // alloc
    94 
    95 static inline forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim ) {
    96         //printf( "X11\n" );
    97         return (T *)(void *)realloc( (void *)ptr, dim * (size_t)sizeof(T) ); // C realloc
    98 } // alloc
     29// C dynamic allocation
     30static inline forall( dtype T | sized(T) ) {
     31        T * malloc( void ) {
     32                // printf( "* malloc\n" );
     33                return (T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc
     34        } // malloc
     35
     36        // T & malloc( void ) {
     37        //      int & p = *(T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc
     38        //      printf( "& malloc %p\n", &p );
     39        //      return p;
     40        //      //      return (T &)*(T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc
     41        // } // malloc
     42
     43        T * calloc( size_t dim ) {
     44                //printf( "X2\n" );
     45                return (T *)(void *)calloc( dim, sizeof(T) );   // C calloc
     46        } // calloc
     47
     48        T * realloc( T * ptr, size_t size ) {
     49                //printf( "X3\n" );
     50                return (T *)(void *)realloc( (void *)ptr, size );
     51        } // realloc
     52
     53        extern "C" { void * memalign( size_t align, size_t size ); } // use default C routine for void *
     54        T * memalign( size_t align ) {
     55                //printf( "X4\n" );
     56                return (T *)memalign( align, sizeof(T) );
     57        } // memalign
     58
     59        extern "C" { void * aligned_alloc( size_t align, size_t size ); } // use default C routine for void *
     60        T * aligned_alloc( size_t align ) {
     61                //printf( "X5\n" );
     62                return (T *)aligned_alloc( align, sizeof(T) );
     63        } // aligned_alloc
     64
     65        int posix_memalign( T ** ptr, size_t align ) {
     66                //printf( "X6\n" );
     67                return posix_memalign( (void **)ptr, align, sizeof(T) ); // C posix_memalign
     68        } // posix_memalign
     69
     70
     71        // Cforall dynamic allocation
     72        extern "C" { void * memset( void * dest, int c, size_t size ); } // use default C routine for void *
     73
     74        T * alloc( void ) {
     75                //printf( "X7\n" );
     76                return (T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc
     77        } // alloc
     78
     79        T * alloc( char fill ) {
     80                //printf( "X8\n" );
     81                T * ptr = (T *)(void *)malloc( (size_t)sizeof(T) );     // C malloc
     82                return (T *)memset( ptr, (int)fill, sizeof(T) );        // initial with fill value
     83        } // alloc
     84
     85        T * alloc( size_t dim ) {
     86                //printf( "X9\n" );
     87                return (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc
     88        } // alloc
     89
     90        T * alloc( size_t dim, char fill ) {
     91                //printf( "X10\n" );
     92                T * ptr = (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc
     93                return (T *)memset( ptr, (int)fill, dim * sizeof(T) );    // initial with fill value
     94        } // alloc
     95
     96        T * alloc( T ptr[], size_t dim ) {
     97                //printf( "X11\n" );
     98                return (T *)(void *)realloc( (void *)ptr, dim * (size_t)sizeof(T) ); // C realloc
     99        } // alloc
     100} // distribution
     101
     102
    99103forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill );
    100104
Note: See TracChangeset for help on using the changeset viewer.