1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-03 00:26:59 +02:00

Rename strPtr()/strPtrNull() to strZ()/strZNull().

We use the Z suffix in many functions to indicate that we are expecting a zero-terminated string so make this function conform to the pattern.

As a bonus the new name is a bit shorter, which is a good quality in a commonly-used function.
This commit is contained in:
David Steele
2020-07-30 07:49:06 -04:00
parent 039d314438
commit 3e9dce0d76
129 changed files with 1803 additions and 1844 deletions

View File

@ -103,7 +103,7 @@ pgClientEscape(const String *string)
// Iterate all characters in the string
for (unsigned stringIdx = 0; stringIdx < strSize(string); stringIdx++)
{
char stringChar = strPtr(string)[stringIdx];
char stringChar = strZ(string)[stringIdx];
// These characters are escaped
if (stringChar == '\'' || stringChar == '\\')
@ -131,18 +131,18 @@ pgClientOpen(PgClient *this)
MEM_CONTEXT_TEMP_BEGIN()
{
// Base connection string
String *connInfo = strNewFmt("dbname=%s port=%u", strPtr(pgClientEscape(this->database)), this->port);
String *connInfo = strNewFmt("dbname=%s port=%u", strZ(pgClientEscape(this->database)), this->port);
// Add user if specified
if (this->user != NULL)
strCatFmt(connInfo, " user=%s", strPtr(pgClientEscape(this->user)));
strCatFmt(connInfo, " user=%s", strZ(pgClientEscape(this->user)));
// Add host if specified
if (this->host != NULL)
strCatFmt(connInfo, " host=%s", strPtr(pgClientEscape(this->host)));
strCatFmt(connInfo, " host=%s", strZ(pgClientEscape(this->host)));
// Make the connection
this->connection = PQconnectdb(strPtr(connInfo));
this->connection = PQconnectdb(strZ(connInfo));
// Set a callback to shutdown the connection
memContextCallbackSet(this->memContext, pgClientFreeResource, this);
@ -151,8 +151,8 @@ pgClientOpen(PgClient *this)
if (PQstatus(this->connection) != CONNECTION_OK)
{
THROW_FMT(
DbConnectError, "unable to connect to '%s': %s", strPtr(connInfo),
strPtr(strTrim(strNew(PQerrorMessage(this->connection)))));
DbConnectError, "unable to connect to '%s': %s", strZ(connInfo),
strZ(strTrim(strNew(PQerrorMessage(this->connection)))));
}
// Set notice and warning processor
@ -181,11 +181,11 @@ pgClientQuery(PgClient *this, const String *query)
MEM_CONTEXT_TEMP_BEGIN()
{
// Send the query without waiting for results so we can timeout if needed
if (!PQsendQuery(this->connection, strPtr(query)))
if (!PQsendQuery(this->connection, strZ(query)))
{
THROW_FMT(
DbQueryError, "unable to send query '%s': %s", strPtr(query),
strPtr(strTrim(strNew(PQerrorMessage(this->connection)))));
DbQueryError, "unable to send query '%s': %s", strZ(query),
strZ(strTrim(strNew(PQerrorMessage(this->connection)))));
}
// Wait for a result
@ -210,7 +210,7 @@ pgClientQuery(PgClient *this, const String *query)
char error[256];
if (!PQcancel(cancel, error, sizeof(error)))
THROW_FMT(DbQueryError, "unable to cancel query '%s': %s", strPtr(query), strPtr(strTrim(strNew(error))));
THROW_FMT(DbQueryError, "unable to cancel query '%s': %s", strZ(query), strZ(strTrim(strNew(error))));
}
FINALLY()
{
@ -226,7 +226,7 @@ pgClientQuery(PgClient *this, const String *query)
{
// Throw timeout error if cancelled
if (busy)
THROW_FMT(DbQueryError, "query '%s' timed out after %" PRIu64 "ms", strPtr(query), this->queryTimeout);
THROW_FMT(DbQueryError, "query '%s' timed out after %" PRIu64 "ms", strZ(query), this->queryTimeout);
// If this was a command that returned no results then we are done
int resultStatus = PQresultStatus(pgResult);
@ -237,8 +237,8 @@ pgClientQuery(PgClient *this, const String *query)
if (resultStatus != PGRES_TUPLES_OK)
{
THROW_FMT(
DbQueryError, "unable to execute query '%s': %s", strPtr(query),
strPtr(strTrim(strNew(PQresultErrorMessage(pgResult)))));
DbQueryError, "unable to execute query '%s': %s", strZ(query),
strZ(strTrim(strNew(PQresultErrorMessage(pgResult)))));
}
// Fetch row and column values
@ -305,7 +305,7 @@ pgClientQuery(PgClient *this, const String *query)
{
THROW_FMT(
FormatError, "unable to parse type %u in column %d for query '%s'",
columnType[columnIdx], columnIdx, strPtr(query));
columnType[columnIdx], columnIdx, strZ(query));
}
}
}
@ -359,6 +359,6 @@ String *
pgClientToLog(const PgClient *this)
{
return strNewFmt(
"{host: %s, port: %u, database: %s, user: %s, queryTimeout %" PRIu64 "}", strPtr(strToLog(this->host)), this->port,
strPtr(strToLog(this->database)), strPtr(strToLog(this->user)), this->queryTimeout);
"{host: %s, port: %u, database: %s, user: %s, queryTimeout %" PRIu64 "}", strZ(strToLog(this->host)), this->port,
strZ(strToLog(this->database)), strZ(strToLog(this->user)), this->queryTimeout);
}

View File

@ -589,7 +589,7 @@ pgTablespaceId(unsigned int pgVersion)
MEM_CONTEXT_PRIOR_BEGIN()
{
result = strNewFmt("PG_%s_%u", strPtr(pgVersionStr), pgCatalogVersion(pgVersion));
result = strNewFmt("PG_%s_%u", strZ(pgVersionStr), pgCatalogVersion(pgVersion));
}
MEM_CONTEXT_PRIOR_END();
}
@ -615,7 +615,7 @@ pgLsnFromStr(const String *lsn)
CHECK(strLstSize(lsnPart) == 2);
result = (cvtZToUInt64Base(strPtr(strLstGet(lsnPart, 0)), 16) << 32) + cvtZToUInt64Base(strPtr(strLstGet(lsnPart, 1)), 16);
result = (cvtZToUInt64Base(strZ(strLstGet(lsnPart, 0)), 16) << 32) + cvtZToUInt64Base(strZ(strLstGet(lsnPart, 1)), 16);
}
MEM_CONTEXT_TEMP_END();
@ -659,8 +659,8 @@ pgLsnFromWalSegment(const String *walSegment, unsigned int walSegmentSize)
ASSERT(walSegmentSize > 0);
FUNCTION_TEST_RETURN(
(cvtZToUInt64Base(strPtr(strSubN(walSegment, 8, 8)), 16) << 32) +
(cvtZToUInt64Base(strPtr(strSubN(walSegment, 16, 8)), 16) * walSegmentSize));
(cvtZToUInt64Base(strZ(strSubN(walSegment, 8, 8)), 16) << 32) +
(cvtZToUInt64Base(strZ(strSubN(walSegment, 16, 8)), 16) * walSegmentSize));
}
/**********************************************************************************************************************************/
@ -837,7 +837,7 @@ pgVersionFromStr(const String *version)
{
// If format is not number.number (9.4) or number only (10) then error
if (!regExpMatchOne(STRDEF("^[0-9]+[.]*[0-9]+$"), version))
THROW_FMT(AssertError, "version %s format is invalid", strPtr(version));
THROW_FMT(AssertError, "version %s format is invalid", strZ(version));
// If there is a dot set the major and minor versions, else just the major
int idxStart = strChr(version, '.');
@ -846,11 +846,11 @@ pgVersionFromStr(const String *version)
if (idxStart != -1)
{
major = cvtZToUInt(strPtr(strSubN(version, 0, (size_t)idxStart)));
minor = cvtZToUInt(strPtr(strSub(version, (size_t)idxStart + 1)));
major = cvtZToUInt(strZ(strSubN(version, 0, (size_t)idxStart)));
minor = cvtZToUInt(strZ(strSub(version, (size_t)idxStart + 1)));
}
else
major = cvtZToUInt(strPtr(version));
major = cvtZToUInt(strZ(version));
// No check to see if valid/supported PG version is on purpose
result = major * 10000 + minor * 100;