diff options
| author | Michael Paquier | 2025-12-09 22:36:46 +0000 |
|---|---|---|
| committer | Michael Paquier | 2025-12-09 22:36:46 +0000 |
| commit | 1b105f9472bdb9a68f709778afafb494997267bd (patch) | |
| tree | 205727d30b0dd4f3060bc1f49a9efa724ee3ff80 /src/backend/storage/ipc | |
| parent | c507ba55f5bfae900baa94f1c657e1d99da5c6dc (diff) | |
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 0c3c5c3b06a3 and 31d3847a37be.
Author: David Geier <geidav.pg@gmail.com>
Discussion: https://postgr.es/m/ad0748d4-3080-436e-b0bc-ac8f86a3466a@gmail.com
Diffstat (limited to 'src/backend/storage/ipc')
| -rw-r--r-- | src/backend/storage/ipc/procarray.c | 8 | ||||
| -rw-r--r-- | src/backend/storage/ipc/shm_mq.c | 2 | ||||
| -rw-r--r-- | src/backend/storage/ipc/shmem.c | 6 |
3 files changed, 7 insertions, 9 deletions
diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c index 200f72c6e25..f3a1603204e 100644 --- a/src/backend/storage/ipc/procarray.c +++ b/src/backend/storage/ipc/procarray.c @@ -1162,7 +1162,7 @@ ProcArrayApplyRecoveryInfo(RunningTransactions running) * Allocate a temporary array to avoid modifying the array passed as * argument. */ - xids = palloc(sizeof(TransactionId) * (running->xcnt + running->subxcnt)); + xids = palloc_array(TransactionId, running->xcnt + running->subxcnt); /* * Add to the temp array any xids which have not already completed. @@ -3012,8 +3012,7 @@ GetVirtualXIDsDelayingChkpt(int *nvxids, int type) Assert(type != 0); /* allocate what's certainly enough result space */ - vxids = (VirtualTransactionId *) - palloc(sizeof(VirtualTransactionId) * arrayP->maxProcs); + vxids = palloc_array(VirtualTransactionId, arrayP->maxProcs); LWLockAcquire(ProcArrayLock, LW_SHARED); @@ -3293,8 +3292,7 @@ GetCurrentVirtualXIDs(TransactionId limitXmin, bool excludeXmin0, int index; /* allocate what's certainly enough result space */ - vxids = (VirtualTransactionId *) - palloc(sizeof(VirtualTransactionId) * arrayP->maxProcs); + vxids = palloc_array(VirtualTransactionId, arrayP->maxProcs); LWLockAcquire(ProcArrayLock, LW_SHARED); diff --git a/src/backend/storage/ipc/shm_mq.c b/src/backend/storage/ipc/shm_mq.c index 2c79a649f46..9c888d3eb78 100644 --- a/src/backend/storage/ipc/shm_mq.c +++ b/src/backend/storage/ipc/shm_mq.c @@ -289,7 +289,7 @@ shm_mq_get_sender(shm_mq *mq) shm_mq_handle * shm_mq_attach(shm_mq *mq, dsm_segment *seg, BackgroundWorkerHandle *handle) { - shm_mq_handle *mqh = palloc(sizeof(shm_mq_handle)); + shm_mq_handle *mqh = palloc_object(shm_mq_handle); Assert(mq->mq_receiver == MyProc || mq->mq_sender == MyProc); mqh->mqh_queue = mq; diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c index ee3408df301..7b63c7dc90a 100644 --- a/src/backend/storage/ipc/shmem.c +++ b/src/backend/storage/ipc/shmem.c @@ -599,7 +599,7 @@ pg_get_shmem_allocations_numa(PG_FUNCTION_ARGS) InitMaterializedSRF(fcinfo, 0); max_nodes = pg_numa_get_max_node(); - nodes = palloc(sizeof(Size) * (max_nodes + 1)); + nodes = palloc_array(Size, max_nodes + 1); /* * Shared memory allocations can vary in size and may not align with OS @@ -624,8 +624,8 @@ pg_get_shmem_allocations_numa(PG_FUNCTION_ARGS) * them using only fraction of the total pages. */ shm_total_page_count = (ShmemSegHdr->totalsize / os_page_size) + 1; - page_ptrs = palloc0(sizeof(void *) * shm_total_page_count); - pages_status = palloc(sizeof(int) * shm_total_page_count); + page_ptrs = palloc0_array(void *, shm_total_page_count); + pages_status = palloc_array(int, shm_total_page_count); if (firstNumaTouch) elog(DEBUG1, "NUMA: page-faulting shared memory segments for proper NUMA readouts"); |
