mirror of
https://github.com/postgres/postgres.git
synced 2025-11-19 13:42:17 +03:00
Make some minor improvements in memory-context infrastructure.
We lack a version of repalloc() that supports MCXT_ALLOC_NO_OOM semantics, so invent repalloc_extended() with the usual set of flags. repalloc_huge() becomes a legacy wrapper for that. Also, fix dynahash.c so that it can support HASH_ENTER_NULL requests when using the default palloc-based allocator. The only reason it didn't do that already was the lack of the MCXT_ALLOC_NO_OOM option when that code was written, ages ago. While here, simplify a few overcomplicated tests in mcxt.c. Discussion: https://postgr.es/m/2982579.1662416866@sss.pgh.pa.us
This commit is contained in:
@@ -289,7 +289,8 @@ static void *
|
||||
DynaHashAlloc(Size size)
|
||||
{
|
||||
Assert(MemoryContextIsValid(CurrentDynaHashCxt));
|
||||
return MemoryContextAlloc(CurrentDynaHashCxt, size);
|
||||
return MemoryContextAllocExtended(CurrentDynaHashCxt, size,
|
||||
MCXT_ALLOC_NO_OOM);
|
||||
}
|
||||
|
||||
|
||||
@@ -939,9 +940,7 @@ calc_bucket(HASHHDR *hctl, uint32 hash_val)
|
||||
*
|
||||
* HASH_ENTER will normally ereport a generic "out of memory" error if
|
||||
* it is unable to create a new entry. The HASH_ENTER_NULL operation is
|
||||
* the same except it will return NULL if out of memory. Note that
|
||||
* HASH_ENTER_NULL cannot be used with the default palloc-based allocator,
|
||||
* since palloc internally ereports on out-of-memory.
|
||||
* the same except it will return NULL if out of memory.
|
||||
*
|
||||
* If foundPtr isn't NULL, then *foundPtr is set true if we found an
|
||||
* existing entry in the table, false otherwise. This is needed in the
|
||||
@@ -1084,12 +1083,8 @@ hash_search_with_hash_value(HTAB *hashp,
|
||||
}
|
||||
return NULL;
|
||||
|
||||
case HASH_ENTER_NULL:
|
||||
/* ENTER_NULL does not work with palloc-based allocator */
|
||||
Assert(hashp->alloc != DynaHashAlloc);
|
||||
/* FALL THRU */
|
||||
|
||||
case HASH_ENTER:
|
||||
case HASH_ENTER_NULL:
|
||||
/* Return existing element if found, else create one */
|
||||
if (currBucket != NULL)
|
||||
return (void *) ELEMENTKEY(currBucket);
|
||||
|
||||
Reference in New Issue
Block a user