From 1b105f9472bdb9a68f709778afafb494997267bd Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Wed, 10 Dec 2025 07:36:46 +0900 Subject: 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 Discussion: https://postgr.es/m/ad0748d4-3080-436e-b0bc-ac8f86a3466a@gmail.com --- src/backend/lib/bipartite_match.c | 2 +- src/backend/lib/dshash.c | 4 ++-- src/backend/lib/integerset.c | 2 +- src/backend/lib/pairingheap.c | 2 +- src/backend/lib/rbtree.c | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/backend/lib') diff --git a/src/backend/lib/bipartite_match.c b/src/backend/lib/bipartite_match.c index 5af789652c7..ed54f190494 100644 --- a/src/backend/lib/bipartite_match.c +++ b/src/backend/lib/bipartite_match.c @@ -38,7 +38,7 @@ static bool hk_depth_search(BipartiteMatchState *state, int u); BipartiteMatchState * BipartiteMatch(int u_size, int v_size, short **adjacency) { - BipartiteMatchState *state = palloc(sizeof(BipartiteMatchState)); + BipartiteMatchState *state = palloc_object(BipartiteMatchState); if (u_size < 0 || u_size >= SHRT_MAX || v_size < 0 || v_size >= SHRT_MAX) diff --git a/src/backend/lib/dshash.c b/src/backend/lib/dshash.c index e1ba367cf17..82f6aa966de 100644 --- a/src/backend/lib/dshash.c +++ b/src/backend/lib/dshash.c @@ -211,7 +211,7 @@ dshash_create(dsa_area *area, const dshash_parameters *params, void *arg) dsa_pointer control; /* Allocate the backend-local object representing the hash table. */ - hash_table = palloc(sizeof(dshash_table)); + hash_table = palloc_object(dshash_table); /* Allocate the control object in shared memory. */ control = dsa_allocate(area, sizeof(dshash_table_control)); @@ -276,7 +276,7 @@ dshash_attach(dsa_area *area, const dshash_parameters *params, dsa_pointer control; /* Allocate the backend-local object representing the hash table. */ - hash_table = palloc(sizeof(dshash_table)); + hash_table = palloc_object(dshash_table); /* Find the control object in shared memory. */ control = handle; diff --git a/src/backend/lib/integerset.c b/src/backend/lib/integerset.c index f4153b0e15a..aca1df2ad5a 100644 --- a/src/backend/lib/integerset.c +++ b/src/backend/lib/integerset.c @@ -284,7 +284,7 @@ intset_create(void) { IntegerSet *intset; - intset = (IntegerSet *) palloc(sizeof(IntegerSet)); + intset = palloc_object(IntegerSet); intset->context = CurrentMemoryContext; intset->mem_used = GetMemoryChunkSpace(intset); diff --git a/src/backend/lib/pairingheap.c b/src/backend/lib/pairingheap.c index fa8431f7946..3497dc7902a 100644 --- a/src/backend/lib/pairingheap.c +++ b/src/backend/lib/pairingheap.c @@ -43,7 +43,7 @@ pairingheap_allocate(pairingheap_comparator compare, void *arg) { pairingheap *heap; - heap = (pairingheap *) palloc(sizeof(pairingheap)); + heap = palloc_object(pairingheap); pairingheap_initialize(heap, compare, arg); return heap; diff --git a/src/backend/lib/rbtree.c b/src/backend/lib/rbtree.c index 1f0553f914d..8fe6bfc539a 100644 --- a/src/backend/lib/rbtree.c +++ b/src/backend/lib/rbtree.c @@ -106,7 +106,7 @@ rbt_create(Size node_size, rbt_freefunc freefunc, void *arg) { - RBTree *tree = (RBTree *) palloc(sizeof(RBTree)); + RBTree *tree = palloc_object(RBTree); Assert(node_size > sizeof(RBTNode)); -- cgit v1.2.3