From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id CEc4Mil4Y2Ww3AAA9RJhRA:P1 (envelope-from ) for ; Sun, 26 Nov 2023 17:54:01 +0100 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id CEc4Mil4Y2Ww3AAA9RJhRA (envelope-from ) for ; Sun, 26 Nov 2023 17:54:01 +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 4CF855A478 for ; Sun, 26 Nov 2023 17:54:01 +0100 (CET) Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=iki.fi header.s=meesny header.b=oigBLyD7; arc=reject ("signature check failed: fail, {[1] = sig:iki.fi:reject}"); 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=2; s=key1; d=yhetil.org; t=1701017641; a=rsa-sha256; cv=fail; b=T6jILbe+bzPxrmATj5/d8Mv0gdLfowT0hSMRnQErn2hhUm/nYozL4IVF2JoJjCuh1NnkdD ORO9zKS7gUwU4ft9cuBaPxFggyggW2pR/PIuuYWmilbguWsovxsaZII8g3caykBryDcrPB xqdJ+A94mvOFpJb2Ryl2Qbyik59wLbrLxlXM+ZKQem1IDIzXPUNLu7kmnblANwMwQMmu3v sjGNpqVMxMoQ9R/z1qH1/eSA+Ved5ZsDcvA/uLSFNQi4MXk9VPB1ggh8CG+JpZDprBqB20 9e93zPcd/oXso/euHysqon7WGxJLKtn3+PY1PGX6yXM7ihv0ysKB3H+0W2/M5w== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=iki.fi header.s=meesny header.b=oigBLyD7; arc=reject ("signature check failed: fail, {[1] = sig:iki.fi:reject}"); 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=2; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1701017641; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=yvWSywnTxIEpJTAxQYZtSm37byQcdbRlPRPK99IiI2c=; b=oD09h1hTQG8JAGsgc/qB0r+Sg2oq6duYIfUC4Af1ZfvNkXnQdf7qQxKsdDYK8vhXf7ipkZ 60c8y8IgeWbc7euVB8h+Uc9rAFZkg52GI1o+Fzf/Q+rPPXgqzlM+75ItgAj493XjoIfwmR AoQtIdPDUCqbgsKs0nmj5qEbwj+gzGsg0xg5NWvXYPJGPy4irSD47RNase6KO6fwjuqqI0 4NVXnnHUALti5DAwniW5Cno4MzW2sBuYjY1QOIkF0F0ue7pUgF1ukH4uYZW7gU5dfVoKbB D+ACMj6m1ad2hiof2HQoKzznNJREQfeF40sRMpq0HvPg6mxDO/QJT4yfTlL/rg== Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 123385E511; Sun, 26 Nov 2023 16:53:59 +0000 (UTC) X-Greylist: delayed 153175 seconds by postgrey-1.36 at yantan; Sun, 26 Nov 2023 16:53:57 UTC Received: from meesny.iki.fi (meesny.iki.fi [IPv6:2001:67c:2b0:1c1::201]) by mail.notmuchmail.org (Postfix) with ESMTPS id 06D785E501 for ; Sun, 26 Nov 2023 16:53:57 +0000 (UTC) Received: from c53 (gw1.nor.fi [185.218.193.67]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: too) by meesny.iki.fi (Postfix) with ESMTPSA id 4SdZYc1k7dzySy; Sun, 26 Nov 2023 18:53:52 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1701017636; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1UXqPZPR2uNJbLnvzKseXCwMJxX5WUcUmYfjKtJu+Os=; b=oigBLyD7RtlI2KfM073NMxHQKO5pRIO0MLkaDCeTymuI7zEflXE4tk+aU02Qo99JjSsTAc q+lUEEnfr3jVCiJ6rDk3WAQjtg093VN33hS3PCVtIi4J2IeYVUtbXkI8nQ6+dlq5Hig4ID Y+D369Dn8L3wbY6REa80ZkXNDZUXIAc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1701017636; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1UXqPZPR2uNJbLnvzKseXCwMJxX5WUcUmYfjKtJu+Os=; b=Aer9WTQ/uvaclK1E1x2cOkMgS5prMYMuGsdByYZtrvE/s0U3ZEQIK8WaY/R9lufDZDOMF9 G6gx7aOfUe6zS0s+x9j8X146qradHVlQ2GEoiHZ4BzpRBrxMeT3gLvIquVGn2I1Ib1V+x/ 4vX1tyq+3G8hDWUxqCIRl+8cEBDXvlA= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=too smtp.mailfrom=tomi.ollila@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1701017636; a=rsa-sha256; cv=none; b=ok6Jx4VikhGIIN5fof7UVkQCcKF0kW5s0WcQeGmzHAi41f523bQ0q/zFNDoUvdEY+R2hlP 7y5FaVr/IuMKtZHx+cl68F+XTETXDeyrGESHVdc1yUX4YxPwv/3zHV6SF7kV71kQIGPnau k+ZJSI4TDn59L3viTpU4YaVtGTfbUcI= From: Tomi Ollila To: David Bremner , notmuch@notmuchmail.org Subject: Re: [PATCH] lib/string_map: simulate stable sorting In-Reply-To: <20231125123352.1508578-1-david@tethera.net> References: <20231125123352.1508578-1-david@tethera.net> User-Agent: Notmuch/0.38+5~gf38f4f8 (https://notmuchmail.org) Emacs/27.1 X-Face: HhBM'cA~ MIME-Version: 1.0 Message-ID-Hash: 2CAV6YFXL5XKGICDI6NIMWKC4GPJC6FC X-Message-ID-Hash: 2CAV6YFXL5XKGICDI6NIMWKC4GPJC6FC X-MailFrom: tomi.ollila@iki.fi 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-Country: DE X-Migadu-Flow: FLOW_IN X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: 1.50 X-Spam-Score: 1.50 X-Migadu-Queue-Id: 4CF855A478 X-TUID: U6cSmV4EQI70 On Sat, Nov 25 2023, David Bremner wrote: > 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. I don't know (from the visible context here) why this is needed, but I can image it is useful, so LGTM. Tomi > > [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