| 193 | int main() { |
| 194 | # else |
| 195 | int main( int argc, char* argv[] ) { |
| 196 | # endif |
| 197 | #endif |
| 198 | |
| 199 | GC_INIT(); |
| 200 | |
| 201 | # if defined(MACOS) // MacOS |
| 202 | char* argv_[] = {"test_cpp", "10"}; // doesn't |
| 203 | argv = argv_; // have a |
| 204 | argc = sizeof(argv_)/sizeof(argv_[0]); // commandline |
| 205 | # endif |
| 206 | int i, iters, n; |
| 207 | # ifdef USE_STD_ALLOCATOR |
| 208 | int *x = gc_allocator<int>().allocate(1); |
| 209 | int **xptr = traceable_allocator<int *>().allocate(1); |
| 210 | # else |
| 211 | # ifdef __GNUC__ |
| 212 | int *x = (int *)gc_alloc::allocate(sizeof(int)); |
| 213 | # else |
| 214 | int *x = (int *)alloc::allocate(sizeof(int)); |
| 215 | # endif |
| 216 | # endif |
| 217 | *x = 29; |
| 218 | # ifdef USE_STD_ALLOCATOR |
| 219 | *xptr = x; |
| 220 | x = 0; |
| 221 | # endif |
| 222 | if (argc != 2 || (0 >= (n = atoi( argv[ 1 ] )))) { |
| 223 | GC_printf( "usage: test_cpp number-of-iterations\nAssuming 10 iters\n" ); |
| 224 | n = 10;} |
| 225 | |
| 226 | for (iters = 1; iters <= n; iters++) { |
| 227 | GC_printf( "Starting iteration %d\n", iters ); |
| 228 | |
| 229 | /* Allocate some uncollectable As and disguise their pointers. |
| 230 | Later we'll check to see if the objects are still there. We're |
| 231 | checking to make sure these objects really are uncollectable. */ |
| 232 | GC_word as[ 1000 ]; |
| 233 | GC_word bs[ 1000 ]; |
| 234 | for (i = 0; i < 1000; i++) { |
| 235 | as[ i ] = Disguise( new (NoGC) A( i ) ); |
| 236 | bs[ i ] = Disguise( new (NoGC) B( i ) );} |
| 237 | |
| 238 | /* Allocate a fair number of finalizable Cs, Ds, and Fs. |
| 239 | Later we'll check to make sure they've gone away. */ |
| 240 | for (i = 0; i < 1000; i++) { |
| 241 | C* c = new C( 2 ); |
| 242 | C c1( 2 ); /* stack allocation should work too */ |
| 243 | D* d = ::new (USE_GC, D::CleanUp, (void*)(GC_word)i) D( i ); |
| 244 | F* f = new F; |
| 245 | if (0 == i % 10) delete c;} |
| 246 | |
| 247 | /* Allocate a very large number of collectable As and Bs and |
| 248 | drop the references to them immediately, forcing many |
| 249 | collections. */ |
| 250 | for (i = 0; i < 1000000; i++) { |
| 251 | A* a = new (USE_GC) A( i ); |
| 252 | B* b = new B( i ); |
nothing calls this directly
no test coverage detected