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 1rxXHR-009VOe-4s for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Apr 2024 19:18:45 +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 1rxXHP-008qNl-2e for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Apr 2024 19:18:43 +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 1rxXHO-008qNZ-2Q for pgsql-hackers@lists.postgresql.org; Thu, 18 Apr 2024 19:18:42 +0000 Received: from fout4-smtp.messagingengine.com ([103.168.172.147]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rxXHK-001fuk-9W for pgsql-hackers@postgresql.org; Thu, 18 Apr 2024 19:18:41 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id B16141380188; Thu, 18 Apr 2024 15:18:35 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 18 Apr 2024 15:18:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eisentraut.org; h=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=fm2; t=1713467915; x=1713554315; bh=u/3EQVwXb3d1YOUpZiNb6iorLnSNRnkozVkxyLM4qwM=; b= LMDH62suWiQwus1CSNVdCoAqi0Ar+v1CV+UpfN3sDwVNfbcegTHUL0Kav33zj7K3 MpnmVp9zVlTaWYZskKpaMhqvEb5HuW6SBDiTX8PwlGT4xMarG2Yb2PVdKMQQWKQv pLCXjK228GM9PiIvMhMNqNi152nMVk3umRcGeH0GkMisIoJIrc78wKl8o6p/6VPy FJKBLEzVNQ4/JLUmdHwLUZpH5Xm6LF8ok7CMawUygYON40gBdT+NI3jAXTkVZ8Cg K/Qf5XNYH0jbZgBO6Y5WDrUolZAMupUfTEFe6uX50gz3gkqrgLi32FSybo9S64QB AgAE2TAf+r80JpVfMxst+Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=fm3; t=1713467915; x= 1713554315; bh=u/3EQVwXb3d1YOUpZiNb6iorLnSNRnkozVkxyLM4qwM=; b=H i5YCiJ3z3IyM13IfkGVXoPc7FMDQXMA3mwFXH7yic1UYA8/Q7dyuI5KYY/L298pm ZvWayljUmRf89pA9mysyhQtaOTBRa6OidolDChi3mMuO5CL7/y74Eg+qLR58kcAc 3RA1HGpVUZmrHFYqZcUKINcvLqAGzb03xGtjbT1d0XmN2JIq6GGE7KRtTNc2zwrG FsjjgZLc7BaEEfuhY4o7UBNN8mMV8EEe4yk9ZE1zcRL4PK76OsR1s3+j+K+4Yo22 stQl9Ptv28A6bbrXfuwJsGh3ddREOxLGJFo6tnup0pQnbY1tAHLMtgXCGeBz/7md 11Y3iDzJBapSqdZ9eQJgw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudektddgudefgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuffvfhfhjggtgfesth ejredttddvjeenucfhrhhomheprfgvthgvrhcugfhishgvnhhtrhgruhhtuceophgvthgv rhesvghishgvnhhtrhgruhhtrdhorhhgqeenucggtffrrghtthgvrhhnpeegueeuvdfhhe euieejtefguddthfevveefuefgtddvgfetteehjeetleeuvdevudenucffohhmrghinhep phhoshhtghhrvghsqhhlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrg hmpehmrghilhhfrhhomhepphgvthgvrhesvghishgvnhhtrhgruhhtrdhorhhg X-ME-Proxy: Feedback-ID: ie0a040ee:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 18 Apr 2024 15:18:34 -0400 (EDT) Message-ID: <8023d3a1-b7d2-4ae5-8ec2-833d1f86cd32@eisentraut.org> Date: Thu, 18 Apr 2024 21:18:33 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [18] clarify the difference between pg_wchar, wchar_t, and Unicode code points To: Jeff Davis , pgsql-hackers@postgresql.org References: <3f2a117fd346c19bdb388e0fc3925873a1728bf6.camel@j-davis.com> Content-Language: en-US From: Peter Eisentraut In-Reply-To: <3f2a117fd346c19bdb388e0fc3925873a1728bf6.camel@j-davis.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 16.04.24 01:40, Jeff Davis wrote: > I'm not sure I understand all of the history behind pg_wchar, but it > seems to be some blend of: > > (a) Postgres's own internal representation of a decoded character > (b) libc's wchar_t > (c) Unicode code point > > For example, Postgres has its own encoding/decoding routines, so (a) is > the most obvious definition. (a) is the correct definition, I think. The other ones are just occasional conveniences, and occasionally wrong. > When using ICU, we also pass a pg_wchar directly to ICU routines, which > depends on definition (c), and can lead to problems like: > > https://www.postgresql.org/message-id/e7b67d24288f811aebada7c33f9ae629dde0def5.camel@j-davis.com That's just a plain bug, I think. It's missing the encoding check that for example pg_strncoll_icu() does. > The comment at the top of pg_regc_locale.c explains some of the above, > but not all. I'd like to organize this a bit better: > > * a new typedef for a Unicode code point ("codepoint"? "uchar"?) > * a no-op conversion routine from pg_wchar to a codepoint that would > assert that the server encoding is UTF-8 (#ifndef FRONTEND, of course) > * a no-op conversion routine from pg_wchar to wchar_t that would be a > good place for a comment describing that it's a "best effort" and may > not be correct in all cases I guess sometimes you really want to just store an array of Unicode code points. But I'm not sure how this would actually address coding mistakes like the one above. You still need to check the server encoding and do encoding conversion when necessary.