GNU bug report logs - #38892
28.0.50: Hash table printing oddities

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Pip Cet <pipcet@HIDDEN>; dated Fri, 3 Jan 2020 12:15:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 3 Jan 2020 12:14:13 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Jan 03 07:14:13 2020
Received: from localhost ([127.0.0.1]:40463 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1inLqH-0006k6-9y
	for submit <at> debbugs.gnu.org; Fri, 03 Jan 2020 07:14:13 -0500
Received: from lists.gnu.org ([209.51.188.17]:58715)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <pipcet@HIDDEN>) id 1inLqD-0006jw-TV
 for submit <at> debbugs.gnu.org; Fri, 03 Jan 2020 07:14:10 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:53671)
 by lists.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <pipcet@HIDDEN>) id 1inLqC-00032Z-KN
 for bug-gnu-emacs@HIDDEN; Fri, 03 Jan 2020 07:14:09 -0500
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM
 autolearn=disabled version=3.3.2
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <pipcet@HIDDEN>) id 1inLqB-0006lx-CM
 for bug-gnu-emacs@HIDDEN; Fri, 03 Jan 2020 07:14:08 -0500
Received: from mail-oi1-x22a.google.com ([2607:f8b0:4864:20::22a]:39642)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
 (Exim 4.71) (envelope-from <pipcet@HIDDEN>) id 1inLqA-0006im-63
 for bug-gnu-emacs@HIDDEN; Fri, 03 Jan 2020 07:14:06 -0500
Received: by mail-oi1-x22a.google.com with SMTP id a67so14139509oib.6
 for <bug-gnu-emacs@HIDDEN>; Fri, 03 Jan 2020 04:14:06 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:from:date:message-id:subject:to;
 bh=3z6orXkX38Tx+IQRv1x6dLDRmwyqL/WLldWOPLkfeec=;
 b=JnvUrRqXbTh4q9Q4tDFyVI0AsFLHa+AL6/niIFIWHOPn4vTIdil9mjolz1eHdbEZCn
 HyT1aoUIwGZOMbEDfIUsP5aY2bVkeSC0V/N2zr3qR6pgEo30xZCsC0EhB8Bg0SuFIUB8
 JkeXtZwDi63FspGytMYMrzEZuO3cCJ61H1fzGYksRf/nonUlHDAyqiu1y+uUUzPd6AgL
 63eyQeTrgdEOtOacil9XRcHV3EBo9yZTvlgV1H5eDUfeZXt8ieCzsuOkGW+t5sePLjHD
 Ttl2vBbt+1PbgeK9kx7sgoTCCdu4FU2kub6y4W5SdVN8DQCX9Qcs1i6sqLxs95aRONzX
 MMFA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:from:date:message-id:subject:to;
 bh=3z6orXkX38Tx+IQRv1x6dLDRmwyqL/WLldWOPLkfeec=;
 b=hwZ8QKsB0a/OsGM9IzsnhnPrMDd8FTa4VoUTzmKhcrmnBfbFClAd4Ip4+hq0lHmqA7
 j3Kwx9L7nLxLEo2VLypagk+HpO7Rjf02j1lriV26DhRDBLlDB17ia0SrUPGQbB+3aelN
 AvpcawWYZxbkmujoz9PYInfwlOM18Fg5YHURbBKXDIrEZNMa9dGLaKTXO9SVNn9XReko
 CFtm+Vz1NQhbP3NF0F9xSLmwpLWQQ1F4YAMIC/iV4YGRJPnWxXj4vi+d++4M3qSM1rYR
 /jl4AdP74BAv7nQCFysJGBsJ0CGTiOCeqGBo5P4LViWTRArmyQL4T8m9fWBiaJyV/7NP
 R4gg==
X-Gm-Message-State: APjAAAXWgCopGjpqmBRDJEcGAk6HM25qlk65NMDSMHpnJezydvjCr7xj
 Zj3TebELQJDsxMM2uiOnmPV1dJK6KReqdvY88LgDSWAq
X-Google-Smtp-Source: APXvYqzAOxsdiWarigJxTK8jcH0OMJq0EAIn/UnO+sGASNVmEGm0Jc+eixaamw/nVLEWHFMfHPxwJ/6qjiw/znbJtjQ=
X-Received: by 2002:a05:6808:208:: with SMTP id
 l8mr3660775oie.112.1578053644642; 
 Fri, 03 Jan 2020 04:14:04 -0800 (PST)
MIME-Version: 1.0
From: Pip Cet <pipcet@HIDDEN>
Date: Fri, 3 Jan 2020 12:13:28 +0000
Message-ID: <CAOqdjBcUy_SF8CefuoObS53=vHDg=D=uCRJwKWgNBvuYnNDNYA@HIDDEN>
Subject: 28.0.50: Hash table printing oddities
To: bug-gnu-emacs@HIDDEN
Content-Type: multipart/mixed; boundary="000000000000ed05be059b3b3e8a"
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
 recognized.
X-Received-From: 2607:f8b0:4864:20::22a
X-Spam-Score: 0.7 (/)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.3 (--)

--000000000000ed05be059b3b3e8a
Content-Type: text/plain; charset="UTF-8"

The hash table printing code has some oddities: it will print extra
spaces sometimes, won't print as many elements as requested under all
circumstances, and behave oddly for empty hash tables when
print-length is 0.

Currently, this code will result in extra spaces in the hash table output:

(let ((h (make-hash-table)))
  (puthash 1 2 h)
  (puthash 2 3 h)
  (remhash 1 h)
  (format "%S" h))

(let ((h (make-hash-table)))
  (let ((print-length 0))
    (format "%S" h)))

In the latter case, the output actually includes "data ( ...)", though
"data ()" would be shorter and more accurate.

Also, the current code contains an oddity that would make it print
fewer than print-length hash cells in the data list:

(let ((h (make-hash-table)))
  (dotimes (i 100)
    (puthash i i h))
  (dotimes (i 99)
    (remhash i h))
  (let ((print-length 1))
    (format "%S" h)))

will produce "data ( ...)", when it should produce "data (99 99)".

Proposed patch attached.

--000000000000ed05be059b3b3e8a
Content-Type: text/x-patch; charset="US-ASCII"; name="0001-Fix-hash-table-printing.patch"
Content-Disposition: attachment; 
	filename="0001-Fix-hash-table-printing.patch"
Content-Transfer-Encoding: base64
Content-ID: <f_k4y4bg790>
X-Attachment-Id: f_k4y4bg790

RnJvbSAyOWZlYjBmYTE5NGZiMWVhOWZlNjUxNDI4YjZmYmUwMWQyMThhYTc1IE1vbiBTZXAgMTcg
MDA6MDA6MDAgMjAwMQpGcm9tOiBQaXAgQ2V0IDxwaXBjZXRAZ21haWwuY29tPgpEYXRlOiBGcmks
IDMgSmFuIDIwMjAgMTI6MDA6NDQgKzAwMDAKU3ViamVjdDogW1BBVENIXSBGaXggaGFzaCB0YWJs
ZSBwcmludGluZwoKUHJldmlvdXNseSwgdGhlIG91dHB1dCB3b3VsZCBzb21ldGltZXMgY29udGFp
biBleHRyYSBzcGFjZXMgb3IgZmV3ZXIKZWxlbWVudHMgdGhhbiB3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nLCBwcmludGNoYXJmdW4pOwotCWZvciAocHRyZGlm
Zl90IGkgPSAwOyBpIDwgc2l6ZTsgaSsrKQorCXB0cmRpZmZfdCBqID0gMDsKKwlmb3IgKHB0cmRp
ZmZfdCBpID0gMDsgaSA8IHJlYWxfc2l6ZTsgaSsrKQogICAgICAgICAgIHsKICAgICAgICAgICAg
IExpc3BfT2JqZWN0IGtleSA9IEhBU0hfS0VZIChoLCBpKTsKIAkgICAgaWYgKCFFUSAoa2V5LCBR
dW5ib3VuZCkpCiAJICAgICAgewotCSAgICAgICAgaWYgKGkpIHByaW50Y2hhciAoJyAnLCBwcmlu
dGNoYXJmdW4pOworCSAgICAgICAgaWYgKGorKykgcHJpbnRjaGFyICgnICcsIHByaW50Y2hhcmZ1
bik7CiAJICAgICAgICBwcmludF9vYmplY3QgKGtleSwgcHJpbnRjaGFyZnVuLCBlc2NhcGVmbGFn
KTsKIAkgICAgICAgIHByaW50Y2hhciAoJyAnLCBwcmludGNoYXJmdW4pOwogCSAgICAgICAgcHJp
bnRfb2JqZWN0IChIQVNIX1ZBTFVFIChoLCBpKSwgcHJpbnRjaGFyZnVuLCBlc2NhcGVmbGFnKTsK
KwkJaWYgKGogPT0gc2l6ZSkKKwkJICBicmVhazsKIAkgICAgICB9CiAgICAgICAgICAgfQogCi0J
aWYgKHNpemUgPCByZWFsX3NpemUpCi0JICBwcmludF9jX3N0cmluZyAoIiAuLi4iLCBwcmludGNo
YXJmdW4pOworCWlmIChqIDwgaC0+Y291bnQpCisJICB7CisJICAgIGlmIChqKQorCSAgICAgIHBy
aW50Y2hhciAoJyAnLCBwcmludGNoYXJmdW4pOworCSAgICBwcmludF9jX3N0cmluZyAoIi4uLiIs
IHByaW50Y2hhcmZ1bik7CisJICB9CiAKIAlwcmludF9jX3N0cmluZyAoIikpIiwgcHJpbnRjaGFy
ZnVuKTsKICAgICAgIH0KLS0gCjIuMjQuMAoK
--000000000000ed05be059b3b3e8a--




Acknowledgement sent to Pip Cet <pipcet@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#38892; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Fri, 3 Jan 2020 12:30:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.