aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xlog.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-03-25 22:42:46 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-03-25 22:42:46 +0000
commit220db7ccd8c88aafea4629f00e8be6f9f073ed00 (patch)
tree772c9dca19736eb9d417cb665a281686c3570b4c /src/backend/access/transam/xlog.c
parentf948197b4055bb0e22e508e9d6966217b7dbea3d (diff)
downloadpostgresql-220db7ccd8c88aafea4629f00e8be6f9f073ed00.tar.gz
postgresql-220db7ccd8c88aafea4629f00e8be6f9f073ed00.zip
Simplify and standardize conversions between TEXT datums and ordinary C
strings. This patch introduces four support functions cstring_to_text, cstring_to_text_with_len, text_to_cstring, and text_to_cstring_buffer, and two macros CStringGetTextDatum and TextDatumGetCString. A number of existing macros that provided variants on these themes were removed. Most of the places that need to make such conversions now require just one function or macro call, in place of the multiple notational layers that used to be needed. There are no longer any direct calls of textout or textin, and we got most of the places that were using handmade conversions via memcpy (there may be a few still lurking, though). This commit doesn't make any serious effort to eliminate transient memory leaks caused by detoasting toasted text objects before they reach text_to_cstring. We changed PG_GETARG_TEXT_P to PG_GETARG_TEXT_PP in a few places where it was easy, but much more could be done. Brendan Jurd and Tom Lane
Diffstat (limited to 'src/backend/access/transam/xlog.c')
-rw-r--r--src/backend/access/transam/xlog.c46
1 files changed, 11 insertions, 35 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 3990f1d863e..1b6a58f6616 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.294 2008/03/10 02:13:22 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.295 2008/03/25 22:42:42 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -6380,7 +6380,6 @@ Datum
pg_start_backup(PG_FUNCTION_ARGS)
{
text *backupid = PG_GETARG_TEXT_P(0);
- text *result;
char *backupidstr;
XLogRecPtr checkpointloc;
XLogRecPtr startpoint;
@@ -6410,8 +6409,7 @@ pg_start_backup(PG_FUNCTION_ARGS)
errhint("archive_command must be defined before "
"online backups can be made safely.")));
- backupidstr = DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(backupid)));
+ backupidstr = text_to_cstring(backupid);
/*
* Mark backup active in shared memory. We must do full-page WAL writes
@@ -6531,9 +6529,7 @@ pg_start_backup(PG_FUNCTION_ARGS)
*/
snprintf(xlogfilename, sizeof(xlogfilename), "%X/%X",
startpoint.xlogid, startpoint.xrecoff);
- result = DatumGetTextP(DirectFunctionCall1(textin,
- CStringGetDatum(xlogfilename)));
- PG_RETURN_TEXT_P(result);
+ PG_RETURN_TEXT_P(cstring_to_text(xlogfilename));
}
/*
@@ -6547,7 +6543,6 @@ pg_start_backup(PG_FUNCTION_ARGS)
Datum
pg_stop_backup(PG_FUNCTION_ARGS)
{
- text *result;
XLogRecPtr startpoint;
XLogRecPtr stoppoint;
pg_time_t stamp_time;
@@ -6669,9 +6664,7 @@ pg_stop_backup(PG_FUNCTION_ARGS)
*/
snprintf(stopxlogfilename, sizeof(stopxlogfilename), "%X/%X",
stoppoint.xlogid, stoppoint.xrecoff);
- result = DatumGetTextP(DirectFunctionCall1(textin,
- CStringGetDatum(stopxlogfilename)));
- PG_RETURN_TEXT_P(result);
+ PG_RETURN_TEXT_P(cstring_to_text(stopxlogfilename));
}
/*
@@ -6680,7 +6673,6 @@ pg_stop_backup(PG_FUNCTION_ARGS)
Datum
pg_switch_xlog(PG_FUNCTION_ARGS)
{
- text *result;
XLogRecPtr switchpoint;
char location[MAXFNAMELEN];
@@ -6696,9 +6688,7 @@ pg_switch_xlog(PG_FUNCTION_ARGS)
*/
snprintf(location, sizeof(location), "%X/%X",
switchpoint.xlogid, switchpoint.xrecoff);
- result = DatumGetTextP(DirectFunctionCall1(textin,
- CStringGetDatum(location)));
- PG_RETURN_TEXT_P(result);
+ PG_RETURN_TEXT_P(cstring_to_text(location));
}
/*
@@ -6711,7 +6701,6 @@ pg_switch_xlog(PG_FUNCTION_ARGS)
Datum
pg_current_xlog_location(PG_FUNCTION_ARGS)
{
- text *result;
char location[MAXFNAMELEN];
/* Make sure we have an up-to-date local LogwrtResult */
@@ -6726,10 +6715,7 @@ pg_current_xlog_location(PG_FUNCTION_ARGS)
snprintf(location, sizeof(location), "%X/%X",
LogwrtResult.Write.xlogid, LogwrtResult.Write.xrecoff);
-
- result = DatumGetTextP(DirectFunctionCall1(textin,
- CStringGetDatum(location)));
- PG_RETURN_TEXT_P(result);
+ PG_RETURN_TEXT_P(cstring_to_text(location));
}
/*
@@ -6740,7 +6726,6 @@ pg_current_xlog_location(PG_FUNCTION_ARGS)
Datum
pg_current_xlog_insert_location(PG_FUNCTION_ARGS)
{
- text *result;
XLogCtlInsert *Insert = &XLogCtl->Insert;
XLogRecPtr current_recptr;
char location[MAXFNAMELEN];
@@ -6754,10 +6739,7 @@ pg_current_xlog_insert_location(PG_FUNCTION_ARGS)
snprintf(location, sizeof(location), "%X/%X",
current_recptr.xlogid, current_recptr.xrecoff);
-
- result = DatumGetTextP(DirectFunctionCall1(textin,
- CStringGetDatum(location)));
- PG_RETURN_TEXT_P(result);
+ PG_RETURN_TEXT_P(cstring_to_text(location));
}
/*
@@ -6789,8 +6771,7 @@ pg_xlogfile_name_offset(PG_FUNCTION_ARGS)
/*
* Read input and parse
*/
- locationstr = DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(location)));
+ locationstr = text_to_cstring(location);
if (sscanf(locationstr, "%X/%X", &uxlogid, &uxrecoff) != 2)
ereport(ERROR,
@@ -6819,8 +6800,7 @@ pg_xlogfile_name_offset(PG_FUNCTION_ARGS)
XLByteToPrevSeg(locationpoint, xlogid, xlogseg);
XLogFileName(xlogfilename, ThisTimeLineID, xlogid, xlogseg);
- values[0] = DirectFunctionCall1(textin,
- CStringGetDatum(xlogfilename));
+ values[0] = CStringGetTextDatum(xlogfilename);
isnull[0] = false;
/*
@@ -6849,7 +6829,6 @@ Datum
pg_xlogfile_name(PG_FUNCTION_ARGS)
{
text *location = PG_GETARG_TEXT_P(0);
- text *result;
char *locationstr;
unsigned int uxlogid;
unsigned int uxrecoff;
@@ -6858,8 +6837,7 @@ pg_xlogfile_name(PG_FUNCTION_ARGS)
XLogRecPtr locationpoint;
char xlogfilename[MAXFNAMELEN];
- locationstr = DatumGetCString(DirectFunctionCall1(textout,
- PointerGetDatum(location)));
+ locationstr = text_to_cstring(location);
if (sscanf(locationstr, "%X/%X", &uxlogid, &uxrecoff) != 2)
ereport(ERROR,
@@ -6873,9 +6851,7 @@ pg_xlogfile_name(PG_FUNCTION_ARGS)
XLByteToPrevSeg(locationpoint, xlogid, xlogseg);
XLogFileName(xlogfilename, ThisTimeLineID, xlogid, xlogseg);
- result = DatumGetTextP(DirectFunctionCall1(textin,
- CStringGetDatum(xlogfilename)));
- PG_RETURN_TEXT_P(result);
+ PG_RETURN_TEXT_P(cstring_to_text(xlogfilename));
}
/*