Changeset 3d5701e for tests/alloc.cfa
- Timestamp:
- Feb 25, 2020, 1:17:33 PM (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:
- 7dc2e015
- Parents:
- 9fb8f01 (diff), dd9e1ca (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/alloc.cfa
r9fb8f01 r3d5701e 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 : 33912 // Last Modified On : Sun Feb 16 09:21:13 2020 13 // Update Count : 405 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, fill49 p = alloc_set( fill ); // CFA alloc, fill 55 50 printf( "CFA alloc, fill %08x\n", *p ); 51 free( p ); 52 53 p = alloc_set( 3 ); // CFA alloc, fill 54 printf( "CFA alloc, fill %d\n", *p ); 56 55 free( p ); 57 56 … … 79 78 free( p ); 80 79 81 p = alloc ( 2 * dim, fill );// CFA array alloc, fill80 p = alloc_set( 2 * dim, fill ); // CFA array alloc, fill 82 81 printf( "CFA array alloc, fill %#hhx\n", fill ); 83 82 for ( i; 2 * dim ) { printf( "%#x ", p[i] ); } 84 83 printf( "\n" ); 85 // do not free 84 free( p ); 85 86 p = alloc_set( 2 * dim, 0xdeadbeef ); // CFA array alloc, fill 87 printf( "CFA array alloc, fill %#hhx\n", 0xdeadbeef ); 88 for ( i; 2 * dim ) { printf( "%#x ", p[i] ); } 89 printf( "\n" ); 90 // do not free 91 92 p1 = alloc_set( 2 * dim, p ); // CFA array alloc, fill 93 printf( "CFA array alloc, fill from array\n" ); 94 for ( i; 2 * dim ) { printf( "%#x %#x, ", p[i], p1[i] ); } 95 free( p1 ); 96 printf( "\n" ); 86 97 87 98 … … 90 101 91 102 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" );103 printf( "C realloc\n" ); 104 for ( i; dim ) { printf( "%#x ", p[i] ); } 105 printf( "\n" ); 106 // do not free 96 107 97 108 p = realloc( p, 2 * dim * sizeof(*p) ); // CFA realloc … … 108 119 p = alloc( p, dim ); // CFA resize array alloc 109 120 for ( i; dim ) { p[i] = 0xdeadbeef; } 110 printf( "CFA resize alloc\n" ); 111 for ( i; dim ) { printf( "%#x ", p[i] ); } 112 printf( "\n" ); 121 printf( "CFA resize array alloc\n" ); 122 for ( i; dim ) { printf( "%#x ", p[i] ); } 123 printf( "\n" ); 124 // do not free 113 125 114 126 p = alloc( p, 2 * dim ); // CFA resize array alloc 115 for ( i; dim ~ 2 * dim ) { p[i] = 0x1010101; } 127 for ( i; dim ~ 2 * dim ) { p[i] = 0x1010101; } // fill upper part 116 128 printf( "CFA resize array alloc\n" ); 117 129 for ( i; 2 * dim ) { printf( "%#x ", p[i] ); } 118 130 printf( "\n" ); 119 120 p = alloc( p, dim ); // CFA array alloc 121 printf( "CFA resize array alloc\n" ); 122 for ( i; dim ) { printf( "%#x ", p[i] ); } 123 printf( "\n" ); 124 125 free( p ); 126 p = 0; 127 128 p = alloc( p, dim, fill ); // CFA array alloc, fill 131 // do not free 132 133 p = alloc( p, dim ); // CFA resize array alloc 134 printf( "CFA resize array alloc\n" ); 135 for ( i; dim ) { printf( "%#x ", p[i] ); } 136 printf( "\n" ); 137 // do not free 138 139 p = alloc_set( p, 3 * dim, fill ); // CFA resize array alloc, fill 140 printf( "CFA resize array alloc\n" ); 141 for ( i; 3 * dim ) { printf( "%#x ", p[i] ); } 142 printf( "\n" ); 143 // do not free 144 145 p = alloc_set( p, dim, fill ); // CFA resize array alloc, fill 146 printf( "CFA resize array alloc\n" ); 147 for ( i; dim ) { printf( "%#x ", p[i] ); } 148 printf( "\n" ); 149 // do not free 150 151 p = alloc_set( p, 3 * dim, fill ); // CFA resize array alloc, fill 129 152 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 134 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 139 printf( "CFA resize array alloc, fill\n" ); 140 for ( i; dim ) { printf( "%#x ", p[i] );; } 153 for ( i; 3 * dim ) { printf( "%#x ", p[i] );; } 141 154 printf( "\n" ); 142 155 free( p ); … … 172 185 free( stp ); 173 186 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 ); 187 stp = &(*alloc_align( Alignment)){ 42, 42.5 }; // CFA alloc_align 188 assert( (uintptr_t)stp % Alignment == 0 ); 189 printf( "CFA alloc_align %d %g\n", stp->x, stp->y ); 190 free( stp ); 191 192 stp = &(*alloc_align( Alignment )){ 42, 42.5 }; // CFA alloc_align 193 assert( (uintptr_t)stp % Alignment == 0 ); 194 printf( "CFA alloc_align %d %g\n", stp->x, stp->y ); 195 free( stp ); 196 197 stp = alloc_align_set( Alignment, fill ); // CFA memalign, fill 198 assert( (uintptr_t)stp % Alignment == 0 ); 199 printf( "CFA alloc_align fill %#x %a\n", stp->x, stp->y ); 200 free( stp ); 201 202 stp = alloc_align_set( Alignment, (Struct){ 42, 42.5 } ); // CFA memalign, fill 203 assert( (uintptr_t)stp % Alignment == 0 ); 204 printf( "CFA alloc_align fill %d %g\n", stp->x, stp->y ); 205 // do not free 206 207 stp = &(*alloc_align( stp, 4096 )){ 42, 42.5 }; // CFA realign 208 assert( (uintptr_t)stp % 4096 == 0 ); 209 printf( "CFA alloc_align %d %g\n", stp->x, stp->y ); 187 210 free( stp ); 188 211 … … 191 214 printf( "\n" ); 192 215 193 stp = al ign_alloc( Alignment, dim ); // CFA array memalign216 stp = alloc_align( Alignment, dim ); // CFA array memalign 194 217 assert( (uintptr_t)stp % Alignment == 0 ); 195 218 for ( i; dim ) { stp[i] = (Struct){ 42, 42.5 }; } 196 printf( "CFA array al ign_alloc\n" );219 printf( "CFA array alloc_align\n" ); 197 220 for ( i; dim ) { printf( "%d %g, ", stp[i].x, stp[i].y ); } 198 221 printf( "\n" ); 199 222 free( stp ); 200 223 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" );224 stp = alloc_align_set( Alignment, dim, fill ); // CFA array memalign, fill 225 assert( (uintptr_t)stp % Alignment == 0 ); 226 printf( "CFA array alloc_align, fill\n" ); 204 227 for ( i; dim ) { printf( "%#x %a, ", stp[i].x, stp[i].y ); } 228 printf( "\n" ); 229 free( stp ); 230 231 stp = alloc_align_set( Alignment, dim, (Struct){ 42, 42.5 } ); // CFA array memalign, fill 232 assert( (uintptr_t)stp % Alignment == 0 ); 233 printf( "CFA array alloc_align, fill\n" ); 234 for ( i; dim ) { printf( "%d %g, ", stp[i].x, stp[i].y ); } 235 printf( "\n" ); 236 // do not free 237 238 stp1 = alloc_align_set( Alignment, dim, stp ); // CFA array memalign, fill 239 assert( (uintptr_t)stp % Alignment == 0 ); 240 printf( "CFA array alloc_align, fill array\n" ); 241 for ( i; dim ) { printf( "%d %g, ", stp1[i].x, stp1[i].y ); } 242 printf( "\n" ); 243 free( stp1 ); 244 245 stp = alloc_align( stp, 4096, dim ); // CFA aligned realloc array 246 assert( (uintptr_t)stp % 4096 == 0 ); 247 for ( i; dim ) { stp[i] = (Struct){ 42, 42.5 }; } 248 printf( "CFA realloc array alloc_align\n" ); 249 for ( i; dim ) { printf( "%d %g, ", stp[i].x, stp[i].y ); } 205 250 printf( "\n" ); 206 251 free( stp );
Note:
See TracChangeset
for help on using the changeset viewer.