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 1tJeip-004Q02-RB for pgsql-bugs@arkaria.postgresql.org; Fri, 06 Dec 2024 20:14:43 +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 1tJein-00DjNR-1Z for pgsql-bugs@arkaria.postgresql.org; Fri, 06 Dec 2024 20:14: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 1tJeim-00DjNF-Ph for pgsql-bugs@lists.postgresql.org; Fri, 06 Dec 2024 20:14:42 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tJeil-001PIC-5B; Fri, 06 Dec 2024 20:14:41 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 4B6KEb522850995; Fri, 6 Dec 2024 15:14:37 -0500 From: Tom Lane To: Tatsuo Ishii cc: koichi.dbms@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18735: Specific multibyte character in psql file path command parameter for Windows In-reply-to: <2840430.1733510664@sss.pgh.pa.us> References: <20241206.142130.1661155698933375612.ishii@postgresql.org> <2751825.1733464455@sss.pgh.pa.us> <20241206.154248.1191531539866262856.ishii@postgresql.org> <2840430.1733510664@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Fri, 06 Dec 2024 13:44:24 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2850993.1733516077.1@sss.pgh.pa.us> Date: Fri, 06 Dec 2024 15:14:37 -0500 Message-ID: <2850994.1733516077@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I wrote: > Anyway, what I'm now thinking is that we can have two variants > of canonicalize_path: > extern void canonicalize_path(char *path); > extern void canonicalize_path_enc(char *path, int encoding); > The first one assumes a server-safe encoding, the second doesn't, > and at least to start with only psql would bother with the second. I thought that part would be trivial, but there's a small annoying problem. The obvious way to write the encoding-aware version of the de-backslashing loop is to use pg_encoding_mblen_bounded(). However, that function is in src/common/wchar.c while path.c is in src/port/ --- and I believe we have a rule that libpgport can't depend on libpgcommon. (The dependencies go the other way, instead.) Now it's pretty dubious that path.c is in src/port/ at all, because it does not meet the expectation that that directory is for functions that replace missing system-library functionality. (We've trodden pretty hard on that expectation over the years, but whatever.) So one reasonable fix could be to move path.c to src/common, but I'm concerned that that would be unsafe to back-patch. Also, we'd really want to move the externs for path.c out of port.h, which would cause additional code churn for callers. Another way, given that we only really need this to work for SJIS, is to hard-wire the logic into path.c --- it's not like pg_sjis_mblen is either long or likely to change. That's ugly but would be a lot less invasive and safer to back-patch. I'm leaning a bit to the second way, mainly because of the extern-relocation annoyance. regards, tom lane