Re: safer node casting
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@anarazel.de>
Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>,
pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2017-01-27T01:29:06Z
Lists: pgsql-hackers
Andres Freund <andres@anarazel.de> writes: > On 2016-12-31 12:08:22 -0500, Peter Eisentraut wrote: >> This is inspired by the dynamic_cast operator in C++, but follows the >> syntax of the well-known makeNode() macro. > The analogy to dynamic_cast goes only so far, because we don't actually > support inheritance. I.e. in c++ we could successfully cast SeqScanState to a > PlanState, ScanState and SeqScanState - but with our model only > SeqScanState can be checked. Yeah, I was thinking about that earlier --- this can only be used to cast to a concrete node type, not one of the "abstract" types like Plan * or Expr *. Not sure if that's worth worrying about though; I don't think I've ever seen actual bugs in PG code from casting the wrong thing in that direction. For the most part, passing the wrong thing would end up firing a default: case in a switch, or some such, so we already do have some defenses for that direction. regards, tom lane
Commits
-
Suppress unused-variable warning.
- c56ac2913a1f 10.0 landed
-
Make more use of castNode()
- 38d103763d14 10.0 cited
-
Add castNode(type, ptr) for safe casting between NodeTag based types.
- 1ad163ef0130 9.3.16 landed
- 14d0e290cbe7 9.2.20 landed
- cf8c86af950b 9.4.11 landed
- 8fef0c34143b 9.5.6 landed
- 5bcab111426e 10.0 landed
- 574b091e5835 9.6.2 landed
-
Use the new castNode() macro in a number of places.
- 9ba8a9ce4548 10.0 landed