From nobody Fri Jun 20 16:40:39 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4bP3BJ2sPrz5yGJ0; Fri, 20 Jun 2025 16:40:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bP3BJ1sK1z3dd7; Fri, 20 Jun 2025 16:40:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1750437640; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=1vtPAQ1tGeSrLqz21SX7nNh7fgYaYyr03S0V8y46NSs=; b=S0d55g2FmWR/KHIeNMBzB2mmb96dgUCsBJcScKvICwq0Nj4VQktDS9kM3D1Nnu4upV+k53 KOmtnmVmeF0NIZuQL9vgDZ0cR9GaEzwHnd4G0RQOdY9kjVf1n1qCCSR64ptaeEop/Fmik/ 002zUsTCF3Fxp4K0PufPBcqAr1/7vwr9vdVsfyz0lYqk1qNIdiG+bJQTD2zlR5i9JekA0S wWFnyNJOPczG64LDAfP/bFRuk/ZvTR4wYUFrNRYvU6/3Kenwd/rQxOVwIs7s0Jyr0yUV38 jw6SKzrGB3l4ujdb4CVZwkCrjGMUDIZLiRMmjAkMoxq8Tt1YNvYDq3NVvei3/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1750437640; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=1vtPAQ1tGeSrLqz21SX7nNh7fgYaYyr03S0V8y46NSs=; b=yiVw3PR2Wg8XDmhIoqwZEsBH39UTBGWrITyja/ZlcPXWMKyVx3vvxAeK0Q0fhSHLY38AzA emWhQnYJT1enyAuOTK7AdsGQFNuYfQNdF6n9utdqvan0MrJZEg2Ci40/SxMVOy1LS5PSfg +WJSvwKO+RMcP/aReB3YgHAZSJZGCeiiwUhU3YGFEpNJU8csJRbrPZAVLW93XPGPDT/NT4 FsTsuc/VlPwE98P4mTjDuLVA5bG7/JnLISCE5aab8pieX6qExNKpsp0BSRGVyx2fZrq/Al 0BULNWDvwiKsGKuFQuUb0kZeTwEM8eI2oc0BnX4GBYOiMKZhqeBcu4sJ/UQOaA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1750437640; a=rsa-sha256; cv=none; b=e4PI2h7pvbY5D8hCnhs+zltpaNEiOv9DV2utZKxmI4WzLX9fkqQnA6Wg24cBRLkzLpIWFB NRMbcuo8/HAVEECLvOx6fekIEpSkv/nzNDK1w85b15Z0eVlvmh/ynL+EB1s6B0RXLkl7Mn aTge6uuh8ihc3fYYyrk6H2MiI0rybgIC05rbIn0wDww/qYhwIPJW28rzav95qJKeoPtX6r 9B3jt2JZ4P2l+rRgUuOlE5KF8E80GNq5f5CMRGr5n8VfhPYv5RJSUpCKtN3tmYcfa06Blz /K9a5vpkxmEylhGtMOYBVn3InTCGZhZJ8jXgVhLLJdlUcG4Jkfy8dJ68jRqYDQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4bP3BJ0hk3zsTW; Fri, 20 Jun 2025 16:40:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 55KGees2074671; Fri, 20 Jun 2025 16:40:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 55KGed3U074668; Fri, 20 Jun 2025 16:40:39 GMT (envelope-from git) Date: Fri, 20 Jun 2025 16:40:39 GMT Message-Id: <202506201640.55KGed3U074668@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 770fba248daf - main - localedef: Use consistent sorting order List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 770fba248daff6cc72ce0bfbd1f2a941c90dc99a Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=770fba248daff6cc72ce0bfbd1f2a941c90dc99a commit 770fba248daff6cc72ce0bfbd1f2a941c90dc99a Author: Mark Johnston AuthorDate: 2025-06-20 16:10:37 +0000 Commit: Mark Johnston CommitDate: 2025-06-20 16:39:22 +0000 localedef: Use consistent sorting order In several modules we build up an RB tree keyed by wide characters. wchar_t has different signedness on different platforms, so iteration over such a tree results in platform-dependent ordering. The ctype module uses this ordering when writing the output file, which creates reproducibility problems when comparing the results of cross builds and native builds (e.g., native amd64 vs. cross-building on arm64). Modify such comparisons to always be unsigned. Introduce a helper function for this purpose. In the other modules I believe the sort order does not affect program output. On systems with signed wchar_t, of the files in /usr/share/locale this only affects zh_CN.GB18030/LC_CTYPE. MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D50756 --- usr.bin/localedef/charmap.c | 2 +- usr.bin/localedef/collate.c | 2 +- usr.bin/localedef/ctype.c | 2 +- usr.bin/localedef/localedef.h | 15 +++++++++++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/usr.bin/localedef/charmap.c b/usr.bin/localedef/charmap.c index a8d723163e74..7fb40845aee3 100644 --- a/usr.bin/localedef/charmap.c +++ b/usr.bin/localedef/charmap.c @@ -236,7 +236,7 @@ cmap_compare_wc(const void *n1, const void *n2) const charmap_t *c1 = n1; const charmap_t *c2 = n2; - return ((c1->wc < c2->wc) ? -1 : (c1->wc > c2->wc) ? 1 : 0); + return (wchar_cmp(c1->wc, c2->wc)); } void diff --git a/usr.bin/localedef/collate.c b/usr.bin/localedef/collate.c index 830235036044..3dc70c7adf94 100644 --- a/usr.bin/localedef/collate.c +++ b/usr.bin/localedef/collate.c @@ -422,7 +422,7 @@ collchar_compare(const void *n1, const void *n2) wchar_t k1 = ((const collchar_t *)n1)->wc; wchar_t k2 = ((const collchar_t *)n2)->wc; - return (k1 < k2 ? -1 : k1 > k2 ? 1 : 0); + return (wchar_cmp(k1, k2)); } RB_GENERATE_STATIC(collchars, collchar, entry, collchar_compare); diff --git a/usr.bin/localedef/ctype.c b/usr.bin/localedef/ctype.c index ab7b76e57b2d..f86a267b0b32 100644 --- a/usr.bin/localedef/ctype.c +++ b/usr.bin/localedef/ctype.c @@ -93,7 +93,7 @@ ctype_compare(const void *n1, const void *n2) const ctype_node_t *c1 = n1; const ctype_node_t *c2 = n2; - return (c1->wc < c2->wc ? -1 : c1->wc > c2->wc ? 1 : 0); + return (wchar_cmp(c1->wc, c2->wc)); } void diff --git a/usr.bin/localedef/localedef.h b/usr.bin/localedef/localedef.h index 34299033214c..4e5c1884a8fb 100644 --- a/usr.bin/localedef/localedef.h +++ b/usr.bin/localedef/localedef.h @@ -38,6 +38,7 @@ #include #include #include +#include extern int com_char; extern int esc_char; @@ -173,5 +174,19 @@ void werr(const char *, ...); const char *get_wide_encoding(void); int max_wide(void); +/* + * A helper function to compare wide characters when sorting. Forcibly cast to + * an unsigned type to help ensure that output is consistent no matter the + * signedness of wchar_t. + */ +static inline int +wchar_cmp(const wchar_t a, const wchar_t b) +{ + return ((uint32_t)a < (uint32_t)b ? -1 : + ((uint32_t)a > (uint32_t)b ? 1 : 0)); +} +_Static_assert(sizeof(wchar_t) == sizeof(uint32_t), + "wchar_t must be 32 bits wide"); + //#define _(x) gettext(x) #define INTERR fprintf(stderr,"internal fault (%s:%d)\n", __FILE__, __LINE__)