Changeset 74b19fb for src/libcfa/stdlib
- Timestamp:
- May 14, 2018, 8:43:44 AM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
- Children:
- 1dbc8590
- Parents:
- a83d08b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/stdlib
ra83d08b r74b19fb 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jan 2 12:21:04201813 // Update Count : 29 212 // Last Modified On : Sun May 13 23:22:23 2018 13 // Update Count : 299 14 14 // 15 15 16 16 #pragma once 17 17 18 //#define _XOPEN_SOURCE 600 // posix_memalign, *rand48 18 #define __USE_ISOC11 // aligned_alloc 19 19 #include <stdlib.h> // strto*, *abs 20 20 … … 28 28 //--------------------------------------- 29 29 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 30 // C dynamic allocation 31 static inline forall( dtype T | sized(T) ) { 32 T * malloc( void ) { 33 // printf( "* malloc\n" ); 34 return (T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc 35 } // malloc 36 37 // T & malloc( void ) { 38 // int & p = *(T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc 39 // printf( "& malloc %p\n", &p ); 40 // return p; 41 // // return (T &)*(T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc 42 // } // malloc 43 44 T * calloc( size_t dim ) { 45 //printf( "X2\n" ); 46 return (T *)(void *)calloc( dim, sizeof(T) ); // C calloc 47 } // calloc 48 49 T * realloc( T * ptr, size_t size ) { 50 //printf( "X3\n" ); 51 return (T *)(void *)realloc( (void *)ptr, size ); 52 } // realloc 53 54 extern "C" { void * memalign( size_t align, size_t size ); } // use default C routine for void * 55 T * memalign( size_t align ) { 56 //printf( "X4\n" ); 57 return (T *)memalign( align, sizeof(T) ); 58 } // memalign 59 60 extern "C" { void * aligned_alloc( size_t align, size_t size ); } // use default C routine for void * 61 T * aligned_alloc( size_t align ) { 62 //printf( "X5\n" ); 63 return (T *)aligned_alloc( align, sizeof(T) ); 64 } // aligned_alloc 65 66 int posix_memalign( T ** ptr, size_t align ) { 67 //printf( "X6\n" ); 68 return posix_memalign( (void **)ptr, align, sizeof(T) ); // C posix_memalign 69 } // posix_memalign 70 71 72 // Cforall dynamic allocation 73 extern "C" { void * memset( void * dest, int c, size_t size ); } // use default C routine for void * 74 75 T * alloc( void ) { 76 //printf( "X7\n" ); 77 return (T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc 78 } // alloc 79 80 T * alloc( char fill ) { 81 //printf( "X8\n" ); 82 T * ptr = (T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc 83 return (T *)memset( ptr, (int)fill, sizeof(T) ); // initial with fill value 84 } // alloc 85 86 T * alloc( size_t dim ) { 87 //printf( "X9\n" ); 88 return (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc 89 } // alloc 90 91 T * alloc( size_t dim, char fill ) { 92 //printf( "X10\n" ); 93 T * ptr = (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc 94 return (T *)memset( ptr, (int)fill, dim * sizeof(T) ); // initial with fill value 95 } // alloc 96 97 T * alloc( T ptr[], size_t dim ) { 98 //printf( "X11\n" ); 99 return (T *)(void *)realloc( (void *)ptr, dim * (size_t)sizeof(T) ); // C realloc 100 } // alloc 101 } // distribution 102 103 99 104 forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill ); 100 105
Note: See TracChangeset
for help on using the changeset viewer.