1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-13 14:22:43 +03:00

Use palloc_object() and palloc_array() in backend code

The idea is to encourage more the use of these new routines across the
tree, as these offer stronger type safety guarantees than palloc().
This batch of changes includes most of the trivial changes suggested by
the author for src/backend/.

A total of 334 files are updated here.  Among these files, 48 of them
have their build change slightly; these are caused by line number
changes as the new allocation formulas are simpler, shaving around 100
lines of code in total.

Similar work has been done in 0c3c5c3b06 and 31d3847a37.

Author: David Geier <geidav.pg@gmail.com>
Discussion: https://postgr.es/m/ad0748d4-3080-436e-b0bc-ac8f86a3466a@gmail.com
This commit is contained in:
Michael Paquier
2025-12-10 07:36:46 +09:00
parent c507ba55f5
commit 1b105f9472
333 changed files with 1357 additions and 1464 deletions

View File

@@ -186,7 +186,7 @@ CreateParallelContext(const char *library_name, const char *function_name,
oldcontext = MemoryContextSwitchTo(TopTransactionContext);
/* Initialize a new ParallelContext. */
pcxt = palloc0(sizeof(ParallelContext));
pcxt = palloc0_object(ParallelContext);
pcxt->subid = GetCurrentSubTransactionId();
pcxt->nworkers = nworkers;
pcxt->nworkers_to_launch = nworkers;
@@ -453,7 +453,7 @@ InitializeParallelDSM(ParallelContext *pcxt)
clientconninfospace);
/* Allocate space for worker information. */
pcxt->worker = palloc0(sizeof(ParallelWorkerInfo) * pcxt->nworkers);
pcxt->worker = palloc0_array(ParallelWorkerInfo, pcxt->nworkers);
/*
* Establish error queues in dynamic shared memory.
@@ -648,8 +648,7 @@ LaunchParallelWorkers(ParallelContext *pcxt)
*/
if (pcxt->nworkers_launched > 0)
{
pcxt->known_attached_workers =
palloc0(sizeof(bool) * pcxt->nworkers_launched);
pcxt->known_attached_workers = palloc0_array(bool, pcxt->nworkers_launched);
pcxt->nknown_attached_workers = 0;
}