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 1uNPQd-001MaW-NN for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Jun 2025 05:15:44 +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 1uNPQb-003PC4-Kp for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Jun 2025 05:15:42 +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 1uNPQb-003PBv-58 for pgsql-hackers@lists.postgresql.org; Fri, 06 Jun 2025 05:15:41 +0000 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uNPQZ-000UMc-1P for pgsql-hackers@postgresql.org; Fri, 06 Jun 2025 05:15:41 +0000 Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-311a6236effso1323449a91.2 for ; Thu, 05 Jun 2025 22:15:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20230601.gappssmtp.com; s=20230601; t=1749186936; x=1749791736; darn=postgresql.org; h=mime-version:user-agent:references:in-reply-to:date:cc:to:from :subject:message-id:from:to:cc:subject:date:message-id:reply-to; bh=87EhgOpphvozpNB3W9COn19ePK/n9x0LVmkhJoJ1l/0=; b=x1jyQ3lRX5ef0tp2azAJFKPnhPSTWCTD5oWtQRuhdxiTAbW4giWpRuMw0lLlXeVpb+ NRYBfN1wobrsxmRinx62LbSjCMXxPiuc4a4/NePU+bJiRWE1Ct5X0zdJdR4v5UAHQ2eD eKtPwAgVZseV63u333GuqFv5NZ3IcvdX4gz8sQyX+nxQ/tPUxJBZ0mr097QmgyEsAY1X A3xsFLmtjqOHHqec4yATRCY7MxbyEcIQblX66ugDumXr0bKUbVMHIhLeqFEZoz1Ftkn2 0W6fWYa9lhZfgIscde92pha2y5R8cuKkeS1YDR+ZJEvBHGVGfP1Vqq1WMFD64xCNsf5W iSfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749186936; x=1749791736; h=mime-version:user-agent: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=87EhgOpphvozpNB3W9COn19ePK/n9x0LVmkhJoJ1l/0=; b=xQ/8Sgl6HUGIrltBIBHHL5U+kuOVrREf3y0WaafpwvBnDIqsk27Cgik0VIA1SHGH4K o14Fr6JqF4WENO08GS7MzpyTeU+R85cbb2jj9cNkMNBdMOPldZZ8iZO26YTH7PrHjZed 3h9U4bKHa1gKPKQk1mb4znWGqfLpgZXwgf3u3a46jFAHEBVlIiSIPT9j0AeDSSeJXL2b 2k56Bp68UwLmmcyijILX0BYoBMiH/wR9hnSqLQAAzq74UFy7hV2npKtnQnOXqEETBtDj vw2TeW0kqabAci+4VYYvO9jVOFgNbYGZG94qySSiHtTcN2edwwD07rDaZe4F/89fEy3N IBgA== X-Forwarded-Encrypted: i=1; AJvYcCUyu7nSSOvJUBdSiPOS/0TojJhlac5/mWsXG1ITohZvl5NNISxUQhNkG75S/M6yVkYn88mJfaj2MdlKQ76f@postgresql.org X-Gm-Message-State: AOJu0YxfLg2gJBcqYz9bBy5N/q7c11fBCw4mVj2+o+EQOfyg/lKrNuRu zPO2xhluRkv1iZH9XKtqTJesySWOIDATHjZgAov9iE2q7mEuWIUgkKuXMdtnU9Y7LRUeHjagDVq YIKg= X-Gm-Gg: ASbGnctTgV0JpzEG7dFHKjSv164FgbXBo+ThQWwiAGSSPBf1ewcNeosQdFPpW6yEeVM TaNOOVHBzBrmlIcMColoaPzBwLmDRPZBzTW7PV/ZSrndfFKFZpz3pj+DzI8m9C/KxYoCFAYSVbd XPmevdB5ZVBSlhUlNYnxBQBb13M3ll8MZz5W7Jnb+PhvFRtUSQTV7j5mJXW5JGFjBsCGczg2+be 9euQd5nrmDfIp1XG5oR3srTTdNM2fb+qt5v+4wII723JGlW3h28MhXHRT8Igy1BMrJiOir4Bb2T ihopwRqljFQ6oKFeGvfXiyzTTKfel9+eae+K4+evwCbItp2CTlhwEN5tRzIqyRGQqqGHLUgxvsE zbGCtLXw0j+ON7mrO38Z99g== X-Google-Smtp-Source: AGHT+IGA1d6Fk7hbF3vEmEgBUBoP6pjjWSJmcS/kMHl3BezrIbK3XN96IoXOvSquC63enUo3mRpwTQ== X-Received: by 2002:a17:90b:57cf:b0:313:15fe:4c13 with SMTP id 98e67ed59e1d1-31346f5a893mr3322996a91.27.1749186936430; Thu, 05 Jun 2025 22:15:36 -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 98e67ed59e1d1-3134b9b730bsm445871a91.18.2025.06.05.22.15.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jun 2025 22:15:35 -0700 (PDT) Message-ID: Subject: Re: Remaining dependency on setlocale() From: Jeff Davis To: Peter Eisentraut , Thomas Munro Cc: Tom Lane , pgsql-hackers@postgresql.org Date: Thu, 05 Jun 2025 22:15:34 -0700 In-Reply-To: References: <4c5da86af36a0d5e430eee3f60ce5e06f1b5cd34.camel@j-davis.com> <1841102.1722982989@sss.pgh.pa.us> Content-Type: multipart/mixed; boundary="=-9ReTaJJ5gP3X4yyG/q2A" 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 --=-9ReTaJJ5gP3X4yyG/q2A Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, 2024-12-17 at 13:14 +0100, Peter Eisentraut wrote: > > > > +1 to this approach. It makes things more consistent across > > > > platforms > > > > and avoids surprising dependencies on the global setting. > > > >=20 > >=20 > > I think this is the best way, and I haven't seen anyone supporting > > any > > other idea.=C2=A0 (I'm working on those setlocale()-removal patches I > > mentioned, more very soon...) >=20 > I also think this is the right direction, and we'll get closer with > the=20 > remaining patches that Thomas has lined up. >=20 > I think at this point, we could already remove all locale settings=20 > related to LC_COLLATE.=C2=A0 Nothing uses that anymore. >=20 > I think we will need to keep the global LC_CTYPE setting set to=20 > something useful, for example so that system error messages come out > in=20 > the right encoding. >=20 > But I'm concerned about the the Perl_setlocale() dance in plperl.c.=20 > Perl apparently does a setlocale(LC_ALL, "") during startup, and that > code is a workaround to reset everything back afterwards.=C2=A0 We need t= o > be=20 > careful not to break that. >=20 > (Perl has fixed that in 5.19, but the fix requires that you set > another=20 > environment variable before launching Perl, which you can't do in a=20 > threaded system, so we'd probably need another fix eventually.=C2=A0 See= =20 > .) To continue this thread, I did a symbol search in the meson build directory like (patterns.txt attached): for f in `find . -name *.o`; do if ( nm --format=3Djust-symbols $f | \ grep -xE -f /tmp/patterns.txt > /dev/null ); then echo $f; fi; done and it output: ./contrib/fuzzystrmatch/fuzzystrmatch.so.p/dmetaphone.c.o ./contrib/fuzzystrmatch/fuzzystrmatch.so.p/fuzzystrmatch.c.o ./contrib/isn/isn.so.p/isn.c.o ./contrib/spi/refint.so.p/refint.c.o ./contrib/ltree/ltree.so.p/crc32.c.o ./src/backend/postgres_lib.a.p/commands_copyfromparse.c.o ./src/backend/postgres_lib.a.p/utils_adt_pg_locale_libc.c.o ./src/backend/postgres_lib.a.p/tsearch_wparser_def.c.o ./src/backend/postgres_lib.a.p/parser_scansup.c.o ./src/backend/postgres_lib.a.p/utils_adt_inet_net_pton.c.o ./src/backend/postgres_lib.a.p/tsearch_ts_locale.c.o ./src/bin/psql/psql.p/meson-generated_.._tab-complete.c.o ./src/interfaces/ecpg/preproc/ecpg.p/meson-generated_.._preproc.c.o ./src/interfaces/ecpg/compatlib/libecpg_compat.so.3.18.p/informix.c.o ./src/interfaces/ecpg/compatlib/libecpg_compat.a.p/informix.c.o ./src/port/libpgport_srv.a.p/pgstrcasecmp.c.o ./src/port/libpgport_shlib.a.p/pgstrcasecmp.c.o ./src/port/libpgport.a.p/pgstrcasecmp.c.o Not a short list, but not a long list, either, so seems tractable. Note that this misses things like isdigit() which is inlined. A few observations while spot-checking these files: --------------------- pgstrcasecmp.c - has code like: else if (IS_HIGHBIT_SET(ch) && islower(ch)) ch =3D toupper(ch); and comments like "Note however that the whole thing is a bit bogus for multibyte character sets." Most of the callers are directly comparing with ascii literals, so I'm not sure what the point is. There are probably some more interesting callers hidden in there. ---------------------- pg_locale_libc.c - char2wchar and wchar2char use mbstowcs and wcstombs when the input locale is NULL. The main culprit seems to be full text search, which has a bunch of /* TODO */ comments. Another caller is get_iso_localename(). There are also a couple false positives where mbstowcs_l/wcstombs_l are emulated with uselocale() and mbstowcs/wcstombs. In that case, it's not actually sensitive to the global setting. ----------------------- copyfromparse.c - the input is ASCII so it can use pg_ascii_tolower() instead of tolower() ----------------------- Regards, Jeff Davis --=-9ReTaJJ5gP3X4yyG/q2A Content-Disposition: attachment; filename="patterns.txt" Content-Transfer-Encoding: base64 Content-Type: text/plain; name="patterns.txt"; charset="UTF-8" c3RyeGZybQpzdHJjb2xsCndjc2NvbGwKd2NzeGZybQppc3c/YWxwaGEKaXN3P2RpZ2l0Cmlzdz9h bG51bQppc3c/c3BhY2UKaXN3P3VwcGVyCmlzdz9sb3dlcgp0b3c/dXBwZXIKdG93P2xvd2VyCmlz dz9ncmFwaAppc3c/cHVuY3QKaXN3P2NudHJsCmlzdz94ZGlnaXQKaXN3P3ByaW50Cndjc3RvbWJz Cm1ic3Rvd2NzCmQ/bj9nZXR0ZXh0CmJpbmR0ZXh0ZG9tYWluCg== --=-9ReTaJJ5gP3X4yyG/q2A--