C:/Users/Dennis/src/lang/russell.orig/src/gc/pcr_interface.c

Go to the documentation of this file.
00001 /* 
00002  * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
00003  * Copyright (c) 1991, 1992 by Xerox Corporation.  All rights reserved.
00004  *
00005  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
00006  * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
00007  *
00008  * Permission is hereby granted to copy this garbage collector for any purpose,
00009  * provided the above notices are retained on all copies.
00010  */
00011 # include "gc_private.h"
00012 
00013 # ifdef PCR
00014 /*
00015  * Note that POSIX PCR requires an ANSI C compiler.  Hence we are allowed
00016  * to make the same assumption here.
00017  * We wrap all of the allocator functions to avoid questions of
00018  * compatibility between the prototyped and nonprototyped versions of the f
00019  */
00020 # include "pcr/mm/PCR_MM.h"
00021 
00022 # define MY_MAGIC 17L
00023 
00024 void * GC_AllocProc(size_t size, PCR_Bool ptrFree, PCR_Bool clear )
00025 {
00026     if (ptrFree) {
00027         void * result = (void *)GC_malloc_atomic(size);
00028         if (clear && result != 0) bzero(result, size);
00029         return(result);
00030     } else {
00031         return((void *)GC_malloc(size));
00032     }
00033 }
00034 
00035 # define GC_ReallocProc GC_realloc
00036 
00037 # define GC_FreeProc GC_free
00038 
00039 typedef struct {
00040   PCR_ERes (*ed_proc)(void *p, size_t size, PCR_Any data);
00041   bool ed_pointerfree;
00042   PCR_ERes ed_fail_code;
00043   PCR_Any ed_client_data;
00044 } enumerate_data;
00045 
00046 void GC_enumerate_block(h, ed)
00047 register struct hblk *h;
00048 enumerate_data * ed;
00049 {
00050     register hdr * hhdr;
00051     register int sz;
00052     word *p;
00053     word * lim;
00054     
00055     hhdr = HDR(h);
00056     sz = hhdr -> hb_sz;
00057     if (sz >= 0 && ed -> ed_pointerfree
00058         || sz <= 0 && !(ed -> ed_pointerfree)) return;
00059     if (sz < 0) sz = -sz;
00060     lim = (word *)(h+1) - sz;
00061     p = (word *)h;
00062     do {
00063         if (PCR_ERes_IsErr(ed -> ed_fail_code)) return;
00064         ed -> ed_fail_code =
00065             (*(ed -> ed_proc))(p, WORDS_TO_BYTES(sz), ed -> ed_client_data);
00066         p+= sz;
00067     } while (p <= lim);
00068 }
00069 
00070 struct PCR_MM_ProcsRep * GC_old_allocator = 0;
00071 
00072 PCR_ERes GC_EnumerateProc(
00073     PCR_Bool ptrFree,
00074     PCR_ERes (*proc)(void *p, size_t size, PCR_Any data),
00075     PCR_Any data
00076 )
00077 {
00078     enumerate_data ed;
00079     
00080     ed.ed_proc = proc;
00081     ed.ed_pointerfree = ptrFree;
00082     ed.ed_fail_code = PCR_ERes_okay;
00083     ed.ed_client_data = data;
00084     GC_apply_to_all_blocks(GC_enumerate_block, &ed);
00085     if (ed.ed_fail_code != PCR_ERes_okay) {
00086         return(ed.ed_fail_code);
00087     } else {
00088         /* Also enumerate objects allocated by my predecessors */
00089         return((*(GC_old_allocator->mmp_enumerate))(ptrFree, proc, data));
00090     }
00091 }
00092 
00093 void GC_DummyFreeProc(void *p) {};
00094 
00095 void GC_DummyShutdownProc(void) {};
00096 
00097 struct PCR_MM_ProcsRep GC_Rep = {
00098         MY_MAGIC,
00099         GC_AllocProc,
00100         GC_ReallocProc,
00101         GC_DummyFreeProc,       /* mmp_free */
00102         GC_FreeProc,            /* mmp_unsafeFree */
00103         GC_EnumerateProc,
00104         GC_DummyShutdownProc    /* mmp_shutdown */
00105 };
00106 
00107 void GC_pcr_install()
00108 {
00109     PCR_MM_Install(&GC_Rep, &GC_old_allocator);
00110 }
00111 # endif

Generated on Fri Jan 25 10:39:45 2008 for russell by  doxygen 1.5.4