]> code.delx.au - gnu-emacs/blobdiff - src/coding.c
Merge emacs-25 into master (using imerge)
[gnu-emacs] / src / coding.c
index 54811588c6a015e9c34dd1ab4d574810e4050148..85b97ce61745e1f8a49ba762d33733662f3f1762 100644 (file)
@@ -297,8 +297,6 @@ encode_coding_XXX (struct coding_system *coding)
 #include "ccl.h"
 #include "composite.h"
 #include "coding.h"
-#include "window.h"
-#include "frame.h"
 #include "termhooks.h"
 
 Lisp_Object Vcoding_system_hash_table;
@@ -350,7 +348,8 @@ static Lisp_Object Vbig5_coding_system;
 #define CODING_ISO_BOL(coding) \
   ((coding)->spec.iso_2022.bol)
 #define CODING_ISO_INVOKED_CHARSET(coding, plane)      \
-  CODING_ISO_DESIGNATION ((coding), CODING_ISO_INVOCATION ((coding), (plane)))
+  (CODING_ISO_INVOCATION (coding, plane) < 0 ? -1      \
+   : CODING_ISO_DESIGNATION (coding, CODING_ISO_INVOCATION (coding, plane)))
 #define CODING_ISO_CMP_STATUS(coding)  \
   (&(coding)->spec.iso_2022.cmp_status)
 #define CODING_ISO_EXTSEGMENT_LEN(coding)      \
@@ -1009,11 +1008,12 @@ coding_change_destination (struct coding_system *coding)
 static void
 coding_alloc_by_realloc (struct coding_system *coding, ptrdiff_t bytes)
 {
-  if (STRING_BYTES_BOUND - coding->dst_bytes < bytes)
+  ptrdiff_t newbytes;
+  if (INT_ADD_WRAPV (coding->dst_bytes, bytes, &newbytes)
+      || SIZE_MAX < newbytes)
     string_overflow ();
-  coding->destination = xrealloc (coding->destination,
-                                 coding->dst_bytes + bytes);
-  coding->dst_bytes += bytes;
+  coding->destination = xrealloc (coding->destination, newbytes);
+  coding->dst_bytes = newbytes;
 }
 
 static void
@@ -4294,6 +4294,9 @@ encode_invocation_designation (struct charset *charset,
          else
            ENCODE_LOCKING_SHIFT_3;
          break;
+
+       default:
+         break;
        }
     }
 
@@ -5978,6 +5981,15 @@ raw_text_coding_system (Lisp_Object coding_system)
          : AREF (raw_text_eol_type, 2));
 }
 
+/* Return true if CODING corresponds to raw-text coding-system.  */
+
+bool
+raw_text_coding_system_p (struct coding_system *coding)
+{
+  return (coding->decoder == decode_coding_raw_text
+         && coding->encoder == encode_coding_raw_text) ? true : false;
+}
+
 
 /* If CODING_SYSTEM doesn't specify end-of-line format, return one of
    the subsidiary that has the same eol-spec as PARENT (if it is not
@@ -5991,6 +6003,8 @@ coding_inherit_eol_type (Lisp_Object coding_system, Lisp_Object parent)
 
   if (NILP (coding_system))
     coding_system = Qraw_text;
+  else
+    CHECK_CODING_SYSTEM (coding_system);
   spec = CODING_SYSTEM_SPEC (coding_system);
   eol_type = AREF (spec, 2);
   if (VECTORP (eol_type))
@@ -6001,6 +6015,7 @@ coding_inherit_eol_type (Lisp_Object coding_system, Lisp_Object parent)
        {
          Lisp_Object parent_spec;
 
+         CHECK_CODING_SYSTEM (parent);
          parent_spec = CODING_SYSTEM_SPEC (parent);
          parent_eol_type = AREF (parent_spec, 2);
          if (VECTORP (parent_eol_type))
@@ -7034,14 +7049,12 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
              if ((dst_end - dst) / MAX_MULTIBYTE_LENGTH < to_nchars)
                {
                  eassert (growable_destination (coding));
-                 if (((min (PTRDIFF_MAX, SIZE_MAX) - (buf_end - buf))
-                      / MAX_MULTIBYTE_LENGTH)
-                     < to_nchars)
+                 ptrdiff_t dst_size;
+                 if (INT_MULTIPLY_WRAPV (to_nchars, MAX_MULTIBYTE_LENGTH,
+                                         &dst_size)
+                     || INT_ADD_WRAPV (buf_end - buf, dst_size, &dst_size))
                    memory_full (SIZE_MAX);
-                 dst = alloc_destination (coding,
-                                          buf_end - buf
-                                          + MAX_MULTIBYTE_LENGTH * to_nchars,
-                                          dst);
+                 dst = alloc_destination (coding, dst_size, dst);
                  if (EQ (coding->src_object, coding->dst_object))
                    {
                      coding_set_source (coding);
@@ -7282,6 +7295,8 @@ produce_annotation (struct coding_system *coding, ptrdiff_t pos)
              case CODING_ANNOTATE_CHARSET_MASK:
                produce_charset (coding, charbuf, pos);
                break;
+             default:
+               break;
              }
          charbuf += len;
        }
@@ -7823,9 +7838,7 @@ static void
 code_conversion_restore (Lisp_Object arg)
 {
   Lisp_Object current, workbuf;
-  struct gcpro gcpro1;
 
-  GCPRO1 (arg);
   current = XCAR (arg);
   workbuf = XCDR (arg);
   if (! NILP (workbuf))
@@ -7836,7 +7849,6 @@ code_conversion_restore (Lisp_Object arg)
        Fkill_buffer (workbuf);
     }
   set_buffer_internal (XBUFFER (current));
-  UNGCPRO;
 }
 
 Lisp_Object
@@ -8108,16 +8120,12 @@ decode_coding_object (struct coding_system *coding,
 
   if (! NILP (CODING_ATTR_POST_READ (attrs)))
     {
-      struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
       ptrdiff_t prev_Z = Z, prev_Z_BYTE = Z_BYTE;
       Lisp_Object val;
 
       TEMP_SET_PT_BOTH (coding->dst_pos, coding->dst_pos_byte);
-      GCPRO5 (coding->src_object, coding->dst_object, src_object, dst_object,
-             old_deactivate_mark);
       val = safe_call1 (CODING_ATTR_POST_READ (attrs),
                        make_number (coding->produced_char));
-      UNGCPRO;
       CHECK_NATNUM (val);
       coding->produced_char += Z - prev_Z;
       coding->produced += Z_BYTE - prev_Z_BYTE;
@@ -8245,15 +8253,8 @@ encode_coding_object (struct coding_system *coding,
          set_buffer_internal (XBUFFER (coding->src_object));
        }
 
-      {
-       struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
-
-       GCPRO5 (coding->src_object, coding->dst_object, src_object, dst_object,
-               old_deactivate_mark);
-       safe_call2 (CODING_ATTR_PRE_WRITE (attrs),
-                   make_number (BEG), make_number (Z));
-       UNGCPRO;
-      }
+      safe_call2 (CODING_ATTR_PRE_WRITE (attrs),
+                 make_number (BEG), make_number (Z));
       if (XBUFFER (coding->src_object) != current_buffer)
        kill_src_buffer = 1;
       coding->src_object = Fcurrent_buffer ();
@@ -8291,7 +8292,11 @@ encode_coding_object (struct coding_system *coding,
        }
     }
   else
-    code_conversion_save (0, 0);
+    {
+      code_conversion_save (0, 0);
+      coding->src_pos = from;
+      coding->src_pos_byte = from_byte;
+    }
 
   if (BUFFERP (dst_object))
     {
@@ -9795,7 +9800,7 @@ DEFUN ("find-operation-coding-system", Ffind_operation_coding_system,
        doc: /* Choose a coding system for an operation based on the target name.
 The value names a pair of coding systems: (DECODING-SYSTEM . ENCODING-SYSTEM).
 DECODING-SYSTEM is the coding system to use for decoding
-\(in case OPERATION does decoding), and ENCODING-SYSTEM is the coding system
+(in case OPERATION does decoding), and ENCODING-SYSTEM is the coding system
 for encoding (in case OPERATION does encoding).
 
 The first argument OPERATION specifies an I/O primitive:
@@ -10818,18 +10823,11 @@ syms_of_coding (void)
   /* Target SERVICE is the fourth argument.  */
   Fput (Qopen_network_stream, Qtarget_idx, make_number (3));
 
-  DEFSYM (Qcoding_system, "coding-system");
-  DEFSYM (Qcoding_aliases, "coding-aliases");
-
-  DEFSYM (Qeol_type, "eol-type");
   DEFSYM (Qunix, "unix");
   DEFSYM (Qdos, "dos");
   DEFSYM (Qmac, "mac");
 
   DEFSYM (Qbuffer_file_coding_system, "buffer-file-coding-system");
-  DEFSYM (Qpost_read_conversion, "post-read-conversion");
-  DEFSYM (Qpre_write_conversion, "pre-write-conversion");
-  DEFSYM (Qdefault_char, "default-char");
   DEFSYM (Qundecided, "undecided");
   DEFSYM (Qno_conversion, "no-conversion");
   DEFSYM (Qraw_text, "raw-text");
@@ -10863,10 +10861,6 @@ syms_of_coding (void)
   DEFSYM (Qtranslation_table, "translation-table");
   Fput (Qtranslation_table, Qchar_table_extra_slots, make_number (2));
   DEFSYM (Qtranslation_table_id, "translation-table-id");
-  DEFSYM (Qtranslation_table_for_decode, "translation-table-for-decode");
-  DEFSYM (Qtranslation_table_for_encode, "translation-table-for-encode");
-
-  DEFSYM (Qvalid_codes, "valid-codes");
 
   /* Coding system emacs-mule and raw-text are for converting only
      end-of-line format.  */
@@ -11054,7 +11048,7 @@ conversion.  */);
 
   DEFVAR_BOOL ("inhibit-eol-conversion", inhibit_eol_conversion,
               doc: /*
-*Non-nil means always inhibit code conversion of end-of-line format.
+Non-nil means always inhibit code conversion of end-of-line format.
 See info node `Coding Systems' and info node `Text and Binary' concerning
 such conversion.  */);
   inhibit_eol_conversion = 0;
@@ -11122,33 +11116,34 @@ See also the function `find-operation-coding-system'.  */);
 
   DEFVAR_LISP ("locale-coding-system", Vlocale_coding_system,
               doc: /* Coding system to use with system messages.
-Also used for decoding keyboard input on X Window system.  */);
+Also used for decoding keyboard input on X Window system, and for
+encoding standard output and error streams.  */);
   Vlocale_coding_system = Qnil;
 
   /* The eol mnemonics are reset in startup.el system-dependently.  */
   DEFVAR_LISP ("eol-mnemonic-unix", eol_mnemonic_unix,
               doc: /*
-*String displayed in mode line for UNIX-like (LF) end-of-line format.  */);
+String displayed in mode line for UNIX-like (LF) end-of-line format.  */);
   eol_mnemonic_unix = build_pure_c_string (":");
 
   DEFVAR_LISP ("eol-mnemonic-dos", eol_mnemonic_dos,
               doc: /*
-*String displayed in mode line for DOS-like (CRLF) end-of-line format.  */);
+String displayed in mode line for DOS-like (CRLF) end-of-line format.  */);
   eol_mnemonic_dos = build_pure_c_string ("\\");
 
   DEFVAR_LISP ("eol-mnemonic-mac", eol_mnemonic_mac,
               doc: /*
-*String displayed in mode line for MAC-like (CR) end-of-line format.  */);
+String displayed in mode line for MAC-like (CR) end-of-line format.  */);
   eol_mnemonic_mac = build_pure_c_string ("/");
 
   DEFVAR_LISP ("eol-mnemonic-undecided", eol_mnemonic_undecided,
               doc: /*
-*String displayed in mode line when end-of-line format is not yet determined.  */);
+String displayed in mode line when end-of-line format is not yet determined.  */);
   eol_mnemonic_undecided = build_pure_c_string (":");
 
   DEFVAR_LISP ("enable-character-translation", Venable_character_translation,
               doc: /*
-*Non-nil enables character translation while encoding and decoding.  */);
+Non-nil enables character translation while encoding and decoding.  */);
   Venable_character_translation = Qt;
 
   DEFVAR_LISP ("standard-translation-table-for-decode",
@@ -11180,7 +11175,7 @@ the cdr part is used for encoding a text to be sent to a process.  */);
 Table of extra Latin codes in the range 128..159 (inclusive).
 This is a vector of length 256.
 If Nth element is non-nil, the existence of code N in a file
-\(or output of subprocess) doesn't prevent it to be detected as
+(or output of subprocess) doesn't prevent it to be detected as
 a coding system of ISO 2022 variant which has a flag
 `accept-latin-extra-code' t (e.g. iso-latin-1) on reading a file
 or reading output of a subprocess.
@@ -11271,15 +11266,15 @@ internal character representation.  */);
 
   Lisp_Object plist[] =
     {
-      intern_c_string (":name"),
+      QCname,
       args[coding_arg_name] = Qno_conversion,
-      intern_c_string (":mnemonic"),
+      QCmnemonic,
       args[coding_arg_mnemonic] = make_number ('='),
       intern_c_string (":coding-type"),
       args[coding_arg_coding_type] = Qraw_text,
-      intern_c_string (":ascii-compatible-p"),
+      QCascii_compatible_p,
       args[coding_arg_ascii_compatible_p] = Qt,
-      intern_c_string (":default-char"),
+      QCdefault_char,
       args[coding_arg_default_char] = make_number (0),
       intern_c_string (":for-unibyte"),
       args[coding_arg_for_unibyte] = Qt,