1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-12 21:01:52 +03:00

Expose more out/readfuncs support functions.

Previously bcac23d exposed a subset of support functions, namely the
ones Kaigai found useful. In
20160304193704.elq773pyg5fyl3mi@alap3.anarazel.de I mentioned that
there's some functions missing to use the facility in an external
project.

To avoid having to add functions piecemeal, add all the functions which
are used to define READ_* and WRITE_* macros; users of the extensible
node functionality are likely to need these. Additionally expose
outDatum(), which doesn't have it's own WRITE_ macro, as it needs
information from the embedding struct.

Discussion: 20160304193704.elq773pyg5fyl3mi@alap3.anarazel.de
This commit is contained in:
Andres Freund
2016-04-08 14:26:36 -07:00
parent 7a542700df
commit c1ddd2361f
3 changed files with 23 additions and 23 deletions

View File

@ -89,7 +89,7 @@
/* Write a Node field */ /* Write a Node field */
#define WRITE_NODE_FIELD(fldname) \ #define WRITE_NODE_FIELD(fldname) \
(appendStringInfo(str, " :" CppAsString(fldname) " "), \ (appendStringInfo(str, " :" CppAsString(fldname) " "), \
_outNode(str, node->fldname)) outNode(str, node->fldname))
/* Write a bitmapset field */ /* Write a bitmapset field */
#define WRITE_BITMAPSET_FIELD(fldname) \ #define WRITE_BITMAPSET_FIELD(fldname) \
@ -99,8 +99,6 @@
#define booltostr(x) ((x) ? "true" : "false") #define booltostr(x) ((x) ? "true" : "false")
static void _outNode(StringInfo str, const void *obj);
/* /*
* _outToken * _outToken
@ -169,7 +167,7 @@ _outList(StringInfo str, const List *node)
*/ */
if (IsA(node, List)) if (IsA(node, List))
{ {
_outNode(str, lfirst(lc)); outNode(str, lfirst(lc));
if (lnext(lc)) if (lnext(lc))
appendStringInfoChar(str, ' '); appendStringInfoChar(str, ' ');
} }
@ -214,8 +212,8 @@ outBitmapset(StringInfo str, const Bitmapset *bms)
/* /*
* Print the value of a Datum given its type. * Print the value of a Datum given its type.
*/ */
static void void
_outDatum(StringInfo str, Datum value, int typlen, bool typbyval) outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
{ {
Size length, Size length,
i; i;
@ -1009,7 +1007,7 @@ _outConst(StringInfo str, const Const *node)
if (node->constisnull) if (node->constisnull)
appendStringInfoString(str, "<>"); appendStringInfoString(str, "<>");
else else
_outDatum(str, node->constvalue, node->constlen, node->constbyval); outDatum(str, node->constvalue, node->constlen, node->constbyval);
} }
static void static void
@ -3219,11 +3217,11 @@ _outConstraint(StringInfo str, const Constraint *node)
/* /*
* _outNode - * outNode -
* converts a Node into ascii string and append it to 'str' * converts a Node into ascii string and append it to 'str'
*/ */
static void void
_outNode(StringInfo str, const void *obj) outNode(StringInfo str, const void *obj)
{ {
if (obj == NULL) if (obj == NULL)
appendStringInfoString(str, "<>"); appendStringInfoString(str, "<>");
@ -3801,7 +3799,7 @@ _outNode(StringInfo str, const void *obj)
/* /*
* This should be an ERROR, but it's too useful to be able to * This should be an ERROR, but it's too useful to be able to
* dump structures that _outNode only understands part of. * dump structures that outNode only understands part of.
*/ */
elog(WARNING, "could not dump unrecognized node type: %d", elog(WARNING, "could not dump unrecognized node type: %d",
(int) nodeTag(obj)); (int) nodeTag(obj));
@ -3822,6 +3820,6 @@ nodeToString(const void *obj)
/* see stringinfo.h for an explanation of this maneuver */ /* see stringinfo.h for an explanation of this maneuver */
initStringInfo(&str); initStringInfo(&str);
_outNode(&str, obj); outNode(&str, obj);
return str.data; return str.data;
} }

View File

@ -172,12 +172,6 @@
((length) == 0 ? NULL : debackslash(token, length)) ((length) == 0 ? NULL : debackslash(token, length))
static Datum readDatum(bool typbyval);
static bool *readBoolCols(int numCols);
static int *readIntCols(int numCols);
static Oid *readOidCols(int numCols);
static AttrNumber *readAttrNumberCols(int numCols);
/* /*
* _readBitmapset * _readBitmapset
*/ */
@ -2499,7 +2493,7 @@ parseNodeString(void)
* Datum. The string representation embeds length info, but not byValue, * Datum. The string representation embeds length info, but not byValue,
* so we must be told that. * so we must be told that.
*/ */
static Datum Datum
readDatum(bool typbyval) readDatum(bool typbyval)
{ {
Size length, Size length,
@ -2556,7 +2550,7 @@ readDatum(bool typbyval)
/* /*
* readAttrNumberCols * readAttrNumberCols
*/ */
static AttrNumber * AttrNumber *
readAttrNumberCols(int numCols) readAttrNumberCols(int numCols)
{ {
int tokenLength, int tokenLength,
@ -2580,7 +2574,7 @@ readAttrNumberCols(int numCols)
/* /*
* readOidCols * readOidCols
*/ */
static Oid * Oid *
readOidCols(int numCols) readOidCols(int numCols)
{ {
int tokenLength, int tokenLength,
@ -2604,7 +2598,7 @@ readOidCols(int numCols)
/* /*
* readIntCols * readIntCols
*/ */
static int * int *
readIntCols(int numCols) readIntCols(int numCols)
{ {
int tokenLength, int tokenLength,
@ -2628,7 +2622,7 @@ readIntCols(int numCols)
/* /*
* readBoolCols * readBoolCols
*/ */
static bool * bool *
readBoolCols(int numCols) readBoolCols(int numCols)
{ {
int tokenLength, int tokenLength,

View File

@ -553,15 +553,23 @@ extern char *nodeToString(const void *obj);
struct Bitmapset; /* not to include bitmapset.h here */ struct Bitmapset; /* not to include bitmapset.h here */
struct StringInfoData; /* not to include stringinfo.h here */ struct StringInfoData; /* not to include stringinfo.h here */
extern void outNode(struct StringInfoData *str, const void *obj);
extern void outToken(struct StringInfoData *str, const char *s); extern void outToken(struct StringInfoData *str, const char *s);
extern void outBitmapset(struct StringInfoData *str, extern void outBitmapset(struct StringInfoData *str,
const struct Bitmapset *bms); const struct Bitmapset *bms);
extern void outDatum(struct StringInfoData *str, uintptr_t value,
int typlen, bool typbyval);
/* /*
* nodes/{readfuncs.c,read.c} * nodes/{readfuncs.c,read.c}
*/ */
extern void *stringToNode(char *str); extern void *stringToNode(char *str);
extern struct Bitmapset *readBitmapset(void); extern struct Bitmapset *readBitmapset(void);
extern uintptr_t readDatum(bool typbyval);
extern bool *readBoolCols(int numCols);
extern int *readIntCols(int numCols);
extern Oid *readOidCols(int numCols);
extern int16 *readAttrNumberCols(int numCols);
/* /*
* nodes/copyfuncs.c * nodes/copyfuncs.c