all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Glenn Morris <rgm@gnu.org>, emacs-devel@gnu.org
Subject: Re: master 37940b3: min and max now return one of their arguments
Date: Tue, 7 Mar 2017 21:27:35 -0800	[thread overview]
Message-ID: <92047e08-5984-12f2-c285-4017fefac7a3@cs.ucla.edu> (raw)
In-Reply-To: <x6shmonbur.fsf@fencepost.gnu.org>

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

Glenn Morris wrote:
> It seems that this change causes a bunch of tests to fail with
>
> (wrong-type-argument numberp #<marker in no buffer>)

Sorry about that. Apparently 'min' and 'max' converted any marker result to an 
integer. I changed them back to do that with the attached patch. This behavior 
is undocumented; I don't know whether it was intended, although it looks like 
some code relies on it now.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-min-and-max-should-not-return-markers.patch --]
[-- Type: text/x-diff; name="0001-min-and-max-should-not-return-markers.patch", Size: 2110 bytes --]

From 79825fd06cfd7140c8d6e25db1c0fdc5a42f6098 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Tue, 7 Mar 2017 21:23:08 -0800
Subject: [PATCH] min and max should not return markers

Problem reported by Glenn Morris in:
http://lists.gnu.org/archive/html/emacs-devel/2017-03/msg00147.html
* src/data.c (minmax_driver): Convert any marker result to an
integer, since some callers assume this.
* test/src/data-tests.el (data-tests-max, data-tests-min):
Test for this.
---
 src/data.c             | 4 ++--
 test/src/data-tests.el | 8 ++++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/data.c b/src/data.c
index 29547d8..c480ed2 100644
--- a/src/data.c
+++ b/src/data.c
@@ -2972,9 +2972,9 @@ minmax_driver (ptrdiff_t nargs, Lisp_Object *args,
       if (argnum == 0 || !NILP (arithcompare (val, accum, comparison)))
 	accum = val;
       else if (FLOATP (accum) && isnan (XFLOAT_DATA (accum)))
-	break;
+	return accum;
     }
-  return accum;
+  return MARKERP (accum) ? make_number (marker_position (accum)) : accum;
 }
 
 DEFUN ("max", Fmax, Smax, 1, MANY, 0,
diff --git a/test/src/data-tests.el b/test/src/data-tests.el
index 70ffdab..67d00a7 100644
--- a/test/src/data-tests.el
+++ b/test/src/data-tests.el
@@ -88,7 +88,9 @@
   (should (= (1+ most-negative-fixnum)
              (max (float most-negative-fixnum) (1+ most-negative-fixnum))))
   (should (= 8 (apply #'max '(3 8 3))))
-  (should-error (max 9 8 'foo)))
+  (should-error (max 9 8 'foo))
+  (should-error (max (make-marker)))
+  (should (eql 1 (max (point-min-marker) 1))))
 
 (ert-deftest data-tests-min ()
   (should-error (min))
@@ -98,7 +100,9 @@
   (should (= most-positive-fixnum
              (min (+ 1.0 most-positive-fixnum) most-positive-fixnum)))
   (should (= 3 (apply #'min '(3 8 3))))
-  (should-error (min 9 8 'foo)))
+  (should-error (min 9 8 'foo))
+  (should-error (min (make-marker)))
+  (should (eql 1 (min (point-min-marker) 1))))
 
 ;; Bool vector tests.  Compactly represent bool vectors as hex
 ;; strings.
-- 
2.9.3


  parent reply	other threads:[~2017-03-08  5:27 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20170307012700.3354.30219@vcs0.savannah.gnu.org>
     [not found] ` <20170307012701.1C05D23F1F@vcs0.savannah.gnu.org>
2017-03-07 15:04   ` [Emacs-diffs] master 37940b3: min and max now return one of their arguments Stefan Monnier
2017-03-08  3:04     ` John Wiegley
2017-03-08  6:08     ` Paul Eggert
2017-03-08 15:54       ` Eli Zaretskii
2017-03-08 22:04         ` Paul Eggert
2017-03-09 16:10           ` Eli Zaretskii
2017-03-09 16:25             ` Clément Pit-Claudel
2017-03-09 16:54               ` Eli Zaretskii
2017-03-09 17:09                 ` Clément Pit-Claudel
2017-03-09 17:45             ` Paul Eggert
2017-03-09 18:34               ` Eli Zaretskii
2017-03-07 19:08   ` Glenn Morris
2017-03-08  4:26     ` Tino Calancha
2017-03-08  5:27     ` Paul Eggert [this message]
2017-03-08  7:54       ` Andreas Schwab
2017-03-08  8:29       ` Andreas Schwab
2017-03-08 18:47         ` Paul Eggert
2017-03-08 22:10           ` Andreas Schwab
2017-03-11 14:46       ` Andreas Politz
2017-03-12  1:46         ` Tino Calancha
2017-03-12 23:33           ` Andreas Politz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=92047e08-5984-12f2-c285-4017fefac7a3@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    --cc=rgm@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.