From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id 6HRmGTHrYWVVWQAA9RJhRA:P1 (envelope-from ) for ; Sat, 25 Nov 2023 13:40:17 +0100 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id 6HRmGTHrYWVVWQAA9RJhRA (envelope-from ) for ; Sat, 25 Nov 2023 13:40:17 +0100 Received: from mail.notmuchmail.org (yantan.tethera.net [135.181.149.255]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id EA2B8204A3 for ; Sat, 25 Nov 2023 13:40:14 +0100 (CET) Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1700916017; a=rsa-sha256; cv=none; b=tzrSTNy2D3xb+q1ebQbMNV/Uq95agP7abwFuBkHdWaVMU9ex6N3WUiRxQZgWAqaKxK5Ho1 RMSOE5i8uG+qSmsB0d4di/WBwrEKOYoDP4MlBf/fFqE/j4OLgrF9UUL8FsygIa9Z6piMJK iJF7pRJ17u3F0FLHGN47kO8DL02iZ1gr16W0H88WlJg06kixUVM0E05lZb95V/MGS95Cq+ knv967H7FBEnT67oNESEZk4p3ZCrX6Dt2lNtRAMmmJtOUgoWNuYkRsBx9wMt770VHO8C/c O2Y883Bf15LBpTKelW6MAocCSqwNOWwpVXaSiAHWIWHZ2VsLHZ0vdd6Zcacr7Q== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1700916017; 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:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post; bh=eRTe8Cth1fwTKOBzurraYPXcaEMssI0MKYFCqjx6H3c=; b=GIlvjBJMXQjD8Syx1KR9p6h3uDwgy8eubLERDgECSMZEdeHzWj5x6rfqH/t97bEQSn8QQY v8cOKDCYDDmmwfEc/sPIBOdQhSvLecaNx2A3VUx0OgNs9W7NptmrHqGj5svnjwSyWmFrEU fcZmx484Qjffvx1GilRan23qH4CAebSFt8QlF3Zb4xCtYb41xXnb1QWUhMY2v8J6OjsGBm 7I0sM6FipEjB7cjuj2x8wSaqA2qcF8SwvtRno9C0PinPfGZO3wUL1QG0TkV2WmWSFRuiq0 /cRYQlNaw6A8g9EJPEjZVVyK+9ANs+TpRu9937Lx1Gl6ry97LJx/Opc6xEZNJQ== Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 691BE609EC; Sat, 25 Nov 2023 12:40:10 +0000 (UTC) X-Greylist: delayed 363 seconds by postgrey-1.36 at yantan; Sat, 25 Nov 2023 12:40:07 UTC Received: from phubs.tethera.net (phubs.tethera.net [IPv6:2607:5300:60:3a9d::1]) by mail.notmuchmail.org (Postfix) with ESMTPS id B6D495F7BD for ; Sat, 25 Nov 2023 12:40:07 +0000 (UTC) Received: from tethera.net (fctnnbsc51w-159-2-185-147.dhcp-dynamic.fibreop.nb.bellaliant.net [159.2.185.147]) by phubs.tethera.net (Postfix) with ESMTPS id 80FDB180066; Sat, 25 Nov 2023 08:34:02 -0400 (AST) Received: (nullmailer pid 1508590 invoked by uid 1000); Sat, 25 Nov 2023 12:34:01 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH] lib/string_map: simulate stable sorting Date: Sat, 25 Nov 2023 08:33:52 -0400 Message-ID: <20231125123352.1508578-1-david@tethera.net> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Message-ID-Hash: E2TFLAV77XN2RDHHL7MJQ3WLBDZX35KD X-Message-ID-Hash: E2TFLAV77XN2RDHHL7MJQ3WLBDZX35KD X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Country: DE X-Migadu-Queue-Id: EA2B8204A3 X-Migadu-Scanner: mx12.migadu.com X-Migadu-Spam-Score: -0.36 X-Spam-Score: -0.36 X-TUID: m+zD1MeGzwg4 qsort(3) does not promise stability, and recent versions of glibc have been showing more unstable behaviour [2]. Michael Gruber observed [1] test breakage due to changing output order for message properties. We provide a sorting order of (key,value) pairs that _looks_ stable by breaking ties based on value if keys are equal. Internally there may be some instability in the case of duplicate (key,value) pairs, but it should not be observable via the iterator API. [1]: id:CAA19uiSHjVFmwH0pMC7WwDYCOSzu3yqNbuYhu3ZMeNNRh313eA@mail.gmail.com [2]: id:87msv3i44u.fsf@oldenburg.str.redhat.com --- lib/string-map.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/string-map.c b/lib/string-map.c index e3a81b4f..99bc2ea2 100644 --- a/lib/string-map.c +++ b/lib/string-map.c @@ -86,10 +86,14 @@ _notmuch_string_map_append (notmuch_string_map_t *map, static int cmppair (const void *pa, const void *pb) { + int cmp = 0; notmuch_string_pair_t *a = (notmuch_string_pair_t *) pa; notmuch_string_pair_t *b = (notmuch_string_pair_t *) pb; - return strcmp (a->key, b->key); + cmp = strcmp (a->key, b->key); + if (cmp == 0) + cmp = strcmp (a->value, b->value); + return cmp; } static void -- 2.42.0