summaryrefslogtreecommitdiff
path: root/src/backend/utils/mmgr
diff options
context:
space:
mode:
authorTom Lane2022-10-06 17:35:31 +0000
committerTom Lane2022-10-06 17:35:31 +0000
commit9543eff5e015b6f6f832da2d95d659629a2022f3 (patch)
treeb5c27a4eaa8720dbf932ec3409df1cb9e1e62b07 /src/backend/utils/mmgr
parent42b746d4c982257bf3f924176632b04dc288174b (diff)
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/[email protected]
Diffstat (limited to 'src/backend/utils/mmgr')
-rw-r--r--src/backend/utils/mmgr/mcxt.c58
1 files changed, 2 insertions, 56 deletions
diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c
index 115a64cfe40..c80236d285a 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.
*