- Timestamp:
- Nov 6, 2020, 4:48:34 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 139775e
- Parents:
- ea3fa25
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/alloc.cfa
rea3fa25 r55acc3a 208 208 209 209 210 int const_count, dest_count; 210 211 struct Struct { int x; double y; }; 212 void ?{}( Struct & a ) { // construct 213 a.[ x, y ] = [ -1, -1.0 ]; 214 } 215 void ?{}( Struct & a, int x, double y ) { // initialize 216 a.[ x, y ] = [ x, y ]; 217 const_count++; 218 } 219 void ^?{}( Struct & a ) { dest_count++; } // destruct 211 220 Struct st, st1, sta[dim], sta1[dim], * stp, * stp1; 212 221 … … 329 338 printf( "\n" ); 330 339 340 const_count = dest_count = 0; 331 341 stp = new( 42, 42.5 ); 342 assert( const_count == 1 && dest_count == 0 ); // assertion for testing 332 343 stp1 = new( 42, 42.5 ); 344 assert( const_count == 2 && dest_count == 0 ); // assertion for testing 345 333 346 printf( "CFA new initialize\n%d %g %d %g\n", stp->x, stp->y, stp1->x, stp1->y ); 334 347 delete( stp, stp1 ); 348 assert( const_count == 2 && dest_count == 2 ); // assertion for testing 335 349 336 350 // new, array types 337 351 stp = anew( dim, 42, 42.5 ); 352 assert( const_count == 2 + dim && dest_count == 2 ); // assertion for testing 338 353 printf( "CFA array new initialize\n" ); 339 354 for ( i; dim ) { printf( "%d %g, ", stp[i].x, stp[i].y ); } 340 355 printf( "\n" ); 356 341 357 stp1 = anew( dim, 42, 42.5 ); 358 assert( const_count == 2 + 2 * dim && dest_count == 2 ); // assertion for testing 342 359 for ( i; dim ) { printf( "%d %g, ", stp1[i].x, stp1[i].y ); } 343 360 printf( "\n" ); 344 361 adelete( stp, stp1 ); 362 assert( const_count == 2 + 2 * dim && dest_count == 2 + 2 * dim); // assertion for testing 345 363 346 364 // extras … … 354 372 *ip = 0xdeadbeef; 355 373 printf( "CFA deep malloc %#x\n", *ip ); 356 free( ip ); 374 375 dp = alloc(5.0`fill); // just for testing multiple free 376 assert(*dp == 5.0); 377 free( ip, dp ); 357 378 358 379 #ifdef ERR1
Note: See TracChangeset
for help on using the changeset viewer.