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.
"incompatible.")));
}
+ initStringInfo(&branchstr);
+ initStringInfo(&chk_branchstr);
+ initStringInfo(&chk_current_key);
+
for (i = 0; i < proc; i++)
{
- /* start a new branch */
- initStringInfo(&branchstr);
-
- /* need these to check for recursion */
- initStringInfo(&chk_branchstr);
- initStringInfo(&chk_current_key);
-
/* initialize branch for this pass */
appendStringInfo(&branchstr, "%s", branch);
appendStringInfo(&chk_branchstr, "%s%s%s", branch_delim, branch, branch_delim);
tupstore);
/* reset branch for next pass */
- xpfree(branchstr.data);
- xpfree(chk_branchstr.data);
- xpfree(chk_current_key.data);
+ resetStringInfo(&branchstr);
+ resetStringInfo(&chk_branchstr);
+ resetStringInfo(&chk_current_key);
}
+
+ xpfree(branchstr.data);
+ xpfree(chk_branchstr.data);
+ xpfree(chk_current_key.data);
}
return tupstore;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/catalog/pg_shdepend.c,v 1.16 2007/01/05 22:19:25 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/catalog/pg_shdepend.c,v 1.17 2007/03/03 19:32:54 neilc Exp $
*
*-------------------------------------------------------------------------
*/
* Note: we don't ever suppress per-database totals, which should be
* OK as long as there aren't too many databases ...
*/
- descs.len = 0; /* reset to empty */
- descs.data[0] = '\0';
+ resetStringInfo(&descs);
if (numLocalDeps > 0)
{
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.276 2007/02/20 17:32:13 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.277 2007/03/03 19:32:54 neilc Exp $
*
*-------------------------------------------------------------------------
*/
break;
}
- /* Reset fe_msgbuf to empty */
- fe_msgbuf->len = 0;
- fe_msgbuf->data[0] = '\0';
+ resetStringInfo(fe_msgbuf);
}
/*
{
bool result;
- /* Reset line_buf to empty */
- cstate->line_buf.len = 0;
- cstate->line_buf.data[0] = '\0';
+ resetStringInfo(&cstate->line_buf);
/* Mark that encoding conversion hasn't occurred yet */
cstate->line_buf_converted = false;
if (cvt != cstate->line_buf.data)
{
/* transfer converted data back to line_buf */
- cstate->line_buf.len = 0;
- cstate->line_buf.data[0] = '\0';
+ resetStringInfo(&cstate->line_buf);
appendBinaryStringInfo(&cstate->line_buf, cvt, strlen(cvt));
pfree(cvt);
}
return 0;
}
- /* reset attribute_buf to empty */
- cstate->attribute_buf.len = 0;
- cstate->attribute_buf.data[0] = '\0';
+ resetStringInfo(&cstate->attribute_buf);
/*
* The de-escaped attributes will certainly not be longer than the input
return 0;
}
- /* reset attribute_buf to empty */
- cstate->attribute_buf.len = 0;
- cstate->attribute_buf.data[0] = '\0';
+ resetStringInfo(&cstate->attribute_buf);
/*
* The de-escaped attributes will certainly not be longer than the input
errmsg("invalid field size")));
/* reset attribute_buf to empty, and load raw data in it */
- cstate->attribute_buf.len = 0;
- cstate->attribute_buf.data[0] = '\0';
- cstate->attribute_buf.cursor = 0;
+ resetStringInfo(&cstate->attribute_buf);
enlargeStringInfo(&cstate->attribute_buf, fld_size);
-
if (CopyGetData(cstate, cstate->attribute_buf.data,
fld_size, fld_size) != fld_size)
ereport(ERROR,
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/lib/stringinfo.c,v 1.44 2007/01/05 22:19:29 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/lib/stringinfo.c,v 1.45 2007/03/03 19:32:54 neilc Exp $
*
*-------------------------------------------------------------------------
*/
str->data = (char *) palloc(size);
str->maxlen = size;
- str->len = 0;
+ resetStringInfo(str);
+}
+
+/*
+ * resetStringInfo
+ *
+ * Reset the StringInfo: the data buffer remains valid, but its
+ * previous content, if any, is cleared.
+ */
+void
+resetStringInfo(StringInfo str)
+{
str->data[0] = '\0';
+ str->len = 0;
str->cursor = 0;
}
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/libpq/pqcomm.c,v 1.190 2007/02/13 19:18:53 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/libpq/pqcomm.c,v 1.191 2007/03/03 19:32:54 neilc Exp $
*
*-------------------------------------------------------------------------
*/
{
int i;
- /* Reset string to empty */
- s->len = 0;
- s->data[0] = '\0';
- s->cursor = 0;
+ resetStringInfo(s);
/* Read until we get the terminating '\0' */
for (;;)
{
int32 len;
- /* Reset message buffer to empty */
- s->len = 0;
- s->data[0] = '\0';
- s->cursor = 0;
+ resetStringInfo(s);
/* Read message length word */
if (pq_getbytes((char *) &len, 4) == EOF)
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/lmgr/deadlock.c,v 1.45 2007/03/03 18:46:40 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/lmgr/deadlock.c,v 1.46 2007/03/03 19:32:54 neilc Exp $
*
* Interface:
*
appendStringInfoChar(&buf, '\n');
/* reset buf2 to hold next object description */
- buf2.len = 0;
- buf2.data[0] = '\0';
+ resetStringInfo(&buf2);
DescribeLockTag(&buf2, &info->locktag);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/tcop/fastpath.c,v 1.95 2007/01/05 22:19:39 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/tcop/fastpath.c,v 1.96 2007/03/03 19:32:54 neilc Exp $
*
* NOTES
* This cruft is the server side of PQfn.
argsize)));
/* Reset abuf to empty, and insert raw data into it */
- abuf.len = 0;
- abuf.data[0] = '\0';
- abuf.cursor = 0;
-
+ resetStringInfo(&abuf);
appendBinaryStringInfo(&abuf,
pq_getmsgbytes(msgBuf, argsize),
argsize);
argsize)));
/* Reset abuf to empty, and insert raw data into it */
- abuf.len = 0;
- abuf.data[0] = '\0';
- abuf.cursor = 0;
-
+ resetStringInfo(&abuf);
appendBinaryStringInfo(&abuf,
pq_getmsgbytes(msgBuf, argsize),
argsize);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.526 2007/03/02 23:37:22 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.527 2007/03/03 19:32:54 neilc Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
printf("backend> ");
fflush(stdout);
- /* Reset inBuf to empty */
- inBuf->len = 0;
- inBuf->data[0] = '\0';
- inBuf->cursor = 0;
+ resetStringInfo(inBuf);
for (;;)
{
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/rowtypes.c,v 1.18 2007/01/05 22:19:42 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/rowtypes.c,v 1.19 2007/03/03 19:32:55 neilc Exp $
*
*-------------------------------------------------------------------------
*/
/* Extract string for this column */
bool inquote = false;
- buf.len = 0;
- buf.data[0] = '\0';
+ resetStringInfo(&buf);
while (inquote || !(*ptr == ',' || *ptr == ')'))
{
char ch = *ptr++;
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.33 2007/03/01 14:52:04 petere Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.34 2007/03/03 19:32:55 neilc Exp $
*
*-------------------------------------------------------------------------
*/
else
{
/* Reset pre-existing buffer to empty */
- xml_err_buf->data[0] = '\0';
- xml_err_buf->len = 0;
+ resetStringInfo(xml_err_buf);
}
/* Now that xml_err_buf exists, safe to call xml_errorHandler */
xmlSetGenericErrorFunc(NULL, xml_errorHandler);
if (xml_err_buf->len > 0)
{
detail = pstrdup(xml_err_buf->data);
- xml_err_buf->data[0] = '\0';
- xml_err_buf->len = 0;
+ resetStringInfo(xml_err_buf);
}
else
detail = NULL;
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/lib/stringinfo.h,v 1.33 2007/01/05 22:19:55 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/lib/stringinfo.h,v 1.34 2007/03/03 19:32:55 neilc Exp $
*
*-------------------------------------------------------------------------
*/
*/
extern void initStringInfo(StringInfo str);
+/*------------------------
+ * resetStringInfo
+ * Clears the current content of the StringInfo, if any. The
+ * StringInfo remains valid.
+ */
+extern void resetStringInfo(StringInfo str);
+
/*------------------------
* appendStringInfo
* Format text data under the control of fmt (an sprintf-style format string)