From: | Andres Freund <andres(at)2ndquadrant(dot)com> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | What about a castNode() macro? |
Date: | 2014-04-29 15:55:37 |
Message-ID: | 20140429155537.GA3806@awork2.anarazel.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi,
There's a repeated pattern of
Assert(IsA(ptr, nodetype));
foo = (nodetype *) ptr;
how about adding a castNode() that combines those? Something like:
#if !defined(USE_ASSERT_CHECKING)
#define castNode(nodeptr,_type_) \
((_type_ *) (nodeptr))
#elif defined(__GNUC__)
#define castNode(nodeptr,_type_) \
((_type_ *) ({ \
Node *_result; \
_result = nodeptr; \
Assert(IsA(_result, _type_)); \
_result; \
}))
#else
extern PGDLLIMPORT Node *newNodeMacroHolder;
#define castNode(nodePtr,_type_) \
( \
newNodeMacroHolder = nodePtr, \
AssertMacro(IsA(newNodeMacroHolder, _type_)), \
(_type_ *) newNodeMacroHolder \
)
#endif
Greetings,
Andres Freund
--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
From | Date | Subject | |
---|---|---|---|
Next Message | Stephen Frost | 2014-04-29 17:10:35 | Planned downtime @ Rackspace - 2014-04-29 2100-2200 UTC |
Previous Message | Tom Lane | 2014-04-29 15:14:41 | Re: pg_dump --pretty-print-views |