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

Commit 9543eff

Browse files
committed
Remove MemoryContextContains().
MemoryContextContains is no longer reliable in the wake of c6e0fe1, because there's no longer very much redundancy in chunk headers. (It wasn't *completely* reliable even before that, as there was a chance of a false positive if you passed it something that didn't point to an mcxt chunk at all. But it was generally good enough.) Hence, remove it. There is no remaining core code that requires it. Extensions that have been using it might be able to substitute a test like "GetMemoryChunkContext(ptr) == context", recognizing that this explicitly requires that the pointer point to some chunk. Tom Lane and David Rowley Discussion: https://postgr.es/m/1913788.1664898906@sss.pgh.pa.us
1 parent 42b746d commit 9543eff

File tree

2 files changed

+2
-57
lines changed

2 files changed

+2
-57
lines changed

src/backend/utils/mmgr/mcxt.c

+2-56
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,8 @@ MemoryContextResetOnly(MemoryContext context)
224224
* If context->ident points into the context's memory, it will become
225225
* a dangling pointer. We could prevent that by setting it to NULL
226226
* here, but that would break valid coding patterns that keep the
227-
* ident elsewhere, e.g. in a parent context. Another idea is to use
228-
* MemoryContextContains(), but we don't require ident strings to be
229-
* in separately-palloc'd chunks, so that risks false positives. So
230-
* for now we assume the programmer got it right.
227+
* ident elsewhere, e.g. in a parent context. So for now we assume
228+
* the programmer got it right.
231229
*/
232230

233231
context->methods->reset(context);
@@ -482,15 +480,6 @@ MemoryContextAllowInCriticalSection(MemoryContext context, bool allow)
482480
MemoryContext
483481
GetMemoryChunkContext(void *pointer)
484482
{
485-
/*
486-
* Try to detect bogus pointers handed to us, poorly though we can.
487-
* Presumably, a pointer that isn't MAXALIGNED isn't pointing at an
488-
* allocated chunk.
489-
*/
490-
Assert(pointer != NULL);
491-
Assert(pointer == (void *) MAXALIGN(pointer));
492-
/* adding further Asserts here? See pre-checks in MemoryContextContains */
493-
494483
return MCXT_METHOD(pointer, get_chunk_context) (pointer);
495484
}
496485

@@ -813,49 +802,6 @@ MemoryContextCheck(MemoryContext context)
813802
}
814803
#endif
815804

816-
/*
817-
* MemoryContextContains
818-
* Detect whether an allocated chunk of memory belongs to a given
819-
* context or not.
820-
*
821-
* Caution: 'pointer' must point to a pointer which was allocated by a
822-
* MemoryContext. It's not safe or valid to use this function on arbitrary
823-
* pointers as obtaining the MemoryContext which 'pointer' belongs to requires
824-
* possibly several pointer dereferences.
825-
*/
826-
bool
827-
MemoryContextContains(MemoryContext context, void *pointer)
828-
{
829-
/*
830-
* Temporarily make this always return false as we don't yet have a fully
831-
* baked idea on how to make it work correctly with the new MemoryChunk
832-
* code.
833-
*/
834-
return false;
835-
836-
#ifdef NOT_USED
837-
MemoryContext ptr_context;
838-
839-
/*
840-
* NB: We must perform run-time checks here which GetMemoryChunkContext()
841-
* does as assertions before calling GetMemoryChunkContext().
842-
*
843-
* Try to detect bogus pointers handed to us, poorly though we can.
844-
* Presumably, a pointer that isn't MAXALIGNED isn't pointing at an
845-
* allocated chunk.
846-
*/
847-
if (pointer == NULL || pointer != (void *) MAXALIGN(pointer))
848-
return false;
849-
850-
/*
851-
* OK, it's probably safe to look at the context.
852-
*/
853-
ptr_context = GetMemoryChunkContext(pointer);
854-
855-
return ptr_context == context;
856-
#endif
857-
}
858-
859805
/*
860806
* MemoryContextCreate
861807
* Context-type-independent part of context creation.

src/include/utils/memutils.h

-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ extern void MemoryContextAllowInCriticalSection(MemoryContext context,
9696
#ifdef MEMORY_CONTEXT_CHECKING
9797
extern void MemoryContextCheck(MemoryContext context);
9898
#endif
99-
extern bool MemoryContextContains(MemoryContext context, void *pointer);
10099

101100
/* Handy macro for copying and assigning context ID ... but note double eval */
102101
#define MemoryContextCopyAndSetIdentifier(cxt, id) \

0 commit comments

Comments
 (0)