Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b23aeb6

Browse files
committed
Cleanup for pull-up-isReset patch.
Clear isReset before, not after, calling the context-specific alloc method, so as to preserve the option to do a tail call in MemoryContextAlloc (and also so this code isn't assuming that a failed alloc call won't have changed the context's state before failing). Fix missed direct invocation of reset method. Reformat a comment.
1 parent 11c08c3 commit b23aeb6

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/backend/utils/mmgr/aset.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ typedef void *AllocPointer;
128128
/*
129129
* AllocSetContext is our standard implementation of MemoryContext.
130130
*
131-
* Note: header.isReset means there is nothing for AllocSetReset to do. This is
132-
* different from the aset being physically empty (empty blocks list) because
133-
* we may still have a keeper block. It's also different from the set being
134-
* logically empty, because we don't attempt to detect pfree'ing the last
135-
* active chunk.
131+
* Note: header.isReset means there is nothing for AllocSetReset to do.
132+
* This is different from the aset being physically empty (empty blocks list)
133+
* because we may still have a keeper block. It's also different from the set
134+
* being logically empty, because we don't attempt to detect pfree'ing the
135+
* last active chunk.
136136
*/
137137
typedef struct AllocSetContext
138138
{

src/backend/utils/mmgr/mcxt.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ MemoryContextResetAndDeleteChildren(MemoryContext context)
234234
AssertArg(MemoryContextIsValid(context));
235235

236236
MemoryContextDeleteChildren(context);
237-
(*context->methods->reset) (context);
237+
MemoryContextReset(context);
238238
}
239239

240240
/*
@@ -510,16 +510,15 @@ MemoryContextCreate(NodeTag tag, Size size,
510510
void *
511511
MemoryContextAlloc(MemoryContext context, Size size)
512512
{
513-
void *ret;
514513
AssertArg(MemoryContextIsValid(context));
515514

516515
if (!AllocSizeIsValid(size))
517516
elog(ERROR, "invalid memory alloc request size %lu",
518517
(unsigned long) size);
519518

520-
ret = (*context->methods->alloc) (context, size);
521519
context->isReset = false;
522-
return ret;
520+
521+
return (*context->methods->alloc) (context, size);
523522
}
524523

525524
/*
@@ -540,11 +539,12 @@ MemoryContextAllocZero(MemoryContext context, Size size)
540539
elog(ERROR, "invalid memory alloc request size %lu",
541540
(unsigned long) size);
542541

542+
context->isReset = false;
543+
543544
ret = (*context->methods->alloc) (context, size);
544545

545546
MemSetAligned(ret, 0, size);
546547

547-
context->isReset = false;
548548
return ret;
549549
}
550550

@@ -566,11 +566,12 @@ MemoryContextAllocZeroAligned(MemoryContext context, Size size)
566566
elog(ERROR, "invalid memory alloc request size %lu",
567567
(unsigned long) size);
568568

569+
context->isReset = false;
570+
569571
ret = (*context->methods->alloc) (context, size);
570572

571573
MemSetLoop(ret, 0, size);
572574

573-
context->isReset = false;
574575
return ret;
575576
}
576577

0 commit comments

Comments
 (0)