threads / patch / 51600

patchcc5e1bf992 (gettext: avoid initialization if the locale dir is not present, 2018-04-21) changed the way the gettext initialization is done skipping most of it for performance reasons if the locale directories wouldn't exist.

Subject: [PATCH] cc5e1bf992 (gettext: avoid initialization if the locale dir is not present, 2018-04-21) changed the way the gettext initialization is done skipping most of it for performance reasons if the locale directories wouldn't exist.

## tl;dr

2 messages between Aug 7, 2019 and Aug 7, 2019. Diffs are folded; open one to read it.

replies: 1people: 1as markdown or json

Carlo Marcelo Arenas Belón· Aug 7, 2019, 09:53 UTC · lore

in environments where the build running wasn't installed and wasn't using NO_GETTEXT the initialization of charset will be skipped, breaking is_utf_locale()

Split the init function on two, so the initialization of charset could be done before a decision to abort was made and therefore keeping most of the performance improvement.

Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
---
 gettext.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
Show changes to gettext.c +11 −3
diff --git a/gettext.c b/gettext.c
index d4021d690c..3ecf456f74 100644
--- a/gettext.c
+++ b/gettext.c
@@ -69,7 +69,14 @@ static int test_vsnprintf(const char *fmt, ...)
 	return ret;
 }
 
-static void init_gettext_charset(const char *domain)
+static void init_gettext_charset(void)
+{
+	const char *current = setlocale(LC_CTYPE, "");
+	charset = locale_charset();
+	setlocale(LC_CTYPE, current);
+}
+
+static void bind_gettext_charset(const char *domain)
 {
 	/*
 	   This trick arranges for messages to be emitted in the user's
@@ -150,7 +157,7 @@ static void init_gettext_charset(const char *domain)
 	   2. E.g. "Content-Type: text/plain; charset=UTF-8\n" in po/is.po
 	*/
 	setlocale(LC_CTYPE, "");
-	charset = locale_charset();
+	/* charset was already initialized in init_gettext_charset() */
 	bind_textdomain_codeset(domain, charset);
 	/* the string is taken from v0.99.6~1 */
 	if (test_vsnprintf("%.*s", 13, "David_K\345gedal") < 0)
@@ -166,6 +173,7 @@ void git_setup_gettext(void)
 		podir = p = system_path(GIT_LOCALE_PATH);
 
 	use_gettext_poison(); /* getenv() reentrancy paranoia */
+	init_gettext_charset();
 
 	if (!is_directory(podir)) {
 		free(p);
@@ -175,7 +183,7 @@ void git_setup_gettext(void)
 	bindtextdomain("git", podir);
 	setlocale(LC_MESSAGES, "");
 	setlocale(LC_TIME, "");
-	init_gettext_charset("git");
+	bind_gettext_charset("git");
 	textdomain("git");
 
 	free(p);
-- 
2.23.0.rc1
Carlo Arenas· Aug 7, 2019, 10:18 UTC · re: Carlo Marcelo Arenas Belón · lore

Re: [PATCH] cc5e1bf992 (gettext: avoid initialization if the locale dir is not present, 2018-04-21) changed the way the gettext initialization is done skipping most of it for performance reasons if the locale directories wouldn't exist.

Subject was meant to be "gettext: fix is_utf8_locale() when not using NO_GETTEXT" and affects mainly PCRE by using UTF-8 flag even when the locale was ISO.

somehow it doesn't break any tests though, but PCRE strongly advices against doing both UTF and chartables and we might end up doing that more often, because of this.

Carlo

PS. apologize for the badly formatted patch, don't think this needs to be fixed in maint, eventhough the patch is based on it with the most likely to be affected being developers (or automated tests)

← back to recent threads