Changeset eb5a115 for tests/alloc.cfa
- Timestamp:
- Oct 21, 2019, 10:20:05 AM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 89124ff
- Parents:
- cafb687
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/alloc.cfa
rcafb687 reb5a115 10 10 // Created On : Wed Feb 3 07:56:22 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Nov 6 17:50:52 201813 // Update Count : 3 3912 // Last Modified On : Sun Oct 20 21:45:21 2019 13 // Update Count : 391 14 14 // 15 15 … … 19 19 #include <stdlib.h> // posix_memalign 20 20 #include <fstream.hfa> 21 #include <stdlib.hfa> 21 #include <stdlib.hfa> // access C malloc, realloc 22 22 23 23 int * foo( int * p, int c ) { return p; } … … 27 27 int main( void ) { 28 28 size_t dim = 10; 29 char fill = '\x ff';30 int * p ;29 char fill = '\xde'; 30 int * p, * p1; 31 31 32 32 // allocation, non-array types 33 34 // int & r = malloc();35 // r = 0xdeadbeef;36 // printf( "C malloc %#x\n", r );37 // free( &r );38 33 39 34 p = (int *)malloc( sizeof(*p) ); // C malloc, type unsafe … … 52 47 free( p ); 53 48 54 p = alloc( fill ); // CFA alloc, fill 49 p = alloc_set( fill ); // CFA alloc, fill 50 printf( "CFA array alloc, fill %#hhx\n", fill ); 55 51 printf( "CFA alloc, fill %08x\n", *p ); 52 free( p ); 53 54 p = alloc_set( 3 ); // CFA alloc, fill 55 printf( "CFA alloc, fill %d\n", *p ); 56 56 free( p ); 57 57 … … 79 79 free( p ); 80 80 81 p = alloc ( 2 * dim, fill );// CFA array alloc, fill81 p = alloc_set( 2 * dim, fill ); // CFA array alloc, fill 82 82 printf( "CFA array alloc, fill %#hhx\n", fill ); 83 83 for ( i; 2 * dim ) { printf( "%#x ", p[i] ); } 84 84 printf( "\n" ); 85 // do not free 85 free( p ); 86 87 p = alloc_set( 2 * dim, 0xdeadbeef ); // CFA array alloc, fill 88 printf( "CFA array alloc, fill %#hhx\n", 0xdeadbeef ); 89 for ( i; 2 * dim ) { printf( "%#x ", p[i] ); } 90 printf( "\n" ); 91 // do not free 92 93 p1 = alloc_set( 2 * dim, p ); // CFA array alloc, fill 94 printf( "CFA array alloc, fill from array\n" ); 95 for ( i; 2 * dim ) { printf( "%#x %#x, ", p[i], p1[i] ); } 96 free( p1 ); 97 printf( "\n" ); 86 98 87 99 … … 90 102 91 103 p = (int *)realloc( p, dim * sizeof(*p) ); // C realloc 92 for ( i; dim ) { p[i] = 0xdeadbeef; }93 printf( "C realloc\n" );94 for ( i; dim ) { printf( "%#x ", p[i] ); }95 printf( "\n" );104 printf( "C realloc\n" ); 105 for ( i; dim ) { printf( "%#x ", p[i] ); } 106 printf( "\n" ); 107 // do not free 96 108 97 109 p = realloc( p, 2 * dim * sizeof(*p) ); // CFA realloc … … 108 120 p = alloc( p, dim ); // CFA resize array alloc 109 121 for ( i; dim ) { p[i] = 0xdeadbeef; } 110 printf( "CFA resize alloc\n" ); 111 for ( i; dim ) { printf( "%#x ", p[i] ); } 112 printf( "\n" ); 122 printf( "CFA resize array alloc\n" ); 123 for ( i; dim ) { printf( "%#x ", p[i] ); } 124 printf( "\n" ); 125 // do not free 113 126 114 127 p = alloc( p, 2 * dim ); // CFA resize array alloc … … 117 130 for ( i; 2 * dim ) { printf( "%#x ", p[i] ); } 118 131 printf( "\n" ); 119 120 p = alloc( p, dim ); // CFA array alloc 132 // do not free 133 134 p = alloc( p, dim ); // CFA resize array alloc 121 135 printf( "CFA resize array alloc\n" ); 122 136 for ( i; dim ) { printf( "%#x ", p[i] ); } 123 137 printf( "\n" ); 124 125 free( p ); 126 p = 0; 127 128 p = alloc( p, dim, fill ); // CFA array alloc, fill 138 // do not free 139 140 p = alloc_set( p, 3 * dim, fill ); // CFA resize array alloc, fill 129 141 printf( "CFA resize array alloc, fill\n" ); 130 for ( i; dim ) { printf( "%#x ", p[i] ); } 131 printf( "\n" ); 132 133 p = alloc( p, 2 * dim, fill ); // CFA array alloc, fill 142 for ( i; 3 * dim ) { printf( "%#x ", p[i] ); } 143 printf( "\n" ); 144 // do not free 145 146 p = alloc_set( p, dim, fill ); // CFA resize array alloc, fill 134 147 printf( "CFA resize array alloc, fill\n" ); 135 for ( i; 2 * dim ) { printf( "%#x ", p[i] ); } 136 printf( "\n" ); 137 138 p = alloc( p, dim, fill ); // CFA array alloc, fill 148 for ( i; dim ) { printf( "%#x ", p[i] ); } 149 printf( "\n" ); 150 // do not free 151 152 p = alloc_set( p, 3 * dim, fill ); // CFA resize array alloc, fill 139 153 printf( "CFA resize array alloc, fill\n" ); 140 for ( i; dim ) { printf( "%#x ", p[i] );; }154 for ( i; 3 * dim ) { printf( "%#x ", p[i] );; } 141 155 printf( "\n" ); 142 156 free( p ); … … 172 186 free( stp ); 173 187 174 stp = &(*aligned_alloc( Alignment )){ 42, 42.5 }; // CFA aligned_alloc 175 assert( (uintptr_t)stp % Alignment == 0 ); 176 printf( "CFA aligned_alloc %d %g\n", stp->x, stp->y ); 177 free( stp ); 178 179 stp = &(*align_alloc( Alignment )){ 42, 42.5 }; // CFA align_alloc 180 assert( (uintptr_t)stp % Alignment == 0 ); 181 printf( "CFA align_alloc %d %g\n", stp->x, stp->y ); 182 free( stp ); 183 184 stp = align_alloc( Alignment, fill ); // CFA memalign, fill 185 assert( (uintptr_t)stp % Alignment == 0 ); 186 printf( "CFA align_alloc fill %#x %a\n", stp->x, stp->y ); 188 stp = &(*alloc_align( Alignment)){ 42, 42.5 }; // CFA alloc_align 189 assert( (uintptr_t)stp % Alignment == 0 ); 190 printf( "CFA alloc_align %d %g\n", stp->x, stp->y ); 191 free( stp ); 192 193 stp = &(*alloc_align( Alignment )){ 42, 42.5 }; // CFA alloc_align 194 assert( (uintptr_t)stp % Alignment == 0 ); 195 printf( "CFA alloc_align %d %g\n", stp->x, stp->y ); 196 free( stp ); 197 198 stp = alloc_align_set( Alignment, fill ); // CFA memalign, fill 199 assert( (uintptr_t)stp % Alignment == 0 ); 200 printf( "CFA alloc_align fill %#x %a\n", stp->x, stp->y ); 201 free( stp ); 202 203 stp = alloc_align_set( Alignment, (Struct){ 42, 42.5 } ); // CFA memalign, fill 204 assert( (uintptr_t)stp % Alignment == 0 ); 205 printf( "CFA alloc_align fill %d %g\n", stp->x, stp->y ); 206 // do not free 207 208 stp = &(*alloc_align( stp, 4096 )){ 42, 42.5 }; // CFA realign 209 assert( (uintptr_t)stp % 4096 == 0 ); 210 printf( "CFA alloc_align %d %g\n", stp->x, stp->y ); 187 211 free( stp ); 188 212 … … 191 215 printf( "\n" ); 192 216 193 stp = al ign_alloc( Alignment, dim ); // CFA array memalign217 stp = alloc_align( Alignment, dim ); // CFA array memalign 194 218 assert( (uintptr_t)stp % Alignment == 0 ); 195 219 for ( i; dim ) { stp[i] = (Struct){ 42, 42.5 }; } 196 printf( "CFA array al ign_alloc\n" );220 printf( "CFA array alloc_align\n" ); 197 221 for ( i; dim ) { printf( "%d %g, ", stp[i].x, stp[i].y ); } 198 222 printf( "\n" ); 199 223 free( stp ); 200 224 201 stp = al ign_alloc( Alignment, dim, fill );// CFA array memalign, fill202 assert( (uintptr_t)stp % Alignment == 0 ); 203 printf( "CFA array al ign_alloc, fill\n" );225 stp = alloc_align_set( Alignment, dim, fill ); // CFA array memalign, fill 226 assert( (uintptr_t)stp % Alignment == 0 ); 227 printf( "CFA array alloc_align, fill\n" ); 204 228 for ( i; dim ) { printf( "%#x %a, ", stp[i].x, stp[i].y ); } 229 printf( "\n" ); 230 free( stp ); 231 232 stp = alloc_align_set( Alignment, dim, (Struct){ 42, 42.5 } ); // CFA array memalign, fill 233 assert( (uintptr_t)stp % Alignment == 0 ); 234 printf( "CFA array alloc_align, fill\n" ); 235 for ( i; dim ) { printf( "%d %g, ", stp[i].x, stp[i].y ); } 236 printf( "\n" ); 237 // do not free 238 239 stp1 = alloc_align_set( Alignment, dim, stp ); // CFA array memalign, fill 240 assert( (uintptr_t)stp % Alignment == 0 ); 241 printf( "CFA array alloc_align, fill array\n" ); 242 for ( i; dim ) { printf( "%d %g, ", stp1[i].x, stp1[i].y ); } 243 printf( "\n" ); 244 free( stp1 ); 245 246 stp = alloc_align( stp, 4096, dim ); // CFA aligned realloc array 247 assert( (uintptr_t)stp % 4096 == 0 ); 248 for ( i; dim ) { stp[i] = (Struct){ 42, 42.5 }; } 249 printf( "CFA realloc array alloc_align\n" ); 250 for ( i; dim ) { printf( "%d %g, ", stp[i].x, stp[i].y ); } 205 251 printf( "\n" ); 206 252 free( stp );
Note: See TracChangeset
for help on using the changeset viewer.