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 1t0hab-00Clok-Hy for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Oct 2024 13:27:53 +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 1t0haZ-006yPY-Hf for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Oct 2024 13:27:51 +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 1t0haZ-006yPQ-8N for pgsql-hackers@lists.postgresql.org; Tue, 15 Oct 2024 13:27:51 +0000 Received: from fout-a2-smtp.messagingengine.com ([103.168.172.145]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t0haX-001Bke-AL for pgsql-hackers@postgresql.org; Tue, 15 Oct 2024 13:27:51 +0000 Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfout.phl.internal (Postfix) with ESMTP id 142BC13801CF; Tue, 15 Oct 2024 09:27:48 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Tue, 15 Oct 2024 09:27:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eisentraut.org; h=cc:cc:content-transfer-encoding:content-type:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:subject:subject:to:to; s=fm1; t=1728998868; x=1729085268; bh=gvxUA5RxfWognP0DJzUOBg5RTYjSsguX O259REi4dLg=; b=jkmd2aBOf5V3XOM8F7I6h9k7Q1eEK7HoKOGgh+noNe2cXru3 VBHatKY+uq98mxJKg/30FIw6kD+aJ+1QBxczM3xsPP4U4S8V0X4zVCoToD/x9ojf fYZbl64d6Idlhm51dMy34MyvVvfac85FPtAmgdkaxK3XCn8/GxSVoKQK6erRYM2n 2u46ef47TxgwleoZUg+bU+2ozVWyMHtpSwGuGgAs6QBZUkStUXAoGaELjGDaQ0Ff qfrBAO0SCW94SSQxp/rGDAZeQslq5lksuvOsgi0Y7R9VA7Uq9p3/jrOmBlMSct4u 5Obp3uWw/ggZ7GAY/tD4otIgigx/jYavDJL8aw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1728998868; x= 1729085268; bh=gvxUA5RxfWognP0DJzUOBg5RTYjSsguXO259REi4dLg=; b=o AqgcurOKTP613ZsacnfD45m2Sa5Sfc0UxRD0VhYGm6OUkhvOn7C/seZwM2bQYyMb o38gU8d0rR1iJbxR+e0pOUgVCfxSYS/h2cO2cTxQJs6PQxMEPcQoDNfmbz9rZMkE p/Gp+ABRz33C+kNBsmv5ERfo2d7Quqar+V1gfyWmaQfeTnmq9F3gDCfuHzrhbDrf IhVQCqHBAIV/8j1SnXhK2yBHOSvKzjbss2JRGDlC95EusjtD48xbAt5rbKk5O68e TMpa9tovRLrsuKOH1A1SgHI6xWnWLE9G+t0KDH7SoNgR0jbgErsMb5mkyq6GuLzP 1jCBgU1M81apNiFwbTVQw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdegjedgieegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtvdej necuhfhrohhmpefrvghtvghrucfgihhsvghnthhrrghuthcuoehpvghtvghrsegvihhsvg hnthhrrghuthdrohhrgheqnecuggftrfgrthhtvghrnhepgfejtdfhkeeftdeugfeileeh teeljeeghfeuledthfeutedvffdukeefjefhgeehnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepphgvthgvrhesvghishgvnhhtrhgruhhtrdho rhhgpdhnsggprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhope grlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgpdhrtghpthhtohepphhgshhq lhdqhhgrtghkvghrshesphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: ie0a040ee:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 15 Oct 2024 09:27:47 -0400 (EDT) Message-ID: Date: Tue, 15 Oct 2024 15:27:46 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: simplify regular expression locale global variables To: Alvaro Herrera Cc: pgsql-hackers References: <202410151008.jnqrposiz6p5@alvherre.pgsql> Content-Language: en-US From: Peter Eisentraut In-Reply-To: <202410151008.jnqrposiz6p5@alvherre.pgsql> 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 15.10.24 12:08, Alvaro Herrera wrote: > On 2024-Oct-15, Peter Eisentraut wrote: > >> @@ -253,8 +241,9 @@ pg_set_regex_collation(Oid collation) >> * catalog access is available, so we can't call >> * pg_newlocale_from_collation(). >> */ >> + static struct pg_locale_struct dummy_locale = {.ctype_is_c = true}; >> + >> + locale = &dummy_locale; >> } >> else >> { >> @@ -264,121 +253,80 @@ pg_set_regex_collation(Oid collation) >> ereport(ERROR, >> (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), >> errmsg("nondeterministic collations are not supported for regular expressions"))); >> [...] >> } >> >> pg_regex_locale = locale; >> } > > Hmm, is it valid to make pg_regex_locale point to a function-local > static here? The lifetime of this static is not clear to me, and I > think this pattern works with at least some compilers, but I remember > comments on previous patch review threads that this pattern isn't > kosher. I think this must be okay. Some classic non-thread-safe C library functions essentially work that way, e.g., char *strerror(int errnum) { static char buf[...]; strcpy(buf, ....); return buf; } and then you can use the return pointer wherever you want.