mirror of
https://github.com/postgres/postgres.git
synced 2025-12-15 02:22:24 +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 in0c3c5c3b06and31d3847a37. Author: David Geier <geidav.pg@gmail.com> Discussion: https://postgr.es/m/ad0748d4-3080-436e-b0bc-ac8f86a3466a@gmail.com
This commit is contained in:
@@ -685,7 +685,7 @@ heap_vacuum_rel(Relation rel, const VacuumParams params,
|
||||
* of each rel. It's convenient for code in lazy_scan_heap to always use
|
||||
* these temp copies.
|
||||
*/
|
||||
vacrel = (LVRelState *) palloc0(sizeof(LVRelState));
|
||||
vacrel = palloc0_object(LVRelState);
|
||||
vacrel->dbname = get_database_name(MyDatabaseId);
|
||||
vacrel->relnamespace = get_namespace_name(RelationGetNamespace(rel));
|
||||
vacrel->relname = pstrdup(RelationGetRelationName(rel));
|
||||
@@ -705,7 +705,7 @@ heap_vacuum_rel(Relation rel, const VacuumParams params,
|
||||
if (instrument && vacrel->nindexes > 0)
|
||||
{
|
||||
/* Copy index names used by instrumentation (not error reporting) */
|
||||
indnames = palloc(sizeof(char *) * vacrel->nindexes);
|
||||
indnames = palloc_array(char *, vacrel->nindexes);
|
||||
for (int i = 0; i < vacrel->nindexes; i++)
|
||||
indnames[i] = pstrdup(RelationGetRelationName(vacrel->indrels[i]));
|
||||
}
|
||||
@@ -3582,7 +3582,7 @@ dead_items_alloc(LVRelState *vacrel, int nworkers)
|
||||
* locally.
|
||||
*/
|
||||
|
||||
dead_items_info = (VacDeadItemsInfo *) palloc(sizeof(VacDeadItemsInfo));
|
||||
dead_items_info = palloc_object(VacDeadItemsInfo);
|
||||
dead_items_info->max_bytes = vac_work_mem * (Size) 1024;
|
||||
dead_items_info->num_items = 0;
|
||||
vacrel->dead_items_info = dead_items_info;
|
||||
|
||||
Reference in New Issue
Block a user