emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r111954: Coding system support cleanu


From: Dmitry Antipov
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r111954: Coding system support cleanup and minor refactoring.
Date: Wed, 06 Mar 2013 15:26:30 +0400
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 111954
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Wed 2013-03-06 15:26:30 +0400
message:
  Coding system support cleanup and minor refactoring.
  * coding.h (enum coding_result_code): Remove
  CODING_RESULT_INCONSISTENT_EOL and CODING_RESULT_INSUFFICIENT_MEM.
  (toplevel): Remove unused CODING_MODE_INHIBIT_INCONSISTENT_EOL.
  (CODING_MODE_LAST_BLOCK, CODING_MODE_SELECTIVE_DISPLAY)
  (CODING_MODE_DIRECTION, CODING_MODE_FIXED_DESTINATION)
  (CODING_MODE_SAFE_ENCODING): Rearrange bit values.
  (decode_coding_region, encode_coding_region, decode_coding_string):
  Remove unused compatibility macros.
  * coding.c (Qinconsistent_eol, Qinsufficient_memory): Remove.
  (record_conversion_result): Adjust user.
  (syms_of_coding): Likewise.
  (ALLOC_CONVERSION_WORK_AREA): Use SAFE_ALLOCA.
  (decode_coding, encode_coding): Add USE_SAFE_ALLOCA and SAFE_FREE.
  (decode_coding_object): Simplify since xrealloc never returns NULL.
  Add eassert.
modified:
  src/ChangeLog
  src/coding.c
  src/coding.h
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-03-06 08:01:47 +0000
+++ b/src/ChangeLog     2013-03-06 11:26:30 +0000
@@ -1,3 +1,22 @@
+2013-03-06  Dmitry Antipov  <address@hidden>
+
+       Coding system support cleanup and minor refactoring.
+       * coding.h (enum coding_result_code): Remove
+       CODING_RESULT_INCONSISTENT_EOL and CODING_RESULT_INSUFFICIENT_MEM.
+       (toplevel): Remove unused CODING_MODE_INHIBIT_INCONSISTENT_EOL.
+       (CODING_MODE_LAST_BLOCK, CODING_MODE_SELECTIVE_DISPLAY)
+       (CODING_MODE_DIRECTION, CODING_MODE_FIXED_DESTINATION)
+       (CODING_MODE_SAFE_ENCODING): Rearrange bit values.
+       (decode_coding_region, encode_coding_region, decode_coding_string):
+       Remove unused compatibility macros.
+       * coding.c (Qinconsistent_eol, Qinsufficient_memory): Remove.
+       (record_conversion_result): Adjust user.
+       (syms_of_coding): Likewise.
+       (ALLOC_CONVERSION_WORK_AREA): Use SAFE_ALLOCA.
+       (decode_coding, encode_coding): Add USE_SAFE_ALLOCA and SAFE_FREE.
+       (decode_coding_object): Simplify since xrealloc never returns NULL.
+       Add eassert.
+
 2013-03-06  Paul Eggert  <address@hidden>
 
        Fix a build failure on OpenBSD 4.x and MirBSD (Bug#13881).

=== modified file 'src/coding.c'
--- a/src/coding.c      2013-02-13 04:31:09 +0000
+++ b/src/coding.c      2013-03-06 11:26:30 +0000
@@ -322,8 +322,7 @@
 Lisp_Object Qstart_process, Qopen_network_stream;
 static Lisp_Object Qtarget_idx;
 
-static Lisp_Object Qinsufficient_source, Qinconsistent_eol, Qinvalid_source;
-static Lisp_Object Qinterrupted, Qinsufficient_memory;
+static Lisp_Object Qinsufficient_source, Qinvalid_source, Qinterrupted;
 
 /* If a symbol has this property, evaluate the value to define the
    symbol as a coding system.  */
@@ -820,18 +819,12 @@
     case CODING_RESULT_INSUFFICIENT_SRC:
       Vlast_code_conversion_error = Qinsufficient_source;
       break;
-    case CODING_RESULT_INCONSISTENT_EOL:
-      Vlast_code_conversion_error = Qinconsistent_eol;
-      break;
     case CODING_RESULT_INVALID_SRC:
       Vlast_code_conversion_error = Qinvalid_source;
       break;
     case CODING_RESULT_INTERRUPT:
       Vlast_code_conversion_error = Qinterrupted;
       break;
-    case CODING_RESULT_INSUFFICIENT_MEM:
-      Vlast_code_conversion_error = Qinsufficient_memory;
-      break;
     case CODING_RESULT_INSUFFICIENT_DST:
       /* Don't record this error in Vlast_code_conversion_error
         because it happens just temporarily and is resolved when the
@@ -6884,22 +6877,8 @@
 
 #define ALLOC_CONVERSION_WORK_AREA(coding)                             \
   do {                                                                 \
-    int size = CHARBUF_SIZE;                                           \
-                                                                       \
-    coding->charbuf = NULL;                                            \
-    while (size > 1024)                                                        
\
-      {                                                                        
\
-       coding->charbuf = alloca (sizeof (int) * size);                 \
-       if (coding->charbuf)                                            \
-         break;                                                        \
-       size >>= 1;                                                     \
-      }                                                                        
\
-    if (! coding->charbuf)                                             \
-      {                                                                        
\
-       record_conversion_result (coding, CODING_RESULT_INSUFFICIENT_MEM); \
-       return;                                                         \
-      }                                                                        
\
-    coding->charbuf_size = size;                                       \
+    coding->charbuf = SAFE_ALLOCA (CHARBUF_SIZE * sizeof (int));       \
+    coding->charbuf_size = CHARBUF_SIZE;                               \
   } while (0)
 
 
@@ -6968,6 +6947,8 @@
   int carryover;
   int i;
 
+  USE_SAFE_ALLOCA;
+
   if (BUFFERP (coding->src_object)
       && coding->src_pos > 0
       && coding->src_pos < GPT
@@ -7090,6 +7071,8 @@
       bset_undo_list (current_buffer, undo_list);
       record_insert (coding->dst_pos, coding->produced_char);
     }
+
+  SAFE_FREE ();
 }
 
 
@@ -7373,6 +7356,8 @@
   int max_lookup;
   struct ccl_spec cclspec;
 
+  USE_SAFE_ALLOCA;
+
   attrs = CODING_ID_ATTRS (coding->id);
   if (coding->encoder == encode_coding_raw_text)
     translation_table = Qnil, max_lookup = 0;
@@ -7407,6 +7392,8 @@
 
   if (BUFFERP (coding->dst_object) && coding->produced_char > 0)
     insert_from_gap (coding->produced_char, coding->produced);
+
+  SAFE_FREE ();
 }
 
 
@@ -7695,14 +7682,8 @@
       set_buffer_internal (XBUFFER (coding->dst_object));
       if (dst_bytes < coding->produced)
        {
+         eassert (coding->produced > 0);
          destination = xrealloc (destination, coding->produced);
-         if (! destination)
-           {
-             record_conversion_result (coding,
-                                       CODING_RESULT_INSUFFICIENT_MEM);
-             unbind_to (count, Qnil);
-             return;
-           }
          if (BEGV < GPT && GPT < BEGV + coding->produced_char)
            move_gap_both (BEGV, BEGV_BYTE);
          memcpy (destination, BEGV_ADDR, coding->produced);
@@ -10408,10 +10389,8 @@
        intern_c_string ("coding-category-undecided"));
 
   DEFSYM (Qinsufficient_source, "insufficient-source");
-  DEFSYM (Qinconsistent_eol, "inconsistent-eol");
   DEFSYM (Qinvalid_source, "invalid-source");
   DEFSYM (Qinterrupted, "interrupted");
-  DEFSYM (Qinsufficient_memory, "insufficient-memory");
   DEFSYM (Qcoding_system_define_form, "coding-system-define-form");
 
   defsubr (&Scoding_system_p);

=== modified file 'src/coding.h'
--- a/src/coding.h      2013-01-02 16:13:04 +0000
+++ b/src/coding.h      2013-03-06 11:26:30 +0000
@@ -272,37 +272,31 @@
     CODING_RESULT_SUCCESS,
     CODING_RESULT_INSUFFICIENT_SRC,
     CODING_RESULT_INSUFFICIENT_DST,
-    CODING_RESULT_INCONSISTENT_EOL,
     CODING_RESULT_INVALID_SRC,
-    CODING_RESULT_INTERRUPT,
-    CODING_RESULT_INSUFFICIENT_MEM
+    CODING_RESULT_INTERRUPT
   };
 
 
 /* Macros used for the member `mode' of the struct coding_system.  */
 
-/* If set, recover the original CR or LF of the already decoded text
-   when the decoding routine encounters an inconsistent eol format.  */
-#define CODING_MODE_INHIBIT_INCONSISTENT_EOL   0x01
-
 /* If set, the decoding/encoding routines treat the current data as
    the last block of the whole text to be converted, and do the
    appropriate finishing job.  */
-#define CODING_MODE_LAST_BLOCK                 0x02
+#define CODING_MODE_LAST_BLOCK                 0x01
 
 /* If set, it means that the current source text is in a buffer which
    enables selective display.  */
-#define CODING_MODE_SELECTIVE_DISPLAY          0x04
+#define CODING_MODE_SELECTIVE_DISPLAY          0x02
 
 /* This flag is used by the decoding/encoding routines on the fly.  If
    set, it means that right-to-left text is being processed.  */
-#define CODING_MODE_DIRECTION                  0x08
+#define CODING_MODE_DIRECTION                  0x04
 
-#define CODING_MODE_FIXED_DESTINATION          0x10
+#define CODING_MODE_FIXED_DESTINATION          0x08
 
 /* If set, it means that the encoding routines produces some safe
    ASCII characters (usually '?') for unsupported characters.  */
-#define CODING_MODE_SAFE_ENCODING              0x20
+#define CODING_MODE_SAFE_ENCODING              0x10
 
   /* For handling composition sequence.  */
 #include "composite.h"
@@ -725,22 +719,6 @@
 
 /* Macros for backward compatibility.  */
 
-#define decode_coding_region(coding, from, to)         \
-  decode_coding_object (coding, Fcurrent_buffer (),    \
-                       from, CHAR_TO_BYTE (from),      \
-                       to, CHAR_TO_BYTE (to), Fcurrent_buffer ())
-
-
-#define encode_coding_region(coding, from, to)         \
-  encode_coding_object (coding, Fcurrent_buffer (),    \
-                       from, CHAR_TO_BYTE (from),      \
-                       to, CHAR_TO_BYTE (to), Fcurrent_buffer ())
-
-
-#define decode_coding_string(coding, string, nocopy)                   \
-  decode_coding_object (coding, string, 0, 0, SCHARS (string),         \
-                       SBYTES (string), Qt)
-
 #define encode_coding_string(coding, string, nocopy)                   \
   (STRING_MULTIBYTE(string) ?                                          \
     (encode_coding_object (coding, string, 0, 0, SCHARS (string),      \


reply via email to

[Prev in Thread] Current Thread [Next in Thread]