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/access/gist/gist.c | |
| 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/access/gist/gist.c')
| -rw-r--r-- | src/backend/access/gist/gist.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c index 3fb1a1285c5..c26d8538f05 100644 --- a/src/backend/access/gist/gist.c +++ b/src/backend/access/gist/gist.c @@ -43,7 +43,7 @@ static void gistprunepage(Relation rel, Page page, Buffer buffer, #define ROTATEDIST(d) do { \ - SplitPageLayout *tmp = (SplitPageLayout *) palloc0(sizeof(SplitPageLayout)); \ + SplitPageLayout *tmp = palloc0_object(SplitPageLayout); \ tmp->block.blkno = InvalidBlockNumber; \ tmp->buffer = InvalidBuffer; \ tmp->next = (d); \ @@ -392,7 +392,7 @@ gistplacetopage(Relation rel, Size freespace, GISTSTATE *giststate, /* Prepare a vector of all the downlinks */ for (ptr = dist; ptr; ptr = ptr->next) ndownlinks++; - downlinks = palloc(sizeof(IndexTuple) * ndownlinks); + downlinks = palloc_array(IndexTuple, ndownlinks); for (i = 0, ptr = dist; ptr; ptr = ptr->next) downlinks[i++] = ptr->itup; @@ -410,7 +410,7 @@ gistplacetopage(Relation rel, Size freespace, GISTSTATE *giststate, /* Prepare split-info to be returned to caller */ for (ptr = dist; ptr; ptr = ptr->next) { - GISTPageSplitInfo *si = palloc(sizeof(GISTPageSplitInfo)); + GISTPageSplitInfo *si = palloc_object(GISTPageSplitInfo); si->buf = ptr->buffer; si->downlink = ptr->itup; @@ -823,7 +823,7 @@ gistdoinsert(Relation r, IndexTuple itup, Size freespace, xlocked = false; /* descend to the chosen child */ - item = (GISTInsertStack *) palloc0(sizeof(GISTInsertStack)); + item = palloc0_object(GISTInsertStack); item->blkno = childblkno; item->parent = stack; item->downlinkoffnum = downlinkoffnum; @@ -923,7 +923,7 @@ gistFindPath(Relation r, BlockNumber child, OffsetNumber *downlinkoffnum) *ptr; BlockNumber blkno; - top = (GISTInsertStack *) palloc0(sizeof(GISTInsertStack)); + top = palloc0_object(GISTInsertStack); top->blkno = GIST_ROOT_BLKNO; top->downlinkoffnum = InvalidOffsetNumber; @@ -975,7 +975,7 @@ gistFindPath(Relation r, BlockNumber child, OffsetNumber *downlinkoffnum) * leaf pages, and we assume that there can't be any non-leaf * pages behind leaf pages. */ - ptr = (GISTInsertStack *) palloc0(sizeof(GISTInsertStack)); + ptr = palloc0_object(GISTInsertStack); ptr->blkno = GistPageGetOpaque(page)->rightlink; ptr->downlinkoffnum = InvalidOffsetNumber; ptr->parent = top->parent; @@ -1000,7 +1000,7 @@ gistFindPath(Relation r, BlockNumber child, OffsetNumber *downlinkoffnum) else { /* Append this child to the list of pages to visit later */ - ptr = (GISTInsertStack *) palloc0(sizeof(GISTInsertStack)); + ptr = palloc0_object(GISTInsertStack); ptr->blkno = blkno; ptr->downlinkoffnum = i; ptr->parent = top; @@ -1218,7 +1218,7 @@ gistfixsplit(GISTInsertState *state, GISTSTATE *giststate) */ for (;;) { - GISTPageSplitInfo *si = palloc(sizeof(GISTPageSplitInfo)); + GISTPageSplitInfo *si = palloc_object(GISTPageSplitInfo); IndexTuple downlink; page = BufferGetPage(buf); @@ -1482,8 +1482,8 @@ gistSplit(Relation r, gistSplitByKey(r, page, itup, len, giststate, &v, 0); /* form left and right vector */ - lvectup = (IndexTuple *) palloc(sizeof(IndexTuple) * (len + 1)); - rvectup = (IndexTuple *) palloc(sizeof(IndexTuple) * (len + 1)); + lvectup = palloc_array(IndexTuple, len + 1); + rvectup = palloc_array(IndexTuple, len + 1); for (i = 0; i < v.splitVector.spl_nleft; i++) lvectup[i] = itup[v.splitVector.spl_left[i] - 1]; @@ -1552,7 +1552,7 @@ initGISTstate(Relation index) oldCxt = MemoryContextSwitchTo(scanCxt); /* Create and fill in the GISTSTATE */ - giststate = (GISTSTATE *) palloc(sizeof(GISTSTATE)); + giststate = palloc_object(GISTSTATE); giststate->scanCxt = scanCxt; giststate->tempCxt = scanCxt; /* caller must change this if needed */ |
