]> git.eshelyaron.com Git - emacs.git/commitdiff
Enable calling decode_coding_object with both SRC and DST_OBJECT Qnil
authorPo Lu <luangruo@yahoo.com>
Sat, 23 Mar 2024 10:14:12 +0000 (18:14 +0800)
committerEshel Yaron <me@eshelyaron.com>
Sun, 24 Mar 2024 14:21:10 +0000 (15:21 +0100)
* src/coding.c (growable_destination): A C destination is also
reallocable.
(produce_chars): Don't consider source and destination identical
if they are EQ but Qnil.

(cherry picked from commit 0e83cbd90ecdf793b2422d9219886d91ea4c385a)

src/coding.c

index ff7cf56c29715cd09e34063d67f40269bb3c0ef6..3f314b46d5e96ffd4193850d0b9b588e853ce03e 100644 (file)
@@ -614,10 +614,11 @@ inhibit_flag (int encoded_flag, bool var)
 static bool
 growable_destination (struct coding_system *coding)
 {
-  return STRINGP (coding->dst_object) || BUFFERP (coding->dst_object);
+  return (STRINGP (coding->dst_object)
+         || BUFFERP (coding->dst_object)
+         || NILP (coding->dst_object));
 }
 
-
 /* Safely get one byte from the source text pointed by SRC which ends
    at SRC_END, and set C to that byte.  If there are not enough bytes
    in the source, it jumps to 'no_more_source'.  If MULTIBYTEP,
@@ -7005,7 +7006,6 @@ get_translation (Lisp_Object trans, int *buf, int *buf_end, ptrdiff_t *nchars)
   return Qnil;
 }
 
-
 static int
 produce_chars (struct coding_system *coding, Lisp_Object translation_table,
               bool last_block)
@@ -7063,7 +7063,10 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
                      || ckd_add (&dst_size, dst_size, buf_end - buf))
                    memory_full (SIZE_MAX);
                  dst = alloc_destination (coding, dst_size, dst);
-                 if (EQ (coding->src_object, coding->dst_object))
+                 if (EQ (coding->src_object, coding->dst_object)
+                     /* Input and output are not C buffers, which are safe to
+                        assume to be different.  */
+                     && !NILP (coding->src_object))
                    {
                      coding_set_source (coding);
                      dst_end = (((unsigned char *) coding->source)
@@ -7098,7 +7101,10 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
       const unsigned char *src = coding->source;
       const unsigned char *src_end = src + coding->consumed;
 
-      if (EQ (coding->dst_object, coding->src_object))
+      if (EQ (coding->dst_object, coding->src_object)
+         /* Input and output are not C buffers, which are safe to
+            assume to be different.  */
+         && !NILP (coding->src_object))
        {
          eassert (growable_destination (coding));
          dst_end = (unsigned char *) src;
@@ -7119,7 +7125,8 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
                  if (dst == dst_end)
                    {
                      eassert (growable_destination (coding));
-                     if (EQ (coding->src_object, coding->dst_object))
+                     if (EQ (coding->src_object, coding->dst_object)
+                         && !NILP (coding->src_object))
                        dst_end = (unsigned char *) src;
                      if (dst == dst_end)
                        {
@@ -7131,7 +7138,8 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
                          coding_set_source (coding);
                          src = coding->source + offset;
                          src_end = coding->source + coding->consumed;
-                         if (EQ (coding->src_object, coding->dst_object))
+                         if (EQ (coding->src_object, coding->dst_object)
+                             && !NILP (coding->src_object))
                            dst_end = (unsigned char *) src;
                        }
                    }
@@ -7150,14 +7158,16 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
                if (dst >= dst_end - 1)
                  {
                    eassert (growable_destination (coding));
-                   if (EQ (coding->src_object, coding->dst_object))
+                   if (EQ (coding->src_object, coding->dst_object)
+                       && !NILP (coding->src_object))
                      dst_end = (unsigned char *) src;
                    if (dst >= dst_end - 1)
                      {
                        ptrdiff_t offset = src - coding->source;
                        ptrdiff_t more_bytes;
 
-                       if (EQ (coding->src_object, coding->dst_object))
+                       if (EQ (coding->src_object, coding->dst_object)
+                           && !NILP (coding->src_object))
                          more_bytes = ((src_end - src) / 2) + 2;
                        else
                          more_bytes = src_end - src + 2;
@@ -7166,7 +7176,8 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
                        coding_set_source (coding);
                        src = coding->source + offset;
                        src_end = coding->source + coding->consumed;
-                       if (EQ (coding->src_object, coding->dst_object))
+                       if (EQ (coding->src_object, coding->dst_object)
+                           && !NILP (coding->src_object))
                          dst_end = (unsigned char *) src;
                      }
                  }
@@ -7175,7 +7186,8 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
        }
       else
        {
-         if (!EQ (coding->src_object, coding->dst_object))
+         if (!EQ (coding->src_object, coding->dst_object)
+             && !NILP (coding->src_object))
            {
              ptrdiff_t require = coding->src_bytes - coding->dst_bytes;