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 1qVvEJ-001acz-69 for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Aug 2023 14:41:08 +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 1qVvEH-00EqXl-M2 for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Aug 2023 14:41:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qVvEH-00EqXa-8j for pgsql-hackers@lists.postgresql.org; Tue, 15 Aug 2023 14:41:05 +0000 Received: from meesny.iki.fi ([195.140.195.201]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qVvEC-000HA7-M7 for pgsql-hackers@postgresql.org; Tue, 15 Aug 2023 14:41:04 +0000 Received: from [192.168.1.115] (dsl-hkibng22-54f8db-125.dhcp.inet.fi [84.248.219.125]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by meesny.iki.fi (Postfix) with ESMTPSA id 4RQDTf1JBHzyZR; Tue, 15 Aug 2023 17:40:54 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1692110456; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1XnWDIlMQGq8wnJpUrhPHFAmdeEqSPkAHk+RvuuQCpk=; b=ntWQgcBsP2uNQiGgsMBzHSecnbCCfmuV3Ee6HdtxJcz/O65paTkhiO/fFaHDuu7wUrWkO5 JcMfjRlgmxK69dEFBue3+fneg9oSTxUBPoBCjXvL1yVlbPLtq5W0NSXcfP1AO20YKaPl4O /mEejsbPgiXvthd6Ixi7GMsEdVbTWlo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1692110456; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1XnWDIlMQGq8wnJpUrhPHFAmdeEqSPkAHk+RvuuQCpk=; b=SEL1TAs05LgrSdc7AjAjwvWq7JvtSTpRvswlwkVnJzElSAeXjpCNYcqt3sQwHsz9v0Cc1t H6W9ePuqOOgYEzESmkQ6Gcwk5JSbav+lJlmf0nnqBntLbFvjCHLIBYTdUoYnia2IC5huRJ SYXParsO+AMJDbpTFlVyc7XRz4qR1+8= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1692110456; a=rsa-sha256; cv=none; b=RQSFhj9qQgDxWT/KbGjUB51kDW6jsjCdPIQOuJ5R0s2DUPT1hYy0tsonVYey2OzBs8j2+N CQ1Nm8OfqW1TBFXAWx0oPd6tIKnn+qEbqOjG+QcdPguTfaA4A/8ImwnlJZG1Nf7bP7qzep 7TPh15HsGEVq1lIih8DvL5SL+D4V2KI= Message-ID: Date: Tue, 15 Aug 2023 17:40:53 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Subject: Re: BUG #17946: LC_MONETARY & DO LANGUAGE plperl - BUG Content-Language: en-US To: Joe Conway , Tristan Partin Cc: 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> <41a4898e-1cdb-960d-f17e-d71886407e04@joeconway.com> <18c6979a-126a-e530-7cc4-3b6984b1997b@joeconway.com> <839d893b-1681-f6b6-e1ba-685c34c582ca@joeconway.com> <933780cc-2265-a47a-9f39-dd9208bd2c64@iki.fi> <82626186-baba-0b1e-9cfb-53e341b51343@joeconway.com> From: Heikki Linnakangas In-Reply-To: <82626186-baba-0b1e-9cfb-53e341b51343@joeconway.com> 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 On 01/08/2023 16:48, Joe Conway wrote: > Any further comments on the posted patch[1]? I would like to apply/push > this prior to the beta and minor releases next week. I'm not sure about the placement of the uselocale() calls. In plperl_spi_exec(), for example, I think we should switch to the global locale right after the check_spi_usage_allowed() call. Otherwise, if an error happens in BeginInternalSubTransaction() or in pg_verifymbstr(), the error would be processed with the perl locale. Maybe that's harmless, error processing hardly cares about LC_MONETARY, but seems wrong in principle. Hmm, come to think of it, if BeginInternalSubTransaction() throws an error, we just jump out of the perl interpreter? That doesn't seem cool. But that's not new with this patch. If I'm reading correctly, compile_plperl_function() calls select_perl_context(), which calls plperl_trusted_init(), which calls uselocale(). So it leaves locale set to the perl locale. Who sets it back? How about adding a small wrapper around eval_pl() that sets and unsets the locale(), just when we enter the interpreter? It's easier to see that we are doing the calls in right places, if we make them as close as possible to entering/exiting the interpreter. Are there other functions in addition to eval_pl() that need to be called with the perl locale? > /* > * plperl_xact_callback --- cleanup at main-transaction end. > */ > static void > plperl_xact_callback(XactEvent event, void *arg) > { > /* ensure global locale is the current locale */ > if (uselocale((locale_t) 0) != LC_GLOBAL_LOCALE) > perl_locale_obj = uselocale(LC_GLOBAL_LOCALE); > } So the assumption is that the if current locale is not LC_GLOBAL_LOCALE, then it was the perl locale. Seems true today, but this could confusion if anything else calls uselocale(). In particular, if another PL implementation copies this, and you use plperl and the other PL at the same time, they would get mixed up. I think we need another "bool perl_locale_obj_in_use" variable to track explicitly whether the perl locale is currently active. If we are careful to put the uselocale() calls in the right places so that we never ereport() while in perl locale, this callback isn't needed. Maybe it's still a good idea, though, to be extra sure that things get reset to a sane state if something unexpected happens. If multiple interpreters are used, is the single perl_locale_obj variable still enough? Each interpreter can have their own locale I believe. PS. please pgindent -- Heikki Linnakangas Neon (https://neon.tech)