From 1c0a74936b61e1f7e662089126a0765e25bf2c29 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 14 Oct 2013 00:12:49 -0700 Subject: [PATCH] * lisp.h (bool_vector_size): New function. All uses of XBOOL_VECTOR (x)->size changed to bool_vector_size (x). * data.c (bool_vector_spare_mask, bool_vector_binop_driver) (Fbool_vector_not, Fbool_vector_count_matches_at): Remove uses of 'eassume' that should no longer be needed, because they are subsumed by the 'eassume' in bool_vector_size. --- src/ChangeLog | 9 +++++++++ src/category.h | 2 +- src/data.c | 24 ++++++++---------------- src/fns.c | 24 ++++++++++++------------ src/image.c | 4 ++-- src/lisp.h | 8 ++++++++ src/print.c | 9 ++++----- 7 files changed, 44 insertions(+), 36 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index b853f874e24..488313e4a1e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2013-10-14 Paul Eggert + + * lisp.h (bool_vector_size): New function. + All uses of XBOOL_VECTOR (x)->size changed to bool_vector_size (x). + * data.c (bool_vector_spare_mask, bool_vector_binop_driver) + (Fbool_vector_not, Fbool_vector_count_matches_at): + Remove uses of 'eassume' that should no longer be needed, + because they are subsumed by the 'eassume' in bool_vector_size. + 2013-10-12 Eli Zaretskii * image.c (GIFLIB_MAJOR, GIFLIB_MINOR, GIFLIB_RELEASE): Move back diff --git a/src/category.h b/src/category.h index 828dcd1f325..a2eaf010132 100644 --- a/src/category.h +++ b/src/category.h @@ -63,7 +63,7 @@ INLINE_HEADER_BEGIN #define XCATEGORY_SET XBOOL_VECTOR #define CATEGORY_SET_P(x) \ - (BOOL_VECTOR_P (x) && XBOOL_VECTOR (x)->size == 128) + (BOOL_VECTOR_P (x) && bool_vector_size (x) == 128) /* Return a new empty category set. */ #define MAKE_CATEGORY_SET (Fmake_bool_vector (make_number (128), Qnil)) diff --git a/src/data.c b/src/data.c index b4257243fb3..dea70ca42d6 100644 --- a/src/data.c +++ b/src/data.c @@ -2130,7 +2130,7 @@ or a byte-code object. IDX starts at 0. */) { int val; - if (idxval < 0 || idxval >= XBOOL_VECTOR (array)->size) + if (idxval < 0 || idxval >= bool_vector_size (array)) args_out_of_range (array, idx); val = (unsigned char) XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR]; @@ -2180,7 +2180,7 @@ bool-vector. IDX starts at 0. */) { int val; - if (idxval < 0 || idxval >= XBOOL_VECTOR (array)->size) + if (idxval < 0 || idxval >= bool_vector_size (array)) args_out_of_range (array, idx); val = (unsigned char) XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR]; @@ -2969,7 +2969,6 @@ lowercase l) for small endian machines. */) static bits_word bool_vector_spare_mask (ptrdiff_t nr_bits) { - eassume (nr_bits > 0); return (((bits_word) 1) << (nr_bits % BITS_PER_BITS_WORD)) - 1; } @@ -3005,8 +3004,7 @@ bool_vector_binop_driver (Lisp_Object op1, CHECK_BOOL_VECTOR (op1); CHECK_BOOL_VECTOR (op2); - nr_bits = min (XBOOL_VECTOR (op1)->size, - XBOOL_VECTOR (op2)->size); + nr_bits = min (bool_vector_size (op1), bool_vector_size (op2)); if (NILP (dest)) { @@ -3016,10 +3014,9 @@ bool_vector_binop_driver (Lisp_Object op1, else { CHECK_BOOL_VECTOR (dest); - nr_bits = min (nr_bits, XBOOL_VECTOR (dest)->size); + nr_bits = min (nr_bits, bool_vector_size (dest)); } - eassume (nr_bits >= 0); nr_words = ROUNDUP (nr_bits, BITS_PER_BITS_WORD) / BITS_PER_BITS_WORD; adata = (bits_word *) XBOOL_VECTOR (dest)->data; @@ -3172,21 +3169,19 @@ Return the destination vector. */) bits_word mword; CHECK_BOOL_VECTOR (a); - nr_bits = XBOOL_VECTOR (a)->size; + nr_bits = bool_vector_size (a); if (NILP (b)) b = Fmake_bool_vector (make_number (nr_bits), Qnil); else { CHECK_BOOL_VECTOR (b); - nr_bits = min (nr_bits, XBOOL_VECTOR (b)->size); + nr_bits = min (nr_bits, bool_vector_size (b)); } bdata = (bits_word *) XBOOL_VECTOR (b)->data; adata = (bits_word *) XBOOL_VECTOR (a)->data; - eassume (nr_bits >= 0); - for (i = 0; i < nr_bits / BITS_PER_BITS_WORD; i++) bdata[i] = ~adata[i]; @@ -3215,13 +3210,11 @@ A must be a bool vector. B is a generalized bool. */) CHECK_BOOL_VECTOR (a); - nr_bits = XBOOL_VECTOR (a)->size; + nr_bits = bool_vector_size (a); count = 0; match = NILP (b) ? -1 : 0; adata = (bits_word *) XBOOL_VECTOR (a)->data; - eassume (nr_bits >= 0); - for (i = 0; i < nr_bits / BITS_PER_BITS_WORD; ++i) count += popcount_bits_word (adata[i] ^ match); @@ -3256,13 +3249,12 @@ index into the vector. */) CHECK_BOOL_VECTOR (a); CHECK_NATNUM (i); - nr_bits = XBOOL_VECTOR (a)->size; + nr_bits = bool_vector_size (a); if (XFASTINT (i) > nr_bits) /* Allow one past the end for convenience */ args_out_of_range (a, i); adata = (bits_word *) XBOOL_VECTOR (a)->data; - eassume (nr_bits >= 0); nr_words = ROUNDUP (nr_bits, BITS_PER_BITS_WORD) / BITS_PER_BITS_WORD; pos = XFASTINT (i) / BITS_PER_BITS_WORD; diff --git a/src/fns.c b/src/fns.c index 1ee0a758fc2..cb439024c08 100644 --- a/src/fns.c +++ b/src/fns.c @@ -114,7 +114,7 @@ To get the number of bytes, use `string-bytes'. */) else if (CHAR_TABLE_P (sequence)) XSETFASTINT (val, MAX_CHAR); else if (BOOL_VECTOR_P (sequence)) - XSETFASTINT (val, XBOOL_VECTOR (sequence)->size); + XSETFASTINT (val, bool_vector_size (sequence)); else if (COMPILEDP (sequence)) XSETFASTINT (val, ASIZE (sequence) & PSEUDOVECTOR_SIZE_MASK); else if (CONSP (sequence)) @@ -437,7 +437,7 @@ with the original. */) { Lisp_Object val; ptrdiff_t size_in_chars - = ((XBOOL_VECTOR (arg)->size + BOOL_VECTOR_BITS_PER_CHAR - 1) + = ((bool_vector_size (arg) + BOOL_VECTOR_BITS_PER_CHAR - 1) / BOOL_VECTOR_BITS_PER_CHAR); val = Fmake_bool_vector (Flength (arg), Qnil); @@ -540,7 +540,7 @@ concat (ptrdiff_t nargs, Lisp_Object *args, if (! ASCII_CHAR_P (c) && ! CHAR_BYTE8_P (c)) some_multibyte = 1; } - else if (BOOL_VECTOR_P (this) && XBOOL_VECTOR (this)->size > 0) + else if (BOOL_VECTOR_P (this) && bool_vector_size (this) > 0) wrong_type_argument (Qintegerp, Faref (this, make_number (0))); else if (CONSP (this)) for (; CONSP (this); this = XCDR (this)) @@ -2070,11 +2070,11 @@ internal_equal (Lisp_Object o1, Lisp_Object o2, int depth, bool props) /* Boolvectors are compared much like strings. */ if (BOOL_VECTOR_P (o1)) { - if (XBOOL_VECTOR (o1)->size != XBOOL_VECTOR (o2)->size) + EMACS_INT size = bool_vector_size (o1); + if (size != bool_vector_size (o2)) return 0; if (memcmp (XBOOL_VECTOR (o1)->data, XBOOL_VECTOR (o2)->data, - ((XBOOL_VECTOR (o1)->size - + BOOL_VECTOR_BITS_PER_CHAR - 1) + ((size + BOOL_VECTOR_BITS_PER_CHAR - 1) / BOOL_VECTOR_BITS_PER_CHAR))) return 0; return 1; @@ -2166,10 +2166,9 @@ ARRAY is a vector, string, char-table, or bool-vector. */) } else if (BOOL_VECTOR_P (array)) { - register unsigned char *p = XBOOL_VECTOR (array)->data; - size = - ((XBOOL_VECTOR (array)->size + BOOL_VECTOR_BITS_PER_CHAR - 1) - / BOOL_VECTOR_BITS_PER_CHAR); + unsigned char *p = XBOOL_VECTOR (array)->data; + size = ((bool_vector_size (array) + BOOL_VECTOR_BITS_PER_CHAR - 1) + / BOOL_VECTOR_BITS_PER_CHAR); if (size) { @@ -4188,11 +4187,12 @@ sxhash_vector (Lisp_Object vec, int depth) static EMACS_UINT sxhash_bool_vector (Lisp_Object vec) { - EMACS_UINT hash = XBOOL_VECTOR (vec)->size; + EMACS_INT size = bool_vector_size (vec); + EMACS_UINT hash = size; int i, n; n = min (SXHASH_MAX_LEN, - ((XBOOL_VECTOR (vec)->size + BOOL_VECTOR_BITS_PER_CHAR - 1) + ((size + BOOL_VECTOR_BITS_PER_CHAR - 1) / BOOL_VECTOR_BITS_PER_CHAR)); for (i = 0; i < n; ++i) hash = sxhash_combine (hash, XBOOL_VECTOR (vec)->data[i]); diff --git a/src/image.c b/src/image.c index bb3290a89f6..2b07b83b816 100644 --- a/src/image.c +++ b/src/image.c @@ -2456,7 +2456,7 @@ xbm_image_p (Lisp_Object object) } else if (BOOL_VECTOR_P (elt)) { - if (XBOOL_VECTOR (elt)->size < width) + if (bool_vector_size (elt) < width) return 0; } else @@ -2471,7 +2471,7 @@ xbm_image_p (Lisp_Object object) } else if (BOOL_VECTOR_P (data)) { - if (XBOOL_VECTOR (data)->size / height < width) + if (bool_vector_size (data) / height < width) return 0; } else diff --git a/src/lisp.h b/src/lisp.h index e4a2caa1083..d25904be379 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -1184,6 +1184,14 @@ struct Lisp_Bool_Vector unsigned char data[FLEXIBLE_ARRAY_MEMBER]; }; +INLINE EMACS_INT +bool_vector_size (Lisp_Object a) +{ + EMACS_INT size = XBOOL_VECTOR (a)->size; + eassume (0 <= size); + return size; +} + /* Some handy constants for calculating sizes and offsets, mostly of vectorlike objects. */ diff --git a/src/print.c b/src/print.c index 4ad34534da3..04552be906f 100644 --- a/src/print.c +++ b/src/print.c @@ -1704,15 +1704,14 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag) int len; unsigned char c; struct gcpro gcpro1; - ptrdiff_t size_in_chars - = ((XBOOL_VECTOR (obj)->size + BOOL_VECTOR_BITS_PER_CHAR - 1) - / BOOL_VECTOR_BITS_PER_CHAR); - + EMACS_INT size = bool_vector_size (obj); + ptrdiff_t size_in_chars = ((size + BOOL_VECTOR_BITS_PER_CHAR - 1) + / BOOL_VECTOR_BITS_PER_CHAR); GCPRO1 (obj); PRINTCHAR ('#'); PRINTCHAR ('&'); - len = sprintf (buf, "%"pI"d", XBOOL_VECTOR (obj)->size); + len = sprintf (buf, "%"pI"d", size); strout (buf, len, len, printcharfun); PRINTCHAR ('\"'); -- 2.39.2