Re: Tree-walker callbacks vs -Wdeprecated-non-prototype
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Thomas Munro <thomas.munro@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2022-09-17T01:08:02Z
Lists: pgsql-hackers
Attachments
- clean-up-tree-walker-warnings-wip.patch (text/x-diff) patch
I wrote:
> Ugh. I wonder if we can get away with declaring the walker arguments
> as something like "bool (*walker) (Node *, void *)" without having
> to change all the actual walkers to be exactly that signature.
> Having to insert casts in the walkers would be a major pain-in-the-butt.
No joy on that: both gcc and clang want the walkers to be declared
as taking exactly "void *".
Attached is an incomplete POC patch that suppresses these warnings
in nodeFuncs.c itself and in costsize.c, which I selected at random
as a typical caller. I'll push forward with converting the other
call sites if this way seems good to people.
In nodeFuncs.c, we can hide the newly-required casts inside macros;
indeed, the mutators barely need any changes because they already
had MUTATE() macros that contained casts. So on that side, it feels
to me that this is actually a bit nicer than before.
For the callers, we can either do it as I did below:
static bool
-cost_qual_eval_walker(Node *node, cost_qual_eval_context *context)
+cost_qual_eval_walker(Node *node, void *ctx)
{
+ cost_qual_eval_context *context = (cost_qual_eval_context *) ctx;
+
if (node == NULL)
return false;
or perhaps like this:
static bool
-cost_qual_eval_walker(Node *node, cost_qual_eval_context *context)
+cost_qual_eval_walker(Node *node, void *context)
{
+ cost_qual_eval_context *cqctx = (cost_qual_eval_context *) context;
+
if (node == NULL)
return false;
but the latter would require changing references further down in the
function, so I felt it more invasive.
It's sad to note that this exercise in hoop-jumping actually leaves
us with net LESS type safety, because the outside callers of
cost_qual_eval_walker are no longer constrained to call it with
the appropriate kind of context struct. Thanks, C committee.
regards, tom lane
Commits
-
Remove accidentally added meson.build
- e7480f3dd6c2 13.22 landed
-
Disable clang 16's -Wcast-function-type-strict.
- 27831127d641 14.13 landed
- 6e2552d180a0 15.8 landed
- 101c37cd342a 16.0 landed
-
Disable -Wdeprecated-non-prototype in the back branches.
- 8c8ee5c99144 9.3 (unreleased) landed
- 5d3ce0d823c8 9.2 (unreleased) landed
- f9a56e726334 15.0 landed
- dcd7dbed5008 14.6 landed
- ca8fd341e165 9.6 (unreleased) landed
- 9afdf395042a 11.18 landed
- 7d5d3f05bfab 9.4 (unreleased) landed
- 52a5fd5b9f8f 12.13 landed
- 4c5a29c0e5e1 10.23 landed
- 43f72e0f73a5 13.9 landed
- 1b698659970e 9.5 (unreleased) landed
-
Revise tree-walk APIs to improve spec compliance & silence warnings.
- 1c27d16e6e5c 16.0 landed
-
Future-proof the recursion inside ExecShutdownNode().
- c35ba141de1f 16.0 landed
- cb7d636e0fb2 11.18 landed
- c58513f095e2 13.9 landed
- c403f97b4eab 15.0 landed
- adc26e0e88b3 12.13 landed
- 7394c763bc72 14.6 landed
- 68707e9c3f32 10.23 landed