Skip to content

Commit d8c61c9

Browse files
committed
Add debugging aid "bmsToString(Bitmapset *bms)".
This function has no direct callers at present, but it's convenient for manual use in a debugger, rather than having to inspect memory and do bit-counting in your head. In passing, get rid of useless outBitmapset() wrapper around _outBitmapset(); let's just export the function that does the work. Likewise for outToken(). Ashutosh Bapat, tweaked a bit by me Discussion: <CAFjFpRdiht8e1HTVirbubr4YzaON5iZTzFJjq909y4sU8M_6eA@mail.gmail.com>
1 parent 5225c66 commit d8c61c9

File tree

2 files changed

+34
-32
lines changed

2 files changed

+34
-32
lines changed

src/backend/nodes/outfuncs.c

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
/* Write a character-string (possibly NULL) field */
8282
#define WRITE_STRING_FIELD(fldname) \
8383
(appendStringInfo(str, " :" CppAsString(fldname) " "), \
84-
_outToken(str, node->fldname))
84+
outToken(str, node->fldname))
8585

8686
/* Write a parse location field (actually same as INT case) */
8787
#define WRITE_LOCATION_FIELD(fldname) \
@@ -95,21 +95,21 @@
9595
/* Write a bitmapset field */
9696
#define WRITE_BITMAPSET_FIELD(fldname) \
9797
(appendStringInfo(str, " :" CppAsString(fldname) " "), \
98-
_outBitmapset(str, node->fldname))
98+
outBitmapset(str, node->fldname))
9999

100100

101101
#define booltostr(x) ((x) ? "true" : "false")
102102

103103

104104
/*
105-
* _outToken
105+
* outToken
106106
* Convert an ordinary string (eg, an identifier) into a form that
107107
* will be decoded back to a plain token by read.c's functions.
108108
*
109109
* If a null or empty string is given, it is encoded as "<>".
110110
*/
111-
static void
112-
_outToken(StringInfo str, const char *s)
111+
void
112+
outToken(StringInfo str, const char *s)
113113
{
114114
if (s == NULL || *s == '\0')
115115
{
@@ -140,13 +140,6 @@ _outToken(StringInfo str, const char *s)
140140
}
141141
}
142142

143-
/* for use by extensions which define extensible nodes */
144-
void
145-
outToken(StringInfo str, const char *s)
146-
{
147-
_outToken(str, s);
148-
}
149-
150143
static void
151144
_outList(StringInfo str, const List *node)
152145
{
@@ -185,13 +178,13 @@ _outList(StringInfo str, const List *node)
185178
}
186179

187180
/*
188-
* _outBitmapset -
181+
* outBitmapset -
189182
* converts a bitmap set of integers
190183
*
191184
* Note: the output format is "(b int int ...)", similar to an integer List.
192185
*/
193-
static void
194-
_outBitmapset(StringInfo str, const Bitmapset *bms)
186+
void
187+
outBitmapset(StringInfo str, const Bitmapset *bms)
195188
{
196189
int x;
197190

@@ -203,13 +196,6 @@ _outBitmapset(StringInfo str, const Bitmapset *bms)
203196
appendStringInfoChar(str, ')');
204197
}
205198

206-
/* for use by extensions which define extensible nodes */
207-
void
208-
outBitmapset(StringInfo str, const Bitmapset *bms)
209-
{
210-
_outBitmapset(str, bms);
211-
}
212-
213199
/*
214200
* Print the value of a Datum given its type.
215201
*/
@@ -632,7 +618,7 @@ _outCustomScan(StringInfo str, const CustomScan *node)
632618
WRITE_BITMAPSET_FIELD(custom_relids);
633619
/* CustomName is a key to lookup CustomScanMethods */
634620
appendStringInfoString(str, " :methods ");
635-
_outToken(str, node->methods->CustomName);
621+
outToken(str, node->methods->CustomName);
636622
}
637623

638624
static void
@@ -1196,7 +1182,7 @@ _outBoolExpr(StringInfo str, const BoolExpr *node)
11961182
break;
11971183
}
11981184
appendStringInfoString(str, " :boolop ");
1199-
_outToken(str, opstr);
1185+
outToken(str, opstr);
12001186

12011187
WRITE_NODE_FIELD(args);
12021188
WRITE_LOCATION_FIELD(location);
@@ -1609,14 +1595,14 @@ _outPathInfo(StringInfo str, const Path *node)
16091595
{
16101596
WRITE_ENUM_FIELD(pathtype, NodeTag);
16111597
appendStringInfoString(str, " :parent_relids ");
1612-
_outBitmapset(str, node->parent->relids);
1598+
outBitmapset(str, node->parent->relids);
16131599
if (node->pathtarget != node->parent->reltarget)
16141600
WRITE_NODE_FIELD(pathtarget);
16151601
appendStringInfoString(str, " :required_outer ");
16161602
if (node->param_info)
1617-
_outBitmapset(str, node->param_info->ppi_req_outer);
1603+
outBitmapset(str, node->param_info->ppi_req_outer);
16181604
else
1619-
_outBitmapset(str, NULL);
1605+
outBitmapset(str, NULL);
16201606
WRITE_BOOL_FIELD(parallel_aware);
16211607
WRITE_BOOL_FIELD(parallel_safe);
16221608
WRITE_INT_FIELD(parallel_workers);
@@ -1740,7 +1726,7 @@ _outCustomPath(StringInfo str, const CustomPath *node)
17401726
WRITE_NODE_FIELD(custom_paths);
17411727
WRITE_NODE_FIELD(custom_private);
17421728
appendStringInfoString(str, " :methods ");
1743-
_outToken(str, node->methods->CustomName);
1729+
outToken(str, node->methods->CustomName);
17441730
}
17451731

17461732
static void
@@ -2994,12 +2980,12 @@ _outValue(StringInfo str, const Value *value)
29942980
case T_String:
29952981

29962982
/*
2997-
* We use _outToken to provide escaping of the string's content,
2983+
* We use outToken to provide escaping of the string's content,
29982984
* but we don't want it to do anything with an empty string.
29992985
*/
30002986
appendStringInfoChar(str, '"');
30012987
if (value->val.str[0] != '\0')
3002-
_outToken(str, value->val.str);
2988+
outToken(str, value->val.str);
30032989
appendStringInfoChar(str, '"');
30042990
break;
30052991
case T_BitString:
@@ -3895,3 +3881,18 @@ nodeToString(const void *obj)
38953881
outNode(&str, obj);
38963882
return str.data;
38973883
}
3884+
3885+
/*
3886+
* bmsToString -
3887+
* returns the ascii representation of the Bitmapset as a palloc'd string
3888+
*/
3889+
char *
3890+
bmsToString(const Bitmapset *bms)
3891+
{
3892+
StringInfoData str;
3893+
3894+
/* see stringinfo.h for an explanation of this maneuver */
3895+
initStringInfo(&str);
3896+
outBitmapset(&str, bms);
3897+
return str.data;
3898+
}

src/include/nodes/nodes.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,16 +551,17 @@ extern PGDLLIMPORT Node *newNodeMacroHolder;
551551
/*
552552
* nodes/{outfuncs.c,print.c}
553553
*/
554-
extern char *nodeToString(const void *obj);
555-
556554
struct Bitmapset; /* not to include bitmapset.h here */
557555
struct StringInfoData; /* not to include stringinfo.h here */
556+
558557
extern void outNode(struct StringInfoData *str, const void *obj);
559558
extern void outToken(struct StringInfoData *str, const char *s);
560559
extern void outBitmapset(struct StringInfoData *str,
561560
const struct Bitmapset *bms);
562561
extern void outDatum(struct StringInfoData *str, uintptr_t value,
563562
int typlen, bool typbyval);
563+
extern char *nodeToString(const void *obj);
564+
extern char *bmsToString(const struct Bitmapset *bms);
564565

565566
/*
566567
* nodes/{readfuncs.c,read.c}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy