APPROVE COMMIT
NOTE: This patch has been committed
# HG changeset patch
# User Aidan Kehoe <kehoea(a)parhasard.net>
# Date 1552238644 0
# Sun Mar 10 17:24:04 2019 +0000
# Node ID 5d1f8a39a8d09a49b87b25c7b27b09fa8b3059c0
# Parent 5aaa9025873317ac1c3054debfddb90c77168838
Make modiff, save_modiff, other buffer variables into EMACS_INT.
src/ChangeLog addition:
2019-03-10 Aidan Kehoe <kehoea(a)parhasard.net>
Make the modiff, save_modiff, face_change, auto_save_modified
buffer slots into EMACS_INTs.
Supply and use an arithcompare function for all of them that pays
attention to the fact that they wrap around.
* buffer.c (Fbuffer_modified_tick):
Caution regarding ordinal comparisons with the result of this
function.
Use make_integer, not make_fixnum, there is no guarantee a fixnum
will have the bit width to represent the complete value.
* buffer.c (Fbuffer_modified_p):
* buffer.c (Fset_buffer_modified_p):
* buffer.c (Fkill_buffer):
Use buf_tick_arithcompare() in these functions.
* buffer.h:
* buffer.h (struct buffer_text):
* buffer.h (struct buffer):
Use EMACS_INT as appropriate in these structures.
* buffer.h (buf_tick_arithcompare): New.
Compare two buffer tick values, heuristically comparing for
wraparound.
* fileio.c (Fdo_auto_save):
Use buf_tick_arithcompare() as appropriate.
* filelock.c (unlock_all_files):
* filelock.c (Flock_buffer):
* filelock.c (Funlock_buffer):
* filelock.c (unlock_buffer):
Use buf_tick_arithcompare() as appropriate in these functions.
* insdel.c (signal_before_change):
* insdel.c (prepare_to_modify_buffer):
Use buf_tick_arithcompare() as appropriate in this file.
* redisplay.c (regenerate_window_extents_only_changed):
* redisplay.c (redisplay_window):
* redisplay.c (decode_mode_spec):
* redisplay.c (validate_line_start_cache):
Use buf_tick_arithcompare() as appropriate in this file.
* undo.c (undo_prelude):
Ditto.
* window.c (Fmove_to_window_line):
Ditto.
diff -r 5aaa90258733 -r 5d1f8a39a8d0 src/ChangeLog
--- a/src/ChangeLog Sun Mar 10 14:06:13 2019 +0000
+++ b/src/ChangeLog Sun Mar 10 17:24:04 2019 +0000
@@ -1,3 +1,45 @@
+2019-03-10 Aidan Kehoe <kehoea(a)parhasard.net>
+
+ Make the modiff, save_modiff, face_change, auto_save_modified
+ buffer slots into EMACS_INTs.
+ Supply and use an arithcompare function for all of them that pays
+ attention to the fact that they wrap around.
+ * buffer.c (Fbuffer_modified_tick):
+ Caution regarding ordinal comparisons with the result of this
+ function.
+ Use make_integer, not make_fixnum, there is no guarantee a fixnum
+ will have the bit width to represent the complete value.
+ * buffer.c (Fbuffer_modified_p):
+ * buffer.c (Fset_buffer_modified_p):
+ * buffer.c (Fkill_buffer):
+ Use buf_tick_arithcompare() in these functions.
+ * buffer.h:
+ * buffer.h (struct buffer_text):
+ * buffer.h (struct buffer):
+ Use EMACS_INT as appropriate in these structures.
+ * buffer.h (buf_tick_arithcompare): New.
+ Compare two buffer tick values, heuristically comparing for
+ wraparound.
+ * fileio.c (Fdo_auto_save):
+ Use buf_tick_arithcompare() as appropriate.
+ * filelock.c (unlock_all_files):
+ * filelock.c (Flock_buffer):
+ * filelock.c (Funlock_buffer):
+ * filelock.c (unlock_buffer):
+ Use buf_tick_arithcompare() as appropriate in these functions.
+ * insdel.c (signal_before_change):
+ * insdel.c (prepare_to_modify_buffer):
+ Use buf_tick_arithcompare() as appropriate in this file.
+ * redisplay.c (regenerate_window_extents_only_changed):
+ * redisplay.c (redisplay_window):
+ * redisplay.c (decode_mode_spec):
+ * redisplay.c (validate_line_start_cache):
+ Use buf_tick_arithcompare() as appropriate in this file.
+ * undo.c (undo_prelude):
+ Ditto.
+ * window.c (Fmove_to_window_line):
+ Ditto.
+
2019-03-10 Aidan Kehoe <kehoea(a)parhasard.net>
* buffer.c (complex_vars_of_buffer):
diff -r 5aaa90258733 -r 5d1f8a39a8d0 src/buffer.c
--- a/src/buffer.c Sun Mar 10 14:06:13 2019 +0000
+++ b/src/buffer.c Sun Mar 10 17:24:04 2019 +0000
@@ -973,7 +973,8 @@
{
struct buffer *buf = decode_buffer (buffer, 0);
- return BUF_SAVE_MODIFF (buf) < BUF_MODIFF (buf) ? Qt : Qnil;
+ return buf_tick_arithcompare (BUF_SAVE_MODIFF (buf), BUF_MODIFF (buf)) < 0
+ ? Qt : Qnil;
}
DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p, 1, 2, 0, /*
@@ -993,7 +994,8 @@
Lisp_Object fn = buf->file_truename;
if (!NILP (fn))
{
- int already = BUF_SAVE_MODIFF (buf) < BUF_MODIFF (buf);
+ Boolint already = buf_tick_arithcompare (BUF_SAVE_MODIFF (buf),
+ BUF_MODIFF (buf)) < 0;
if (already == NILP (flag))
{
int count = specpdl_depth ();
@@ -1027,14 +1029,15 @@
DEFUN ("buffer-modified-tick", Fbuffer_modified_tick, 0, 1, 0, /*
Return BUFFER's tick counter, incremented for each change in text.
Each buffer has a tick counter which is incremented each time the text in
-that buffer is changed. It wraps around occasionally.
+that buffer is changed. It wraps around occasionally, and so user
+code needs to be careful about ordinal comparisons.
No argument or nil as argument means use current buffer as BUFFER.
*/
(buffer))
{
struct buffer *buf = decode_buffer (buffer, 0);
- return make_fixnum (BUF_MODIFF (buf));
+ return make_integer (BUF_MODIFF (buf));
}
DEFUN ("rename-buffer", Frename_buffer, 1, 2,
@@ -1245,7 +1248,7 @@
/* Query if the buffer is still modified. */
if (INTERACTIVE && !NILP (b->filename)
- && BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
+ && buf_tick_arithcompare (BUF_MODIFF (b), BUF_SAVE_MODIFF (b)) > 0)
{
Lisp_Object killp;
GCPRO1 (buf);
diff -r 5aaa90258733 -r 5d1f8a39a8d0 src/buffer.h
--- a/src/buffer.h Sun Mar 10 14:06:13 2019 +0000
+++ b/src/buffer.h Sun Mar 10 17:24:04 2019 +0000
@@ -86,12 +86,12 @@
Charbpos bufz; /* Equivalent as a Charbpos. */
Bytecount gap_size;/* Size of buffer's gap */
Bytecount end_gap_size;/* Size of buffer's end gap */
- long modiff; /* This counts buffer-modification events
+ EMACS_INT modiff; /* This counts buffer-modification events
for this buffer. It is incremented for
each such event, and never otherwise
changed. */
- long save_modiff; /* Previous value of modiff, as of last
- time buffer visited or saved a file. */
+ EMACS_INT save_modiff; /* Previous value of modiff, as of last
+ time buffer visited or saved a file. */
#ifdef MULE
@@ -172,8 +172,8 @@
Bytebpos zv; /* Index of end of accessible range. */
Charbpos bufzv; /* Equivalent as a Charbpos. */
- int face_change; /* This is set when a change in how the text should
- be displayed (e.g., font, color) is made. */
+ EMACS_INT face_change; /* This is set when a change in how the text should
+ be displayed (e.g., font, color) is made. */
/* Whether buffer specific face is specified. */
int buffer_local_face_property;
@@ -248,7 +248,7 @@
time_t modtime;
/* the value of text->modiff at the last auto-save. */
- long auto_save_modified;
+ EMACS_INT auto_save_modified;
/* The time at which we detected a failure to auto-save,
Or -1 if we didn't have a failure. */
@@ -1133,6 +1133,21 @@
/* Modification count */
#define BUF_MODIFF(buf) ((buf)->text->modiff)
+/* The modification count wraps around, use the following to compare, which
+ uses the same approach as Fevent_timestamp_lessp(). */
+DECLARE_INLINE_HEADER (
+int
+buf_tick_arithcompare (EMACS_INT val1, EMACS_INT val2)
+)
+{
+ if (val1 < val2 && ((val2 - val1) < (EMACS_INT) ((~(EMACS_UINT)(0)
>> 2))))
+ {
+ return -1;
+ }
+
+ return val1 != val2;
+}
+
/* Saved modification count */
#define BUF_SAVE_MODIFF(buf) ((buf)->text->save_modiff)
diff -r 5aaa90258733 -r 5d1f8a39a8d0 src/fileio.c
--- a/src/fileio.c Sun Mar 10 14:06:13 2019 +0000
+++ b/src/fileio.c Sun Mar 10 17:24:04 2019 +0000
@@ -4178,9 +4178,12 @@
and file changed since last auto save
and file changed since last real save. */
if (STRINGP (b->auto_save_file_name)
- && BUF_SAVE_MODIFF (b) < BUF_MODIFF (b)
- && b->auto_save_modified < BUF_MODIFF (b)
- /* -1 means we've turned off autosaving for a while--see below. */
+ && buf_tick_arithcompare (BUF_SAVE_MODIFF (b),
+ BUF_MODIFF (b)) < 0
+ && buf_tick_arithcompare (b->auto_save_modified,
+ BUF_MODIFF (b)) < 0
+ /* -1 means we've turned off autosaving for a while--see
+ below. */
&& XFIXNUM (b->saved_size) >= 0
&& (do_handled_files
|| NILP (Ffind_file_name_handler (b->auto_save_file_name,
diff -r 5aaa90258733 -r 5d1f8a39a8d0 src/filelock.c
--- a/src/filelock.c Sun Mar 10 14:06:13 2019 +0000
+++ b/src/filelock.c Sun Mar 10 17:24:04 2019 +0000
@@ -405,7 +405,8 @@
for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
{
struct buffer *b = XBUFFER (XCDR (XCAR (tail)));
- if (STRINGP (b->file_truename) && BUF_SAVE_MODIFF (b) < BUF_MODIFF
(b))
+ if (STRINGP (b->file_truename)
+ && buf_tick_arithcompare (BUF_SAVE_MODIFF (b), BUF_MODIFF (b)) < 0)
unlock_file (b->file_truename);
}
}
@@ -420,7 +421,8 @@
if (NILP (file))
file = current_buffer->file_truename;
CHECK_STRING (file);
- if (BUF_SAVE_MODIFF (current_buffer) < BUF_MODIFF (current_buffer)
+ if (buf_tick_arithcompare (BUF_SAVE_MODIFF (current_buffer),
+ BUF_MODIFF (current_buffer)) < 0
&& !NILP (file))
lock_file (file);
return Qnil;
@@ -437,7 +439,8 @@
mean nasty things with pointy teeth. If you call this make sure
you protect things right. */
- if (BUF_SAVE_MODIFF (current_buffer) < BUF_MODIFF (current_buffer)
+ if (buf_tick_arithcompare (BUF_SAVE_MODIFF (current_buffer),
+ BUF_MODIFF (current_buffer)) < 0
&& STRINGP (current_buffer->file_truename))
unlock_file (current_buffer->file_truename);
return Qnil;
@@ -453,7 +456,8 @@
/* dmoore - and can destroy current_buffer and all sorts of other
mean nasty things with pointy teeth. If you call this make sure
you protect things right. */
- if (BUF_SAVE_MODIFF (buffer) < BUF_MODIFF (buffer)
+ if (buf_tick_arithcompare (BUF_SAVE_MODIFF (buffer),
+ BUF_MODIFF (buffer)) < 0
&& STRINGP (buffer->file_truename))
unlock_file (buffer->file_truename);
}
diff -r 5aaa90258733 -r 5d1f8a39a8d0 src/insdel.c
--- a/src/insdel.c Sun Mar 10 14:06:13 2019 +0000
+++ b/src/insdel.c Sun Mar 10 17:24:04 2019 +0000
@@ -797,7 +797,8 @@
}
/* If buffer is unmodified, run a special hook for that case. */
- if (BUF_SAVE_MODIFF (buf) >= BUF_MODIFF (buf))
+ if (buf_tick_arithcompare (BUF_SAVE_MODIFF (buf), BUF_MODIFF (buf))
+ > -1)
{
MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons)
{
@@ -979,7 +980,7 @@
buffer = wrap_buffer (buf);
GCPRO1 (buffer);
if (!NILP (buf->filename) && lockit &&
- BUF_SAVE_MODIFF (buf) >= BUF_MODIFF (buf))
+ buf_tick_arithcompare (BUF_SAVE_MODIFF (buf), BUF_MODIFF (buf)) >= 0)
{
#ifdef CLASH_DETECTION
if (!NILP (buf->file_truename))
diff -r 5aaa90258733 -r 5d1f8a39a8d0 src/redisplay.c
--- a/src/redisplay.c Sun Mar 10 14:06:13 2019 +0000
+++ b/src/redisplay.c Sun Mar 10 17:24:04 2019 +0000
@@ -5805,7 +5805,8 @@
under which this can happen, but I believe that it is probably a
reasonable happening. */
if (!point_visible (w, pointm, CURRENT_DISP)
- || XFIXNUM (w->last_modified[CURRENT_DISP]) < BUF_MODIFF (b))
+ || buf_tick_arithcompare (XFIXNUM (w->last_modified[CURRENT_DISP]),
+ BUF_MODIFF (b)) < 0)
return 0;
byte_pointm = charbpos_to_bytebpos (b, pointm);
@@ -6490,8 +6491,10 @@
/* If nothing has changed since the last redisplay, then we just
need to make sure that point is still visible. */
- if (XFIXNUM (w->last_modified[CURRENT_DISP]) >= BUF_MODIFF (b)
- && XFIXNUM (w->last_facechange[CURRENT_DISP]) >= BUF_FACECHANGE (b)
+ if (buf_tick_arithcompare (XFIXNUM (w->last_modified[CURRENT_DISP]),
+ BUF_MODIFF (b)) >= 0
+ && buf_tick_arithcompare (w->last_facechange[CURRENT_DISP],
+ BUF_FACECHANGE (b)) >= 0
&& pointm >= startp
/* This check is to make sure we restore the minibuffer after a
temporary change to the echo area. */
@@ -6604,8 +6607,10 @@
&& regenerate_window_incrementally (w, startp, pointm))
{
if (f->modeline_changed
- || XFIXNUM (w->last_modified[CURRENT_DISP]) < BUF_MODIFF (b)
- || XFIXNUM (w->last_facechange[CURRENT_DISP]) < BUF_FACECHANGE (b))
+ || buf_tick_arithcompare (XFIXNUM (w->last_modified[CURRENT_DISP]),
+ BUF_MODIFF (b)) < 0
+ || buf_tick_arithcompare (XFIXNUM (w->last_facechange[CURRENT_DISP]),
+ BUF_FACECHANGE (b)) < 0)
regenerate_modeline (w);
skip_output = 1;
@@ -7457,14 +7462,15 @@
/* print %, * or hyphen, if buffer is read-only, modified or neither */
case '*':
str = (!NILP (b->read_only)
- ? "%" : ((BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
+ ? "%" : (buf_tick_arithcompare (BUF_MODIFF (b),
+ BUF_SAVE_MODIFF (b)) > 0
? "*" : "-"));
break;
/* print * or hyphen -- XEmacs change to allow a buffer to be
read-only but still indicate whether it is modified. */
case '+':
- str = ((BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
+ str = ((buf_tick_arithcompare (BUF_MODIFF (b), BUF_SAVE_MODIFF (b)) > 0)
? "*"
: (!NILP (b->read_only)
? "%"
@@ -7475,9 +7481,9 @@
modeline-format doc string. */
/* This differs from %* in that it ignores read-only-ness. */
case '&':
- str = ((BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
+ str = (buf_tick_arithcompare (BUF_MODIFF (b), BUF_SAVE_MODIFF (b)) > 0)
? "*"
- : "-");
+ : "-";
break;
/* print process status */
@@ -7840,7 +7846,8 @@
does redisplay will catch it pretty quickly we no longer
invalidate the cache if it is set. This greatly speeds up
dragging out regions with the mouse. */
- if (XFIXNUM (w->line_cache_last_updated) < BUF_MODIFF (b)
+ if (buf_tick_arithcompare (XFIXNUM (w->line_cache_last_updated),
+ BUF_MODIFF (b)) < 0
|| f->faces_changed
|| f->clip_changed)
{
diff -r 5aaa90258733 -r 5d1f8a39a8d0 src/undo.c
--- a/src/undo.c Sun Mar 10 14:06:13 2019 +0000
+++ b/src/undo.c Sun Mar 10 17:24:04 2019 +0000
@@ -85,7 +85,7 @@
if (hack_pending_boundary && NILP (pending_boundary))
pending_boundary = Fcons (Qnil, Qnil);
- if (BUF_MODIFF (b) <= BUF_SAVE_MODIFF (b))
+ if (buf_tick_arithcompare (BUF_MODIFF (b), BUF_SAVE_MODIFF (b)) <= 0)
{
/* Record that an unmodified buffer is about to be changed.
Record the file modification date so that when undoing this
diff -r 5aaa90258733 -r 5d1f8a39a8d0 src/window.c
--- a/src/window.c Sun Mar 10 14:06:13 2019 +0000
+++ b/src/window.c Sun Mar 10 17:24:04 2019 +0000
@@ -5126,8 +5126,10 @@
{
int retval;
- if (XFIXNUM (w->last_modified[CURRENT_DISP]) >= BUF_MODIFF (b)
- && XFIXNUM (w->last_facechange[CURRENT_DISP]) >= BUF_FACECHANGE (b))
+ if (buf_tick_arithcompare (XFIXNUM (w->last_modified[CURRENT_DISP]),
+ BUF_MODIFF (b)) >= 0
+ && buf_tick_arithcompare (XFIXNUM
(w->last_facechange[CURRENT_DISP]),
+ BUF_FACECHANGE (b)) >= 0)
{
new_point = point_at_center (w, CURRENT_DISP, 0, 0);
--
‘As I sat looking up at the Guinness ad, I could never figure out /
How your man stayed up on the surfboard after forty pints of stout’
(C. Moore)