Fix minor problems found by static checking.
[bpt/emacs.git] / src / lisp.h
index 688c89c..3773398 100644 (file)
@@ -31,6 +31,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <limits.h>
 
 #include <intprops.h>
+#include <verify.h>
 
 INLINE_HEADER_BEGIN
 
@@ -63,6 +64,11 @@ typedef unsigned int EMACS_UINT;
 # endif
 #endif
 
+/* An unsigned integer type representing a fixed-length bit sequence,
+   suitable for words in a Lisp bool vector.  */
+typedef size_t bits_word;
+#define BITS_WORD_MAX SIZE_MAX
+
 /* Number of bits in some machine integer types.  */
 enum
   {
@@ -70,6 +76,7 @@ enum
     BITS_PER_SHORT     = CHAR_BIT * sizeof (short),
     BITS_PER_INT       = CHAR_BIT * sizeof (int),
     BITS_PER_LONG      = CHAR_BIT * sizeof (long int),
+    BITS_PER_BITS_WORD = CHAR_BIT * sizeof (bits_word),
     BITS_PER_EMACS_INT = CHAR_BIT * sizeof (EMACS_INT)
   };
 
@@ -107,11 +114,12 @@ typedef EMACS_UINT uprintmax_t;
 
 /* Extra internal type checking?  */
 
-/* Define an Emacs version of 'assert (COND)', since some
-   system-defined 'assert's are flaky.  COND should be free of side
-   effects; it may or may not be evaluated.  */
+/* Define an Emacs version of 'assert (COND)'.  COND should be free of
+   side effects; it may be evaluated zero or more times.  If COND is false,
+   Emacs reliably crashes if ENABLE_CHECKING is defined and behavior
+   is undefined if not.  The compiler may assume COND while optimizing.  */
 #ifndef ENABLE_CHECKING
-# define eassert(X) ((void) (0 && (X))) /* Check that X compiles.  */
+# define eassert(cond) assume (cond)
 #else /* ENABLE_CHECKING */
 
 extern _Noreturn void die (const char *, const char *, int);
@@ -128,16 +136,10 @@ extern bool suppress_checking EXTERNALLY_VISIBLE;
 
 # define eassert(cond)                                         \
    (suppress_checking || (cond)                                \
-    ? (void) 0                                                 \
+    ? assume (cond)                                            \
     : die (# cond, __FILE__, __LINE__))
 #endif /* ENABLE_CHECKING */
 
-/* When checking is enabled, identical to eassert.  When checking is
- * disabled, instruct the compiler (when the compiler has such
- * capability) to assume that cond is true and optimize
- * accordingly.  */
-#define eassert_and_assume(cond) (eassert (cond), assume (cond))
-
 \f
 /* Use the configure flag --enable-check-lisp-object-type to make
    Lisp_Object use a struct type instead of the default int.  The flag
@@ -1145,9 +1147,9 @@ struct Lisp_Vector
       /* ...but sometimes there is also a pointer internally used in
         vector allocation code.  Usually you don't want to touch this.  */
       struct Lisp_Vector *next;
-      
+
       /* We can't use FLEXIBLE_ARRAY_MEMBER here.  */
-      Lisp_Object contents[1]; 
+      Lisp_Object contents[1];
     } u;
   };
 
@@ -3388,7 +3390,6 @@ extern Lisp_Object Qimage, Qtext, Qboth, Qboth_horiz, Qtext_image_horiz;
 extern Lisp_Object Qspace, Qcenter, QCalign_to;
 extern Lisp_Object Qbar, Qhbar, Qbox, Qhollow;
 extern Lisp_Object Qleft_margin, Qright_margin;
-extern Lisp_Object Qglyphless_char;
 extern Lisp_Object QCdata, QCfile;
 extern Lisp_Object QCmap;
 extern Lisp_Object Qrisky_local_variable;
@@ -3904,6 +3905,7 @@ extern bool detect_input_pending_run_timers (bool);
 extern void safe_run_hooks (Lisp_Object);
 extern void cmd_error_internal (Lisp_Object, const char *);
 extern Lisp_Object command_loop_1 (void);
+extern Lisp_Object read_menu_command (void);
 extern Lisp_Object recursive_edit_1 (void);
 extern void record_auto_save (void);
 extern void force_auto_save_soon (void);
@@ -4090,9 +4092,9 @@ extern _Noreturn void emacs_abort (void) NO_INLINE;
 extern int emacs_open (const char *, int, int);
 extern int emacs_pipe (int[2]);
 extern int emacs_close (int);
-extern ptrdiff_t emacs_read (int, char *, ptrdiff_t);
-extern ptrdiff_t emacs_write (int, const char *, ptrdiff_t);
-extern ptrdiff_t emacs_write_sig (int, char const *, ptrdiff_t);
+extern ptrdiff_t emacs_read (int, void *, ptrdiff_t);
+extern ptrdiff_t emacs_write (int, void const *, ptrdiff_t);
+extern ptrdiff_t emacs_write_sig (int, void const *, ptrdiff_t);
 extern void emacs_perror (char const *);
 
 extern void unlock_all_files (void);
@@ -4371,36 +4373,6 @@ functionp (Lisp_Object object)
     return 0;
 }
 
-INLINE uint16_t
-swap16 (uint16_t val)
-{
-    return (val << 8) | (val & 0xFF);
-}
-
-INLINE uint32_t
-swap32 (uint32_t val)
-{
-  uint32_t low = swap16 (val & 0xFFFF);
-  uint32_t high = swap16 (val >> 16);
-  return (low << 16) | high;
-}
-
-#ifdef UINT64_MAX
-INLINE uint64_t
-swap64 (uint64_t val)
-{
-  uint64_t low = swap32 (val & 0xFFFFFFFF);
-  uint64_t high = swap32 (val >> 32);
-  return (low << 32) | high;
-}
-#endif
-
-#if ((SIZE_MAX >> 31) >> 1) & 1
-# define BITS_PER_SIZE_T 64
-#else
-# define BITS_PER_SIZE_T 32
-#endif
-
 /* Round x to the next multiple of y.  Does not overflow.  Evaluates
    arguments repeatedly.  */
 #define ROUNDUP(x,y) ((y)*((x)/(y) + ((x)%(y)!=0)))