Remove INT64_FORMAT in translatable strings

Started by Japin Lialmost 4 years ago4 messages
#1Japin Li
japinli@hotmail.com
1 attachment(s)

Hi,

I found the following lines in pg_backup_tar.c.

if (len != th->fileLen)
{
char buf1[32],
buf2[32];

snprintf(buf1, sizeof(buf1), INT64_FORMAT, (int64) len);
snprintf(buf2, sizeof(buf2), INT64_FORMAT, (int64) th->fileLen);
fatal("actual file length (%s) does not match expected (%s)",
buf1, buf2);
}

we can rely on %lld/%llu and we decided to use them in translatable strings.
See 6a1cd8b.

However, I am not sure how to update the *.po files under the pg_dump/po
directory. Any suggestions?

--
Regrads,
Japin Li.
ChengDu WenWu Information Technology Co.,Ltd.

Attachments:

v1-0001-Remove-use-of-U-INT64_FORMAT-in-some-translatable.patchtext/x-patchDownload
From 29bfcdf96324433cd8f4beada7023a27fc2bf0b8 Mon Sep 17 00:00:00 2001
From: Japin Li <japinli@hotmail.com>
Date: Fri, 18 Mar 2022 23:09:22 +0800
Subject: [PATCH v1] Remove use of [U]INT64_FORMAT in some translatable strings

This is similar to 62aa2bb and 6a1cd8b.
---
 src/bin/pg_dump/pg_backup_tar.c | 48 +++++++--------------------------
 1 file changed, 9 insertions(+), 39 deletions(-)

diff --git a/src/bin/pg_dump/pg_backup_tar.c b/src/bin/pg_dump/pg_backup_tar.c
index 5c351acda0..b5e26a4b6f 100644
--- a/src/bin/pg_dump/pg_backup_tar.c
+++ b/src/bin/pg_dump/pg_backup_tar.c
@@ -1102,15 +1102,8 @@ _tarAddFile(ArchiveHandle *AH, TAR_MEMBER *th)
 		fatal("could not close temporary file: %m");
 
 	if (len != th->fileLen)
-	{
-		char		buf1[32],
-					buf2[32];
-
-		snprintf(buf1, sizeof(buf1), INT64_FORMAT, (int64) len);
-		snprintf(buf2, sizeof(buf2), INT64_FORMAT, (int64) th->fileLen);
-		fatal("actual file length (%s) does not match expected (%s)",
-			  buf1, buf2);
-	}
+		fatal("actual file length (%lld) does not match expected (%lld)",
+			  (long long int) len, (long long int) th->fileLen);
 
 	pad = tarPaddingBytesRequired(len);
 	for (i = 0; i < pad; i++)
@@ -1140,24 +1133,14 @@ _tarPositionTo(ArchiveHandle *AH, const char *filename)
 	/* Go to end of current file, if any */
 	if (ctx->tarFHpos != 0)
 	{
-		char		buf1[100],
-					buf2[100];
-
-		snprintf(buf1, sizeof(buf1), INT64_FORMAT, (int64) ctx->tarFHpos);
-		snprintf(buf2, sizeof(buf2), INT64_FORMAT, (int64) ctx->tarNextMember);
-		pg_log_debug("moving from position %s to next member at file position %s",
-					 buf1, buf2);
+		pg_log_debug("moving from position %lld to next member at file position %lld",
+					 (long long int) ctx->tarFHpos, (long long int) ctx->tarNextMember);
 
 		while (ctx->tarFHpos < ctx->tarNextMember)
 			_tarReadRaw(AH, &c, 1, NULL, ctx->tarFH);
 	}
 
-	{
-		char		buf[100];
-
-		snprintf(buf, sizeof(buf), INT64_FORMAT, (int64) ctx->tarFHpos);
-		pg_log_debug("now at file position %s", buf);
-	}
+	pg_log_debug("now at file position %lld", (long long int) ctx->tarFHpos);
 
 	/* We are at the start of the file, or at the next member */
 
@@ -1265,25 +1248,12 @@ _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER *th)
 
 	len = read_tar_number(&h[124], 12);
 
-	{
-		char		posbuf[32];
-		char		lenbuf[32];
-
-		snprintf(posbuf, sizeof(posbuf), UINT64_FORMAT, (uint64) hPos);
-		snprintf(lenbuf, sizeof(lenbuf), UINT64_FORMAT, (uint64) len);
-		pg_log_debug("TOC Entry %s at %s (length %s, checksum %d)",
-					 tag, posbuf, lenbuf, sum);
-	}
+	pg_log_debug("TOC Entry %s at %llu (length %llu, checksum %d)",
+				 tag, (unsigned long long) hPos, (unsigned long long) len, sum);
 
 	if (chk != sum)
-	{
-		char		posbuf[32];
-
-		snprintf(posbuf, sizeof(posbuf), UINT64_FORMAT,
-				 (uint64) ftello(ctx->tarFH));
-		fatal("corrupt tar header found in %s (expected %d, computed %d) file position %s",
-			  tag, sum, chk, posbuf);
-	}
+		fatal("corrupt tar header found in %s (expected %d, computed %d) file position %llu",
+			  tag, sum, chk, (unsigned long long) ftello(ctx->tarFH));
 
 	th->targetFile = pg_strdup(tag);
 	th->fileLen = len;
-- 
2.25.1

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Japin Li (#1)
Re: Remove INT64_FORMAT in translatable strings

Japin Li <japinli@hotmail.com> writes:

we can rely on %lld/%llu and we decided to use them in translatable strings.

Seems like good cleanup, so pushed. I think though that project style
is to use "long long" or "unsigned long long", without the unnecessary
"int" --- it certainly makes little sense to do it both ways in the
same patch.

However, I am not sure how to update the *.po files under the pg_dump/po
directory. Any suggestions?

The translation team manages those files. We don't normally touch them
during code development.

regards, tom lane

#3Justin Pryzby
pryzby@telsasoft.com
In reply to: Tom Lane (#2)
Re: Remove INT64_FORMAT in translatable strings

On Fri, Mar 18, 2022 at 01:12:40PM -0400, Tom Lane wrote:

Japin Li <japinli@hotmail.com> writes:

we can rely on %lld/%llu and we decided to use them in translatable strings.

Seems like good cleanup, so pushed. I think though that project style
is to use "long long" or "unsigned long long", without the unnecessary
"int" --- it certainly makes little sense to do it both ways in the
same patch.

This seemed familiar - it's about the same thing I sent here, while fixing
ftello().

/messages/by-id/20210104025321.GA9712@telsasoft.com
0002-Fix-broken-error-message-on-unseekable-input.patch

--
Justin

#4Japin Li
japinli@hotmail.com
In reply to: Tom Lane (#2)
Re: Remove INT64_FORMAT in translatable strings

On Sat, 19 Mar 2022 at 01:12, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Japin Li <japinli@hotmail.com> writes:

we can rely on %lld/%llu and we decided to use them in translatable strings.

Seems like good cleanup, so pushed. I think though that project style
is to use "long long" or "unsigned long long", without the unnecessary
"int" --- it certainly makes little sense to do it both ways in the
same patch.

However, I am not sure how to update the *.po files under the pg_dump/po
directory. Any suggestions?

The translation team manages those files. We don't normally touch them
during code development.

Thank you for pushing the patch.

--
Regrads,
Japin Li.
ChengDu WenWu Information Technology Co.,Ltd.