Back to index

plt-scheme  4.2.1
Classes | Defines | Functions
test_cpp.cc File Reference
#include "gc_cpp.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gc_allocator.h"
#include "private/gc_priv.h"

Go to the source code of this file.

Classes

class  A
class  B
class  C
class  D
class  E
class  F

Defines

#define USE_STD_ALLOCATOR
#define USE_GC   GC
#define my_assert(e)

Functions

long Disguise (void *p)
voidUndisguise (long i)
int main (int argc, char *argv[])

Define Documentation

#define my_assert (   e)
Value:
if (! (e)) { \
        GC_printf1( "Assertion failure in " __FILE__ ", line %d: " #e "\n", \
                    __LINE__ ); \
        exit( 1 ); }

Definition at line 53 of file test_cpp.cc.

#define USE_GC   GC

Definition at line 49 of file test_cpp.cc.

Definition at line 31 of file test_cpp.cc.


Function Documentation

long Disguise ( void p)

Definition at line 169 of file test_cpp.cc.

                         {
    return ~ (long) p;}

Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 191 of file test_cpp.cc.

                                       {
# endif
#endif

   GC_INIT();

#  if defined(MACOS)                        // MacOS
    char* argv_[] = {"test_cpp", "10"};     //   doesn't
    argv = argv_;                           //     have a
    argc = sizeof(argv_)/sizeof(argv_[0]);  //       commandline
#  endif 
    int i, iters, n;
#   ifdef USE_STD_ALLOCATOR
      int *x = gc_allocator<int>().allocate(1);
      int **xptr = traceable_allocator<int *>().allocate(1);
#   else 
#     ifdef __GNUC__
          int *x = (int *)gc_alloc::allocate(sizeof(int));
#     else
          int *x = (int *)alloc::allocate(sizeof(int));
#     endif
#   endif
    *x = 29;
#   ifdef USE_STD_ALLOCATOR
      *xptr = x;
      x = 0;
#   endif
    if (argc != 2 || (0 >= (n = atoi( argv[ 1 ] )))) {
        GC_printf0( "usage: test_cpp number-of-iterations\nAssuming 10 iters\n" );
        n = 10;}
        
    for (iters = 1; iters <= n; iters++) {
        GC_printf1( "Starting iteration %d\n", iters );

            /* Allocate some uncollectable As and disguise their pointers.
            Later we'll check to see if the objects are still there.  We're
            checking to make sure these objects really are uncollectable. */
        long as[ 1000 ];
        long bs[ 1000 ];
        for (i = 0; i < 1000; i++) {
            as[ i ] = Disguise( new (NoGC) A( i ) );
            bs[ i ] = Disguise( new (NoGC) B( i ) );}

            /* Allocate a fair number of finalizable Cs, Ds, and Fs.
            Later we'll check to make sure they've gone away. */
        for (i = 0; i < 1000; i++) {
            C* c = new C( 2 );
            C c1( 2 );           /* stack allocation should work too */
            D* d = ::new (USE_GC, D::CleanUp, (void*)(long)i) D( i );
            F* f = new F;
            if (0 == i % 10) delete c;}

            /* Allocate a very large number of collectable As and Bs and
            drop the references to them immediately, forcing many
            collections. */
        for (i = 0; i < 1000000; i++) {
            A* a = new (USE_GC) A( i );
            B* b = new B( i );
            b = new (USE_GC) B( i );
            if (0 == i % 10) {
                B::Deleting( 1 );
                delete b;
                B::Deleting( 0 );}
#          ifdef FINALIZE_ON_DEMAND
             GC_invoke_finalizers();
#          endif
           }

            /* Make sure the uncollectable As and Bs are still there. */
        for (i = 0; i < 1000; i++) {
            A* a = (A*) Undisguise( as[ i ] );
            B* b = (B*) Undisguise( bs[ i ] );
            a->Test( i );
            delete a;
            b->Test( i );
            B::Deleting( 1 );
            delete b;
            B::Deleting( 0 );
#          ifdef FINALIZE_ON_DEMAND
               GC_invoke_finalizers();
#          endif

           }

            /* Make sure most of the finalizable Cs, Ds, and Fs have
            gone away. */
        C::Test();
        D::Test();
        F::Test();}

#   ifdef USE_STD_ALLOCATOR
      x = *xptr;
#   endif
    my_assert (29 == x[0]);
    GC_printf0( "The test appears to have succeeded.\n" );
    return( 0 );}

Here is the call graph for this function:

void* Undisguise ( long  i)

Definition at line 172 of file test_cpp.cc.

                           {
    return (void*) ~ i;}

Here is the caller graph for this function: