unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#34792: 27.0.50; format %x and %X don't print as unsigned
@ 2019-03-09  0:58 Ivan Andrus
  2019-03-09  2:03 ` Glenn Morris
  0 siblings, 1 reply; 5+ messages in thread
From: Ivan Andrus @ 2019-03-09  0:58 UTC (permalink / raw)
  To: 34792

The following snippets return strings with negative signs, but the
docstring of format says they should be unsigned.  I get the same
results from emacs -Q as well

(format "%s_%X%X" "bob" (random) (random))
;; "bob_143E5019B284E085-3D71BF28F82AFD0"
(format "%s_%x%x" "bob" (random) (random))
;; "bob_114d97ac7a6b2a84-15fcceadc374b70e"


-Ivan

In GNU Emacs 27.0.50 (build 7, x86_64-apple-darwin18.2.0, NS appkit-1671.20 Version 10.14.3 (Build 18D109))
of 2019-03-08 built on iandrus-macOS
Repository revision: dd77d672d8a9529ce8d4a0649be1b44bbd1a03b1
Repository branch: master
Windowing system distributor 'Apple', version 10.3.1671
System Description:  Mac OS X 10.14.3

Recent messages:
Mark set
Occurrence 1/2 in buffer
find-function-library: Symbol’s function definition is void: ## [2 times]
C-h C-u is undefined
Mark saved where search started
Mark set [2 times]
"bob_-3D1C1371061ABEA-1D876D356D7D25DF"
Saving file /Users/iandrus/.emacs.d/init.el...
Wrote /Users/iandrus/.emacs.d/init.el
Undo! [2 times]

Configured using:
'configure
PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig:/usr/local/opt/libxml2/lib/pkgconfig
--with-sound=yes --with-ns --with-modules --with-file-notification=yes
--enable-gcc-warnings=warn-only --with-xpm --with-jpeg --with-tiff
--with-gif --with-png --with-rsvg --with-xml2 --with-imagemagick
--with-json --with-xft --with-libotf --with-gnutls=no --with-makeinfo
--with-libgmp'

Configured features:
RSVG IMAGEMAGICK GLIB NOTIFY KQUEUE ACL LIBXML2 ZLIB TOOLKIT_SCROLL_BARS
XIM NS MODULES THREADS PDUMPER GMP

Important settings:
 value of $LANG: en_US.UTF-8
 locale-coding-system: utf-8-unix

Major mode: ELisp:Dyn





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#34792: 27.0.50; format %x and %X don't print as unsigned
  2019-03-09  0:58 bug#34792: 27.0.50; format %x and %X don't print as unsigned Ivan Andrus
@ 2019-03-09  2:03 ` Glenn Morris
  2019-03-09 18:48   ` Ivan Andrus
  0 siblings, 1 reply; 5+ messages in thread
From: Glenn Morris @ 2019-03-09  2:03 UTC (permalink / raw)
  To: Ivan Andrus; +Cc: 34792

Ivan Andrus wrote:

> The following snippets return strings with negative signs, but the
> docstring of format says they should be unsigned. 

See etc/NEWS 'Numbers formatted via...'

I don't understand the "bignums, a planned feature." in that entry.
It makes it sound like bignum will be implemented in future, but they
already are?

Also the sense of the entry seems backwards, since binary-as-unsigned is
nil by default (but from editfns.c I see "it depends").

Anyway, it seems like the doc the 'format' function wasn't updated.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#34792: 27.0.50; format %x and %X don't print as unsigned
  2019-03-09  2:03 ` Glenn Morris
@ 2019-03-09 18:48   ` Ivan Andrus
  2019-03-09 22:54     ` Glenn Morris
  0 siblings, 1 reply; 5+ messages in thread
From: Ivan Andrus @ 2019-03-09 18:48 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 34792

On Mar 8, 2019, at 7:03 PM, Glenn Morris <rgm@gnu.org> wrote:
> 
> Ivan Andrus wrote:
> 
>> The following snippets return strings with negative signs, but the
>> docstring of format says they should be unsigned. 
> 
> See etc/NEWS 'Numbers formatted via...'
> 
> I don't understand the "bignums, a planned feature." in that entry.
> It makes it sound like bignum will be implemented in future, but they
> already are?
> 
> Also the sense of the entry seems backwards, since binary-as-unsigned is
> nil by default (but from editfns.c I see "it depends").
> 
> Anyway, it seems like the doc the 'format' function wasn't updated.

Thanks! I should have thought to check NEWS.

I took the liberty for pushing a change to the docstring to master.  Hopefully, it's acceptable.

-Ivan




^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#34792: 27.0.50; format %x and %X don't print as unsigned
  2019-03-09 18:48   ` Ivan Andrus
@ 2019-03-09 22:54     ` Glenn Morris
  2019-03-11  6:49       ` Paul Eggert
  0 siblings, 1 reply; 5+ messages in thread
From: Glenn Morris @ 2019-03-09 22:54 UTC (permalink / raw)
  To: 34792; +Cc: Ivan Andrus, Paul Eggert


(Adding explicit cc:)

>> See etc/NEWS 'Numbers formatted via...'
>> 
>> I don't understand the "bignums, a planned feature." in that entry.
>> It makes it sound like bignum will be implemented in future, but they
>> already are?
>> 
>> Also the sense of the entry seems backwards, since binary-as-unsigned is
>> nil by default (but from editfns.c I see "it depends").
>> 
>> Anyway, it seems like the doc the 'format' function wasn't updated.
>
> Thanks! I should have thought to check NEWS.
>
> I took the liberty for pushing a change to the docstring to master.

I think this area may still need some updating.
(It feels like it predates the addition of bignum support?)





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#34792: 27.0.50; format %x and %X don't print as unsigned
  2019-03-09 22:54     ` Glenn Morris
@ 2019-03-11  6:49       ` Paul Eggert
  0 siblings, 0 replies; 5+ messages in thread
From: Paul Eggert @ 2019-03-11  6:49 UTC (permalink / raw)
  To: Glenn Morris, 34792; +Cc: Ivan Andrus

[-- Attachment #1: Type: text/plain, Size: 231 bytes --]

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.

[-- Attachment #2: 0001-Improve-binary-as-unsigned-treatment-Bug-34792.patch --]
[-- Type: text/x-patch, Size: 4255 bytes --]

From 9b4d34fa7884d6b67ec19593c5d2d3b587434966 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
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


[-- Attachment #3: 0002-src-editfns.c-Fix-docstring-typo.patch --]
[-- Type: text/x-patch, Size: 947 bytes --]

From 27466c62fdc977e8d3b23c5ae4f529a64ac7374f Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-03-11  6:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-09  0:58 bug#34792: 27.0.50; format %x and %X don't print as unsigned Ivan Andrus
2019-03-09  2:03 ` Glenn Morris
2019-03-09 18:48   ` Ivan Andrus
2019-03-09 22:54     ` Glenn Morris
2019-03-11  6:49       ` Paul Eggert

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).