diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2022-10-06 13:35:31 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2022-10-06 13:35:31 -0400 |
commit | 9543eff5e015b6f6f832da2d95d659629a2022f3 (patch) | |
tree | b5c27a4eaa8720dbf932ec3409df1cb9e1e62b07 | |
parent | 42b746d4c982257bf3f924176632b04dc288174b (diff) | |
download | postgresql-9543eff5e015b6f6f832da2d95d659629a2022f3.tar.gz |
Remove MemoryContextContains().
MemoryContextContains is no longer reliable in the wake of c6e0fe1f2,
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
-rw-r--r-- | src/backend/utils/mmgr/mcxt.c | 58 | ||||
-rw-r--r-- | src/include/utils/memutils.h | 1 |
2 files changed, 2 insertions, 57 deletions
diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c index 115a64cfe4..c80236d285 100644 --- a/src/backend/utils/mmgr/mcxt.c +++ b/src/backend/utils/mmgr/mcxt.c @@ -224,10 +224,8 @@ MemoryContextResetOnly(MemoryContext context) * If context->ident points into the context's memory, it will become * a dangling pointer. We could prevent that by setting it to NULL * here, but that would break valid coding patterns that keep the - * ident elsewhere, e.g. in a parent context. Another idea is to use - * MemoryContextContains(), but we don't require ident strings to be - * in separately-palloc'd chunks, so that risks false positives. So - * for now we assume the programmer got it right. + * ident elsewhere, e.g. in a parent context. So for now we assume + * the programmer got it right. */ context->methods->reset(context); @@ -482,15 +480,6 @@ MemoryContextAllowInCriticalSection(MemoryContext context, bool allow) MemoryContext GetMemoryChunkContext(void *pointer) { - /* - * Try to detect bogus pointers handed to us, poorly though we can. - * Presumably, a pointer that isn't MAXALIGNED isn't pointing at an - * allocated chunk. - */ - Assert(pointer != NULL); - Assert(pointer == (void *) MAXALIGN(pointer)); - /* adding further Asserts here? See pre-checks in MemoryContextContains */ - return MCXT_METHOD(pointer, get_chunk_context) (pointer); } @@ -814,49 +803,6 @@ MemoryContextCheck(MemoryContext context) #endif /* - * MemoryContextContains - * Detect whether an allocated chunk of memory belongs to a given - * context or not. - * - * Caution: 'pointer' must point to a pointer which was allocated by a - * MemoryContext. It's not safe or valid to use this function on arbitrary - * pointers as obtaining the MemoryContext which 'pointer' belongs to requires - * possibly several pointer dereferences. - */ -bool -MemoryContextContains(MemoryContext context, void *pointer) -{ - /* - * Temporarily make this always return false as we don't yet have a fully - * baked idea on how to make it work correctly with the new MemoryChunk - * code. - */ - return false; - -#ifdef NOT_USED - MemoryContext ptr_context; - - /* - * NB: We must perform run-time checks here which GetMemoryChunkContext() - * does as assertions before calling GetMemoryChunkContext(). - * - * Try to detect bogus pointers handed to us, poorly though we can. - * Presumably, a pointer that isn't MAXALIGNED isn't pointing at an - * allocated chunk. - */ - if (pointer == NULL || pointer != (void *) MAXALIGN(pointer)) - return false; - - /* - * OK, it's probably safe to look at the context. - */ - ptr_context = GetMemoryChunkContext(pointer); - - return ptr_context == context; -#endif -} - -/* * MemoryContextCreate * Context-type-independent part of context creation. * diff --git a/src/include/utils/memutils.h b/src/include/utils/memutils.h index 52bc41ec53..4f6c5435ca 100644 --- a/src/include/utils/memutils.h +++ b/src/include/utils/memutils.h @@ -96,7 +96,6 @@ extern void MemoryContextAllowInCriticalSection(MemoryContext context, #ifdef MEMORY_CONTEXT_CHECKING extern void MemoryContextCheck(MemoryContext context); #endif -extern bool MemoryContextContains(MemoryContext context, void *pointer); /* Handy macro for copying and assigning context ID ... but note double eval */ #define MemoryContextCopyAndSetIdentifier(cxt, id) \ |