mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Assorted examples of expanded type-safer palloc/pg_malloc API
This adds some uses of the new palloc/pg_malloc variants here and there as a demonstration and test. This is kept separate from the actual API patch, since the latter might be backpatched at some point. Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/flat/bb755632-2a43-d523-36f8-a1e7a389a907@enterprisedb.com
This commit is contained in:
@@ -329,7 +329,7 @@ brinbeginscan(Relation r, int nkeys, int norderbys)
|
||||
|
||||
scan = RelationGetIndexScan(r, nkeys, norderbys);
|
||||
|
||||
opaque = (BrinOpaque *) palloc(sizeof(BrinOpaque));
|
||||
opaque = palloc_object(BrinOpaque);
|
||||
opaque->bo_rmAccess = brinRevmapInitialize(r, &opaque->bo_pagesPerRange,
|
||||
scan->xs_snapshot);
|
||||
opaque->bo_bdesc = brin_build_desc(r);
|
||||
@@ -394,7 +394,7 @@ bringetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
|
||||
* don't look them up here; we do that lazily the first time we see a scan
|
||||
* key reference each of them. We rely on zeroing fn_oid to InvalidOid.
|
||||
*/
|
||||
consistentFn = palloc0(sizeof(FmgrInfo) * bdesc->bd_tupdesc->natts);
|
||||
consistentFn = palloc0_array(FmgrInfo, bdesc->bd_tupdesc->natts);
|
||||
|
||||
/*
|
||||
* Make room for per-attribute lists of scan keys that we'll pass to the
|
||||
@@ -881,7 +881,7 @@ brinbuild(Relation heap, Relation index, IndexInfo *indexInfo)
|
||||
/*
|
||||
* Return statistics
|
||||
*/
|
||||
result = (IndexBuildResult *) palloc(sizeof(IndexBuildResult));
|
||||
result = palloc_object(IndexBuildResult);
|
||||
|
||||
result->heap_tuples = reltuples;
|
||||
result->index_tuples = idxtuples;
|
||||
@@ -925,7 +925,7 @@ brinbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
|
||||
{
|
||||
/* allocate stats if first time through, else re-use existing struct */
|
||||
if (stats == NULL)
|
||||
stats = (IndexBulkDeleteResult *) palloc0(sizeof(IndexBulkDeleteResult));
|
||||
stats = palloc0_object(IndexBulkDeleteResult);
|
||||
|
||||
return stats;
|
||||
}
|
||||
@@ -944,7 +944,7 @@ brinvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
|
||||
return stats;
|
||||
|
||||
if (!stats)
|
||||
stats = (IndexBulkDeleteResult *) palloc0(sizeof(IndexBulkDeleteResult));
|
||||
stats = palloc0_object(IndexBulkDeleteResult);
|
||||
stats->num_pages = RelationGetNumberOfBlocks(info->index);
|
||||
/* rest of stats is initialized by zeroing */
|
||||
|
||||
@@ -1204,7 +1204,7 @@ brin_build_desc(Relation rel)
|
||||
* Obtain BrinOpcInfo for each indexed column. While at it, accumulate
|
||||
* the number of columns stored, since the number is opclass-defined.
|
||||
*/
|
||||
opcinfo = (BrinOpcInfo **) palloc(sizeof(BrinOpcInfo *) * tupdesc->natts);
|
||||
opcinfo = palloc_array(BrinOpcInfo*, tupdesc->natts);
|
||||
for (keyno = 0; keyno < tupdesc->natts; keyno++)
|
||||
{
|
||||
FmgrInfo *opcInfoFn;
|
||||
@@ -1276,7 +1276,7 @@ initialize_brin_buildstate(Relation idxRel, BrinRevmap *revmap,
|
||||
{
|
||||
BrinBuildState *state;
|
||||
|
||||
state = palloc(sizeof(BrinBuildState));
|
||||
state = palloc_object(BrinBuildState);
|
||||
|
||||
state->bs_irel = idxRel;
|
||||
state->bs_numtuples = 0;
|
||||
|
||||
Reference in New Issue
Block a user