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 1vEWGv-00CiLG-4g for pgsql-hackers@arkaria.postgresql.org; Thu, 30 Oct 2025 17:17:12 +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 1vEWGt-009oA9-UC for pgsql-hackers@arkaria.postgresql.org; Thu, 30 Oct 2025 17:17:10 +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 1vEWGt-009o9l-Dh for pgsql-hackers@lists.postgresql.org; Thu, 30 Oct 2025 17:17:10 +0000 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vEWGp-0056YS-24 for pgsql-hackers@postgresql.org; Thu, 30 Oct 2025 17:17:09 +0000 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-b593def09e3so973980a12.2 for ; Thu, 30 Oct 2025 10:17:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20230601.gappssmtp.com; s=20230601; t=1761844625; x=1762449425; 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=hfYS47CedDvCzqFQdQr5jNL9CUhhIQdYe3n9UKHsCTY=; b=vS5+e+vGbUOq62/iVeK/zKzFBvmprtgHrCOqIrV12yjWJA5h49Wwp9Vgfms259smho 5i7O0APjYM56Og0IiIkEW2vjWW2raGew2CPN0fZXqklzH5hnHIu6JiKOnf8sKzirTmMS MSywvjeTCj22AO7E70wvSFf89FBtyD99NlrZpL1zW+eKRe/Ykah4oFw+CY+hHgMNuic7 t5cgLRKZW9dQc8v8F294joWK6i6sb60Ybd/oEyQ1jBh+PrEoXO5fqwNbxrg2P+SjuZ9+ XkBY23yX9ztI0vNNbES+GQaQEc7IWlwNWy8E5idcND9rtpXFwXsFaU0TaHhlTjhPSnWR t8/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761844625; x=1762449425; 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=hfYS47CedDvCzqFQdQr5jNL9CUhhIQdYe3n9UKHsCTY=; b=JrkEMbAkbSYZe+JjnYJx/BmpP6QoPdKd7TwRFd1wFvDK08LK5zeuYHNokgyLSBcWZj izk5Q2PoVh5FaJI7mhTF8udp/gqMKIElnrqxb1bLjjvXECLQ5lh9yt7KM/KTPyW6/TTI W0qMTWnXsnhWmYlqc1OOyVl3AFS4secty7OhINl8TtN5o/v+loi/lJddIdn+NeX93yjz /Y4y6O9xlUmEPMhhOwx6EpDyU1eQhYPCkLiTTE7sKbOx9UFzzm+E5JZxuSXpSoUvn7pf JfhUfVS4vZLgbrBOLD19mqbnMMotwvBlSEFsRycWKtZuw3LtwecfBy8mI0mTWWa57/i9 0lxw== X-Forwarded-Encrypted: i=1; AJvYcCWE6TAyMHhidBhURhD8Ka3G9IEFkRxuKvpOUS/3XoBWh/nqttmacYeBI6r7cZ2s2RSLmliACgG/aUAyw6UX@postgresql.org X-Gm-Message-State: AOJu0YxulSDLmb5BluG7GnlBned+M+cdhSIN1vZAeF49zVVK1XqfTwcn hBxv29MnvpYYboWQ8E0B288AUntdtW7nNTRk69H+Ag4+gFZwne1AKJqABcUDy7S62Q== X-Gm-Gg: ASbGnctl14E8KyosQ+Hye5GB0G8TD07MdXwAeWOs4MWMwkO9n37DQqgus1WPLVr97oW I9FpXRWbECioB4lbZFAtsRScgko1Fa4wU3bGsI4gCCzoxnE4bZGi+eKYLoWxO19VIwYmtKWfTKv VxR9x6IaDzUWFqaTS5X0UlOWrM0b2yY4Gs+pIJ8YAUxAkHm5IegbsD7H6K/d8HH/I70m04MoMg1 fNdRMEVBPV2O2cNY8iSVVnFygm98OrejKmWHvw6ytsAOU3fYnGQ59BK1UfbL7D/ChK/QKLEG5Gy mVJwyXzob7+/8f24QkIjLCHEOkJHKYi8hJ7U0SX/vwqRInE18G29Ti1ujDgYOWQDurLR4826zMs 98KkP4NG7mKJp927lOhfjLAtScqrjKIiT8pz2roXuCNvOfLekOn4q0A+PPU7IkJ2O2Rpfx9tUjQ K73xd13KU5Z8Btj27rnyacRBuPZ1pCU3Tg2NSieVsi4oE= X-Google-Smtp-Source: AGHT+IFk9CC2gcIL02ScFWbA5hCaWm/rP9Tn54uPUVZIPRAIqi2auJYp5TrUYxrbEC4mWwfF1Jlgsg== X-Received: by 2002:a17:903:944:b0:28e:80d7:663e with SMTP id d9443c01a7336-2951a475160mr6115215ad.40.1761844624855; Thu, 30 Oct 2025 10:17:04 -0700 (PDT) Received: from jeff-ws-bridge.lan (c-24-7-19-3.hsd1.ca.comcast.net. [24.7.19.3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29498cf3405sm196540345ad.2.2025.10.30.10.17.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Oct 2025 10:17:04 -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, 30 Oct 2025 10:17:03 -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 Tue, 2025-10-28 at 17:19 -0700, Jeff Davis wrote: > Attached a new patch series, v6. I'm eager to start committing this series so that we have plenty of time to sort out any problems. I welcome feedback before or after commit, and I can revert if necessary. The goal here is to do a permanent: setlocale(LC_CTYPE, "C") in the postmaster, and instead use _l() variants where necessary. Forcing the global LC_CTYPE to C will avoid platform-specific nuances spread throughout the code, and prevent new code from accidentally depending on platform-specific libc behavior. Instead, libc ctype behavior will only happen through a pg_locale_t object. It also takes us a step closer to thread safety. LC_COLLATE was already permenently set to "C" (5e6e42e4), and most of LC_CTYPE behavior already uses a pg_locale_t object. This series is about removing the last few places that rely on raw calls to tolower()/toupper() (sometimes through pg_tolower()). Where there isn't a pg_locale_t immediately available it uses the database default locale (which might or might not be libc). There's another thread for what to do about strerror_r[1], which depends on LC_CTYPE for the encoding: https://www.postgresql.org/message-id/90f176c5b85b9da26a3265b2630ece3552068= 566.camel@j-davis.com pg_localeconv_r() does depend on the LC_CTYPE for the encoding, but it already sets it from lc_monetary and lc_numeric, without using datctype or the global setting. Then PGLC_localeconv() converts to the database encoding, if necessary. So it's an exception to the rule that all ctype behavior goes through a pg_locale_t, but it's not a problem. (Aside: we could consider this approach as a narrower fix for strerror_r(), as well.) There may be a loose end around plperl, as well, but not sure if this will make it any worse. Some other LC_* settings still rely on setlocale(), which can be considered separately unless there's some interaction that I missed. Note that the datcollate and datctype fields are already mostly irrelevant for non-libc providers. We could set those to NULL, but for now I don't intend to do that. Regards, Jeff Davis