pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chao Li <li.evan.chao@gmail.com>
To: Jeff Davis <pgsql@j-davis.com>
Cc: Peter Eisentraut <peter@eisentraut.org>
Cc: Thomas Munro <thomas.munro@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers@postgresql.org
Subject: Re: Remaining dependency on setlocale()
Date: Thu, 27 Nov 2025 09:08:16 +0800
Message-ID: <6DDB0693-29E0-41B6-AE63-F0723F7DA8CD@gmail.com> (raw)
In-Reply-To: <83F6E6A9-FF29-41C9-9E15-EA5360E912D0@gmail.com>
References: <4c5da86af36a0d5e430eee3f60ce5e06f1b5cd34.camel@j-davis.com>
	<b19ea499a6d78c101dc55b61bfb42069b427445c.camel@j-davis.com>
	<fa04b56430fa4b5da7311c2faa113f406c6d192a.camel@j-davis.com>
	<CA+hUKGKcS-Zhi8Ud+tv2TanzXBQjH+WsLyPY9DUDXob5VoYAtg@mail.gmail.com>
	<cd3517c7-ddb8-454e-9dd5-70e3d84ff6a2@eisentraut.org>
	<d2e7d63c0cc98f425652527cf260a3e6da17d2b0.camel@j-davis.com>
	<a1396f17f462ee6561820f755caaf2d12eb9fd15.camel@j-davis.com>
	<9875f7f9-50f1-4b5d-86fc-ee8b03e8c162@eisentraut.org>
	<a8666c391dfcabe79868d95f7160eac533ace718.camel@j-davis.com>
	<6956823dd669abc64183fc91e64dc2e56e31f3ea.camel@j-davis.com>
	<ed394f839d813762ddcd65cfcab0e062f8b5e0b1.camel@j-davis.com>
	<CA+hUKGLYcbnHBXhHk_OFwZ03LE+D=cAirm7TVN8fMhT9rgcTbA@mail.gmail.com>
	<f040113cf384ada69558ec004a04a3ddb3e40a26.camel@j-davis.com>
	<CA+hUKGJxSDFcTZSGi++PTC=jM49q1oK=v7Lcdf96VQXXvLhoow@mail.gmail.com>
	<cdd20efc0f5418c597791a1e3a5abb68fa3ce35b.camel@j-davis.com>
	<d9657a6e51aa20702447bb2386b32fea6218670f.camel@j-davis.com>
	<b1ea6756-279a-4924-9146-e125af2057b2@eisentraut.org>
	<8186b28a1a39e61a0d833a4c25a8909ebbbabd48.camel@j-davis.com>
	<450ceb6260cad30d7afdf155d991a9caafee7c0d.camel@j-davis.com>
	<DDD50039-02B4-4033-8D22-B086BC448E1C@gmail.com>
	<78edc741a168c54d57cc898a5877b6443527a2c8.camel@j-davis.com>
	<83F6E6A9-FF29-41C9-9E15-EA5360E912D0@gmail.com>



> On Nov 26, 2025, at 09:50, Chao Li <li.evan.chao@gmail.com> wrote:
> 
> I will review the rest 3 commits tomorrow.

10 - 0009
```
 {
 	if (isalpha((unsigned char) c))
 	{
-		c = toupper((unsigned char) c);
+		c = pg_ascii_toupper((unsigned char) c);
```

Just curious. As isaplha() and toupper() come from the same header file ctype.h, if we replace toupper with pg_ascii_toupper, does isapha also need to be handled?

11 - 0010
```
-	for (i = 0; i < len; i++)
-	{
-		unsigned char ch = (unsigned char) ident[i];
+	dstsize = len + 1;
+	result = palloc(dstsize);
 
-		if (ch >= 'A' && ch <= 'Z')
-			ch += 'a' - 'A';
-		else if (enc_is_single_byte && IS_HIGHBIT_SET(ch) && isupper(ch))
-			ch = tolower(ch);
-		result[i] = (char) ch;
-	}
-	result[i] = '\0';
+	needed = pg_strfold_ident(result, dstsize, ident, len);
+	Assert(needed + 1 == dstsize);
+	Assert(needed == len);
```

I think assert both dstsize and len are redundant, because dstsize=len+1, and no place to change their values.

12 - 0010
```
+/*
+ * Fold an identifier using the database default locale.
+ *
+ * For historical reasons, does not use ordinary locale behavior. Should only
+ * be used for identifier folding. XXX: can we make this equivalent to
+ * pg_strfold(..., default_locale)?
+ */
+size_t
+pg_strfold_ident(char *dest, size_t destsize, const char *src, ssize_t srclen)
+{
+	if (default_locale == NULL || default_locale->ctype == NULL)
+	{
+		int			i;
+
+		for (i = 0; i < srclen && i < destsize; i++)
+		{
+			unsigned char ch = (unsigned char) src[i];
+
+			if (ch >= 'A' && ch <= 'Z')
+				ch += 'a' - 'A';
+			dest[i] = (char) ch;
+		}
+
+		if (i < destsize)
+			dest[i] = '\0';
+
+		return srclen;
+	}
+	return default_locale->ctype->strfold_ident(dest, destsize, src, srclen,
+												default_locale);
+}
```

Given default_local can be NULL only at some specific moment, can we do something like

Local = default_local;
If (local == NULL || local->ctype == NULL)
  Local = libc or other fallback;
Return default_locale->ctype->strfold_ident(dest, destsize, src, srclen, local);

This way avoids the duplicate code.

13 - 0011
```
+{ name => 'lc_collate', type => 'string', context => 'PGC_SUSET', group => 'CLIENT_CONN_LOCALE',
+  short_desc => 'Sets the locale for text ordering in extensions.',
```

I just feel the GUC name is very misleading. Without carefully reading the doc, users may very easy to consider lc_collate the system’s locale. If it only affects extensions, then let’s name it accordingly, for example, “extension_lc_collate”, or “legacy_lc_collate”.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/









view thread (96+ messages)  latest in thread

Message-ID: <6DDB0693-29E0-41B6-AE63-F0723F7DA8CD@gmail.com>
Permalink:  ../6DDB0693-29E0-41B6-AE63-F0723F7DA8CD@gmail.com/
Also on:    postgresql.org/message-id/6DDB0693-29E0-41B6-AE63-F0723F7DA8CD@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: li.evan.chao@gmail.com, pgsql@j-davis.com, peter@eisentraut.org, thomas.munro@gmail.com, tgl@sss.pgh.pa.us
  Subject: Re: Remaining dependency on setlocale()
  In-Reply-To: <6DDB0693-29E0-41B6-AE63-F0723F7DA8CD@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox