From a8afd8e6f43e3230178c7a8ce93c8e18fd3985e3 Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Wed, 8 May 2013 16:21:12 +0100 Subject: [PATCH] Converting pools to use keyword arguments, mostly, and so far inconsistently, but at least it compiles. Copied from Perforce Change: 181635 ServerID: perforce.ravenbrook.com --- mps/code/arena.c | 6 +- mps/code/arenacv.c | 6 +- mps/code/arg.c | 2 + mps/code/cbs.c | 9 ++- mps/code/config.h | 16 +++- mps/code/dbgpool.c | 29 ++++++- mps/code/global.c | 2 +- mps/code/mpm.h | 11 ++- mps/code/mpmtypes.h | 2 +- mps/code/mps.h | 15 ++++ mps/code/mps.xcodeproj/project.pbxproj | 106 +++++++++++++++++++++++++ mps/code/mpscams.h | 3 + mps/code/mpscawl.h | 5 ++ mps/code/mpscmfs.h | 5 ++ mps/code/mpscmv.h | 7 ++ mps/code/mpsi.c | 31 ++++++-- mps/code/pool.c | 35 +++----- mps/code/poolabs.c | 3 +- mps/code/poolamc.c | 34 ++++++-- mps/code/poolams.c | 40 +++++++++- mps/code/poolams.h | 1 + mps/code/poolawl.c | 28 ++++++- mps/code/poollo.c | 18 ++++- mps/code/poolmfs.c | 33 +++++++- mps/code/poolmfs.h | 1 + mps/code/poolmrg.c | 3 +- mps/code/poolmv.c | 47 ++++++++--- mps/code/poolmv.h | 1 + mps/code/poolmv2.c | 51 +++++++----- mps/code/poolmvff.c | 24 ++++-- mps/code/pooln.c | 2 +- mps/code/poolncv.c | 2 +- mps/code/poolsnc.c | 18 ++++- mps/code/reserv.c | 4 +- mps/code/segsmss.c | 23 +++++- mps/manual/source/topic/interface.rst | 10 ++- 36 files changed, 497 insertions(+), 136 deletions(-) diff --git a/mps/code/arena.c b/mps/code/arena.c index e36aa03cea4..b8397c4dfc3 100644 --- a/mps/code/arena.c +++ b/mps/code/arena.c @@ -301,10 +301,8 @@ Res ControlInit(Arena arena) Res res; AVERT(Arena, arena); - res = PoolInit(&arena->controlPoolStruct.poolStruct, - arena, PoolClassMV(), - ARENA_CONTROL_EXTENDBY, ARENA_CONTROL_AVGSIZE, - ARENA_CONTROL_MAXSIZE); + res = PoolInit(&arena->controlPoolStruct.poolStruct, arena, + PoolClassMV(), argsNone); if (res != ResOK) return res; arena->poolReady = TRUE; /* */ diff --git a/mps/code/arenacv.c b/mps/code/arenacv.c index 60f482b2a93..18b5ba3418f 100644 --- a/mps/code/arenacv.c +++ b/mps/code/arenacv.c @@ -337,7 +337,7 @@ static void testPageTable(ArenaClass class, Size size, Addr addr) Arena arena; Pool pool; Size pageSize; Count tractsPerPage; - ArgStruct args[3]; + ArgStruct args[4]; args[0].key = MPS_KEY_ARENA_SIZE; args[0].val.size = size; @@ -346,9 +346,7 @@ static void testPageTable(ArenaClass class, Size size, Addr addr) args[2].key = MPS_KEY_ARGS_END; die(ArenaCreate(&arena, class, args), "ArenaCreate"); - die(PoolCreate(&pool, arena, PoolClassMV(), - (Size)65536, (Size)32, (Size)65536), - "PoolCreate"); + die(PoolCreate(&pool, arena, PoolClassMV(), argsNone), "PoolCreate"); pageSize = ArenaAlign(arena); tractsPerPage = pageSize / sizeof(TractStruct); diff --git a/mps/code/arg.c b/mps/code/arg.c index 3528dcce136..b74b9d6886b 100644 --- a/mps/code/arg.c +++ b/mps/code/arg.c @@ -25,6 +25,8 @@ Bool ArgCheckCant(Arg arg) { const KeyStruct _mps_key_varargs = {KeySig, "VARARGS", ArgCheckCant}; +ArgStruct mps_args_none[] = {{MPS_KEY_ARGS_END}}; + /* KeyCheck -- check the validity of an argument key */ diff --git a/mps/code/cbs.c b/mps/code/cbs.c index a9cb0d0b087..4c48c690cc3 100644 --- a/mps/code/cbs.c +++ b/mps/code/cbs.c @@ -273,6 +273,7 @@ Res CBSInit(Arena arena, CBS cbs, void *owner, Bool mayUseInline, Bool fastFind) { Res res; + ArgStruct args[3]; AVERT(Arena, arena); AVER(new == NULL || FUNCHECK(new)); @@ -286,8 +287,12 @@ Res CBSInit(Arena arena, CBS cbs, void *owner, SplayTreeInit(splayTreeOfCBS(cbs), &cbsSplayCompare, fastFind ? &cbsUpdateNode : NULL); - res = PoolCreate(&(cbs->blockPool), arena, PoolClassMFS(), - sizeof(CBSBlockStruct) * 64, sizeof(CBSBlockStruct)); + args[0].key = MPS_KEY_MFS_UNIT_SIZE; + args[0].val.size = sizeof(CBSBlockStruct); + args[1].key = MPS_KEY_MFS_EXTEND_BY; + args[1].val.size = sizeof(CBSBlockStruct) * 64; + args[2].key = MPS_KEY_ARGS_END; + res = PoolCreate(&(cbs->blockPool), arena, PoolClassMFS(), args); if (res != ResOK) return res; cbs->splayTreeSize = 0; diff --git a/mps/code/config.h b/mps/code/config.h index 33ce96951ec..9fc57096bc7 100644 --- a/mps/code/config.h +++ b/mps/code/config.h @@ -238,6 +238,18 @@ #define EPVMDefaultSubsequentSegSIZE ((Size)64 * 1024) +/* Pool MV Configuration -- see */ + +#define MV_EXTEND_BY_DEFAULT ((Size)4096) +#define MV_AVG_SIZE_DEFAULT ((Size)32) +#define MV_MAX_SIZE_DEFAULT ((Size)65536) + + +/* Pool MFS Configuration -- see */ + +#define MFS_EXTEND_BY_DEFAULT ((Size)65536) + + /* Arena Configuration -- see * * .client.seg-size: ARENA_CLIENT_PAGE_SIZE is the size in bytes of a @@ -245,10 +257,6 @@ * with no particular justification. */ -#define ARENA_CONTROL_EXTENDBY ((Size)4096) -#define ARENA_CONTROL_AVGSIZE ((Size)32) -#define ARENA_CONTROL_MAXSIZE ((Size)65536) - #define ArenaPollALLOCTIME (65536.0) #define ARENA_ZONESHIFT ((Shift)20) diff --git a/mps/code/dbgpool.c b/mps/code/dbgpool.c index 8a3bc7e3034..447ed1672d8 100644 --- a/mps/code/dbgpool.c +++ b/mps/code/dbgpool.c @@ -117,17 +117,32 @@ static Bool PoolDebugOptionsCheck(PoolDebugOptions opt) * Someday, this could be split into fence and tag init methods. */ -static Res DebugPoolInit(Pool pool, va_list args) +const KeyStruct _mps_key_pool_debug_option = { + KeySig, "POOL_DEBUG_OPTION", ArgCheckCant /* FIXME: ArgCheckPoolDebugOption */ +}; + +static Res DebugPoolInit(Pool pool, ArgList args) { Res res; PoolDebugOptions options; PoolDebugMixin debug; TagInitMethod tagInit; Size tagSize; + ArgStruct arg; AVERT(Pool, pool); - options = va_arg(args, PoolDebugOptions); + + /* FIXME: Split this structure into separate keys */ + /* FIXME: Can't use varargs -- update docs. */ + if (ArgPick(&arg, args, MPS_KEY_POOL_DEBUG_OPTION)) + options = (PoolDebugOptions)arg.val.pool_debug_option; + else { + res = ResPARAM; + goto failParam; + } + AVERT(PoolDebugOptions, options); + /* @@@@ Tag parameters should be taken from options, but tags have */ /* not been published yet. */ tagInit = NULL; tagSize = 0; @@ -173,11 +188,16 @@ static Res DebugPoolInit(Pool pool, va_list args) /* tag init */ debug->tagInit = tagInit; if (debug->tagInit != NULL) { + ArgStruct pcArgs[3]; debug->tagSize = tagSize + sizeof(tagStruct) - 1; /* This pool has to be like the arena control pool: the blocks */ /* allocated must be accessible using void*. */ - res = PoolCreate(&debug->tagPool, PoolArena(pool), PoolClassMFS(), - debug->tagSize, debug->tagSize); + pcArgs[0].key = MPS_KEY_MFS_EXTEND_BY; + pcArgs[0].val.size = debug->tagSize; /* FIXME: Really? */ + pcArgs[1].key = MPS_KEY_MFS_UNIT_SIZE; + pcArgs[1].val.size = debug->tagSize; + pcArgs[2].key = MPS_KEY_ARGS_END; + res = PoolCreate(&debug->tagPool, PoolArena(pool), PoolClassMFS(), pcArgs); if (res != ResOK) goto tagFail; debug->missingTags = 0; @@ -191,6 +211,7 @@ static Res DebugPoolInit(Pool pool, va_list args) tagFail: alignFail: SuperclassOfPool(pool)->finish(pool); +failParam: return res; } diff --git a/mps/code/global.c b/mps/code/global.c index 2071918ad0e..a1204332d9c 100644 --- a/mps/code/global.c +++ b/mps/code/global.c @@ -834,7 +834,7 @@ Res ArenaFinalize(Arena arena, Ref obj) if (!arena->isFinalPool) { Pool pool; - res = PoolCreate(&pool, arena, PoolClassMRG()); + res = PoolCreate(&pool, arena, PoolClassMRG(), argsNone); if (res != ResOK) return res; arena->finalPool = pool; diff --git a/mps/code/mpm.h b/mps/code/mpm.h index db4e2415045..bd3752460f7 100644 --- a/mps/code/mpm.h +++ b/mps/code/mpm.h @@ -132,6 +132,7 @@ extern Bool ResIsAllocFailure(Res res); /* Argument Lists */ +#define argsNone mps_args_none extern Bool KeyCheck(Key key); extern Bool ArgCheck(Arg arg); extern Bool ArgListCheck(ArgList args); @@ -187,8 +188,7 @@ extern char *MPSVersion(void); /* Pool Interface -- see impl.c.pool */ -extern Res PoolInit(Pool pool, Arena arena, PoolClass class, ...); -extern Res PoolInitV(Pool pool, Arena arena, PoolClass class, va_list args); +extern Res PoolInit(Pool pool, Arena arena, PoolClass class, ArgList args); extern void PoolFinish(Pool pool); extern Bool PoolClassCheck(PoolClass class); extern Bool PoolCheck(Pool pool); @@ -205,9 +205,8 @@ extern double PoolMutatorAllocSize(Pool pool); extern Bool PoolOfAddr(Pool *poolReturn, Arena arena, Addr addr); extern Bool PoolHasAddr(Pool pool, Addr addr); -extern Res PoolCreate(Pool *poolReturn, Arena arena, PoolClass class, ...); -extern Res PoolCreateV(Pool *poolReturn, Arena arena, PoolClass class, - va_list arg); +extern Res PoolCreate(Pool *poolReturn, Arena arena, PoolClass class, + ArgList args); extern void PoolDestroy(Pool pool); extern BufferClass PoolDefaultBufferClass(Pool pool); extern Res PoolAlloc(Addr *pReturn, Pool pool, Size size, @@ -229,7 +228,7 @@ extern void PoolTraceEnd(Pool pool, Trace trace); extern void PoolWalk(Pool pool, Seg seg, FormattedObjectsStepMethod f, void *v, size_t s); extern void PoolFreeWalk(Pool pool, FreeBlockStepMethod f, void *p); -extern Res PoolTrivInit(Pool pool, va_list arg); +extern Res PoolTrivInit(Pool pool, ArgList arg); extern void PoolTrivFinish(Pool pool); extern Res PoolNoAlloc(Addr *pReturn, Pool pool, Size size, Bool withReservoirPermit); diff --git a/mps/code/mpmtypes.h b/mps/code/mpmtypes.h index 8df2e91dbb0..cadb8f2bff1 100644 --- a/mps/code/mpmtypes.h +++ b/mps/code/mpmtypes.h @@ -182,7 +182,7 @@ typedef Res (*BufferDescribeMethod)(Buffer buffer, mps_lib_FILE *stream); /* Order of types corresponds to PoolClassStruct in */ -typedef Res (*PoolInitMethod)(Pool pool, va_list args); +typedef Res (*PoolInitMethod)(Pool pool, ArgList args); typedef void (*PoolFinishMethod)(Pool pool); typedef Res (*PoolAllocMethod)(Addr *pReturn, Pool pool, Size size, Bool withReservoirPermit); diff --git a/mps/code/mps.h b/mps/code/mps.h index 0b450da9f5b..4b30f133187 100644 --- a/mps/code/mps.h +++ b/mps/code/mps.h @@ -107,6 +107,10 @@ typedef struct mps_arg_s { size_t size; va_list varargs; mps_addr_t addr; + mps_fmt_t format; + mps_chain_t chain; + struct mps_pool_debug_option_s *pool_debug_option; + mps_addr_t (*addr_method)(mps_addr_t); } val; } mps_arg_s; @@ -120,6 +124,12 @@ extern const struct mps_key_s _mps_key_varargs; #define MPS_KEY_VARARGS (&_mps_key_varargs) extern const struct mps_key_s _mps_key_arena_size; #define MPS_KEY_ARENA_SIZE (&_mps_key_arena_size) +extern const struct mps_key_s _mps_key_format; +#define MPS_KEY_FORMAT (&_mps_key_format) +extern const struct mps_key_s _mps_key_chain; +#define MPS_KEY_CHAIN (&_mps_key_chain) + +extern mps_arg_s mps_args_none[]; /* Keep in sync with @@ -347,6 +357,8 @@ extern mps_res_t mps_pool_create(mps_pool_t *, mps_arena_t, mps_class_t, ...); extern mps_res_t mps_pool_create_v(mps_pool_t *, mps_arena_t, mps_class_t, va_list); +extern mps_res_t mps_pool_create_k(mps_pool_t *, mps_arena_t, + mps_class_t, mps_arg_s []); extern void mps_pool_destroy(mps_pool_t); /* .gen-param: This structure must match . */ @@ -634,6 +646,9 @@ typedef struct mps_pool_debug_option_s { size_t free_size; } mps_pool_debug_option_s; +extern const struct mps_key_s _mps_key_pool_debug_option; +#define MPS_KEY_POOL_DEBUG_OPTION (&_mps_key_pool_debug_option) + extern void mps_pool_check_fenceposts(mps_pool_t); extern void mps_pool_check_free_space(mps_pool_t); diff --git a/mps/code/mps.xcodeproj/project.pbxproj b/mps/code/mps.xcodeproj/project.pbxproj index 134e873becc..20510f2cf75 100644 --- a/mps/code/mps.xcodeproj/project.pbxproj +++ b/mps/code/mps.xcodeproj/project.pbxproj @@ -1038,6 +1038,51 @@ 3114A6C6156E9815001E0AA3 /* mpseventcnv */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = mpseventcnv; sourceTree = BUILT_PRODUCTS_DIR; }; 3114A6D0156E9829001E0AA3 /* eventcnv.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = eventcnv.c; sourceTree = ""; }; 3114A6D9156E9950001E0AA3 /* eventpro.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = eventpro.c; sourceTree = ""; }; + 311F2F5017398AD500C15B6A /* boot.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = boot.h; sourceTree = ""; }; + 311F2F5117398AE900C15B6A /* bt.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = bt.h; sourceTree = ""; }; + 311F2F5217398AE900C15B6A /* cbs.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = cbs.h; sourceTree = ""; }; + 311F2F5317398AE900C15B6A /* chain.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = chain.h; sourceTree = ""; }; + 311F2F5417398AE900C15B6A /* check.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = check.h; sourceTree = ""; }; + 311F2F5517398AE900C15B6A /* clock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = clock.h; sourceTree = ""; }; + 311F2F5617398AE900C15B6A /* config.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = ""; }; + 311F2F5717398AE900C15B6A /* dbgpool.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = dbgpool.h; sourceTree = ""; }; + 311F2F5817398AE900C15B6A /* event.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = event.h; sourceTree = ""; }; + 311F2F5917398AE900C15B6A /* eventcom.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = eventcom.h; sourceTree = ""; }; + 311F2F5A17398AE900C15B6A /* eventdef.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = eventdef.h; sourceTree = ""; }; + 311F2F5B17398AE900C15B6A /* eventpro.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = eventpro.h; sourceTree = ""; }; + 311F2F5C17398AE900C15B6A /* eventrep.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = eventrep.h; sourceTree = ""; }; + 311F2F5D17398B0400C15B6A /* lo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = lo.h; sourceTree = ""; }; + 311F2F5E17398B0E00C15B6A /* lock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = lock.h; sourceTree = ""; }; + 311F2F5F17398B0E00C15B6A /* meter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = meter.h; sourceTree = ""; }; + 311F2F6017398B0E00C15B6A /* misc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = misc.h; sourceTree = ""; }; + 311F2F6117398B0E00C15B6A /* mpm.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mpm.h; sourceTree = ""; }; + 311F2F6217398B1A00C15B6A /* mpmst.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mpmst.h; sourceTree = ""; }; + 311F2F6317398B1A00C15B6A /* mpmtypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mpmtypes.h; sourceTree = ""; }; + 311F2F6417398B1A00C15B6A /* mps.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mps.h; sourceTree = ""; }; + 311F2F6517398B3B00C15B6A /* mpsacl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mpsacl.h; sourceTree = ""; }; + 311F2F6617398B3B00C15B6A /* mpsavm.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mpsavm.h; sourceTree = ""; }; + 311F2F6717398B3B00C15B6A /* mpsio.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mpsio.h; sourceTree = ""; }; + 311F2F6817398B3B00C15B6A /* mpslib.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mpslib.h; sourceTree = ""; }; + 311F2F6917398B3B00C15B6A /* mpstd.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mpstd.h; sourceTree = ""; }; + 311F2F6A17398B4C00C15B6A /* mpsw3.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mpsw3.h; sourceTree = ""; }; + 311F2F6B17398B4C00C15B6A /* mpswin.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mpswin.h; sourceTree = ""; }; + 311F2F6C17398B5800C15B6A /* osxc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = osxc.h; sourceTree = ""; }; + 311F2F6D17398B6300C15B6A /* prmci3.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = prmci3.h; sourceTree = ""; }; + 311F2F6E17398B6300C15B6A /* prmci6.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = prmci6.h; sourceTree = ""; }; + 311F2F6F17398B6300C15B6A /* prmcix.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = prmcix.h; sourceTree = ""; }; + 311F2F7017398B6300C15B6A /* prmcw3.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = prmcw3.h; sourceTree = ""; }; + 311F2F7117398B7100C15B6A /* protocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = protocol.h; sourceTree = ""; }; + 311F2F7217398B7100C15B6A /* pthrdext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = pthrdext.h; sourceTree = ""; }; + 311F2F7317398B7100C15B6A /* ring.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ring.h; sourceTree = ""; }; + 311F2F7417398B7100C15B6A /* sac.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = sac.h; sourceTree = ""; }; + 311F2F7517398B8E00C15B6A /* sc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = sc.h; sourceTree = ""; }; + 311F2F7617398B8E00C15B6A /* splay.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = splay.h; sourceTree = ""; }; + 311F2F7717398B8E00C15B6A /* ss.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ss.h; sourceTree = ""; }; + 311F2F7817398B8E00C15B6A /* th.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = th.h; sourceTree = ""; }; + 311F2F7917398B8E00C15B6A /* thw3.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = thw3.h; sourceTree = ""; }; + 311F2F7A17398B8E00C15B6A /* tract.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = tract.h; sourceTree = ""; }; + 311F2F7B17398E7600C15B6A /* poolmv.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = poolmv.h; sourceTree = ""; }; + 311F2F7C17398E9A00C15B6A /* mpscmv.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mpscmv.h; sourceTree = ""; }; 3124CAB8156BE3EC00753214 /* awlut */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = awlut; sourceTree = BUILT_PRODUCTS_DIR; }; 3124CAC2156BE40100753214 /* awlut.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = awlut.c; sourceTree = ""; }; 3124CAC6156BE48D00753214 /* fmtdy.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = fmtdy.c; sourceTree = ""; }; @@ -1053,6 +1098,9 @@ 317B3C2A1731830100F9A469 /* arg.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = arg.c; sourceTree = ""; }; 31A47BA3156C1E130039B1C2 /* mps.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mps.c; sourceTree = ""; }; 31A47BA5156C1E5E0039B1C2 /* ssixi3.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = ssixi3.c; sourceTree = ""; }; + 31CD33BB173A9F1500524741 /* mpscams.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mpscams.h; sourceTree = ""; }; + 31CD33BC173A9F1500524741 /* poolams.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = poolams.c; sourceTree = ""; }; + 31CD33BD173A9F1500524741 /* poolams.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = poolams.h; sourceTree = ""; }; 31D60006156D3C5F00337B26 /* segsmss.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = segsmss.c; sourceTree = ""; }; 31D6000D156D3CB200337B26 /* awluthe */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = awluthe; sourceTree = BUILT_PRODUCTS_DIR; }; 31D60017156D3CC300337B26 /* awluthe.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = awluthe.c; sourceTree = ""; }; @@ -1120,6 +1168,11 @@ 31EEAC74156AB58E00714D05 /* mpmss.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mpmss.c; sourceTree = SOURCE_ROOT; }; 31EEAC9E156AB73400714D05 /* testlib.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = testlib.c; sourceTree = ""; }; 31EEACA7156AB79800714D05 /* span.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = span.c; sourceTree = ""; }; + 31F6CCA91739B0CF00C48748 /* mpscamc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mpscamc.h; sourceTree = ""; }; + 31F6CCAA1739B0CF00C48748 /* mpscawl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mpscawl.h; sourceTree = ""; }; + 31F6CCAB1739B0CF00C48748 /* mpsclo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mpsclo.h; sourceTree = ""; }; + 31F6CCAC1739B0CF00C48748 /* mpscmvff.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mpscmvff.h; sourceTree = ""; }; + 31F6CCAD1739B0CF00C48748 /* mpscsnc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mpscsnc.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -1572,38 +1625,82 @@ 31EEAC03156AB23A00714D05 /* arenavm.c */, 317B3C2A1731830100F9A469 /* arg.c */, 31EEAC3F156AB32500714D05 /* boot.c */, + 311F2F5017398AD500C15B6A /* boot.h */, 31EEAC27156AB2F200714D05 /* bt.c */, + 311F2F5117398AE900C15B6A /* bt.h */, 31EEAC19156AB2B200714D05 /* buffer.c */, 31EEAC40156AB32500714D05 /* cbs.c */, + 311F2F5217398AE900C15B6A /* cbs.h */, + 311F2F5317398AE900C15B6A /* chain.h */, + 311F2F5417398AE900C15B6A /* check.h */, + 311F2F5517398AE900C15B6A /* clock.h */, + 311F2F5617398AE900C15B6A /* config.h */, 31EEAC28156AB2F200714D05 /* dbgpool.c */, + 311F2F5717398AE900C15B6A /* dbgpool.h */, 31EEAC29156AB2F200714D05 /* dbgpooli.c */, 31EEAC41156AB32500714D05 /* diag.c */, 31EEAC2A156AB2F200714D05 /* event.c */, + 311F2F5817398AE900C15B6A /* event.h */, + 311F2F5917398AE900C15B6A /* eventcom.h */, + 311F2F5A17398AE900C15B6A /* eventdef.h */, + 311F2F5B17398AE900C15B6A /* eventpro.h */, + 311F2F5C17398AE900C15B6A /* eventrep.h */, 31EEAC1A156AB2B200714D05 /* format.c */, 31EEAC07156AB27B00714D05 /* global.c */, 31EEAC2B156AB2F200714D05 /* ld.c */, + 311F2F5E17398B0E00C15B6A /* lock.h */, 31EEAC08156AB27B00714D05 /* locus.c */, 31EEAC2C156AB2F200714D05 /* message.c */, 31EEAC42156AB32500714D05 /* meter.c */, + 311F2F5F17398B0E00C15B6A /* meter.h */, + 311F2F6017398B0E00C15B6A /* misc.h */, 31EEAC01156AB21B00714D05 /* mpm.c */, + 311F2F6117398B0E00C15B6A /* mpm.h */, + 311F2F6217398B1A00C15B6A /* mpmst.h */, + 311F2F6317398B1A00C15B6A /* mpmtypes.h */, + 311F2F6417398B1A00C15B6A /* mps.h */, + 311F2F6517398B3B00C15B6A /* mpsacl.h */, + 311F2F6617398B3B00C15B6A /* mpsavm.h */, 31EEABF5156AAF7C00714D05 /* mpsi.c */, + 311F2F6717398B3B00C15B6A /* mpsio.h */, + 311F2F6817398B3B00C15B6A /* mpslib.h */, + 311F2F6917398B3B00C15B6A /* mpstd.h */, + 311F2F6A17398B4C00C15B6A /* mpsw3.h */, + 311F2F6B17398B4C00C15B6A /* mpswin.h */, + 311F2F6C17398B5800C15B6A /* osxc.h */, 31EEAC09156AB27B00714D05 /* pool.c */, 31EEAC0A156AB27B00714D05 /* poolabs.c */, 31EEAC2D156AB2F200714D05 /* poolmfs.c */, 31EEAC2E156AB2F200714D05 /* poolmrg.c */, 31EEAC2F156AB2F200714D05 /* poolmv.c */, + 311F2F7B17398E7600C15B6A /* poolmv.h */, + 311F2F7C17398E9A00C15B6A /* mpscmv.h */, + 311F2F6D17398B6300C15B6A /* prmci3.h */, + 311F2F6E17398B6300C15B6A /* prmci6.h */, + 311F2F6F17398B6300C15B6A /* prmcix.h */, + 311F2F7017398B6300C15B6A /* prmcw3.h */, 31EEAC0B156AB27B00714D05 /* protocol.c */, + 311F2F7117398B7100C15B6A /* protocol.h */, + 311F2F7217398B7100C15B6A /* pthrdext.h */, 31EEAC1B156AB2B200714D05 /* ref.c */, 31EEAC0C156AB27B00714D05 /* reserv.c */, 31EEAC30156AB2F200714D05 /* ring.c */, + 311F2F7317398B7100C15B6A /* ring.h */, 31EEAC1C156AB2B200714D05 /* root.c */, 31EEAC31156AB2F200714D05 /* sac.c */, + 311F2F7417398B7100C15B6A /* sac.h */, + 311F2F7517398B8E00C15B6A /* sc.h */, 31EEAC1D156AB2B200714D05 /* seg.c */, 31EEAC32156AB2F200714D05 /* shield.c */, 31EEAC43156AB32500714D05 /* splay.c */, + 311F2F7617398B8E00C15B6A /* splay.h */, + 311F2F7717398B8E00C15B6A /* ss.h */, + 311F2F7817398B8E00C15B6A /* th.h */, + 311F2F7917398B8E00C15B6A /* thw3.h */, 31EEAC1E156AB2B200714D05 /* trace.c */, 31EEAC1F156AB2B200714D05 /* traceanc.c */, 31EEAC0D156AB27B00714D05 /* tract.c */, + 311F2F7A17398B8E00C15B6A /* tract.h */, 31EEAC44156AB32500714D05 /* version.c */, 31EEAC0E156AB27B00714D05 /* walk.c */, ); @@ -1629,7 +1726,16 @@ 31EEAC5A156AB40800714D05 /* Extra pools */ = { isa = PBXGroup; children = ( + 311F2F5D17398B0400C15B6A /* lo.h */, + 31F6CCA91739B0CF00C48748 /* mpscamc.h */, + 31CD33BB173A9F1500524741 /* mpscams.h */, + 31F6CCAA1739B0CF00C48748 /* mpscawl.h */, + 31F6CCAB1739B0CF00C48748 /* mpsclo.h */, + 31F6CCAC1739B0CF00C48748 /* mpscmvff.h */, + 31F6CCAD1739B0CF00C48748 /* mpscsnc.h */, 31EEAC5B156AB41900714D05 /* poolamc.c */, + 31CD33BC173A9F1500524741 /* poolams.c */, + 31CD33BD173A9F1500524741 /* poolams.h */, 3124CACE156BE4CF00753214 /* poolawl.c */, 3124CACA156BE4A300753214 /* poollo.c */, 31EEAC5F156AB44D00714D05 /* poolmvff.c */, diff --git a/mps/code/mpscams.h b/mps/code/mpscams.h index 22fc9185157..f8013467a5d 100644 --- a/mps/code/mpscams.h +++ b/mps/code/mpscams.h @@ -10,6 +10,9 @@ #include "mps.h" +extern const struct mps_key_s _mps_key_ams_support_ambiguous; +#define MPS_KEY_AMS_SUPPORT_AMBIGUOUS (&_mps_key_ams_support_ambiguous) + extern mps_class_t mps_class_ams(void); extern mps_class_t mps_class_ams_debug(void); diff --git a/mps/code/mpscawl.h b/mps/code/mpscawl.h index 0b5bc790acf..a332c5057f1 100644 --- a/mps/code/mpscawl.h +++ b/mps/code/mpscawl.h @@ -9,8 +9,13 @@ #include "mps.h" +extern const struct mps_key_s _mps_key_awl_find_dependent; +#define MPS_KEY_AWL_FIND_DEPENDENT (&_mps_key_awl_find_dependent) + extern mps_class_t mps_class_awl(void); +typedef mps_addr_t (*mps_awl_find_dependent_t)(mps_addr_t addr); + #endif /* mpscawl_h */ diff --git a/mps/code/mpscmfs.h b/mps/code/mpscmfs.h index 4a46e10a84b..056576ec17f 100644 --- a/mps/code/mpscmfs.h +++ b/mps/code/mpscmfs.h @@ -9,6 +9,11 @@ #include "mps.h" +extern const struct mps_key_s _mps_mfs_extend_by; +#define MPS_KEY_MFS_EXTEND_BY (&_mps_mfs_extend_by) +extern const struct mps_key_s _mps_mfs_unit_size; +#define MPS_KEY_MFS_UNIT_SIZE (&_mps_mfs_unit_size) + extern mps_class_t mps_class_mfs(void); #endif /* mpscmfs_h */ diff --git a/mps/code/mpscmv.h b/mps/code/mpscmv.h index 805db19b8af..779c8b6d8e7 100644 --- a/mps/code/mpscmv.h +++ b/mps/code/mpscmv.h @@ -9,6 +9,13 @@ #include "mps.h" +extern const struct mps_key_s _mps_key_mv_extend_by; +#define MPS_KEY_MV_EXTEND_BY (&_mps_key_mv_extend_by) +extern const struct mps_key_s _mps_key_mv_avg_size; +#define MPS_KEY_MV_AVG_SIZE (&_mps_key_mv_avg_size) +extern const struct mps_key_s _mps_key_mv_max_size; +#define MPS_KEY_MV_MAX_SIZE (&_mps_key_mv_max_size) + extern size_t mps_mv_free_size(mps_pool_t mps_pool); extern size_t mps_mv_size(mps_pool_t mps_pool); extern mps_class_t mps_class_mv(void); diff --git a/mps/code/mpsi.c b/mps/code/mpsi.c index 15f44a24ff1..94034a0c71f 100644 --- a/mps/code/mpsi.c +++ b/mps/code/mpsi.c @@ -321,7 +321,7 @@ mps_res_t mps_arena_create(mps_arena_t *mps_arena_o, va_start(args[0].val.varargs, mps_arena_class); args[1].key = MPS_KEY_ARGS_END; res = mps_arena_create_args(mps_arena_o, mps_arena_class, args); - va_end(args[0].val.varargs); + /* FIXME: Can't va_end? */ return res; } @@ -633,15 +633,31 @@ mps_res_t mps_pool_create(mps_pool_t *mps_pool_o, mps_arena_t arena, mps_class_t mps_class, ...) { mps_res_t res; - va_list args; - va_start(args, mps_class); - res = mps_pool_create_v(mps_pool_o, arena, mps_class, args); - va_end(args); + mps_arg_s args[2]; + args[0].key = MPS_KEY_VARARGS; + va_start(args[0].val.varargs, mps_class); + args[1].key = MPS_KEY_ARGS_END; + res = mps_pool_create_k(mps_pool_o, arena, mps_class, args); + /* FIXME: Can't va_end? */ return res; } mps_res_t mps_pool_create_v(mps_pool_t *mps_pool_o, mps_arena_t arena, - mps_class_t class, va_list args) + mps_class_t class, va_list varargs) +{ + mps_arg_s args[2]; + + args[0].key = MPS_KEY_VARARGS; + /* FIXME: va_copy not available in C89 */ + memcpy(&args[0].val.varargs, &varargs, sizeof(va_list)); + args[1].key = MPS_KEY_ARGS_END; + + return mps_pool_create_k(mps_pool_o, arena, class, args); +} + + +mps_res_t mps_pool_create_k(mps_pool_t *mps_pool_o, mps_arena_t arena, + mps_class_t class, mps_arg_s args[]) { Pool pool; Res res; @@ -651,8 +667,9 @@ mps_res_t mps_pool_create_v(mps_pool_t *mps_pool_o, mps_arena_t arena, AVER(mps_pool_o != NULL); AVERT(Arena, arena); AVERT(PoolClass, class); + AVER(ArgListCheck(args)); - res = PoolCreateV(&pool, arena, class, args); + res = PoolCreate(&pool, arena, class, args); ArenaLeave(arena); diff --git a/mps/code/pool.c b/mps/code/pool.c index 315bbac4fb2..09a10f13d62 100644 --- a/mps/code/pool.c +++ b/mps/code/pool.c @@ -105,22 +105,18 @@ Bool PoolCheck(Pool pool) } -/* PoolInit, PoolInitV -- initialize a pool +/* Common keywords to PoolInit */ + +const KeyStruct _mps_key_format = {KeySig, "AMS_FORMAT", ArgCheckCant}; /* FIXME: ArgCheckFormat */ +const KeyStruct _mps_key_chain = {KeySig, "AMS_CHAIN", ArgCheckCant}; /* FIXME: ArgCheckChain */ + + +/* PoolInit -- initialize a pool * * Initialize the generic fields of the pool and calls class-specific * init. See . */ -Res PoolInit(Pool pool, Arena arena, PoolClass class, ...) -{ - Res res; - va_list args; - va_start(args, class); - res = PoolInitV(pool, arena, class, args); - va_end(args); - return res; -} - -Res PoolInitV(Pool pool, Arena arena, PoolClass class, va_list args) +Res PoolInit(Pool pool, Arena arena, PoolClass class, ArgList args) { Res res; Word classId; @@ -185,18 +181,7 @@ failInit: /* PoolCreate, PoolCreateV: Allocate and initialise pool */ Res PoolCreate(Pool *poolReturn, Arena arena, - PoolClass class, ...) -{ - Res res; - va_list args; - va_start(args, class); - res = PoolCreateV(poolReturn, arena, class, args); - va_end(args); - return res; -} - -Res PoolCreateV(Pool *poolReturn, Arena arena, - PoolClass class, va_list args) + PoolClass class, ArgList args) { Res res; Pool pool; @@ -219,7 +204,7 @@ Res PoolCreateV(Pool *poolReturn, Arena arena, pool = (Pool)PointerAdd(base, class->offset); /* Initialize the pool. */ - res = PoolInitV(pool, arena, class, args); + res = PoolInit(pool, arena, class, args); if (res != ResOK) goto failPoolInit; diff --git a/mps/code/poolabs.c b/mps/code/poolabs.c index e3e45b7480c..1456ec66143 100644 --- a/mps/code/poolabs.c +++ b/mps/code/poolabs.c @@ -194,9 +194,10 @@ void PoolTrivFinish(Pool pool) NOOP; } -Res PoolTrivInit(Pool pool, va_list args) +Res PoolTrivInit(Pool pool, ArgList args) { AVERT(Pool, pool); + AVER(ArgListCheck(args)); UNUSED(args); return ResOK; } diff --git a/mps/code/poolamc.c b/mps/code/poolamc.c index e96acb0f977..30ee17cc656 100644 --- a/mps/code/poolamc.c +++ b/mps/code/poolamc.c @@ -933,7 +933,7 @@ static Bool amcNailRangeIsMarked(Seg seg, Addr base, Addr limit) * See . * Shared by AMCInit and AMCZinit. */ -static Res amcInitComm(Pool pool, RankSet rankSet, va_list arg) +static Res amcInitComm(Pool pool, RankSet rankSet, ArgList args) { AMC amc; Res res; @@ -943,6 +943,7 @@ static Res amcInitComm(Pool pool, RankSet rankSet, va_list arg) Index i; size_t genArraySize; size_t genCount; + ArgStruct arg; /* Suppress a warning about this structure not being used when there are no statistics. Note that simply making the declaration conditional @@ -959,11 +960,27 @@ static Res amcInitComm(Pool pool, RankSet rankSet, va_list arg) amc = Pool2AMC(pool); arena = PoolArena(pool); - pool->format = va_arg(arg, Format); + if (ArgPick(&arg, args, MPS_KEY_VARARGS)) { + pool->format = va_arg(arg.val.varargs, Format); + amc->chain = va_arg(arg.val.varargs, Chain); + } else { + if (ArgPick(&arg, args, MPS_KEY_FORMAT)) + pool->format = arg.val.format; + else { + res = ResPARAM; + goto failParam; + } + if (ArgPick(&arg, args, MPS_KEY_CHAIN)) + amc->chain = arg.val.chain; + else { + res = ResPARAM; + goto failParam; + } + } + AVERT(Format, pool->format); - pool->alignment = pool->format->alignment; - amc->chain = va_arg(arg, Chain); AVERT(Chain, amc->chain); + pool->alignment = pool->format->alignment; amc->rankSet = rankSet; RingInit(&amc->genRing); @@ -1035,17 +1052,18 @@ failGenAlloc: } ControlFree(arena, amc->gen, genArraySize); failGensAlloc: +failParam: return res; } -static Res AMCInit(Pool pool, va_list arg) +static Res AMCInit(Pool pool, ArgList args) { - return amcInitComm(pool, RankSetSingle(RankEXACT), arg); + return amcInitComm(pool, RankSetSingle(RankEXACT), args); } -static Res AMCZInit(Pool pool, va_list arg) +static Res AMCZInit(Pool pool, ArgList args) { - return amcInitComm(pool, RankSetEMPTY, arg); + return amcInitComm(pool, RankSetEMPTY, args); } diff --git a/mps/code/poolams.c b/mps/code/poolams.c index 34e07fceccc..d922e36a2a0 100644 --- a/mps/code/poolams.c +++ b/mps/code/poolams.c @@ -733,18 +733,47 @@ static void AMSSegsDestroy(AMS ams) * Takes one additional argument: the format of the objects * allocated in the pool. See . */ -static Res AMSInit(Pool pool, va_list args) + +const KeyStruct _mps_key_ams_support_ambiguous = { + KeySig, "AMS_SUPPORT_AMBIGUOUS", ArgCheckCant /* FIXME: ArgCheckBool */ +}; + +static Res AMSInit(Pool pool, ArgList args) { Res res; Format format; Chain chain; Bool supportAmbiguous; + ArgStruct arg; AVERT(Pool, pool); + AVER(ArgListCheck(args)); + + if (ArgPick(&arg, args, MPS_KEY_VARARGS)) { + format = va_arg(arg.val.varargs, Format); + chain = va_arg(arg.val.varargs, Chain); + supportAmbiguous = va_arg(arg.val.varargs, Bool); + } else { + if (ArgPick(&arg, args, MPS_KEY_CHAIN)) + chain = arg.val.chain; + else { + res = ResPARAM; + goto failParam; + } + if (ArgPick(&arg, args, MPS_KEY_FORMAT)) + format = arg.val.format; + else { + res = ResPARAM; + goto failParam; + } + if (ArgPick(&arg, args, MPS_KEY_AMS_SUPPORT_AMBIGUOUS)) + supportAmbiguous = arg.val.b; + else { + res = ResPARAM; + goto failParam; + } + } - format = va_arg(args, Format); - chain = va_arg(args, Chain); - supportAmbiguous = va_arg(args, Bool); /* .ambiguous.noshare: If the pool is required to support ambiguous */ /* references, the alloc and white tables cannot be shared. */ res = AMSInitInternal(Pool2AMS(pool), format, chain, !supportAmbiguous); @@ -752,6 +781,9 @@ static Res AMSInit(Pool pool, va_list args) EVENT3(PoolInitAMS, pool, PoolArena(pool), format); } return res; + +failParam: + return res; } diff --git a/mps/code/poolams.h b/mps/code/poolams.h index 292085fbf10..f05f72085ca 100644 --- a/mps/code/poolams.h +++ b/mps/code/poolams.h @@ -13,6 +13,7 @@ #include "mpmst.h" #include "ring.h" #include "bt.h" +#include "mpscams.h" #include diff --git a/mps/code/poolawl.c b/mps/code/poolawl.c index e775517a7b2..b96d29500cb 100644 --- a/mps/code/poolawl.c +++ b/mps/code/poolawl.c @@ -511,7 +511,11 @@ static Bool AWLSegAlloc(Addr *baseReturn, Addr *limitReturn, /* AWLInit -- initialize an AWL pool */ -static Res AWLInit(Pool pool, va_list arg) +const KeyStruct _mps_key_awl_find_dependent = { + KeySig, "AWL_FIND_DEPENDENT", ArgCheckCant /* FIXME: ArgCheckFun */ +}; + +static Res AWLInit(Pool pool, ArgList args) { AWL awl; Format format; @@ -519,17 +523,34 @@ static Res AWLInit(Pool pool, va_list arg) Chain chain; Res res; static GenParamStruct genParam = { SizeMAX, 0.5 /* dummy */ }; + ArgStruct arg; /* Weak check, as half-way through initialization. */ AVER(pool != NULL); awl = Pool2AWL(pool); + + if (ArgPick(&arg, args, MPS_KEY_VARARGS)) { + format = va_arg(arg.val.varargs, Format); + findDependent = va_arg(arg.val.varargs, FindDependentMethod); + } else { + if (ArgPick(&arg, args, MPS_KEY_FORMAT)) + format = arg.val.format; + else { + res = ResPARAM; + goto failParam; + } + if (ArgPick(&arg, args, MPS_KEY_AWL_FIND_DEPENDENT)) + findDependent = (FindDependentMethod)arg.val.addr_method; + else { + res = ResPARAM; + goto failParam; + } + } - format = va_arg(arg, Format); AVERT(Format, format); pool->format = format; - findDependent = va_arg(arg, FindDependentMethod); AVER(FUNCHECK(findDependent)); awl->findDependent = findDependent; @@ -557,6 +578,7 @@ static Res AWLInit(Pool pool, va_list arg) failGenInit: ChainDestroy(chain); +failParam: return res; } diff --git a/mps/code/poollo.c b/mps/code/poollo.c index 3ad825905a2..5879a246cf9 100644 --- a/mps/code/poollo.c +++ b/mps/code/poollo.c @@ -469,19 +469,30 @@ static void LOWalk(Pool pool, Seg seg, /* LOInit -- initialize an LO pool */ -static Res LOInit(Pool pool, va_list arg) +static Res LOInit(Pool pool, ArgList args) { Format format; LO lo; Arena arena; Res res; static GenParamStruct loGenParam = { 1024, 0.2 }; + ArgStruct arg; AVERT(Pool, pool); arena = PoolArena(pool); - - format = va_arg(arg, Format); + + if (ArgPick(&arg, args, MPS_KEY_VARARGS)) { + format = va_arg(arg.val.varargs, Format); + } else { + if (ArgPick(&arg, args, MPS_KEY_FORMAT)) + format = arg.val.format; + else { + res = ResPARAM; + goto failParam; + } + } + AVERT(Format, format); lo = PoolPoolLO(pool); @@ -507,6 +518,7 @@ static Res LOInit(Pool pool, va_list arg) failGenInit: ChainDestroy(lo->chain); +failParam: return res; } diff --git a/mps/code/poolmfs.c b/mps/code/poolmfs.c index b39b283fbe9..184f41c956b 100644 --- a/mps/code/poolmfs.c +++ b/mps/code/poolmfs.c @@ -77,16 +77,38 @@ Pool (MFSPool)(MFS mfs) } -static Res MFSInit(Pool pool, va_list arg) +const KeyStruct _mps_mfs_extend_by = {KeySig, "MFS_EXTEND_BY", ArgCheckCant}; +const KeyStruct _mps_mfs_unit_size = {KeySig, "MFS_UNIT_SIZE", ArgCheckCant}; + +static Res MFSInit(Pool pool, ArgList args) { + Res res; Size extendBy, unitSize; MFS mfs; Arena arena; + ArgStruct arg; AVER(pool != NULL); - - extendBy = va_arg(arg, Size); - unitSize = va_arg(arg, Size); + AVER(ArgListCheck(args)); + + if (ArgPick(&arg, args, MPS_KEY_VARARGS)) { + extendBy = va_arg(arg.val.varargs, Size); + unitSize = va_arg(arg.val.varargs, Size); + } else { + if (ArgPick(&arg, args, MPS_KEY_MFS_UNIT_SIZE)) + unitSize = arg.val.size; + else { + res = ResPARAM; + goto failParam; + } + if (ArgPick(&arg, args, MPS_KEY_MFS_EXTEND_BY)) + extendBy = arg.val.size; + else { + extendBy = MFS_EXTEND_BY_DEFAULT; + if (extendBy < unitSize) + extendBy = unitSize; + } + } AVER(unitSize >= UNIT_MIN); AVER(extendBy >= unitSize); @@ -109,6 +131,9 @@ static Res MFSInit(Pool pool, va_list arg) AVERT(MFS, mfs); EVENT4(PoolInitMFS, pool, arena, extendBy, unitSize); return ResOK; + +failParam: + return res; } diff --git a/mps/code/poolmfs.h b/mps/code/poolmfs.h index f77f7ef0e14..467743ce8e2 100644 --- a/mps/code/poolmfs.h +++ b/mps/code/poolmfs.h @@ -29,6 +29,7 @@ #define poolmfs_h #include "mpm.h" +#include "mpscmfs.h" typedef struct MFSStruct *MFS; diff --git a/mps/code/poolmrg.c b/mps/code/poolmrg.c index 298e5f7788f..5e25c039b42 100644 --- a/mps/code/poolmrg.c +++ b/mps/code/poolmrg.c @@ -616,11 +616,12 @@ static Res MRGRefSegScan(ScanState ss, MRGRefSeg refseg, MRG mrg) /* MRGInit -- init method for MRG */ -static Res MRGInit(Pool pool, va_list args) +static Res MRGInit(Pool pool, ArgList args) { MRG mrg; AVER(pool != NULL); /* Can't check more; see pool contract @@@@ */ + AVER(ArgListCheck(args)); UNUSED(args); mrg = Pool2MRG(pool); diff --git a/mps/code/poolmv.c b/mps/code/poolmv.c index a645eb4d235..6df455b497a 100644 --- a/mps/code/poolmv.c +++ b/mps/code/poolmv.c @@ -184,16 +184,33 @@ static Bool MVSpanCheck(MVSpan span) /* MVInit -- init method for class MV */ -static Res MVInit(Pool pool, va_list arg) +const KeyStruct _mps_key_mv_extend_by = {KeySig, "MV_EXTEND_BY", ArgCheckCant}; +const KeyStruct _mps_key_mv_avg_size = {KeySig, "MV_AVG_SIZE", ArgCheckCant}; +const KeyStruct _mps_key_mv_max_size = {KeySig, "MV_MAX_SIZE", ArgCheckCant}; + +static Res MVInit(Pool pool, ArgList args) { - Size extendBy, avgSize, maxSize, blockExtendBy, spanExtendBy; + Size extendBy = MV_EXTEND_BY_DEFAULT; + Size avgSize = MV_AVG_SIZE_DEFAULT; + Size maxSize = MV_MAX_SIZE_DEFAULT; + Size blockExtendBy, spanExtendBy; MV mv; Arena arena; Res res; - - extendBy = va_arg(arg, Size); - avgSize = va_arg(arg, Size); - maxSize = va_arg(arg, Size); + ArgStruct arg; + ArgStruct piArgs[3]; + + if (ArgPick(&arg, args, MPS_KEY_VARARGS)) { + extendBy = va_arg(arg.val.varargs, Size); + avgSize = va_arg(arg.val.varargs, Size); + maxSize = va_arg(arg.val.varargs, Size); + } + if (ArgPick(&arg, args, MPS_KEY_MV_EXTEND_BY)) + extendBy = arg.val.size; + if (ArgPick(&arg, args, MPS_KEY_MV_AVG_SIZE)) + avgSize = arg.val.size; + if (ArgPick(&arg, args, MPS_KEY_MV_MAX_SIZE)) + maxSize = arg.val.size; AVER(extendBy > 0); AVER(avgSize > 0); @@ -211,17 +228,23 @@ static Res MVInit(Pool pool, va_list arg) blockExtendBy = sizeof(MVBlockStruct); } - res = PoolInit(&mv->blockPoolStruct.poolStruct, - arena, PoolClassMFS(), - blockExtendBy, sizeof(MVBlockStruct)); + piArgs[0].key = MPS_KEY_MFS_EXTEND_BY; + piArgs[0].val.size = blockExtendBy; + piArgs[1].key = MPS_KEY_MFS_UNIT_SIZE; + piArgs[1].val.size = sizeof(MVBlockStruct); + piArgs[2].key = MPS_KEY_ARGS_END; + res = PoolInit(&mv->blockPoolStruct.poolStruct, arena, PoolClassMFS(), piArgs); if(res != ResOK) return res; spanExtendBy = sizeof(MVSpanStruct) * (maxSize/extendBy); - res = PoolInit(&mv->spanPoolStruct.poolStruct, - arena, PoolClassMFS(), - spanExtendBy, sizeof(MVSpanStruct)); + piArgs[0].key = MPS_KEY_MFS_EXTEND_BY; + piArgs[0].val.size = spanExtendBy; + piArgs[1].key = MPS_KEY_MFS_UNIT_SIZE; + piArgs[1].val.size = sizeof(MVSpanStruct); + piArgs[2].key = MPS_KEY_ARGS_END; + res = PoolInit(&mv->spanPoolStruct.poolStruct, arena, PoolClassMFS(), piArgs); if(res != ResOK) return res; diff --git a/mps/code/poolmv.h b/mps/code/poolmv.h index 1eba70cafa5..098cd3eaa2e 100644 --- a/mps/code/poolmv.h +++ b/mps/code/poolmv.h @@ -43,6 +43,7 @@ #include "mpmtypes.h" +#include "mpscmv.h" typedef struct MVStruct *MV; diff --git a/mps/code/poolmv2.c b/mps/code/poolmv2.c index dc10ce990a8..9c537171ff0 100644 --- a/mps/code/poolmv2.c +++ b/mps/code/poolmv2.c @@ -27,7 +27,7 @@ SRCID(poolmv2, "$Id$"); /* Private prototypes */ typedef struct MVTStruct *MVT; -static Res MVTInit(Pool pool, va_list arg); +static Res MVTInit(Pool pool, ArgList arg); static Bool MVTCheck(MVT mvt); static void MVTFinish(Pool pool); static Res MVTBufferFill(Addr *baseReturn, Addr *limitReturn, @@ -194,38 +194,46 @@ static SegPref MVTSegPref(MVT mvt) * Parameters are: * minSize, meanSize, maxSize, reserveDepth, fragLimit */ -static Res MVTInit(Pool pool, va_list arg) +static Res MVTInit(Pool pool, ArgList args) { Arena arena; Size minSize, meanSize, maxSize, reuseSize, fillSize; Count reserveDepth, abqDepth, fragLimit; MVT mvt; Res res; + ArgStruct arg; AVERT(Pool, pool); mvt = Pool2MVT(pool); /* can't AVERT mvt, yet */ arena = PoolArena(pool); AVERT(Arena, arena); - - /* --- Should there be a ResBADARG ? */ - minSize = va_arg(arg, Size); - unless (minSize > 0) - return ResLIMIT; - meanSize = va_arg(arg, Size); - unless (meanSize >= minSize) - return ResLIMIT; - maxSize = va_arg(arg, Size); - unless (maxSize >= meanSize) - return ResLIMIT; - /* --- check that maxSize is not too large */ - reserveDepth = va_arg(arg, Count); - unless (reserveDepth > 0) - return ResLIMIT; - /* --- check that reserveDepth is not too large or small */ - fragLimit = va_arg(arg, Count); - unless (fragLimit <= 100) - return ResLIMIT; + + if (ArgPick(&arg, args, MPS_KEY_VARARGS)) { + /* FIXME: Inconsistent reporting of bad arguments. Elsewhere we assert or return ResPARAM. */ + /* --- Should there be a ResBADARG ? */ + minSize = va_arg(arg.val.varargs, Size); + unless (minSize > 0) + return ResLIMIT; + meanSize = va_arg(arg.val.varargs, Size); + unless (meanSize >= minSize) + return ResLIMIT; + maxSize = va_arg(arg.val.varargs, Size); + unless (maxSize >= meanSize) + return ResLIMIT; + /* --- check that maxSize is not too large */ + reserveDepth = va_arg(arg.val.varargs, Count); + unless (reserveDepth > 0) + return ResLIMIT; + /* --- check that reserveDepth is not too large or small */ + fragLimit = va_arg(arg.val.varargs, Count); + unless (fragLimit <= 100) + return ResLIMIT; + } else { + /* FIXME: Keywords not yet supported. */ + res = ResPARAM; + goto failParam; + } /* see */ fillSize = SizeAlignUp(maxSize, ArenaAlign(arena)); @@ -319,6 +327,7 @@ static Res MVTInit(Pool pool, va_list arg) failABQ: CBSFinish(MVTCBS(mvt)); failCBS: +failParam: AVER(res != ResOK); return res; } diff --git a/mps/code/poolmvff.c b/mps/code/poolmvff.c index a2647608187..16e6fa8f731 100644 --- a/mps/code/poolmvff.c +++ b/mps/code/poolmvff.c @@ -409,7 +409,7 @@ static void MVFFBufferEmpty(Pool pool, Buffer buffer, /* MVFFInit -- initialize method for MVFF */ -static Res MVFFInit(Pool pool, va_list arg) +static Res MVFFInit(Pool pool, ArgList args) { Size extendBy, avgSize, align; Bool slotHigh, arenaHigh, firstFit; @@ -418,6 +418,7 @@ static Res MVFFInit(Pool pool, va_list arg) Res res; void *p; ZoneSet zones; + ArgStruct arg; AVERT(Pool, pool); @@ -425,12 +426,20 @@ static Res MVFFInit(Pool pool, va_list arg) /* */ /* .arg.check: we do the same checks here and in MVFFCheck */ /* except for arenaHigh, which is stored only in the segPref. */ - extendBy = va_arg(arg, Size); - avgSize = va_arg(arg, Size); - align = va_arg(arg, Size); - slotHigh = va_arg(arg, Bool); - arenaHigh = va_arg(arg, Bool); - firstFit = va_arg(arg, Bool); + + if (ArgPick(&arg, args, MPS_KEY_VARARGS)) { + extendBy = va_arg(arg.val.varargs, Size); + avgSize = va_arg(arg.val.varargs, Size); + align = va_arg(arg.val.varargs, Size); + slotHigh = va_arg(arg.val.varargs, Bool); + arenaHigh = va_arg(arg.val.varargs, Bool); + firstFit = va_arg(arg.val.varargs, Bool); + } else { + /* FIXME: Accept keywords! */ + res = ResPARAM; + goto failParam; + } + AVER(extendBy > 0); /* .arg.check */ AVER(avgSize > 0); /* .arg.check */ AVER(avgSize <= extendBy); /* .arg.check */ @@ -479,6 +488,7 @@ static Res MVFFInit(Pool pool, va_list arg) failInit: ControlFree(arena, p, sizeof(SegPrefStruct)); +failParam: return res; } diff --git a/mps/code/pooln.c b/mps/code/pooln.c index dcd59f65df5..f0851f56fd5 100644 --- a/mps/code/pooln.c +++ b/mps/code/pooln.c @@ -30,7 +30,7 @@ typedef struct PoolNStruct { /* NInit -- init method for class N */ -static Res NInit(Pool pool, va_list args) +static Res NInit(Pool pool, ArgList args) { PoolN poolN = PoolPoolN(pool); diff --git a/mps/code/poolncv.c b/mps/code/poolncv.c index cbbda34d78b..f7598c5539a 100644 --- a/mps/code/poolncv.c +++ b/mps/code/poolncv.c @@ -19,7 +19,7 @@ static void testit(ArenaClass class, ArgList args) die(ArenaCreate(&arena, class, args), "ArenaCreate"); - die(PoolCreate(&pool, arena, PoolClassN()), "PoolNCreate"); + die(PoolCreate(&pool, arena, PoolClassN(), argsNone), "PoolNCreate"); res = PoolAlloc(&p, pool, 1, /* withReservoirPermit */ FALSE); if (res == ResOK) { error("Error: Unexpectedly succeeded in" diff --git a/mps/code/poolsnc.c b/mps/code/poolsnc.c index 4dcb7115902..608fb1eb735 100644 --- a/mps/code/poolsnc.c +++ b/mps/code/poolsnc.c @@ -361,17 +361,28 @@ static Bool sncFindFreeSeg(Seg *segReturn, SNC snc, Size size) /* SNCInit -- initialize an SNC pool */ -static Res SNCInit(Pool pool, va_list arg) +static Res SNCInit(Pool pool, ArgList args) { + Res res; SNC snc; Format format; + ArgStruct arg; /* weak check, as half-way through initialization */ AVER(pool != NULL); snc = Pool2SNC(pool); - format = va_arg(arg, Format); + if (ArgPick(&arg, args, MPS_KEY_VARARGS)) + format = va_arg(arg.val.varargs, Format); + else { + if (ArgPick(&arg, args, MPS_KEY_FORMAT)) + format = arg.val.format; + else { + res = ResPARAM; + goto failParam; + } + } AVERT(Format, format); pool->format = format; @@ -384,6 +395,9 @@ static Res SNCInit(Pool pool, va_list arg) AVERT(SNC, snc); EVENT2(PoolInitSNC, pool, format); return ResOK; + +failParam: + return res; } diff --git a/mps/code/reserv.c b/mps/code/reserv.c index d50e02b931f..6dfcd8543ad 100644 --- a/mps/code/reserv.c +++ b/mps/code/reserv.c @@ -35,7 +35,7 @@ SRCID(reserv, "$Id$"); /* ResPoolInit -- Reservoir pool init method */ -static Res ResPoolInit(Pool pool, va_list arg) +static Res ResPoolInit(Pool pool, ArgList arg) { AVER(pool != NULL); @@ -388,7 +388,7 @@ Res ReservoirInit(Reservoir reservoir, Arena arena) reservoir->sig = ReservoirSig; /* initialize the reservoir pool, */ res = PoolInit(&reservoir->poolStruct, - arena, EnsureReservoirPoolClass()); + arena, EnsureReservoirPoolClass(), argsNone); if (res == ResOK) { AVERT(Reservoir, reservoir); } diff --git a/mps/code/segsmss.c b/mps/code/segsmss.c index 4741b33f89b..46b3e0288ee 100644 --- a/mps/code/segsmss.c +++ b/mps/code/segsmss.c @@ -330,17 +330,24 @@ static Res AMSTSegSizePolicy(Size *sizeReturn, /* AMSTInit -- the pool class initialization method */ -static Res AMSTInit(Pool pool, va_list args) +static Res AMSTInit(Pool pool, ArgList args) { AMST amst; AMS ams; Format format; Chain chain; Res res; static GenParamStruct genParam = { 1024, 0.2 }; + ArgStruct arg; AVERT(Pool, pool); - - format = va_arg(args, Format); + + if (ArgPick(&arg, args, MPS_KEY_FORMAT)) + format = arg.val.format; + else { + res = ResPARAM; + goto failParam; + } + res = ChainCreate(&chain, pool->arena, 1, &genParam); if (res != ResOK) return res; @@ -362,6 +369,10 @@ static Res AMSTInit(Pool pool, va_list args) amst->sig = AMSTSig; AVERT(AMST, amst); return ResOK; + +failParam: + AVER(res != ResOK); + return res; } @@ -755,13 +766,17 @@ static void *test(void *arg, size_t s) mps_ap_t busy_ap; mps_addr_t busy_init; char *indent = " "; + mps_arg_s args[2]; arena = (mps_arena_t)arg; (void)s; /* unused */ die(mps_fmt_create_A(&format, arena, dylan_fmt_A()), "fmt_create"); - die(mps_pool_create(&pool, arena, mps_class_amst(), format), + args[0].key = MPS_KEY_FORMAT; + args[0].val.format = format; + args[1].key = MPS_KEY_ARGS_END; + die(mps_pool_create_k(&pool, arena, mps_class_amst(), args), "pool_create(amst)"); die(mps_ap_create(&ap, pool, mps_rank_exact()), "BufferCreate"); diff --git a/mps/manual/source/topic/interface.rst b/mps/manual/source/topic/interface.rst index 9735b01958f..088578f5275 100644 --- a/mps/manual/source/topic/interface.rst +++ b/mps/manual/source/topic/interface.rst @@ -265,7 +265,7 @@ Keyword arguments Some functions take :term:`keyword arguments` in order to pass values that might be optional, or are only required in some circumstances. For -example, :ref:`topic-arena-client` require a base address. These +example, :term:`client arenas` require a base address. These arguments are passed in a keyword argument array, like this:: mps_res_t res; @@ -288,12 +288,14 @@ If you are writing C99, you can write this more concisely as:: {MPS_KEY_ARGS_END}}); The argument array must not be ``NULL``, and must end with -``MPS_KEY_ARGS_END``. +``MPS_KEY_ARGS_END``. If you don't want to pass any arguments, you can +either call the equivalent function that does not take keyword arguments +(named without the ``_k``) or pass ``mps_args_none``. On return, the keyword argument array will be *modified* to remove any arguments that have been used. If all arguments have been used the -first element key will be MPS_KEY_ARGS_END. - +first element key will be ``MPS_KEY_ARGS_END``. + .. _topic-interface-general: