From d4b89073892a613ffecb044d60a8dcd19e05b228 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Tue, 14 Oct 2014 22:21:43 +0100 Subject: [PATCH] Assert if you try to create a pool using a format from another arena, a pool using a chain from another arena, or a root using a thread from another arena. Copied from Perforce Change: 187268 ServerID: perforce.ravenbrook.com --- mps/code/poolamc.c | 2 ++ mps/code/poolams.c | 10 ++++++---- mps/code/poolawl.c | 2 ++ mps/code/poollo.c | 2 ++ mps/code/poolsnc.c | 1 + mps/code/root.c | 1 + mps/test/conerr/18.c | 4 ++++ 7 files changed, 18 insertions(+), 4 deletions(-) diff --git a/mps/code/poolamc.c b/mps/code/poolamc.c index 4e9ed70396d..1e27af4adcd 100644 --- a/mps/code/poolamc.c +++ b/mps/code/poolamc.c @@ -844,7 +844,9 @@ static Res amcInitComm(Pool pool, RankSet rankSet, ArgList args) largeSize = arg.val.size; AVERT(Format, pool->format); + AVER(FormatArena(pool->format) == arena); AVERT(Chain, chain); + AVER(chain->arena == arena); AVER(extendBy > 0); AVER(largeSize > 0); /* TODO: it would be nice to be able to manage large objects that diff --git a/mps/code/poolams.c b/mps/code/poolams.c index 0c9c9d2ff97..3f7f170ddbc 100644 --- a/mps/code/poolams.c +++ b/mps/code/poolams.c @@ -831,13 +831,15 @@ Res AMSInitInternal(AMS ams, Format format, Chain chain, unsigned gen, Res res; /* Can't check ams, it's not initialized. */ - AVERT(Format, format); - AVERT(Chain, chain); - AVER(gen <= ChainGens(chain)); - pool = AMSPool(ams); AVERT(Pool, pool); + AVERT(Format, format); + AVER(FormatArena(format) == PoolArena(pool)); pool->format = format; + AVERT(Chain, chain); + AVER(gen <= ChainGens(chain)); + AVER(chain->arena == PoolArena(pool)); + pool->alignment = pool->format->alignment; ams->grainShift = SizeLog2(PoolAlignment(pool)); diff --git a/mps/code/poolawl.c b/mps/code/poolawl.c index 9fd9afc3250..01ca12ea46f 100644 --- a/mps/code/poolawl.c +++ b/mps/code/poolawl.c @@ -575,6 +575,7 @@ static Res AWLInit(Pool pool, ArgList args) gen = arg.val.u; AVERT(Format, format); + AVER(FormatArena(format) == PoolArena(pool)); pool->format = format; pool->alignment = format->alignment; @@ -583,6 +584,7 @@ static Res AWLInit(Pool pool, ArgList args) AVERT(Chain, chain); AVER(gen <= ChainGens(chain)); + AVER(chain->arena == PoolArena(pool)); res = PoolGenInit(&awl->pgen, ChainGen(chain, gen), pool); if (res != ResOK) diff --git a/mps/code/poollo.c b/mps/code/poollo.c index 5b3ddd608f9..a1a3f328468 100644 --- a/mps/code/poollo.c +++ b/mps/code/poollo.c @@ -504,8 +504,10 @@ static Res LOInit(Pool pool, ArgList args) gen = arg.val.u; AVERT(Format, pool->format); + AVER(FormatArena(pool->format) == arena); AVERT(Chain, chain); AVER(gen <= ChainGens(chain)); + AVER(chain->arena == arena); pool->alignment = pool->format->alignment; lo->alignShift = SizeLog2((Size)PoolAlignment(pool)); diff --git a/mps/code/poolsnc.c b/mps/code/poolsnc.c index df2d964340b..f507d41222b 100644 --- a/mps/code/poolsnc.c +++ b/mps/code/poolsnc.c @@ -387,6 +387,7 @@ static Res SNCInit(Pool pool, ArgList args) format = arg.val.format; AVERT(Format, format); + AVER(FormatArena(format) == PoolArena(pool)); pool->format = format; snc->freeSegs = NULL; snc->sig = SNCSig; diff --git a/mps/code/root.c b/mps/code/root.c index 71813ec9015..f7640b8554b 100644 --- a/mps/code/root.c +++ b/mps/code/root.c @@ -304,6 +304,7 @@ Res RootCreateReg(Root *rootReturn, Arena arena, AVERT(Arena, arena); AVERT(Rank, rank); AVERT(Thread, thread); + AVER(ThreadArena(thread) == arena); AVER(scan != NULL); theUnion.reg.scan = scan; diff --git a/mps/test/conerr/18.c b/mps/test/conerr/18.c index 5594c264931..4d13dede9b9 100644 --- a/mps/test/conerr/18.c +++ b/mps/test/conerr/18.c @@ -4,6 +4,10 @@ TEST_HEADER summary = create a pool with a format in the wrong arena language = c link = testlib.o +OUTPUT_SPEC + assert = true + assertfile P= poollo.c + assertcond = FormatArena(pool->format) == arena END_HEADER */