Merge from trunk.
[bpt/emacs.git] / src / charset.h
index 53784bf..6d90792 100644 (file)
@@ -27,6 +27,8 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #ifndef EMACS_CHARSET_H
 #define EMACS_CHARSET_H
 
+#include <verify.h>
+
 /* Index to arguments of Fdefine_charset_internal.  */
 
 enum define_charset_arg_index
@@ -146,12 +148,12 @@ struct charset
   int id;
 
   /* Index to Vcharset_hash_table.  */
-  int hash_index;
+  ptrdiff_t hash_index;
 
   /* Dimension of the charset: 1, 2, 3, or 4.  */
   int dimension;
 
-  /* Byte code range of each dimension.  <code_space>[4N] is a mininum
+  /* Byte code range of each dimension.  <code_space>[4N] is a minimum
      byte code of the (N+1)th dimension, <code_space>[4N+1] is a
      maximum byte code of the (N+1)th dimension, <code_space>[4N+2] is
      (<code_space>[4N+1] - <code_space>[4N] + 1), <code_space>[4N+3]
@@ -197,14 +199,14 @@ struct charset
   /* The method for encoding/decoding characters of the charset.  */
   enum charset_method method;
 
-  /* Mininum and Maximum code points of the charset.  */
+  /* Minimum and Maximum code points of the charset.  */
   unsigned min_code, max_code;
 
   /* Offset value used by macros CODE_POINT_TO_INDEX and
       INDEX_TO_CODE_POINT. .  */
   unsigned char_index_offset;
 
-  /* Mininum and Maximum character codes of the charset.  If the
+  /* Minimum and Maximum character codes of the charset.  If the
      charset is compatible with ASCII, min_char is a minimum non-ASCII
      character of the charset.  If the method of charset is
      CHARSET_METHOD_OFFSET, even if the charset is unified, min_char
@@ -339,7 +341,7 @@ extern int emacs_mule_charset[256];
    number of the charset.  Otherwise, signal an error. */
 #define CHECK_CHARSET_GET_ID(x, id)                                    \
   do {                                                                 \
-    int idx;                                                           \
+    ptrdiff_t idx;                                                     \
                                                                        \
     if (! SYMBOLP (x) || (idx = CHARSET_SYMBOL_HASH_INDEX (x)) < 0)    \
       wrong_type_argument (Qcharsetp, (x));                            \
@@ -399,7 +401,7 @@ extern Lisp_Object Vchar_charset_set;
    ? decode_char ((charset), (code))                                   \
    : (charset)->method == CHARSET_METHOD_OFFSET                                \
    ? ((charset)->code_linear_p                                         \
-      ? (code) - (charset)->min_code + (charset)->code_offset          \
+      ? (int) ((code) - (charset)->min_code) + (charset)->code_offset  \
       : decode_char ((charset), (code)))                               \
    : (charset)->method == CHARSET_METHOD_MAP                           \
    ? (((charset)->code_linear_p                                                \
@@ -409,43 +411,35 @@ extern Lisp_Object Vchar_charset_set;
       : decode_char ((charset), (code)))                               \
    : decode_char ((charset), (code)))
 
-
-/* If CHARSET is a simple offset base charset, return it's offset,
-   otherwise return -1.  */
-#define CHARSET_OFFSET(charset)                                \
-  (((charset)->method == CHARSET_METHOD_OFFSET         \
-    && (charset)->code_linear_p                                \
-    && ! (charset)->unified_p)                         \
-   ? (charset)->code_offset - (charset)->min_code      \
-   : -1)
-
 extern Lisp_Object charset_work;
 
 /* Return a code point of CHAR in CHARSET.
    Try some optimization before calling encode_char.  */
 
-#define ENCODE_CHAR(charset, c)                                                 \
-  ((ASCII_CHAR_P (c) && (charset)->ascii_compatible_p)                  \
-   ? (c)                                                                \
-   : ((charset)->unified_p                                              \
-      || (charset)->method == CHARSET_METHOD_SUBSET                     \
-      || (charset)->method == CHARSET_METHOD_SUPERSET)                  \
-   ? encode_char ((charset), (c))                                       \
-   : ((c) < (charset)->min_char || (c) > (charset)->max_char)           \
-   ? (charset)->invalid_code                                            \
-   : (charset)->method == CHARSET_METHOD_OFFSET                                 \
-   ? ((charset)->code_linear_p                                          \
-      ? (c) - (charset)->code_offset + (charset)->min_code              \
-      : encode_char ((charset), (c)))                                   \
-   : (charset)->method == CHARSET_METHOD_MAP                            \
-   ? (((charset)->compact_codes_p                                       \
-       && CHAR_TABLE_P (CHARSET_ENCODER (charset)))                     \
-      ? (charset_work = CHAR_TABLE_REF (CHARSET_ENCODER (charset), (c)), \
-        (NILP (charset_work)                                            \
-         ? (charset)->invalid_code                                      \
-         : XFASTINT (charset_work)))                                    \
-      : encode_char ((charset), (c)))                                   \
-   : encode_char ((charset), (c)))
+#define ENCODE_CHAR(charset, c)                                                \
+  (verify_expr                                                         \
+   (sizeof (c) <= sizeof (int),                                                \
+    (ASCII_CHAR_P (c) && (charset)->ascii_compatible_p                 \
+     ? (unsigned) (c)                                                  \
+     : ((charset)->unified_p                                           \
+       || (charset)->method == CHARSET_METHOD_SUBSET                   \
+       || (charset)->method == CHARSET_METHOD_SUPERSET)                \
+     ? encode_char (charset, c)                                                \
+     : (c) < (charset)->min_char || (c) > (charset)->max_char          \
+     ? (charset)->invalid_code                                         \
+     : (charset)->method == CHARSET_METHOD_OFFSET                      \
+     ? ((charset)->code_linear_p                                       \
+       ? (unsigned) ((c) - (charset)->code_offset) + (charset)->min_code \
+       : encode_char (charset, c))                                     \
+     : (charset)->method == CHARSET_METHOD_MAP                         \
+     ? (((charset)->compact_codes_p                                    \
+        && CHAR_TABLE_P (CHARSET_ENCODER (charset)))                   \
+       ? (charset_work = CHAR_TABLE_REF (CHARSET_ENCODER (charset), c), \
+          (NILP (charset_work)                                         \
+           ? (charset)->invalid_code                                   \
+           : (unsigned) XFASTINT (charset_work)))                      \
+       : encode_char (charset, c))                                     \
+     : encode_char (charset, c))))
 
 
 /* Set to 1 when a charset map is loaded to warn that a buffer text