From e5eee25c09b2d2eb15ec4d269d9d2d9e0021916d Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Thu, 31 Oct 1996 16:09:30 +0000 Subject: [PATCH] Review.impl.h.mpmtypes.4 Copied from Perforce Change: 16223 ServerID: perforce.ravenbrook.com --- mps/src/misc.h | 55 +------------------------------------------------- mps/src/mpm.c | 33 ++++++++++++++++++++++++++++-- mps/src/mpm.h | 12 ++++++++--- 3 files changed, 41 insertions(+), 59 deletions(-) diff --git a/mps/src/misc.h b/mps/src/misc.h index a4ac422c77f..42e502c774c 100644 --- a/mps/src/misc.h +++ b/mps/src/misc.h @@ -1,6 +1,6 @@ /* impl.h.misc: MISCELLANEOUS DEFINITIONS * - * $HopeName: MMsrc!misc.h(trunk.5) $ + * $HopeName: MMsrc!misc.h(trunk.6) $ * Copyright (C) 1994,1995,1996 Harlequin Group, all rights reserved * * Small general things which are useful for C but aren't part of the @@ -52,22 +52,6 @@ typedef const struct SrcIdStruct { #define END } while(0) -/* Bool -- boolean type - * - * Using a boolean type in C is a tricky thing. Non-zero values are - * "true" but are not all equal to TRUE. The Bool type is therefore - * mostly defined so that the intention of the code is clearer. - * Use with care. - */ - -typedef int Bool; /* boolean type */ -enum -{ - FALSE = 0, - TRUE = 1 -}; -#define BoolCheck(b) ((b) == TRUE || (b) == FALSE) - /* NOOP -- null statement * * Do not be tempted to use NULL, or just semicolon as the null @@ -104,41 +88,4 @@ enum ((type *)((char *)(p) - offsetof(type, field))) -/* Object Signatures - * - * .sig: Signatures are magic numbers which are written into structures - * when they are created and invalidated (by overwriting with - * SigInvalid) when they are destroyed. They provide a limited form - * of run-time type checking and dynamic scope checking. - * - * .sig.form: The first three hex digits of signatures should be 519 - * (which resembles "SIG"), and should be chosen to be mnemonic when - * viewed in hex, so that structures can be recognized visually when - * debugging and dumping memory. - */ - -typedef unsigned long Sig; -#define SigInvalid ((Sig)0x51915BAD) - - -/* Res -- Result Code - * - * .res: See also impl.h.mps.res, impl.c.mpsi.check.res. - */ - -typedef int Res; /* result code type */ -enum { - ResOK = 0, /* success */ - ResFAIL, /* unspecified failure */ - ResRESOURCE, /* unable to obtain resources */ - ResMEMORY, /* unable to obtain memory */ - ResLIMIT, /* internal limitation reached */ - ResUNIMPL, /* unimplemented facility */ - ResIO /* system I/O error */ -}; - - -/* Functions - no type */ -#define FunctionCheck(fun) ((fun) != NULL) /* Could do more ? */ - #endif /* misc_h */ diff --git a/mps/src/mpm.c b/mps/src/mpm.c index 468eeb78bdf..be25aeafb67 100644 --- a/mps/src/mpm.c +++ b/mps/src/mpm.c @@ -1,6 +1,6 @@ /* impl.c.mpm: GENERAL MPM SUPPORT * - * $HopeName: MMsrc!mpm.c(trunk.5) $ + * $HopeName: MMsrc!mpm.c(trunk.6) $ * Copyright (C) 1996 Harlequin Group, all rights reserved. * * .readership: MM developers. @@ -13,7 +13,7 @@ #include "mpm.h" -SRCID(mpm, "$HopeName: MMsrc!mpm.c(trunk.5) $"); +SRCID(mpm, "$HopeName: MMsrc!mpm.c(trunk.6) $"); /* MPMCheck -- test MPM assumptions */ @@ -51,6 +51,35 @@ Bool MPMCheck(void) } +/* BoolCheck -- check that a boolean is valid */ + +Bool BoolCheck(Bool b) +{ + AVER(b == TRUE || b == FALSE); + return TRUE; +} + + +/* FunCheck -- check that a function pointer is valid */ + +Bool FunCheck(Fun f) +{ + AVER(f != NULL); + /* Could assert various platform-specific things here. */ + return TRUE; +} + + +/* AttrCheck -- check that a set of pool attributes are valid */ + +Bool AttrCheck(Attr attr) +{ + AVER(((attr) & ~AttrMASK) == 0); + /* Could check for legal combinations of attributes. */ + return TRUE; +} + + /* AlignCheck -- check that an alignment is valid */ Bool AlignCheck(Align align) diff --git a/mps/src/mpm.h b/mps/src/mpm.h index 2016df58682..49c30789a2c 100644 --- a/mps/src/mpm.h +++ b/mps/src/mpm.h @@ -1,6 +1,6 @@ /* impl.h.mpm: MEMORY POOL MANAGER DEFINITIONS * - * $HopeName: MMsrc!mpm.h(trunk.10) $ + * $HopeName: MMsrc!mpm.h(trunk.11) $ * Copyright (C) 1996 Harlequin Group, all rights reserved. */ @@ -39,6 +39,14 @@ extern Bool MPMCheck(void); +/* Miscellaneous Checks -- see impl.c.mpm */ + +extern Bool BoolCheck(Bool b); +extern Bool FunCheck(Fun f); +extern Bool AttrCheck(Attr attr); +#define FUNCHECK(f) (FunCheck((Fun)f)) + + /* Address/Size Interface -- see impl.c.mpm */ extern Bool (WordIsAligned)(Word word, Align align); @@ -431,6 +439,4 @@ extern void VMUnmap(Space space, Addr base, Addr limit); extern Size VMReserved(Space space); extern Size VMMapped(Space space); -#define AttrCheck(attr) (((attr) & ~AttrMask) == 0) - #endif /* mpm_h */