Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q8in1-0004cS-Nv for pgsql-hackers@arkaria.postgresql.org; Mon, 12 Jun 2023 14:45:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q8imx-0008Ft-OZ for pgsql-hackers@arkaria.postgresql.org; Mon, 12 Jun 2023 14:44:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q8imx-0008Fh-2R for pgsql-hackers@lists.postgresql.org; Mon, 12 Jun 2023 14:44:59 +0000 Received: from mail-yw1-x1131.google.com ([2607:f8b0:4864:20::1131]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1q8imt-001wYc-MI for pgsql-hackers@postgresql.org; Mon, 12 Jun 2023 14:44:58 +0000 Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-56d05daf0d5so20927907b3.0 for ; Mon, 12 Jun 2023 07:44:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joeconway.com; s=google; t=1686581094; x=1689173094; h=content-transfer-encoding:in-reply-to:subject:from:references:cc:to :content-language:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=WaqnRVVEUbohv4MEN0QVqy/KZrSa3TafYyJQ6I0zgoE=; b=KllErkAGmyjBk5Ym+M4T07lV2FXA+FZwPvBuu9umBeGLFHwD/VhwE5FlUosZ0GCVfo tqy/F7aIPEC52YQDTrMABvZLXBkWszLaHcd/Xg2yoo+IbNdttAfQ3GSwpzVCHDgnu/bs w25pjhQ47lO1UMJcrq0pKFO0IKJPHF5/QulCe5MT8rPGs36F4ojl86G4RsePQxzWLbm7 OmP29rmbMOXmfjQA+ybFRe18pUl9m0cRrffpLdtoVsFxylZ2chtIe0YBbBamYpwCVYLa Opin9D7uF7eVcKAStvpy9guue1jIa3U6bU4FHz6fbL/FCZevWY5tKp27Aa8HD68cSddC yi5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686581094; x=1689173094; h=content-transfer-encoding:in-reply-to:subject:from:references:cc:to :content-language:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WaqnRVVEUbohv4MEN0QVqy/KZrSa3TafYyJQ6I0zgoE=; b=NqEYcN1DEw8jfnplXQTjxKB6Gl1NJieDzWVhb6/dAM4WrHeQKjpFiHmepHHMht3re1 c2oxoFGIDLknHZMwwbvjpJOU346bWVYd+pfx5y7HOvKrEV45WrrLfuBZzcmA2LPBK8sL bhT0HsxTGttl67GHIkzb1doUlFB184vc1ZelpsjDMRL+s+enUaSZQlBvnZcqi74nKg3/ uD/14iEGrBLP2ley3v5RTkaQ7O2y6cM4Xc231gG60VrNVwoPoWJ++WZ+dV3w5jXu1o07 DC8+Qnt7qNKeg49C7SvldeL2iaEb6/QO12mXH+zT+DV78NQYwlHPVRlBts2Fl5myPb7z HTeA== X-Gm-Message-State: AC+VfDyswIGKE2xv6/ePxgHv+g0Wq2v5upaux6LHhPPEQwy76bhfrwSD tGq8f//JBDFrbd9rjW+ePK+hGw== X-Google-Smtp-Source: ACHHUZ6PSzaNKbcoonsFrVVKpAI0Pw2f3CwMtwPi5mysMubf4hrQb8B7/srqkZf1m0fzmbZ0aCDX+Q== X-Received: by 2002:a0d:dac4:0:b0:569:82b1:2ba5 with SMTP id c187-20020a0ddac4000000b0056982b12ba5mr10764959ywe.20.1686581094069; Mon, 12 Jun 2023 07:44:54 -0700 (PDT) Received: from [192.168.4.41] (162-239-31-113.lightspeed.dybhfl.sbcglobal.net. [162.239.31.113]) by smtp.gmail.com with ESMTPSA id j65-20020a0df944000000b00545a08184e0sm2537984ywf.112.2023.06.12.07.44.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 12 Jun 2023 07:44:53 -0700 (PDT) Message-ID: <41a4898e-1cdb-960d-f17e-d71886407e04@joeconway.com> Date: Mon, 12 Jun 2023 10:44:52 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Content-Language: en-US To: Heikki Linnakangas Cc: Tristan Partin , gdo@leader.it, Tom Lane , PostgreSQL-development References: <17946-3e84cb577e9551c3@postgresql.org> <1564676.1685043220@sss.pgh.pa.us> <555bb26e-c27c-ab65-028f-3fd5b82df9de@iki.fi> <5676b739-0854-f924-4b97-466e3504c692@joeconway.com> <665279.1686422574@sss.pgh.pa.us> <574a1afa-5c6e-829c-0fed-a9ff44719f9f@joeconway.com> <49dfcad8-90fa-8577-008f-d142e61af46b@iki.fi> From: Joe Conway Subject: Re: BUG #17946: LC_MONETARY & DO LANGUAGE plperl - BUG In-Reply-To: <49dfcad8-90fa-8577-008f-d142e61af46b@iki.fi> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk (moving to hackers) On 6/12/23 05:13, Heikki Linnakangas wrote: > On 10/06/2023 22:28, Joe Conway wrote: >> On 6/10/23 15:07, Joe Conway wrote: >>> On 6/10/23 14:42, Tom Lane wrote: >>>> Joe Conway writes: >>>>> 5/ The attached fixes the issue for me on pg10 and passes check-world. >>>>> Comments? >>>> >>>> The call in PGLC_localeconv seems *very* oddly placed. Why not >>>> do that before it does any other locale calls? Otherwise you don't >>>> really have reason to believe you're saving the appropriate >>>> values to restore later. >>> >>> >>> As far as I can tell it really only affects localeconv(), so I tried to >>> place it close to those. But I am fine with moving it up. >> >> This version is against pg16 (rather than pg10), moves up that hunk, >> mentions localeconv() in the comment as the reason for the call, and >> fixes some whitespace sloppiness. I will plan to apply to all supported >> branches. >> >> Better? > > The man page for uselocale(LC_GLOBAL_LOCALE) says: "The calling thread's > current locale is set to the global locale determined by setlocale(3)." > Does that undo the effect of calling uselocale() previously, so if you > later call setlocale(), the new locale takes effect in the thread too? > Or is it equivalent to "uselocale(LC_ALL, setlocale(NULL))", so that it > sets the thread's locale to the current global locale, but later > setlocale() calls have no effect on it? setlocale() changes the global locale, but uselocale() changes the locale that is currently active, as I understand it. Also note that uselocale man page says "Unlike setlocale(3), uselocale() does not allow selective replacement of individual locale categories. To employ a locale that differs in only a few categories from the current locale, use calls to duplocale(3) and newlocale(3) to obtain a locale object equivalent to the current locale and modify the desired categories in that object." > In any case, this still doesn't feel like the right place. We have many > more setlocale() calls. Shouldn't we sprinkle them all with > uselocale(LC_GLOBAL_LOCALE)? cache_locale_time() for example. Or rather, > all the places where we use any functions that depend on the current locale. > > How about we replace all setlocale() calls with uselocale()? I don't see us backpatching something that invasive. It might be the right thing to do for pg17, or even pg16, but I think that is a different discussion > Shouldn't we restore the old thread-specific locale after the calls? I'm > not sure why libperl calls uselocale(), but we are now overwriting the > locale that it sets. That is a good question. Though arguably perl is doing the wrong thing by not resetting the global locale when it is being used embedded. > We have a few other uselocale() calls in pg_locale.c, and we take > care to restore the old locale in those. I think as long as we are relying on setlocale rather than uselocale in general (see above), the global locale is where we want things left. > There are a few uselocale() calls in ecpg, and they are protected by > HAVE_USELOCALE. Interestingly, the calls in pg_locale.c are not, but > they are protected by HAVE_LOCALE_T. Seems a little inconsistent. Possibly something we should clean up, but I think that is separate from this fix. In general I think we have 2 or possibly three distinct things here: 1/ how do we fix the misbehavior reported due to libperl in existing stable branches 2/ what makes most sense going forward (and does that mean pg16 or pg17) 3/ misc code cleanups I was mostly trying to concentrate on #1, but 2 & 3 are worthy of discussion. -- Joe Conway PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com