1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-01 01:04:50 +03:00

Remove workarounds for avoiding [U]INT64_FORMAT in translatable strings.

Further code simplification along the same lines as d914eb347
and earlier patches.

Aleksander Alekseev, Japin Li

Discussion: https://postgr.es/m/CAJ7c6TMSKi3Xs8h5MP38XOnQQpBLazJvVxVfPn++roitDJcR7g@mail.gmail.com
This commit is contained in:
Tom Lane 2022-03-21 11:11:55 -04:00
parent c540d37157
commit 1f8bc44868
5 changed files with 66 additions and 143 deletions

View File

@ -1017,13 +1017,10 @@ brin_summarize_range(PG_FUNCTION_ARGS)
errhint("BRIN control functions cannot be executed during recovery."))); errhint("BRIN control functions cannot be executed during recovery.")));
if (heapBlk64 > BRIN_ALL_BLOCKRANGES || heapBlk64 < 0) if (heapBlk64 > BRIN_ALL_BLOCKRANGES || heapBlk64 < 0)
{
char *blk = psprintf(INT64_FORMAT, heapBlk64);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("block number out of range: %s", blk))); errmsg("block number out of range: %lld",
} (long long) heapBlk64)));
heapBlk = (BlockNumber) heapBlk64; heapBlk = (BlockNumber) heapBlk64;
/* /*
@ -1094,13 +1091,10 @@ brin_desummarize_range(PG_FUNCTION_ARGS)
errhint("BRIN control functions cannot be executed during recovery."))); errhint("BRIN control functions cannot be executed during recovery.")));
if (heapBlk64 > MaxBlockNumber || heapBlk64 < 0) if (heapBlk64 > MaxBlockNumber || heapBlk64 < 0)
{
char *blk = psprintf(INT64_FORMAT, heapBlk64);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("block number out of range: %s", blk))); errmsg("block number out of range: %lld",
} (long long) heapBlk64)));
heapBlk = (BlockNumber) heapBlk64; heapBlk = (BlockNumber) heapBlk64;
/* /*

View File

@ -115,21 +115,19 @@ void
CopyFromErrorCallback(void *arg) CopyFromErrorCallback(void *arg)
{ {
CopyFromState cstate = (CopyFromState) arg; CopyFromState cstate = (CopyFromState) arg;
char curlineno_str[32];
snprintf(curlineno_str, sizeof(curlineno_str), UINT64_FORMAT,
cstate->cur_lineno);
if (cstate->opts.binary) if (cstate->opts.binary)
{ {
/* can't usefully display the data */ /* can't usefully display the data */
if (cstate->cur_attname) if (cstate->cur_attname)
errcontext("COPY %s, line %s, column %s", errcontext("COPY %s, line %llu, column %s",
cstate->cur_relname, curlineno_str, cstate->cur_relname,
(unsigned long long) cstate->cur_lineno,
cstate->cur_attname); cstate->cur_attname);
else else
errcontext("COPY %s, line %s", errcontext("COPY %s, line %llu",
cstate->cur_relname, curlineno_str); cstate->cur_relname,
(unsigned long long) cstate->cur_lineno);
} }
else else
{ {
@ -139,16 +137,19 @@ CopyFromErrorCallback(void *arg)
char *attval; char *attval;
attval = limit_printout_length(cstate->cur_attval); attval = limit_printout_length(cstate->cur_attval);
errcontext("COPY %s, line %s, column %s: \"%s\"", errcontext("COPY %s, line %llu, column %s: \"%s\"",
cstate->cur_relname, curlineno_str, cstate->cur_relname,
cstate->cur_attname, attval); (unsigned long long) cstate->cur_lineno,
cstate->cur_attname,
attval);
pfree(attval); pfree(attval);
} }
else if (cstate->cur_attname) else if (cstate->cur_attname)
{ {
/* error is relevant to a particular column, value is NULL */ /* error is relevant to a particular column, value is NULL */
errcontext("COPY %s, line %s, column %s: null input", errcontext("COPY %s, line %llu, column %s: null input",
cstate->cur_relname, curlineno_str, cstate->cur_relname,
(unsigned long long) cstate->cur_lineno,
cstate->cur_attname); cstate->cur_attname);
} }
else else
@ -163,14 +164,16 @@ CopyFromErrorCallback(void *arg)
char *lineval; char *lineval;
lineval = limit_printout_length(cstate->line_buf.data); lineval = limit_printout_length(cstate->line_buf.data);
errcontext("COPY %s, line %s: \"%s\"", errcontext("COPY %s, line %llu: \"%s\"",
cstate->cur_relname, curlineno_str, lineval); cstate->cur_relname,
(unsigned long long) cstate->cur_lineno, lineval);
pfree(lineval); pfree(lineval);
} }
else else
{ {
errcontext("COPY %s, line %s", errcontext("COPY %s, line %llu",
cstate->cur_relname, curlineno_str); cstate->cur_relname,
(unsigned long long) cstate->cur_lineno);
} }
} }
} }

View File

@ -706,15 +706,11 @@ nextval_internal(Oid relid, bool check_permissions)
if (rescnt > 0) if (rescnt > 0)
break; /* stop fetching */ break; /* stop fetching */
if (!cycle) if (!cycle)
{
char buf[100];
snprintf(buf, sizeof(buf), INT64_FORMAT, maxv);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SEQUENCE_GENERATOR_LIMIT_EXCEEDED), (errcode(ERRCODE_SEQUENCE_GENERATOR_LIMIT_EXCEEDED),
errmsg("nextval: reached maximum value of sequence \"%s\" (%s)", errmsg("nextval: reached maximum value of sequence \"%s\" (%lld)",
RelationGetRelationName(seqrel), buf))); RelationGetRelationName(seqrel),
} (long long) maxv)));
next = minv; next = minv;
} }
else else
@ -729,15 +725,11 @@ nextval_internal(Oid relid, bool check_permissions)
if (rescnt > 0) if (rescnt > 0)
break; /* stop fetching */ break; /* stop fetching */
if (!cycle) if (!cycle)
{
char buf[100];
snprintf(buf, sizeof(buf), INT64_FORMAT, minv);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SEQUENCE_GENERATOR_LIMIT_EXCEEDED), (errcode(ERRCODE_SEQUENCE_GENERATOR_LIMIT_EXCEEDED),
errmsg("nextval: reached minimum value of sequence \"%s\" (%s)", errmsg("nextval: reached minimum value of sequence \"%s\" (%lld)",
RelationGetRelationName(seqrel), buf))); RelationGetRelationName(seqrel),
} (long long) minv)));
next = maxv; next = maxv;
} }
else else
@ -975,20 +967,11 @@ do_setval(Oid relid, int64 next, bool iscalled)
seq = read_seq_tuple(seqrel, &buf, &seqdatatuple); seq = read_seq_tuple(seqrel, &buf, &seqdatatuple);
if ((next < minv) || (next > maxv)) if ((next < minv) || (next > maxv))
{
char bufv[100],
bufm[100],
bufx[100];
snprintf(bufv, sizeof(bufv), INT64_FORMAT, next);
snprintf(bufm, sizeof(bufm), INT64_FORMAT, minv);
snprintf(bufx, sizeof(bufx), INT64_FORMAT, maxv);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("setval: value %s is out of bounds for sequence \"%s\" (%s..%s)", errmsg("setval: value %lld is out of bounds for sequence \"%s\" (%lld..%lld)",
bufv, RelationGetRelationName(seqrel), (long long) next, RelationGetRelationName(seqrel),
bufm, bufx))); (long long) minv, (long long) maxv)));
}
/* Set the currval() state only if iscalled = true */ /* Set the currval() state only if iscalled = true */
if (iscalled) if (iscalled)
@ -1468,16 +1451,11 @@ init_params(ParseState *pstate, List *options, bool for_identity,
/* Validate maximum value. No need to check INT8 as seqmax is an int64 */ /* Validate maximum value. No need to check INT8 as seqmax is an int64 */
if ((seqform->seqtypid == INT2OID && (seqform->seqmax < PG_INT16_MIN || seqform->seqmax > PG_INT16_MAX)) if ((seqform->seqtypid == INT2OID && (seqform->seqmax < PG_INT16_MIN || seqform->seqmax > PG_INT16_MAX))
|| (seqform->seqtypid == INT4OID && (seqform->seqmax < PG_INT32_MIN || seqform->seqmax > PG_INT32_MAX))) || (seqform->seqtypid == INT4OID && (seqform->seqmax < PG_INT32_MIN || seqform->seqmax > PG_INT32_MAX)))
{
char bufx[100];
snprintf(bufx, sizeof(bufx), INT64_FORMAT, seqform->seqmax);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("MAXVALUE (%s) is out of range for sequence data type %s", errmsg("MAXVALUE (%lld) is out of range for sequence data type %s",
bufx, format_type_be(seqform->seqtypid)))); (long long) seqform->seqmax,
} format_type_be(seqform->seqtypid))));
/* MINVALUE (null arg means NO MINVALUE) */ /* MINVALUE (null arg means NO MINVALUE) */
if (min_value != NULL && min_value->arg) if (min_value != NULL && min_value->arg)
@ -1505,30 +1483,19 @@ init_params(ParseState *pstate, List *options, bool for_identity,
/* Validate minimum value. No need to check INT8 as seqmin is an int64 */ /* Validate minimum value. No need to check INT8 as seqmin is an int64 */
if ((seqform->seqtypid == INT2OID && (seqform->seqmin < PG_INT16_MIN || seqform->seqmin > PG_INT16_MAX)) if ((seqform->seqtypid == INT2OID && (seqform->seqmin < PG_INT16_MIN || seqform->seqmin > PG_INT16_MAX))
|| (seqform->seqtypid == INT4OID && (seqform->seqmin < PG_INT32_MIN || seqform->seqmin > PG_INT32_MAX))) || (seqform->seqtypid == INT4OID && (seqform->seqmin < PG_INT32_MIN || seqform->seqmin > PG_INT32_MAX)))
{
char bufm[100];
snprintf(bufm, sizeof(bufm), INT64_FORMAT, seqform->seqmin);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("MINVALUE (%s) is out of range for sequence data type %s", errmsg("MINVALUE (%lld) is out of range for sequence data type %s",
bufm, format_type_be(seqform->seqtypid)))); (long long) seqform->seqmin,
} format_type_be(seqform->seqtypid))));
/* crosscheck min/max */ /* crosscheck min/max */
if (seqform->seqmin >= seqform->seqmax) if (seqform->seqmin >= seqform->seqmax)
{
char bufm[100],
bufx[100];
snprintf(bufm, sizeof(bufm), INT64_FORMAT, seqform->seqmin);
snprintf(bufx, sizeof(bufx), INT64_FORMAT, seqform->seqmax);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("MINVALUE (%s) must be less than MAXVALUE (%s)", errmsg("MINVALUE (%lld) must be less than MAXVALUE (%lld)",
bufm, bufx))); (long long) seqform->seqmin,
} (long long) seqform->seqmax)));
/* START WITH */ /* START WITH */
if (start_value != NULL) if (start_value != NULL)
@ -1545,29 +1512,17 @@ init_params(ParseState *pstate, List *options, bool for_identity,
/* crosscheck START */ /* crosscheck START */
if (seqform->seqstart < seqform->seqmin) if (seqform->seqstart < seqform->seqmin)
{
char bufs[100],
bufm[100];
snprintf(bufs, sizeof(bufs), INT64_FORMAT, seqform->seqstart);
snprintf(bufm, sizeof(bufm), INT64_FORMAT, seqform->seqmin);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("START value (%s) cannot be less than MINVALUE (%s)", errmsg("START value (%lld) cannot be less than MINVALUE (%lld)",
bufs, bufm))); (long long) seqform->seqstart,
} (long long) seqform->seqmin)));
if (seqform->seqstart > seqform->seqmax) if (seqform->seqstart > seqform->seqmax)
{
char bufs[100],
bufm[100];
snprintf(bufs, sizeof(bufs), INT64_FORMAT, seqform->seqstart);
snprintf(bufm, sizeof(bufm), INT64_FORMAT, seqform->seqmax);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("START value (%s) cannot be greater than MAXVALUE (%s)", errmsg("START value (%lld) cannot be greater than MAXVALUE (%lld)",
bufs, bufm))); (long long) seqform->seqstart,
} (long long) seqform->seqmax)));
/* RESTART [WITH] */ /* RESTART [WITH] */
if (restart_value != NULL) if (restart_value != NULL)
@ -1587,44 +1542,27 @@ init_params(ParseState *pstate, List *options, bool for_identity,
/* crosscheck RESTART (or current value, if changing MIN/MAX) */ /* crosscheck RESTART (or current value, if changing MIN/MAX) */
if (seqdataform->last_value < seqform->seqmin) if (seqdataform->last_value < seqform->seqmin)
{
char bufs[100],
bufm[100];
snprintf(bufs, sizeof(bufs), INT64_FORMAT, seqdataform->last_value);
snprintf(bufm, sizeof(bufm), INT64_FORMAT, seqform->seqmin);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("RESTART value (%s) cannot be less than MINVALUE (%s)", errmsg("RESTART value (%lld) cannot be less than MINVALUE (%lld)",
bufs, bufm))); (long long) seqdataform->last_value,
} (long long) seqform->seqmin)));
if (seqdataform->last_value > seqform->seqmax) if (seqdataform->last_value > seqform->seqmax)
{
char bufs[100],
bufm[100];
snprintf(bufs, sizeof(bufs), INT64_FORMAT, seqdataform->last_value);
snprintf(bufm, sizeof(bufm), INT64_FORMAT, seqform->seqmax);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("RESTART value (%s) cannot be greater than MAXVALUE (%s)", errmsg("RESTART value (%lld) cannot be greater than MAXVALUE (%lld)",
bufs, bufm))); (long long) seqdataform->last_value,
} (long long) seqform->seqmax)));
/* CACHE */ /* CACHE */
if (cache_value != NULL) if (cache_value != NULL)
{ {
seqform->seqcache = defGetInt64(cache_value); seqform->seqcache = defGetInt64(cache_value);
if (seqform->seqcache <= 0) if (seqform->seqcache <= 0)
{
char buf[100];
snprintf(buf, sizeof(buf), INT64_FORMAT, seqform->seqcache);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("CACHE (%s) must be greater than zero", errmsg("CACHE (%lld) must be greater than zero",
buf))); (long long) seqform->seqcache)));
}
seqdataform->log_cnt = 0; seqdataform->log_cnt = 0;
} }
else if (isInit) else if (isInit)

View File

@ -113,9 +113,8 @@ TransactionIdInRecentPast(FullTransactionId fxid, TransactionId *extracted_xid)
if (!FullTransactionIdPrecedes(fxid, now_fullxid)) if (!FullTransactionIdPrecedes(fxid, now_fullxid))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("transaction ID %s is in the future", errmsg("transaction ID %llu is in the future",
psprintf(UINT64_FORMAT, (unsigned long long) U64FromFullTransactionId(fxid))));
U64FromFullTransactionId(fxid)))));
/* /*
* ShmemVariableCache->oldestClogXid is protected by XactTruncationLock, * ShmemVariableCache->oldestClogXid is protected by XactTruncationLock,

View File

@ -132,8 +132,6 @@ static void
progress_report(bool finished) progress_report(bool finished)
{ {
int percent; int percent;
char total_size_str[32];
char current_size_str[32];
pg_time_t now; pg_time_t now;
Assert(showprogress); Assert(showprogress);
@ -152,18 +150,9 @@ progress_report(bool finished)
/* Calculate current percentage of size done */ /* Calculate current percentage of size done */
percent = total_size ? (int) ((current_size) * 100 / total_size) : 0; percent = total_size ? (int) ((current_size) * 100 / total_size) : 0;
/* fprintf(stderr, _("%lld/%lld MB (%d%%) computed"),
* Separate step to keep platform-dependent format code out of (long long) (current_size / (1024 * 1024)),
* translatable strings. And we only test for INT64_FORMAT availability (long long) (total_size / (1024 * 1024)),
* in snprintf, not fprintf.
*/
snprintf(total_size_str, sizeof(total_size_str), INT64_FORMAT,
total_size / (1024 * 1024));
snprintf(current_size_str, sizeof(current_size_str), INT64_FORMAT,
current_size / (1024 * 1024));
fprintf(stderr, _("%*s/%s MB (%d%%) computed"),
(int) strlen(current_size_str), current_size_str, total_size_str,
percent); percent);
/* /*
@ -657,11 +646,11 @@ main(int argc, char *argv[])
progress_report(true); progress_report(true);
printf(_("Checksum operation completed\n")); printf(_("Checksum operation completed\n"));
printf(_("Files scanned: %s\n"), psprintf(INT64_FORMAT, files_scanned)); printf(_("Files scanned: %lld\n"), (long long) files_scanned);
printf(_("Blocks scanned: %s\n"), psprintf(INT64_FORMAT, blocks_scanned)); printf(_("Blocks scanned: %lld\n"), (long long) blocks_scanned);
if (mode == PG_MODE_CHECK) if (mode == PG_MODE_CHECK)
{ {
printf(_("Bad checksums: %s\n"), psprintf(INT64_FORMAT, badblocks)); printf(_("Bad checksums: %lld\n"), (long long) badblocks);
printf(_("Data checksum version: %u\n"), ControlFile->data_checksum_version); printf(_("Data checksum version: %u\n"), ControlFile->data_checksum_version);
if (badblocks > 0) if (badblocks > 0)
@ -669,8 +658,8 @@ main(int argc, char *argv[])
} }
else if (mode == PG_MODE_ENABLE) else if (mode == PG_MODE_ENABLE)
{ {
printf(_("Files written: %s\n"), psprintf(INT64_FORMAT, files_written)); printf(_("Files written: %lld\n"), (long long) files_written);
printf(_("Blocks written: %s\n"), psprintf(INT64_FORMAT, blocks_written)); printf(_("Blocks written: %lld\n"), (long long) blocks_written);
} }
} }