mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Tweak palloc/repalloc to allow zero bytes to be requested, as per recent
proposal. Eliminate several dozen now-unnecessary hacks to avoid palloc(0). (It's likely there are more that I didn't find.)
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.73 2004/05/26 04:41:09 neilc Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.74 2004/06/05 19:48:07 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -226,9 +226,8 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt)
|
||||
else
|
||||
{
|
||||
attr_cnt = onerel->rd_att->natts;
|
||||
/* +1 here is just to avoid palloc(0) with zero-column table */
|
||||
vacattrstats = (VacAttrStats **) palloc((attr_cnt + 1) *
|
||||
sizeof(VacAttrStats *));
|
||||
vacattrstats = (VacAttrStats **)
|
||||
palloc(attr_cnt * sizeof(VacAttrStats *));
|
||||
tcnt = 0;
|
||||
for (i = 1; i <= attr_cnt; i++)
|
||||
{
|
||||
@@ -505,8 +504,8 @@ compute_index_stats(Relation onerel, double totalrows,
|
||||
estate);
|
||||
|
||||
/* Compute and save index expression values */
|
||||
exprvals = (Datum *) palloc((numrows * attr_cnt + 1) * sizeof(Datum));
|
||||
exprnulls = (bool *) palloc((numrows * attr_cnt + 1) * sizeof(bool));
|
||||
exprvals = (Datum *) palloc(numrows * attr_cnt * sizeof(Datum));
|
||||
exprnulls = (bool *) palloc(numrows * attr_cnt * sizeof(bool));
|
||||
numindexrows = 0;
|
||||
tcnt = 0;
|
||||
for (rowno = 0; rowno < numrows; rowno++)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.224 2004/05/26 04:41:10 neilc Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.225 2004/06/05 19:48:07 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1158,13 +1158,11 @@ CopyTo(Relation rel, List *attnumlist, bool binary, bool oids,
|
||||
|
||||
/*
|
||||
* Get info about the columns we need to process.
|
||||
*
|
||||
* +1's here are to avoid palloc(0) in a zero-column table.
|
||||
*/
|
||||
out_functions = (FmgrInfo *) palloc((num_phys_attrs + 1) * sizeof(FmgrInfo));
|
||||
elements = (Oid *) palloc((num_phys_attrs + 1) * sizeof(Oid));
|
||||
isvarlena = (bool *) palloc((num_phys_attrs + 1) * sizeof(bool));
|
||||
force_quote = (bool *) palloc((num_phys_attrs + 1) * sizeof(bool));
|
||||
out_functions = (FmgrInfo *) palloc(num_phys_attrs * sizeof(FmgrInfo));
|
||||
elements = (Oid *) palloc(num_phys_attrs * sizeof(Oid));
|
||||
isvarlena = (bool *) palloc(num_phys_attrs * sizeof(bool));
|
||||
force_quote = (bool *) palloc(num_phys_attrs * sizeof(bool));
|
||||
foreach(cur, attnumlist)
|
||||
{
|
||||
int attnum = lfirst_int(cur);
|
||||
@@ -1501,14 +1499,13 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
|
||||
* relation, including the input function, the element type (to pass
|
||||
* to the input function), and info about defaults and constraints.
|
||||
* (Which input function we use depends on text/binary format choice.)
|
||||
* +1's here are to avoid palloc(0) in a zero-column table.
|
||||
*/
|
||||
in_functions = (FmgrInfo *) palloc((num_phys_attrs + 1) * sizeof(FmgrInfo));
|
||||
elements = (Oid *) palloc((num_phys_attrs + 1) * sizeof(Oid));
|
||||
defmap = (int *) palloc((num_phys_attrs + 1) * sizeof(int));
|
||||
defexprs = (ExprState **) palloc((num_phys_attrs + 1) * sizeof(ExprState *));
|
||||
constraintexprs = (ExprState **) palloc0((num_phys_attrs + 1) * sizeof(ExprState *));
|
||||
force_notnull = (bool *) palloc((num_phys_attrs + 1) * sizeof(bool));
|
||||
in_functions = (FmgrInfo *) palloc(num_phys_attrs * sizeof(FmgrInfo));
|
||||
elements = (Oid *) palloc(num_phys_attrs * sizeof(Oid));
|
||||
defmap = (int *) palloc(num_phys_attrs * sizeof(int));
|
||||
defexprs = (ExprState **) palloc(num_phys_attrs * sizeof(ExprState *));
|
||||
constraintexprs = (ExprState **) palloc0(num_phys_attrs * sizeof(ExprState *));
|
||||
force_notnull = (bool *) palloc(num_phys_attrs * sizeof(bool));
|
||||
|
||||
for (attnum = 1; attnum <= num_phys_attrs; attnum++)
|
||||
{
|
||||
@@ -1635,8 +1632,8 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
|
||||
fmgr_info(in_func_oid, &oid_in_function);
|
||||
}
|
||||
|
||||
values = (Datum *) palloc((num_phys_attrs + 1) * sizeof(Datum));
|
||||
nulls = (char *) palloc((num_phys_attrs + 1) * sizeof(char));
|
||||
values = (Datum *) palloc(num_phys_attrs * sizeof(Datum));
|
||||
nulls = (char *) palloc(num_phys_attrs * sizeof(char));
|
||||
|
||||
/* Make room for a PARAM_EXEC value for domain constraint checks */
|
||||
if (hasConstraints)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.110 2004/06/04 20:35:21 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.111 2004/06/05 19:48:07 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -727,10 +727,10 @@ MergeAttributes(List *schema, List *supers, bool istemp,
|
||||
* newattno[] will contain the child-table attribute numbers for
|
||||
* the attributes of this parent table. (They are not the same
|
||||
* for parents after the first one, nor if we have dropped
|
||||
* columns.) +1 is to prevent error if parent has zero columns.
|
||||
* columns.)
|
||||
*/
|
||||
newattno = (AttrNumber *)
|
||||
palloc((tupleDesc->natts + 1) * sizeof(AttrNumber));
|
||||
palloc(tupleDesc->natts * sizeof(AttrNumber));
|
||||
|
||||
for (parent_attno = 1; parent_attno <= tupleDesc->natts;
|
||||
parent_attno++)
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.279 2004/05/31 19:24:05 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.280 2004/06/05 19:48:07 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -2883,9 +2883,8 @@ vac_update_fsm(Relation onerel, VacPageList fraged_pages,
|
||||
*/
|
||||
threshold = GetAvgFSMRequestSize(&onerel->rd_node);
|
||||
|
||||
/* +1 to avoid palloc(0) */
|
||||
pageSpaces = (PageFreeSpaceInfo *)
|
||||
palloc((nPages + 1) * sizeof(PageFreeSpaceInfo));
|
||||
palloc(nPages * sizeof(PageFreeSpaceInfo));
|
||||
outPages = 0;
|
||||
|
||||
for (i = 0; i < nPages; i++)
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.41 2004/05/31 19:24:05 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.42 2004/06/05 19:48:07 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -918,9 +918,6 @@ lazy_space_alloc(LVRelStats *vacrelstats, BlockNumber relblocks)
|
||||
/* No need to allocate more pages than the relation has blocks */
|
||||
if (relblocks < (BlockNumber) maxpages)
|
||||
maxpages = (int) relblocks;
|
||||
/* avoid palloc(0) */
|
||||
if (maxpages < 1)
|
||||
maxpages = 1;
|
||||
|
||||
vacrelstats->fs_is_heap = false;
|
||||
vacrelstats->num_free_pages = 0;
|
||||
|
||||
Reference in New Issue
Block a user