]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Future-proof the recursion inside ExecShutdownNode().
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 19 Sep 2022 16:16:02 +0000 (12:16 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 19 Sep 2022 16:16:02 +0000 (12:16 -0400)
The API contract for planstate_tree_walker() callbacks is that they
take a PlanState pointer and a context pointer.  Somebody figured
they could save a couple lines of code by ignoring that, and passing
ExecShutdownNode itself as the walker even though it has but one
argument.  Somewhat remarkably, we've gotten away with that so far.
However, it seems clear that the upcoming C2x standard means to
forbid such cases, and compilers that actively break such code
likely won't be far behind.  So spend the extra few lines of code
to do it honestly with a separate walker function.

In HEAD, we might as well go further and remove ExecShutdownNode's
useless return value.  I left that as-is in back branches though,
to forestall complaints about ABI breakage.

Back-patch, with the thought that this might become of practical
importance before our stable branches are all out of service.
It doesn't seem to be fixing any live bug on any currently known
platform, however.

Discussion: https://postgr.es/m/208054.1663534665@sss.pgh.pa.us

src/backend/executor/execProcnode.c

index ed78cf82c1060941d4e30540bdebd90c29b6ab4c..d8104b1c6e1973b6f063620bfe3d18579a7b2796 100644 (file)
 
 static TupleTableSlot *ExecProcNodeFirst(PlanState *node);
 static TupleTableSlot *ExecProcNodeInstr(PlanState *node);
+static bool ExecShutdownNode_walker(PlanState *node, void *context);
 
 
 /* ------------------------------------------------------------------------
@@ -725,6 +726,12 @@ ExecEndNode(PlanState *node)
  */
 bool
 ExecShutdownNode(PlanState *node)
+{
+       return ExecShutdownNode_walker(node, NULL);
+}
+
+static bool
+ExecShutdownNode_walker(PlanState *node, void *context)
 {
        if (node == NULL)
                return false;
@@ -744,7 +751,7 @@ ExecShutdownNode(PlanState *node)
        if (node->instrument && node->instrument->running)
                InstrStartNode(node->instrument);
 
-       planstate_tree_walker(node, ExecShutdownNode, NULL);
+       planstate_tree_walker(node, ExecShutdownNode_walker, context);
 
        switch (nodeTag(node))
        {