From: Paul Eggert Date: Wed, 4 Sep 2019 04:54:58 +0000 (-0700) Subject: Take last_per_buffer_idx private X-Git-Tag: emacs-27.0.90~1553^2~45 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=97cfda2638afc7fed6ac7e465c6fe927f428a932;p=emacs.git Take last_per_buffer_idx private This will simplify future changes. Turn the runtime check into an eassert, since it’s not needed in production. * src/buffer.c (last_per_buffer_idx): Now static. (valid_per_buffer_idx): New function. * src/buffer.h (PER_BUFFER_VALUE_P, SET_PER_BUFFER_VALUE_P): Use it. --- diff --git a/src/buffer.c b/src/buffer.c index 62a3d66c8b7..77e8b6bb779 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -105,7 +105,7 @@ static char buffer_permanent_local_flags[MAX_PER_BUFFER_VARS]; /* Number of per-buffer variables used. */ -int last_per_buffer_idx; +static int last_per_buffer_idx; static void call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay, bool after, Lisp_Object arg1, @@ -655,6 +655,12 @@ set_buffer_overlays_after (struct buffer *b, struct Lisp_Overlay *o) b->overlays_after = o; } +bool +valid_per_buffer_idx (int idx) +{ + return 0 <= idx && idx < last_per_buffer_idx; +} + /* Clone per-buffer values of buffer FROM. Buffer TO gets the same per-buffer values as FROM, with the diff --git a/src/buffer.h b/src/buffer.h index 2080a6f40b7..14de70c6482 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -1268,10 +1268,6 @@ buffer_window_count (struct buffer *b) Buffer-local Variables ***********************************************************************/ -/* Number of per-buffer variables used. */ - -extern int last_per_buffer_idx; - /* Return the offset in bytes of member VAR of struct buffer from the start of a buffer structure. */ @@ -1296,23 +1292,21 @@ extern int last_per_buffer_idx; #define PER_BUFFER_VAR_IDX(VAR) \ PER_BUFFER_IDX (PER_BUFFER_VAR_OFFSET (VAR)) +extern bool valid_per_buffer_idx (int); + /* Value is true if the variable with index IDX has a local value in buffer B. */ #define PER_BUFFER_VALUE_P(B, IDX) \ - (((IDX) < 0 || IDX >= last_per_buffer_idx) \ - ? (emacs_abort (), false) \ - : ((B)->local_flags[IDX] != 0)) + (eassert (valid_per_buffer_idx (IDX)), \ + (B)->local_flags[IDX]) /* Set whether per-buffer variable with index IDX has a buffer-local value in buffer B. VAL zero means it hasn't. */ #define SET_PER_BUFFER_VALUE_P(B, IDX, VAL) \ - do { \ - if ((IDX) < 0 || (IDX) >= last_per_buffer_idx) \ - emacs_abort (); \ - (B)->local_flags[IDX] = (VAL); \ - } while (false) + (eassert (valid_per_buffer_idx (IDX)), \ + (B)->local_flags[IDX] = (VAL)) /* Return the index value of the per-buffer variable at offset OFFSET in the buffer structure.