Changeset 58e97d9 for tests/alloc.cfa
- Timestamp:
- Apr 24, 2022, 10:45:07 AM (2 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
- Children:
- 19e5d65d
- Parents:
- 31a5f418
- git-author:
- Peter A. Buhr <pabuhr@…> (04/24/22 10:44:01)
- git-committer:
- Peter A. Buhr <pabuhr@…> (04/24/22 10:45:07)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/alloc.cfa
r31a5f418 r58e97d9 10 10 // Created On : Wed Feb 3 07:56:22 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Nov 12 10:02:18 202013 // Update Count : 43 212 // Last Modified On : Mon Apr 18 17:13:52 2022 13 // Update Count : 433 14 14 // 15 15 … … 47 47 free( ip ); 48 48 49 ip = alloc( fill`fill ); 49 ip = alloc( fill`fill ); // CFA alloc, fill 50 50 printf( "CFA alloc, fill %08x\n", *ip ); 51 51 free( ip ); … … 84 84 free( ip ); 85 85 86 ip = alloc( 2 * dim, ((int)0xdeadbeef)`fill ); 86 ip = alloc( 2 * dim, ((int)0xdeadbeef)`fill ); // CFA array alloc, fill 87 87 printf( "CFA array alloc, fill %#hhx\n", 0xdeadbeef ); 88 88 for ( i; 2 * dim ) { printf( "%#x ", ip[i] ); } … … 90 90 // do not free 91 91 92 ip1 = alloc( 2 * dim, [ip, 2 * dim]`fill ); 92 ip1 = alloc( 2 * dim, [ip, 2 * dim]`fill ); // CFA array alloc, fill 93 93 printf( "CFA array alloc, fill from array\n" ); 94 94 for ( i; 2 * dim ) { printf( "%#x %#x, ", ip[i], ip1[i] ); } … … 117 117 printf( "\n" ); 118 118 119 ip = alloc( dim, ip`realloc ); 119 ip = alloc( dim, ip`realloc ); // CFA realloc array alloc 120 120 for ( i; dim ) { ip[i] = 0xdeadbeef; } 121 121 printf( "CFA realloc array alloc\n" ); … … 124 124 // do not free 125 125 126 ip = alloc( 2 * dim, ip`realloc ); 126 ip = alloc( 2 * dim, ip`realloc ); // CFA realloc array alloc 127 127 for ( i; dim ~ 2 * dim ) { ip[i] = 0x1010101; } // fill upper part 128 128 printf( "CFA realloc array alloc\n" ); … … 131 131 // do not free 132 132 133 ip = alloc( dim, ip`realloc ); 133 ip = alloc( dim, ip`realloc ); // CFA realloc array alloc 134 134 printf( "CFA realloc array alloc\n" ); 135 135 for ( i; dim ) { printf( "%#x ", ip[i] ); } … … 137 137 // do not free 138 138 139 ip = alloc( 3 * dim, ip`realloc, fill`fill ); 139 ip = alloc( 3 * dim, ip`realloc, fill`fill ); // CFA realloc array alloc, fill 140 140 printf( "CFA realloc array alloc, fill\n" ); 141 141 for ( i; 3 * dim ) { printf( "%#x ", ip[i] ); } … … 143 143 // do not free 144 144 145 ip = alloc( dim, ip`realloc, fill`fill ); 145 ip = alloc( dim, ip`realloc, fill`fill ); // CFA realloc array alloc, fill 146 146 printf( "CFA realloc array alloc, fill\n" ); 147 147 for ( i; dim ) { printf( "%#x ", ip[i] ); } … … 149 149 // do not free 150 150 151 ip = alloc( 3 * dim, ip`realloc, fill`fill ); 151 ip = alloc( 3 * dim, ip`realloc, fill`fill ); // CFA realloc array alloc, fill 152 152 printf( "CFA realloc array alloc, fill\n" ); 153 153 for ( i; 3 * dim ) { printf( "%#x ", ip[i] ); } … … 155 155 // do not free 156 156 #if 0 // FIX ME 157 ip = alloc( 5 * dim, ip`realloc, 5`fill ); 157 ip = alloc( 5 * dim, ip`realloc, 5`fill ); // CFA realloc array alloc, 5 158 158 printf( "CFA realloc array alloc, 5\n" ); 159 159 for ( i; 5 * dim ) { printf( "%#x ", ip[i] ); } … … 161 161 // do not free 162 162 163 ip = alloc( dim, ip`realloc, 5`fill ); 163 ip = alloc( dim, ip`realloc, 5`fill ); // CFA realloc array alloc, 5 164 164 printf( "CFA realloc array alloc, 5\n" ); 165 165 for ( i; dim ) { printf( "%#x ", ip[i] ); } … … 167 167 // do not free 168 168 169 ip = alloc( 5 * dim, ip`realloc, 5`fill ); 169 ip = alloc( 5 * dim, ip`realloc, 5`fill ); // CFA realloc array alloc, 5 170 170 printf( "CFA realloc array alloc, 5\n" ); 171 171 for ( i; 5 * dim ) { printf( "%#x ", ip[i] ); } … … 210 210 int const_count, dest_count; 211 211 struct Struct { int x; double y; }; 212 void ?{}( Struct & a ) { // construct212 void ?{}( Struct & a ) { // construct 213 213 a.[ x, y ] = [ -1, -1.0 ]; 214 214 } 215 void ?{}( Struct & a, int x, double y ) { // initialize215 void ?{}( Struct & a, int x, double y ) { // initialize 216 216 a.[ x, y ] = [ x, y ]; 217 217 const_count++; 218 218 } 219 void ^?{}( Struct & a ) { dest_count++; } // destruct219 void ^?{}( Struct & a ) { dest_count++; } // destruct 220 220 Struct st, st1, sta[dim], sta1[dim], * stp, * stp1; 221 221 … … 266 266 // do not free 267 267 268 stp = &(*alloc( stp`realloc, 4096`align )){ 42, 42.5 }; 268 stp = &(*alloc( stp`realloc, 4096`align )){ 42, 42.5 }; // CFA realign 269 269 assert( (uintptr_t)stp % 4096 == 0 ); 270 270 printf( "CFA alloc_align %d %g\n", stp->x, stp->y ); … … 304 304 free( stp1 ); 305 305 306 stp = alloc( dim, stp`realloc, 4096`align ); 306 stp = alloc( dim, stp`realloc, 4096`align ); // CFA aligned realloc array 307 307 assert( (uintptr_t)stp % 4096 == 0 ); 308 308 for ( i; dim ) { stp[i] = (Struct){ 42, 42.5 }; } … … 340 340 const_count = dest_count = 0; 341 341 stp = new( 42, 42.5 ); 342 assert( const_count == 1 && dest_count == 0 ); 342 assert( const_count == 1 && dest_count == 0 ); // assertion for testing 343 343 stp1 = new( 42, 42.5 ); 344 assert( const_count == 2 && dest_count == 0 ); 344 assert( const_count == 2 && dest_count == 0 ); // assertion for testing 345 345 346 346 printf( "CFA new initialize\n%d %g %d %g\n", stp->x, stp->y, stp1->x, stp1->y ); 347 347 delete( stp, stp1 ); 348 assert( const_count == 2 && dest_count == 2 ); 348 assert( const_count == 2 && dest_count == 2 ); // assertion for testing 349 349 350 350 // new, array types 351 351 stp = anew( dim, 42, 42.5 ); 352 assert( const_count == 2 + dim && dest_count == 2 ); 352 assert( const_count == 2 + dim && dest_count == 2 ); // assertion for testing 353 353 printf( "CFA array new initialize\n" ); 354 354 for ( i; dim ) { printf( "%d %g, ", stp[i].x, stp[i].y ); } … … 356 356 357 357 stp1 = anew( dim, 42, 42.5 ); 358 assert( const_count == 2 + 2 * dim && dest_count == 2 ); 358 assert( const_count == 2 + 2 * dim && dest_count == 2 ); // assertion for testing 359 359 for ( i; dim ) { printf( "%d %g, ", stp1[i].x, stp1[i].y ); } 360 360 printf( "\n" ); 361 361 adelete( stp, stp1 ); 362 assert( const_count == 2 + 2 * dim && dest_count == 2 + 2 * dim); 362 assert( const_count == 2 + 2 * dim && dest_count == 2 + 2 * dim); // assertion for testing 363 363 364 364 // extras … … 373 373 printf( "CFA deep malloc %#x\n", *ip ); 374 374 375 dp = alloc(5.0`fill); 375 dp = alloc(5.0`fill); // just for testing multiple free 376 376 assert(*dp == 5.0); 377 377 free( ip, dp, 0p );
Note: See TracChangeset
for help on using the changeset viewer.