Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit90d7652

Browse files
author
Neil Conway
committed
Add resetStringInfo(), which clears the content of a StringInfo, and
fixup various places in the tree that were clearing a StringInfo by hand.Making this function a part of the API simplifies client code slightly,and avoids needlessly peeking inside the StringInfo interface.
1 parent053981f commit90d7652

File tree

11 files changed

+57
-69
lines changed

11 files changed

+57
-69
lines changed

‎contrib/tablefunc/tablefunc.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,15 +1378,12 @@ build_tuplestore_recursively(char *key_fld,
13781378
"incompatible.")));
13791379
}
13801380

1381+
initStringInfo(&branchstr);
1382+
initStringInfo(&chk_branchstr);
1383+
initStringInfo(&chk_current_key);
1384+
13811385
for (i=0;i<proc;i++)
13821386
{
1383-
/* start a new branch */
1384-
initStringInfo(&branchstr);
1385-
1386-
/* need these to check for recursion */
1387-
initStringInfo(&chk_branchstr);
1388-
initStringInfo(&chk_current_key);
1389-
13901387
/* initialize branch for this pass */
13911388
appendStringInfo(&branchstr,"%s",branch);
13921389
appendStringInfo(&chk_branchstr,"%s%s%s",branch_delim,branch,branch_delim);
@@ -1459,10 +1456,14 @@ build_tuplestore_recursively(char *key_fld,
14591456
tupstore);
14601457

14611458
/* reset branch for next pass */
1462-
xpfree(branchstr.data);
1463-
xpfree(chk_branchstr.data);
1464-
xpfree(chk_current_key.data);
1459+
resetStringInfo(&branchstr);
1460+
resetStringInfo(&chk_branchstr);
1461+
resetStringInfo(&chk_current_key);
14651462
}
1463+
1464+
xpfree(branchstr.data);
1465+
xpfree(chk_branchstr.data);
1466+
xpfree(chk_current_key.data);
14661467
}
14671468

14681469
returntupstore;

‎src/backend/catalog/pg_shdepend.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/pg_shdepend.c,v 1.16 2007/01/05 22:19:25 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/pg_shdepend.c,v 1.17 2007/03/0319:32:54 neilc Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -588,8 +588,7 @@ checkSharedDependencies(Oid classId, Oid objectId)
588588
* Note: we don't ever suppress per-database totals, which should be
589589
* OK as long as there aren't too many databases ...
590590
*/
591-
descs.len=0;/* reset to empty */
592-
descs.data[0]='\0';
591+
resetStringInfo(&descs);
593592

594593
if (numLocalDeps>0)
595594
{

‎src/backend/commands/copy.c

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.276 2007/02/20 17:32:13 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.277 2007/03/03 19:32:54 neilc Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -466,9 +466,7 @@ CopySendEndOfRow(CopyState cstate)
466466
break;
467467
}
468468

469-
/* Reset fe_msgbuf to empty */
470-
fe_msgbuf->len=0;
471-
fe_msgbuf->data[0]='\0';
469+
resetStringInfo(fe_msgbuf);
472470
}
473471

474472
/*
@@ -2193,9 +2191,7 @@ CopyReadLine(CopyState cstate)
21932191
{
21942192
boolresult;
21952193

2196-
/* Reset line_buf to empty */
2197-
cstate->line_buf.len=0;
2198-
cstate->line_buf.data[0]='\0';
2194+
resetStringInfo(&cstate->line_buf);
21992195

22002196
/* Mark that encoding conversion hasn't occurred yet */
22012197
cstate->line_buf_converted= false;
@@ -2262,8 +2258,7 @@ CopyReadLine(CopyState cstate)
22622258
if (cvt!=cstate->line_buf.data)
22632259
{
22642260
/* transfer converted data back to line_buf */
2265-
cstate->line_buf.len=0;
2266-
cstate->line_buf.data[0]='\0';
2261+
resetStringInfo(&cstate->line_buf);
22672262
appendBinaryStringInfo(&cstate->line_buf,cvt,strlen(cvt));
22682263
pfree(cvt);
22692264
}
@@ -2686,9 +2681,7 @@ CopyReadAttributesText(CopyState cstate, int maxfields, char **fieldvals)
26862681
return0;
26872682
}
26882683

2689-
/* reset attribute_buf to empty */
2690-
cstate->attribute_buf.len=0;
2691-
cstate->attribute_buf.data[0]='\0';
2684+
resetStringInfo(&cstate->attribute_buf);
26922685

26932686
/*
26942687
* The de-escaped attributes will certainly not be longer than the input
@@ -2886,9 +2879,7 @@ CopyReadAttributesCSV(CopyState cstate, int maxfields, char **fieldvals)
28862879
return0;
28872880
}
28882881

2889-
/* reset attribute_buf to empty */
2890-
cstate->attribute_buf.len=0;
2891-
cstate->attribute_buf.data[0]='\0';
2882+
resetStringInfo(&cstate->attribute_buf);
28922883

28932884
/*
28942885
* The de-escaped attributes will certainly not be longer than the input
@@ -3040,12 +3031,9 @@ CopyReadBinaryAttribute(CopyState cstate,
30403031
errmsg("invalid field size")));
30413032

30423033
/* reset attribute_buf to empty, and load raw data in it */
3043-
cstate->attribute_buf.len=0;
3044-
cstate->attribute_buf.data[0]='\0';
3045-
cstate->attribute_buf.cursor=0;
3034+
resetStringInfo(&cstate->attribute_buf);
30463035

30473036
enlargeStringInfo(&cstate->attribute_buf,fld_size);
3048-
30493037
if (CopyGetData(cstate,cstate->attribute_buf.data,
30503038
fld_size,fld_size)!=fld_size)
30513039
ereport(ERROR,

‎src/backend/lib/stringinfo.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
1010
* Portions Copyright (c) 1994, Regents of the University of California
1111
*
12-
* $PostgreSQL: pgsql/src/backend/lib/stringinfo.c,v 1.44 2007/01/05 22:19:29 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/lib/stringinfo.c,v 1.45 2007/03/0319:32:54 neilc Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -49,8 +49,20 @@ initStringInfo(StringInfo str)
4949

5050
str->data= (char*)palloc(size);
5151
str->maxlen=size;
52-
str->len=0;
52+
resetStringInfo(str);
53+
}
54+
55+
/*
56+
* resetStringInfo
57+
*
58+
* Reset the StringInfo: the data buffer remains valid, but its
59+
* previous content, if any, is cleared.
60+
*/
61+
void
62+
resetStringInfo(StringInfostr)
63+
{
5364
str->data[0]='\0';
65+
str->len=0;
5466
str->cursor=0;
5567
}
5668

‎src/backend/libpq/pqcomm.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
3131
* Portions Copyright (c) 1994, Regents of the University of California
3232
*
33-
*$PostgreSQL: pgsql/src/backend/libpq/pqcomm.c,v 1.190 2007/02/13 19:18:53 tgl Exp $
33+
*$PostgreSQL: pgsql/src/backend/libpq/pqcomm.c,v 1.191 2007/03/03 19:32:54 neilc Exp $
3434
*
3535
*-------------------------------------------------------------------------
3636
*/
@@ -860,10 +860,7 @@ pq_getstring(StringInfo s)
860860
{
861861
inti;
862862

863-
/* Reset string to empty */
864-
s->len=0;
865-
s->data[0]='\0';
866-
s->cursor=0;
863+
resetStringInfo(s);
867864

868865
/* Read until we get the terminating '\0' */
869866
for (;;)
@@ -915,10 +912,7 @@ pq_getmessage(StringInfo s, int maxlen)
915912
{
916913
int32len;
917914

918-
/* Reset message buffer to empty */
919-
s->len=0;
920-
s->data[0]='\0';
921-
s->cursor=0;
915+
resetStringInfo(s);
922916

923917
/* Read message length word */
924918
if (pq_getbytes((char*)&len,4)==EOF)

‎src/backend/storage/lmgr/deadlock.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/backend/storage/lmgr/deadlock.c,v 1.45 2007/03/0318:46:40 momjian Exp $
15+
* $PostgreSQL: pgsql/src/backend/storage/lmgr/deadlock.c,v 1.46 2007/03/0319:32:54 neilc Exp $
1616
*
1717
*Interface:
1818
*
@@ -933,8 +933,7 @@ DeadLockReport(void)
933933
appendStringInfoChar(&buf,'\n');
934934

935935
/* reset buf2 to hold next object description */
936-
buf2.len=0;
937-
buf2.data[0]='\0';
936+
resetStringInfo(&buf2);
938937

939938
DescribeLockTag(&buf2,&info->locktag);
940939

‎src/backend/tcop/fastpath.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/tcop/fastpath.c,v 1.95 2007/01/05 22:19:39 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/fastpath.c,v 1.96 2007/03/0319:32:54 neilc Exp $
1212
*
1313
* NOTES
1414
* This cruft is the server side of PQfn.
@@ -480,10 +480,7 @@ parse_fcall_arguments(StringInfo msgBuf, struct fp_info * fip,
480480
argsize)));
481481

482482
/* Reset abuf to empty, and insert raw data into it */
483-
abuf.len=0;
484-
abuf.data[0]='\0';
485-
abuf.cursor=0;
486-
483+
resetStringInfo(&abuf);
487484
appendBinaryStringInfo(&abuf,
488485
pq_getmsgbytes(msgBuf,argsize),
489486
argsize);
@@ -613,10 +610,7 @@ parse_fcall_arguments_20(StringInfo msgBuf, struct fp_info * fip,
613610
argsize)));
614611

615612
/* Reset abuf to empty, and insert raw data into it */
616-
abuf.len=0;
617-
abuf.data[0]='\0';
618-
abuf.cursor=0;
619-
613+
resetStringInfo(&abuf);
620614
appendBinaryStringInfo(&abuf,
621615
pq_getmsgbytes(msgBuf,argsize),
622616
argsize);

‎src/backend/tcop/postgres.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.526 2007/03/02 23:37:22 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.527 2007/03/03 19:32:54 neilc Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -205,10 +205,7 @@ InteractiveBackend(StringInfo inBuf)
205205
printf("backend> ");
206206
fflush(stdout);
207207

208-
/* Reset inBuf to empty */
209-
inBuf->len=0;
210-
inBuf->data[0]='\0';
211-
inBuf->cursor=0;
208+
resetStringInfo(inBuf);
212209

213210
for (;;)
214211
{

‎src/backend/utils/adt/rowtypes.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/rowtypes.c,v 1.18 2007/01/05 22:19:42 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/rowtypes.c,v 1.19 2007/03/0319:32:55 neilc Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -168,8 +168,7 @@ record_in(PG_FUNCTION_ARGS)
168168
/* Extract string for this column */
169169
boolinquote= false;
170170

171-
buf.len=0;
172-
buf.data[0]='\0';
171+
resetStringInfo(&buf);
173172
while (inquote|| !(*ptr==','||*ptr==')'))
174173
{
175174
charch=*ptr++;

‎src/backend/utils/adt/xml.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.33 2007/03/01 14:52:04 petere Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.34 2007/03/03 19:32:55 neilc Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -835,8 +835,7 @@ xml_init(void)
835835
else
836836
{
837837
/* Reset pre-existing buffer to empty */
838-
xml_err_buf->data[0]='\0';
839-
xml_err_buf->len=0;
838+
resetStringInfo(xml_err_buf);
840839
}
841840
/* Now that xml_err_buf exists, safe to call xml_errorHandler */
842841
xmlSetGenericErrorFunc(NULL,xml_errorHandler);
@@ -1197,8 +1196,7 @@ xml_ereport(int level, int sqlcode,
11971196
if (xml_err_buf->len>0)
11981197
{
11991198
detail=pstrdup(xml_err_buf->data);
1200-
xml_err_buf->data[0]='\0';
1201-
xml_err_buf->len=0;
1199+
resetStringInfo(xml_err_buf);
12021200
}
12031201
else
12041202
detail=NULL;

‎src/include/lib/stringinfo.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
1111
* Portions Copyright (c) 1994, Regents of the University of California
1212
*
13-
* $PostgreSQL: pgsql/src/include/lib/stringinfo.h,v 1.33 2007/01/05 22:19:55momjian Exp $
13+
* $PostgreSQL: pgsql/src/include/lib/stringinfo.h,v 1.34 2007/03/0319:32:55neilc Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -78,6 +78,13 @@ extern StringInfo makeStringInfo(void);
7878
*/
7979
externvoidinitStringInfo(StringInfostr);
8080

81+
/*------------------------
82+
* resetStringInfo
83+
* Clears the current content of the StringInfo, if any. The
84+
* StringInfo remains valid.
85+
*/
86+
externvoidresetStringInfo(StringInfostr);
87+
8188
/*------------------------
8289
* appendStringInfo
8390
* Format text data under the control of fmt (an sprintf-style format string)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp