Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uZvv8-00Aed3-Fc for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Jul 2025 18:22:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uZvv6-00FzUc-H2 for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Jul 2025 18:22:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uZvv6-00FzUS-6z for pgsql-hackers@lists.postgresql.org; Thu, 10 Jul 2025 18:22:56 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uZvv4-006swU-1h for pgsql-hackers@postgresql.org; Thu, 10 Jul 2025 18:22:56 +0000 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-23c8a505177so13584625ad.2 for ; Thu, 10 Jul 2025 11:22:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20230601.gappssmtp.com; s=20230601; t=1752171772; x=1752776572; darn=postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=w8OBCGMLsuTN8AWgwJx1+UqCGQNbOLvuyu+Z4OlDOkU=; b=o2WHZdoHjHvdj8mNxmOpAeMsQ8ZZq395jSslD/fTvrCIhmblPOcxG7VtlKvAsoPEY+ 2EuEzBvWAD3n6oCrz7+GfxZej+jRkMvm3+ndn1yqg91k9miY63jy7O0xtU9ZMA0gcZPe qXM7YzIjWKGk4sn84wDxebpvaUTf/Q+Oqblcc9dRuMZVnFDN8iHx+ut5t3d7fEYBOu/3 PelSxJP6bb1dMkAZborJDTM9eUpIKx1BHl4nzIo1epQ21gzKkqy11HwZLh9i+qtR2oc/ on5mOJbSpAhpRyEU5efEGcTdax5IshJ3Dh+wHtHpobc7H+cp+hoI8fnQ03MQZ728iEUo QLqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752171772; x=1752776572; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=w8OBCGMLsuTN8AWgwJx1+UqCGQNbOLvuyu+Z4OlDOkU=; b=W93I8UPS8xWPnouZwm/aFaAGeC12CYUWhTFkwbbjVmjQWKjlOqwNMLAqAPFkYOH8yy PA4HxPSU/2/GoWCb1fas8mLW4fJG/9H71xDw+I/y9kweXQWfsVaHlHmZ0gMl2ZzBzAAF 3XLy1aR7eP+442FhRAuJOos3KknYK3b+5LBvM3TIZ3gazyLocAXqmzxyy1+ZkJSYMat0 R/HzqtoD5sKH+jw3Vxeayu+wrN5zmksuPmYC+xFCnVyoVe518q6grxdsbLm5sX/etPvt AOoDpCRlrqDRXZBcYKfpoTAgk5WYxkpF28fJdoUgqXGetPIbDxfwWiBv4Uj/v55VmnyN okrw== X-Forwarded-Encrypted: i=1; AJvYcCVqfifJ92TLtfjD1dqPyIxT3Lx10QoJZzPCXXauFbLUJDp4Jyfr6cDZgDaG3ctXMfjkBtq/CUIM9Xyi/zQz@postgresql.org X-Gm-Message-State: AOJu0YyTOygdEPEe9Hwv61Ye1+WSGtHA+nvKYbEtYCaWnzuXukSvU+Bn SxfKtf1kuj3K3cUrQ3AZ2HiH19lj1OXpWO1PJIW/szb7zwRZC7qfL1EDY8ceZQA+sg== X-Gm-Gg: ASbGnctcfyliBnE69LuXxLBSJvjty+TGtgD7ZoRCXjYF0zFH/omxWZbnI7gv387LCGf Kcw7i3krjIvHMMYqJqXKYS4A1ke9r+aHwfEpQ+HldrwGMRsyR+b+aMpyJTSO8JttWyOAM4kmGGH VETUE4rl1JG73ZtZ0YIf6ASELn0zklpwk6dMsMMDJvo8SPMa5Ydf4GnnEg/SnH0SIv0z+LolC9J ps5ApxbtVEqdQgjfr9K8+5sAvUMYJWwMtEVyh0KQVrPf90NabcWrmicTuIBuRZs+rwaNCk9CPsp K2s2HnwrTBugC0ym/reuqYPLymau7HuD3zT16CFI4MD/XAJZwXQzTzsOigJBj+dMfBs4W/ueNur ct9A2XiP7Fw172yN/wPEzgxN4azZsSVvq X-Google-Smtp-Source: AGHT+IG9yQdwM1LREZ2hhKSQLAcfqSXj8bg91iqjo8Avk2jRD47t82ooELGtFFvvlBE0SEGdr6+ktA== X-Received: by 2002:a17:903:11c3:b0:234:f6ba:e68a with SMTP id d9443c01a7336-23dedea4833mr3391985ad.45.1752171772173; Thu, 10 Jul 2025 11:22:52 -0700 (PDT) Received: from jeff-ws-bridge.lan (c-76-102-242-158.hsd1.ca.comcast.net. [76.102.242.158]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-23de4322cbcsm29998885ad.137.2025.07.10.11.22.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jul 2025 11:22:51 -0700 (PDT) Message-ID: Subject: Re: Remaining dependency on setlocale() From: Jeff Davis To: Thomas Munro Cc: Peter Eisentraut , Tom Lane , pgsql-hackers@postgresql.org Date: Thu, 10 Jul 2025 11:22:50 -0700 In-Reply-To: References: <4c5da86af36a0d5e430eee3f60ce5e06f1b5cd34.camel@j-davis.com> <1841102.1722982989@sss.pgh.pa.us> <9875f7f9-50f1-4b5d-86fc-ee8b03e8c162@eisentraut.org> <6956823dd669abc64183fc91e64dc2e56e31f3ea.camel@j-davis.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.3-0ubuntu1 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 2025-07-10 at 11:53 +1200, Thomas Munro wrote: > On Thu, Jul 10, 2025 at 10:52=E2=80=AFAM Jeff Davis > wrote: > > The first problem -- how to affect the encoding of strings returned > > by > > strerror() on windows -- may be solvable as well. It looks like > > LC_MESSAGES is not supported at all on windows, so the only thing > > to be > > concerned about is the encoding, which is affected by LC_CTYPE. But > > windows doesn't offer uselocale() or strerror_l(). The only way > > seems > > to be to call _configthreadlocale(_ENABLE_PER_THREAD_LOCALE) and > > then > > setlocale(LC_CTYPE, datctype) right before strerror(), and switch > > it > > back to "C" right afterward. Comments welcome. >=20 > FWIW there is an example of that in src/port/pg_localeconv_r.c. OK, so it seems we have a path forward here: 1. Have a global_libc_locale that represents all of the categories, and keep it up to date with GUC changes. On windows, it requires keeping the textual locale names handy (e.g. copies of datcollate and datctype), and building the special locale string and doing _create_locale(LC_ALL, "LC_ABC=3Dsomelocale;LC_XYZ=3Dotherlocale"). 2. When there's no _l() variant of a function, like strerror_r(), wrap with uselocale(). On windows, this means using the trick above with _configthreadlocale(_ENABLE_PER_THREAD_LOCALE). I don't have a great windows development environment, and it appears CI and the buildfarm don't offer great coverage either. Can I ask for a volunteer to do the windows side of this work? Regards, Jeff Davis