emacs-diffs
[Top][All Lists]
Advanced

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

master 0e83cbd90ec 3/4: Enable calling decode_coding_object with both SR


From: Po Lu
Subject: master 0e83cbd90ec 3/4: Enable calling decode_coding_object with both SRC and DST_OBJECT Qnil
Date: Sat, 23 Mar 2024 06:15:48 -0400 (EDT)

branch: master
commit 0e83cbd90ecdf793b2422d9219886d91ea4c385a
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Enable calling decode_coding_object with both SRC and DST_OBJECT Qnil
    
    * 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.
---
 src/coding.c | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)

diff --git a/src/coding.c b/src/coding.c
index ff7cf56c297..3f314b46d5e 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -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;
 



reply via email to

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