From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#34792: 27.0.50; format %x and %X don't print as unsigned Date: Sun, 10 Mar 2019 23:49:05 -0700 Organization: UCLA Computer Science Department Message-ID: References: <79489389-7B99-4F84-BC48-3AF622B8EF26@gmail.com> <1vwol8ls6y.fsf@fencepost.gnu.org> <9DBA5B35-1F73-457B-8ADE-A495CB326F17@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------00F2E106D578633E4F6A90CF" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="253522"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 Cc: Ivan Andrus To: Glenn Morris , 34792@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Mar 11 07:51:38 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h3Emf-0013nH-GS for geb-bug-gnu-emacs@m.gmane.org; Mon, 11 Mar 2019 07:51:37 +0100 Original-Received: from localhost ([127.0.0.1]:56253 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3Eme-0002CE-A3 for geb-bug-gnu-emacs@m.gmane.org; Mon, 11 Mar 2019 02:51:36 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:42346) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3EmX-0002Br-Km for bug-gnu-emacs@gnu.org; Mon, 11 Mar 2019 02:51:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3El9-0003qH-0u for bug-gnu-emacs@gnu.org; Mon, 11 Mar 2019 02:50:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:53268) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h3El8-0003pe-Q5 for bug-gnu-emacs@gnu.org; Mon, 11 Mar 2019 02:50:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1h3El8-000578-Ii for bug-gnu-emacs@gnu.org; Mon, 11 Mar 2019 02:50:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 11 Mar 2019 06:50:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 34792 X-GNU-PR-Package: emacs Original-Received: via spool by 34792-submit@debbugs.gnu.org id=B34792.155228695619594 (code B ref 34792); Mon, 11 Mar 2019 06:50:02 +0000 Original-Received: (at 34792) by debbugs.gnu.org; 11 Mar 2019 06:49:16 +0000 Original-Received: from localhost ([127.0.0.1]:38579 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h3EkN-00055y-SS for submit@debbugs.gnu.org; Mon, 11 Mar 2019 02:49:16 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:52818) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h3EkL-00055l-5G for 34792@debbugs.gnu.org; Mon, 11 Mar 2019 02:49:14 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 8EBB51614E4; Sun, 10 Mar 2019 23:49:07 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 1YIaGasWvgpO; Sun, 10 Mar 2019 23:49:06 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 7394816155E; Sun, 10 Mar 2019 23:49:06 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id QTCXqc84uerH; Sun, 10 Mar 2019 23:49:06 -0700 (PDT) Original-Received: from [192.168.1.9] (cpe-23-242-74-103.socal.res.rr.com [23.242.74.103]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 426051614E4; Sun, 10 Mar 2019 23:49:06 -0700 (PDT) In-Reply-To: Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:156228 Archived-At: This is a multi-part message in MIME format. --------------00F2E106D578633E4F6A90CF Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Glenn Morris wrote: > I think this area may still need some updating. > (It feels like it predates the addition of bignum support?) Yes, you're right on both counts. I installed the attached patches to master to try to fix this. --------------00F2E106D578633E4F6A90CF Content-Type: text/x-patch; name="0001-Improve-binary-as-unsigned-treatment-Bug-34792.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Improve-binary-as-unsigned-treatment-Bug-34792.patch" >From 9b4d34fa7884d6b67ec19593c5d2d3b587434966 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 10 Mar 2019 23:39:48 -0700 Subject: [PATCH 1/2] Improve binary-as-unsigned treatment (Bug#34792) * etc/NEWS: * src/editfns.c (Fformat, binary_as_unsigned): Update now that we always have bignums. (syms_of_editfns) [!defined lisp_h_FIXNUMP]: Remove now-obsolete code, since lisp_h_FIXNUMP is always defined now. * test/src/editfns-tests.el (read-large-integer): Simplify, now that we can assume binary-as-unsigned defaults to nil. --- etc/NEWS | 6 +++--- src/editfns.c | 14 +++++--------- test/src/editfns-tests.el | 11 +++++------ 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 0a1d9ea222..3dc21dfe89 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1490,10 +1490,10 @@ between two strings. '(quote x)' instead of 'x you will have to bind it to nil where applicable. +++ -** Numbers formatted via '%o' or '%x' may now be formatted as signed integers. +** Numbers formatted via '%o' or '%x' are now formatted as signed integers. This avoids problems in calls like '(read (format "#x%x" -1))', and is -more compatible with bignums, a planned feature. To get this -behavior, set the experimental variable 'binary-as-unsigned' to nil, +more compatible with bignums. To get the traditional machine-dependent +behavior, set the experimental variable 'binary-as-unsigned' to t, and if the new behavior breaks your code please email 32252@debbugs.gnu.org. Because '%o' and '%x' can now format signed integers, they now support the '+' and space flags. diff --git a/src/editfns.c b/src/editfns.c index f5a9e0a640..7f11037f1e 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -3001,8 +3001,8 @@ the next available argument, or the argument explicitly specified: %S means print any object as an s-expression (using `prin1'). The argument used for %d, %o, %x, %e, %f, %g or %c must be a number. -The value of `binary-as-unsigned' determines whether it's printed as - signed or unsigned by %o, %x, and %X. +%o, %x, and %X treat arguments as unsigned if `binary-as-unsigned' is t + (this is experimental; email 32252@debbugs.gnu.org if you need it). Use %% to put a single % into the output. A %-sequence other than %% may contain optional field number, flag, @@ -4485,17 +4485,13 @@ functions if all the text being accessed has this property. */); binary_as_unsigned, doc: /* Non-nil means `format' %x and %o treat integers as unsigned. This has machine-dependent results. Nil means to treat integers as -signed, which is portable; for example, if N is a negative integer, -(read (format "#x%x") N) returns N only when this variable is nil. +signed, which is portable and is the default; for example, if N is a +negative integer, (read (format "#x%x") N) returns N only when this +variable is nil. This variable is experimental; email 32252@debbugs.gnu.org if you need it to be non-nil. */); - /* For now, default to true if bignums exist, false in traditional Emacs. */ -#ifdef lisp_h_FIXNUMP binary_as_unsigned = false; -#else - binary_as_unsigned = true; -#endif defsubr (&Spropertize); defsubr (&Schar_equal); diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el index a01dc4a478..449f00f378 100644 --- a/test/src/editfns-tests.el +++ b/test/src/editfns-tests.el @@ -184,12 +184,11 @@ transpose-test-get-byte-positions 'integer)) (should (eq (type-of (read (format "#32rG%x" most-positive-fixnum))) 'integer)) - (let ((binary-as-unsigned nil)) - (dolist (fmt '("%d" "%s" "#o%o" "#x%x")) - (dolist (val (list most-negative-fixnum (1+ most-negative-fixnum) - -1 0 1 - (1- most-positive-fixnum) most-positive-fixnum)) - (should (eq val (read (format fmt val)))))))) + (dolist (fmt '("%d" "%s" "#o%o" "#x%x")) + (dolist (val (list most-negative-fixnum (1+ most-negative-fixnum) + -1 0 1 + (1- most-positive-fixnum) most-positive-fixnum)) + (should (eq val (read (format fmt val))))))) (ert-deftest format-%o-invalid-float () (should-error (format "%o" -1e-37) -- 2.17.1 --------------00F2E106D578633E4F6A90CF Content-Type: text/x-patch; name="0002-src-editfns.c-Fix-docstring-typo.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0002-src-editfns.c-Fix-docstring-typo.patch" >From 27466c62fdc977e8d3b23c5ae4f529a64ac7374f Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 10 Mar 2019 23:46:26 -0700 Subject: [PATCH 2/2] * src/editfns.c: Fix docstring typo. --- src/editfns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/editfns.c b/src/editfns.c index 7f11037f1e..d6ad7474fe 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -4486,7 +4486,7 @@ functions if all the text being accessed has this property. */); doc: /* Non-nil means `format' %x and %o treat integers as unsigned. This has machine-dependent results. Nil means to treat integers as signed, which is portable and is the default; for example, if N is a -negative integer, (read (format "#x%x") N) returns N only when this +negative integer, (read (format "#x%x" N)) returns N only when this variable is nil. This variable is experimental; email 32252@debbugs.gnu.org if you need -- 2.17.1 --------------00F2E106D578633E4F6A90CF--