diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2022-09-12 08:31:56 +0200 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2022-09-12 08:45:03 +0200 |
commit | 5015e1e1b58f81a036e4ad16291ef4b3bb7a596c (patch) | |
tree | 86ee608e961dc830e733c534db089f1e45706414 /src/bin/pg_dump/common.c | |
parent | 2016055a92f26d648aba9f66d26cc0bcd1619eff (diff) | |
download | postgresql-5015e1e1b58f81a036e4ad16291ef4b3bb7a596c.tar.gz postgresql-5015e1e1b58f81a036e4ad16291ef4b3bb7a596c.zip |
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
Diffstat (limited to 'src/bin/pg_dump/common.c')
-rw-r--r-- | src/bin/pg_dump/common.c | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/src/bin/pg_dump/common.c b/src/bin/pg_dump/common.c index 794e6e7ce99..395f817fa8f 100644 --- a/src/bin/pg_dump/common.c +++ b/src/bin/pg_dump/common.c @@ -400,7 +400,7 @@ flagInhIndexes(Archive *fout, TableInfo tblinfo[], int numTables) if (parentidx == NULL) continue; - attachinfo = (IndexAttachInfo *) pg_malloc(sizeof(IndexAttachInfo)); + attachinfo = pg_malloc_object(IndexAttachInfo); attachinfo->dobj.objType = DO_INDEX_ATTACH; attachinfo->dobj.catId.tableoid = 0; @@ -530,7 +530,7 @@ flagInhAttrs(DumpOptions *dopt, TableInfo *tblinfo, int numTables) { AttrDefInfo *attrDef; - attrDef = (AttrDefInfo *) pg_malloc(sizeof(AttrDefInfo)); + attrDef = pg_malloc_object(AttrDefInfo); attrDef->dobj.objType = DO_ATTRDEF; attrDef->dobj.catId.tableoid = 0; attrDef->dobj.catId.oid = 0; @@ -600,14 +600,12 @@ AssignDumpId(DumpableObject *dobj) if (allocedDumpIds <= 0) { newAlloc = 256; - dumpIdMap = (DumpableObject **) - pg_malloc(newAlloc * sizeof(DumpableObject *)); + dumpIdMap = pg_malloc_array(DumpableObject *, newAlloc); } else { newAlloc = allocedDumpIds * 2; - dumpIdMap = (DumpableObject **) - pg_realloc(dumpIdMap, newAlloc * sizeof(DumpableObject *)); + dumpIdMap = pg_realloc_array(dumpIdMap, DumpableObject *, newAlloc); } memset(dumpIdMap + allocedDumpIds, 0, (newAlloc - allocedDumpIds) * sizeof(DumpableObject *)); @@ -700,8 +698,7 @@ getDumpableObjects(DumpableObject ***objs, int *numObjs) int i, j; - *objs = (DumpableObject **) - pg_malloc(allocedDumpIds * sizeof(DumpableObject *)); + *objs = pg_malloc_array(DumpableObject *, allocedDumpIds); j = 0; for (i = 1; i < allocedDumpIds; i++) { @@ -724,15 +721,13 @@ addObjectDependency(DumpableObject *dobj, DumpId refId) if (dobj->allocDeps <= 0) { dobj->allocDeps = 16; - dobj->dependencies = (DumpId *) - pg_malloc(dobj->allocDeps * sizeof(DumpId)); + dobj->dependencies = pg_malloc_array(DumpId, dobj->allocDeps); } else { dobj->allocDeps *= 2; - dobj->dependencies = (DumpId *) - pg_realloc(dobj->dependencies, - dobj->allocDeps * sizeof(DumpId)); + dobj->dependencies = pg_realloc_array(dobj->dependencies, + DumpId, dobj->allocDeps); } } dobj->dependencies[dobj->nDeps++] = refId; @@ -990,8 +985,7 @@ findParentsByOid(TableInfo *self, if (numParents > 0) { - self->parents = (TableInfo **) - pg_malloc(sizeof(TableInfo *) * numParents); + self->parents = pg_malloc_array(TableInfo *, numParents); j = 0; for (i = 0; i < numInherits; i++) { |