Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions
test_cpp.cc File Reference
#include "gc_cpp.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gc_alloc.h"
#include "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 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 42 of file test_cpp.cc.


Function Documentation

long Disguise ( void p)

Definition at line 158 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 177 of file test_cpp.cc.

                                     {
#endif

#  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;
#   if !defined(__GNUC__) && !defined(MACOS)
      int *x = (int *)alloc::allocate(sizeof(int));

      *x = 29;
      x -= 3;
#   endif
    if (argc != 2 || (0 >= (n = atoi( argv[ 1 ] )))) {
        GC_printf0( "usage: test_cpp number-of-iterations\n" );
        exit( 1 );}
        
    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 (GC, D::CleanUp, (void*) 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 (GC) A( i );
            B* b = new B( i );
            b = new (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();}

#   if !defined(__GNUC__) && !defined(MACOS)
      my_assert (29 == x[3]);
#   endif
    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 161 of file test_cpp.cc.

                           {
    return (void*) ~ i;}

Here is the caller graph for this function: