mirror of
https://github.com/postgres/postgres.git
synced 2025-07-08 11:42:09 +03:00
Cast result of copyObject() to correct type
copyObject() is declared to return void *, which allows easily assigning the result independent of the input, but it loses all type checking. If the compiler supports typeof or something similar, cast the result to the input type. This creates a greater amount of type safety. In some cases, where the result is assigned to a generic type such as Node * or Expr *, new casts are now necessary, but in general casts are now unnecessary in the normal case and indicate that something unusual is happening. Reviewed-by: Mark Dilger <hornschnorter@gmail.com>
This commit is contained in:
@ -4004,9 +4004,9 @@ adjust_rowcompare_for_index(RowCompareExpr *clause,
|
||||
matching_cols);
|
||||
rc->inputcollids = list_truncate(list_copy(clause->inputcollids),
|
||||
matching_cols);
|
||||
rc->largs = list_truncate((List *) copyObject(clause->largs),
|
||||
rc->largs = list_truncate(copyObject(clause->largs),
|
||||
matching_cols);
|
||||
rc->rargs = list_truncate((List *) copyObject(clause->rargs),
|
||||
rc->rargs = list_truncate(copyObject(clause->rargs),
|
||||
matching_cols);
|
||||
return (Expr *) rc;
|
||||
}
|
||||
|
@ -1275,7 +1275,7 @@ create_unique_plan(PlannerInfo *root, UniquePath *best_path, int flags)
|
||||
|
||||
foreach(l, uniq_exprs)
|
||||
{
|
||||
Node *uniqexpr = lfirst(l);
|
||||
Expr *uniqexpr = lfirst(l);
|
||||
TargetEntry *tle;
|
||||
|
||||
tle = tlist_member(uniqexpr, newtlist);
|
||||
@ -1318,7 +1318,7 @@ create_unique_plan(PlannerInfo *root, UniquePath *best_path, int flags)
|
||||
groupColPos = 0;
|
||||
foreach(l, uniq_exprs)
|
||||
{
|
||||
Node *uniqexpr = lfirst(l);
|
||||
Expr *uniqexpr = lfirst(l);
|
||||
TargetEntry *tle;
|
||||
|
||||
tle = tlist_member(uniqexpr, newtlist);
|
||||
@ -4318,7 +4318,7 @@ process_subquery_nestloop_params(PlannerInfo *root, List *subplan_params)
|
||||
/* No, so add it */
|
||||
nlp = makeNode(NestLoopParam);
|
||||
nlp->paramno = pitem->paramId;
|
||||
nlp->paramval = copyObject(phv);
|
||||
nlp->paramval = (Var *) copyObject(phv);
|
||||
root->curOuterParams = lappend(root->curOuterParams, nlp);
|
||||
}
|
||||
}
|
||||
|
@ -2306,8 +2306,8 @@ process_implied_equality(PlannerInfo *root,
|
||||
clause = make_opclause(opno,
|
||||
BOOLOID, /* opresulttype */
|
||||
false, /* opretset */
|
||||
(Expr *) copyObject(item1),
|
||||
(Expr *) copyObject(item2),
|
||||
copyObject(item1),
|
||||
copyObject(item2),
|
||||
InvalidOid,
|
||||
collation);
|
||||
|
||||
@ -2369,8 +2369,8 @@ build_implied_join_equality(Oid opno,
|
||||
clause = make_opclause(opno,
|
||||
BOOLOID, /* opresulttype */
|
||||
false, /* opretset */
|
||||
(Expr *) copyObject(item1),
|
||||
(Expr *) copyObject(item2),
|
||||
copyObject(item1),
|
||||
copyObject(item2),
|
||||
InvalidOid,
|
||||
collation);
|
||||
|
||||
|
@ -369,11 +369,11 @@ build_minmax_path(PlannerInfo *root, MinMaxAggInfo *mminfo,
|
||||
subroot->outer_params = NULL;
|
||||
subroot->init_plans = NIL;
|
||||
|
||||
subroot->parse = parse = (Query *) copyObject(root->parse);
|
||||
subroot->parse = parse = copyObject(root->parse);
|
||||
IncrementVarSublevelsUp((Node *) parse, 1, 1);
|
||||
|
||||
/* append_rel_list might contain outer Vars? */
|
||||
subroot->append_rel_list = (List *) copyObject(root->append_rel_list);
|
||||
subroot->append_rel_list = copyObject(root->append_rel_list);
|
||||
IncrementVarSublevelsUp((Node *) subroot->append_rel_list, 1, 1);
|
||||
/* There shouldn't be any OJ info to translate, as yet */
|
||||
Assert(subroot->join_info_list == NIL);
|
||||
|
@ -1157,7 +1157,7 @@ inheritance_planner(PlannerInfo *root)
|
||||
* executor doesn't need to see the modified copies --- we can just
|
||||
* pass it the original rowMarks list.)
|
||||
*/
|
||||
subroot->rowMarks = (List *) copyObject(root->rowMarks);
|
||||
subroot->rowMarks = copyObject(root->rowMarks);
|
||||
|
||||
/*
|
||||
* The append_rel_list likewise might contain references to subquery
|
||||
@ -1179,7 +1179,7 @@ inheritance_planner(PlannerInfo *root)
|
||||
AppendRelInfo *appinfo2 = (AppendRelInfo *) lfirst(lc2);
|
||||
|
||||
if (bms_is_member(appinfo2->child_relid, modifiableARIindexes))
|
||||
appinfo2 = (AppendRelInfo *) copyObject(appinfo2);
|
||||
appinfo2 = copyObject(appinfo2);
|
||||
|
||||
subroot->append_rel_list = lappend(subroot->append_rel_list,
|
||||
appinfo2);
|
||||
|
@ -111,10 +111,10 @@ static Var *search_indexed_tlist_for_var(Var *var,
|
||||
indexed_tlist *itlist,
|
||||
Index newvarno,
|
||||
int rtoffset);
|
||||
static Var *search_indexed_tlist_for_non_var(Node *node,
|
||||
static Var *search_indexed_tlist_for_non_var(Expr *node,
|
||||
indexed_tlist *itlist,
|
||||
Index newvarno);
|
||||
static Var *search_indexed_tlist_for_sortgroupref(Node *node,
|
||||
static Var *search_indexed_tlist_for_sortgroupref(Expr *node,
|
||||
Index sortgroupref,
|
||||
indexed_tlist *itlist,
|
||||
Index newvarno);
|
||||
@ -1440,7 +1440,7 @@ fix_param_node(PlannerInfo *root, Param *p)
|
||||
elog(ERROR, "unexpected PARAM_MULTIEXPR ID: %d", p->paramid);
|
||||
return copyObject(list_nth(params, colno - 1));
|
||||
}
|
||||
return copyObject(p);
|
||||
return (Node *) copyObject(p);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1727,7 +1727,7 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
|
||||
if (tle->ressortgroupref != 0 && !IsA(tle->expr, Var))
|
||||
{
|
||||
newexpr = (Node *)
|
||||
search_indexed_tlist_for_sortgroupref((Node *) tle->expr,
|
||||
search_indexed_tlist_for_sortgroupref(tle->expr,
|
||||
tle->ressortgroupref,
|
||||
subplan_itlist,
|
||||
OUTER_VAR);
|
||||
@ -1810,7 +1810,7 @@ convert_combining_aggrefs(Node *node, void *context)
|
||||
*/
|
||||
child_agg->args = NIL;
|
||||
child_agg->aggfilter = NULL;
|
||||
parent_agg = (Aggref *) copyObject(child_agg);
|
||||
parent_agg = copyObject(child_agg);
|
||||
child_agg->args = orig_agg->args;
|
||||
child_agg->aggfilter = orig_agg->aggfilter;
|
||||
|
||||
@ -2054,7 +2054,7 @@ search_indexed_tlist_for_var(Var *var, indexed_tlist *itlist,
|
||||
* so there's a correctness reason not to call it unless that's set.
|
||||
*/
|
||||
static Var *
|
||||
search_indexed_tlist_for_non_var(Node *node,
|
||||
search_indexed_tlist_for_non_var(Expr *node,
|
||||
indexed_tlist *itlist, Index newvarno)
|
||||
{
|
||||
TargetEntry *tle;
|
||||
@ -2095,7 +2095,7 @@ search_indexed_tlist_for_non_var(Node *node,
|
||||
* And it's also faster than search_indexed_tlist_for_non_var.
|
||||
*/
|
||||
static Var *
|
||||
search_indexed_tlist_for_sortgroupref(Node *node,
|
||||
search_indexed_tlist_for_sortgroupref(Expr *node,
|
||||
Index sortgroupref,
|
||||
indexed_tlist *itlist,
|
||||
Index newvarno)
|
||||
@ -2229,7 +2229,7 @@ fix_join_expr_mutator(Node *node, fix_join_expr_context *context)
|
||||
/* See if the PlaceHolderVar has bubbled up from a lower plan node */
|
||||
if (context->outer_itlist && context->outer_itlist->has_ph_vars)
|
||||
{
|
||||
newvar = search_indexed_tlist_for_non_var((Node *) phv,
|
||||
newvar = search_indexed_tlist_for_non_var((Expr *) phv,
|
||||
context->outer_itlist,
|
||||
OUTER_VAR);
|
||||
if (newvar)
|
||||
@ -2237,7 +2237,7 @@ fix_join_expr_mutator(Node *node, fix_join_expr_context *context)
|
||||
}
|
||||
if (context->inner_itlist && context->inner_itlist->has_ph_vars)
|
||||
{
|
||||
newvar = search_indexed_tlist_for_non_var((Node *) phv,
|
||||
newvar = search_indexed_tlist_for_non_var((Expr *) phv,
|
||||
context->inner_itlist,
|
||||
INNER_VAR);
|
||||
if (newvar)
|
||||
@ -2252,7 +2252,7 @@ fix_join_expr_mutator(Node *node, fix_join_expr_context *context)
|
||||
/* Try matching more complex expressions too, if tlists have any */
|
||||
if (context->outer_itlist && context->outer_itlist->has_non_vars)
|
||||
{
|
||||
newvar = search_indexed_tlist_for_non_var(node,
|
||||
newvar = search_indexed_tlist_for_non_var((Expr *) node,
|
||||
context->outer_itlist,
|
||||
OUTER_VAR);
|
||||
if (newvar)
|
||||
@ -2260,7 +2260,7 @@ fix_join_expr_mutator(Node *node, fix_join_expr_context *context)
|
||||
}
|
||||
if (context->inner_itlist && context->inner_itlist->has_non_vars)
|
||||
{
|
||||
newvar = search_indexed_tlist_for_non_var(node,
|
||||
newvar = search_indexed_tlist_for_non_var((Expr *) node,
|
||||
context->inner_itlist,
|
||||
INNER_VAR);
|
||||
if (newvar)
|
||||
@ -2344,7 +2344,7 @@ fix_upper_expr_mutator(Node *node, fix_upper_expr_context *context)
|
||||
/* See if the PlaceHolderVar has bubbled up from a lower plan node */
|
||||
if (context->subplan_itlist->has_ph_vars)
|
||||
{
|
||||
newvar = search_indexed_tlist_for_non_var((Node *) phv,
|
||||
newvar = search_indexed_tlist_for_non_var((Expr *) phv,
|
||||
context->subplan_itlist,
|
||||
context->newvarno);
|
||||
if (newvar)
|
||||
@ -2380,7 +2380,7 @@ fix_upper_expr_mutator(Node *node, fix_upper_expr_context *context)
|
||||
/* Try matching more complex expressions too, if tlist has any */
|
||||
if (context->subplan_itlist->has_non_vars)
|
||||
{
|
||||
newvar = search_indexed_tlist_for_non_var(node,
|
||||
newvar = search_indexed_tlist_for_non_var((Expr *) node,
|
||||
context->subplan_itlist,
|
||||
context->newvarno);
|
||||
if (newvar)
|
||||
|
@ -125,7 +125,7 @@ assign_param_for_var(PlannerInfo *root, Var *var)
|
||||
}
|
||||
|
||||
/* Nope, so make a new one */
|
||||
var = (Var *) copyObject(var);
|
||||
var = copyObject(var);
|
||||
var->varlevelsup = 0;
|
||||
|
||||
pitem = makeNode(PlannerParamItem);
|
||||
@ -224,7 +224,7 @@ assign_param_for_placeholdervar(PlannerInfo *root, PlaceHolderVar *phv)
|
||||
}
|
||||
|
||||
/* Nope, so make a new one */
|
||||
phv = (PlaceHolderVar *) copyObject(phv);
|
||||
phv = copyObject(phv);
|
||||
if (phv->phlevelsup != 0)
|
||||
{
|
||||
IncrementVarSublevelsUp((Node *) phv, -((int) phv->phlevelsup), 0);
|
||||
@ -316,7 +316,7 @@ replace_outer_agg(PlannerInfo *root, Aggref *agg)
|
||||
* It does not seem worthwhile to try to match duplicate outer aggs. Just
|
||||
* make a new slot every time.
|
||||
*/
|
||||
agg = (Aggref *) copyObject(agg);
|
||||
agg = copyObject(agg);
|
||||
IncrementVarSublevelsUp((Node *) agg, -((int) agg->agglevelsup), 0);
|
||||
Assert(agg->agglevelsup == 0);
|
||||
|
||||
@ -358,7 +358,7 @@ replace_outer_grouping(PlannerInfo *root, GroupingFunc *grp)
|
||||
* It does not seem worthwhile to try to match duplicate outer aggs. Just
|
||||
* make a new slot every time.
|
||||
*/
|
||||
grp = (GroupingFunc *) copyObject(grp);
|
||||
grp = copyObject(grp);
|
||||
IncrementVarSublevelsUp((Node *) grp, -((int) grp->agglevelsup), 0);
|
||||
Assert(grp->agglevelsup == 0);
|
||||
|
||||
@ -491,7 +491,7 @@ make_subplan(PlannerInfo *root, Query *orig_subquery,
|
||||
* same sub-Query node, but the planner wants to scribble on the Query.
|
||||
* Try to clean this up when we do querytree redesign...
|
||||
*/
|
||||
subquery = (Query *) copyObject(orig_subquery);
|
||||
subquery = copyObject(orig_subquery);
|
||||
|
||||
/*
|
||||
* If it's an EXISTS subplan, we might be able to simplify it.
|
||||
@ -568,7 +568,7 @@ make_subplan(PlannerInfo *root, Query *orig_subquery,
|
||||
List *paramIds;
|
||||
|
||||
/* Make a second copy of the original subquery */
|
||||
subquery = (Query *) copyObject(orig_subquery);
|
||||
subquery = copyObject(orig_subquery);
|
||||
/* and re-simplify */
|
||||
simple_exists = simplify_EXISTS_query(root, subquery);
|
||||
Assert(simple_exists);
|
||||
@ -1431,7 +1431,7 @@ convert_EXISTS_sublink_to_join(PlannerInfo *root, SubLink *sublink,
|
||||
* Copy the subquery so we can modify it safely (see comments in
|
||||
* make_subplan).
|
||||
*/
|
||||
subselect = (Query *) copyObject(subselect);
|
||||
subselect = copyObject(subselect);
|
||||
|
||||
/*
|
||||
* See if the subquery can be simplified based on the knowledge that it's
|
||||
|
@ -1592,7 +1592,7 @@ pull_up_simple_values(PlannerInfo *root, Node *jtnode, RangeTblEntry *rte)
|
||||
* Need a modifiable copy of the VALUES list to hack on, just in case it's
|
||||
* multiply referenced.
|
||||
*/
|
||||
values_list = (List *) copyObject(linitial(rte->values_lists));
|
||||
values_list = copyObject(linitial(rte->values_lists));
|
||||
|
||||
/*
|
||||
* The VALUES RTE can't contain any Vars of level zero, let alone any that
|
||||
@ -2128,7 +2128,7 @@ pullup_replace_vars_callback(Var *var,
|
||||
varattno);
|
||||
|
||||
/* Make a copy of the tlist item to return */
|
||||
newnode = copyObject(tle->expr);
|
||||
newnode = (Node *) copyObject(tle->expr);
|
||||
|
||||
/* Insert PlaceHolderVar if needed */
|
||||
if (rcon->need_phvs)
|
||||
|
@ -180,7 +180,7 @@ preprocess_targetlist(PlannerInfo *root, List *tlist)
|
||||
var->varno == result_relation)
|
||||
continue; /* don't need it */
|
||||
|
||||
if (tlist_member((Node *) var, tlist))
|
||||
if (tlist_member((Expr *) var, tlist))
|
||||
continue; /* already got it */
|
||||
|
||||
tle = makeTargetEntry((Expr *) var,
|
||||
|
@ -1274,7 +1274,7 @@ generate_append_tlist(List *colTypes, List *colCollations,
|
||||
static List *
|
||||
generate_setop_grouplist(SetOperationStmt *op, List *targetlist)
|
||||
{
|
||||
List *grouplist = (List *) copyObject(op->groupClauses);
|
||||
List *grouplist = copyObject(op->groupClauses);
|
||||
ListCell *lg;
|
||||
ListCell *lt;
|
||||
|
||||
@ -1879,7 +1879,7 @@ adjust_appendrel_attrs_mutator(Node *node,
|
||||
|
||||
rte = rt_fetch(appinfo->parent_relid,
|
||||
context->root->parse->rtable);
|
||||
fields = (List *) copyObject(appinfo->translated_vars);
|
||||
fields = copyObject(appinfo->translated_vars);
|
||||
rowexpr = makeNode(RowExpr);
|
||||
rowexpr->args = fields;
|
||||
rowexpr->row_typeid = var->vartype;
|
||||
|
@ -51,7 +51,7 @@ static bool split_pathtarget_walker(Node *node,
|
||||
* equal() to the given expression. Result is NULL if no such member.
|
||||
*/
|
||||
TargetEntry *
|
||||
tlist_member(Node *node, List *targetlist)
|
||||
tlist_member(Expr *node, List *targetlist)
|
||||
{
|
||||
ListCell *temp;
|
||||
|
||||
@ -72,12 +72,12 @@ tlist_member(Node *node, List *targetlist)
|
||||
* involving binary-compatible sort operations.
|
||||
*/
|
||||
TargetEntry *
|
||||
tlist_member_ignore_relabel(Node *node, List *targetlist)
|
||||
tlist_member_ignore_relabel(Expr *node, List *targetlist)
|
||||
{
|
||||
ListCell *temp;
|
||||
|
||||
while (node && IsA(node, RelabelType))
|
||||
node = (Node *) ((RelabelType *) node)->arg;
|
||||
node = ((RelabelType *) node)->arg;
|
||||
|
||||
foreach(temp, targetlist)
|
||||
{
|
||||
@ -139,7 +139,7 @@ add_to_flat_tlist(List *tlist, List *exprs)
|
||||
|
||||
foreach(lc, exprs)
|
||||
{
|
||||
Node *expr = (Node *) lfirst(lc);
|
||||
Expr *expr = (Expr *) lfirst(lc);
|
||||
|
||||
if (!tlist_member(expr, tlist))
|
||||
{
|
||||
@ -762,7 +762,7 @@ apply_pathtarget_labeling_to_tlist(List *tlist, PathTarget *target)
|
||||
if (expr && IsA(expr, Var))
|
||||
tle = tlist_member_match_var((Var *) expr, tlist);
|
||||
else
|
||||
tle = tlist_member((Node *) expr, tlist);
|
||||
tle = tlist_member(expr, tlist);
|
||||
|
||||
/*
|
||||
* Complain if noplace for the sortgrouprefs label, or if we'd
|
||||
@ -999,7 +999,7 @@ split_pathtarget_at_srfs(PlannerInfo *root,
|
||||
|
||||
foreach(lcx, input_srfs)
|
||||
{
|
||||
Node *srf = (Node *) lfirst(lcx);
|
||||
Expr *srf = (Expr *) lfirst(lcx);
|
||||
|
||||
if (list_member(prev_level_tlist, srf))
|
||||
add_new_column_to_pathtarget(ntarget, copyObject(srf));
|
||||
|
Reference in New Issue
Block a user