aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
diff options
context:
space:
mode:
authorPo Lu2024-03-23 18:14:12 +0800
committerPo Lu2024-03-23 18:14:12 +0800
commit0e83cbd90ecdf793b2422d9219886d91ea4c385a (patch)
tree39d1bf90691813cb33f69c10a1cef14f056c5729 /src/coding.c
parent023a5fe5a3bd2f20eb168bc4763fa98e14201fff (diff)
downloademacs-0e83cbd90ecdf793b2422d9219886d91ea4c385a.tar.gz
emacs-0e83cbd90ecdf793b2422d9219886d91ea4c385a.zip
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.
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c34
1 files 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)
614static bool 614static bool
615growable_destination (struct coding_system *coding) 615growable_destination (struct coding_system *coding)
616{ 616{
617 return STRINGP (coding->dst_object) || BUFFERP (coding->dst_object); 617 return (STRINGP (coding->dst_object)
618 || BUFFERP (coding->dst_object)
619 || NILP (coding->dst_object));
618} 620}
619 621
620
621/* Safely get one byte from the source text pointed by SRC which ends 622/* Safely get one byte from the source text pointed by SRC which ends
622 at SRC_END, and set C to that byte. If there are not enough bytes 623 at SRC_END, and set C to that byte. If there are not enough bytes
623 in the source, it jumps to 'no_more_source'. If MULTIBYTEP, 624 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)
7005 return Qnil; 7006 return Qnil;
7006} 7007}
7007 7008
7008
7009static int 7009static int
7010produce_chars (struct coding_system *coding, Lisp_Object translation_table, 7010produce_chars (struct coding_system *coding, Lisp_Object translation_table,
7011 bool last_block) 7011 bool last_block)
@@ -7063,7 +7063,10 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
7063 || ckd_add (&dst_size, dst_size, buf_end - buf)) 7063 || ckd_add (&dst_size, dst_size, buf_end - buf))
7064 memory_full (SIZE_MAX); 7064 memory_full (SIZE_MAX);
7065 dst = alloc_destination (coding, dst_size, dst); 7065 dst = alloc_destination (coding, dst_size, dst);
7066 if (EQ (coding->src_object, coding->dst_object)) 7066 if (EQ (coding->src_object, coding->dst_object)
7067 /* Input and output are not C buffers, which are safe to
7068 assume to be different. */
7069 && !NILP (coding->src_object))
7067 { 7070 {
7068 coding_set_source (coding); 7071 coding_set_source (coding);
7069 dst_end = (((unsigned char *) coding->source) 7072 dst_end = (((unsigned char *) coding->source)
@@ -7098,7 +7101,10 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
7098 const unsigned char *src = coding->source; 7101 const unsigned char *src = coding->source;
7099 const unsigned char *src_end = src + coding->consumed; 7102 const unsigned char *src_end = src + coding->consumed;
7100 7103
7101 if (EQ (coding->dst_object, coding->src_object)) 7104 if (EQ (coding->dst_object, coding->src_object)
7105 /* Input and output are not C buffers, which are safe to
7106 assume to be different. */
7107 && !NILP (coding->src_object))
7102 { 7108 {
7103 eassert (growable_destination (coding)); 7109 eassert (growable_destination (coding));
7104 dst_end = (unsigned char *) src; 7110 dst_end = (unsigned char *) src;
@@ -7119,7 +7125,8 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
7119 if (dst == dst_end) 7125 if (dst == dst_end)
7120 { 7126 {
7121 eassert (growable_destination (coding)); 7127 eassert (growable_destination (coding));
7122 if (EQ (coding->src_object, coding->dst_object)) 7128 if (EQ (coding->src_object, coding->dst_object)
7129 && !NILP (coding->src_object))
7123 dst_end = (unsigned char *) src; 7130 dst_end = (unsigned char *) src;
7124 if (dst == dst_end) 7131 if (dst == dst_end)
7125 { 7132 {
@@ -7131,7 +7138,8 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
7131 coding_set_source (coding); 7138 coding_set_source (coding);
7132 src = coding->source + offset; 7139 src = coding->source + offset;
7133 src_end = coding->source + coding->consumed; 7140 src_end = coding->source + coding->consumed;
7134 if (EQ (coding->src_object, coding->dst_object)) 7141 if (EQ (coding->src_object, coding->dst_object)
7142 && !NILP (coding->src_object))
7135 dst_end = (unsigned char *) src; 7143 dst_end = (unsigned char *) src;
7136 } 7144 }
7137 } 7145 }
@@ -7150,14 +7158,16 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
7150 if (dst >= dst_end - 1) 7158 if (dst >= dst_end - 1)
7151 { 7159 {
7152 eassert (growable_destination (coding)); 7160 eassert (growable_destination (coding));
7153 if (EQ (coding->src_object, coding->dst_object)) 7161 if (EQ (coding->src_object, coding->dst_object)
7162 && !NILP (coding->src_object))
7154 dst_end = (unsigned char *) src; 7163 dst_end = (unsigned char *) src;
7155 if (dst >= dst_end - 1) 7164 if (dst >= dst_end - 1)
7156 { 7165 {
7157 ptrdiff_t offset = src - coding->source; 7166 ptrdiff_t offset = src - coding->source;
7158 ptrdiff_t more_bytes; 7167 ptrdiff_t more_bytes;
7159 7168
7160 if (EQ (coding->src_object, coding->dst_object)) 7169 if (EQ (coding->src_object, coding->dst_object)
7170 && !NILP (coding->src_object))
7161 more_bytes = ((src_end - src) / 2) + 2; 7171 more_bytes = ((src_end - src) / 2) + 2;
7162 else 7172 else
7163 more_bytes = src_end - src + 2; 7173 more_bytes = src_end - src + 2;
@@ -7166,7 +7176,8 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
7166 coding_set_source (coding); 7176 coding_set_source (coding);
7167 src = coding->source + offset; 7177 src = coding->source + offset;
7168 src_end = coding->source + coding->consumed; 7178 src_end = coding->source + coding->consumed;
7169 if (EQ (coding->src_object, coding->dst_object)) 7179 if (EQ (coding->src_object, coding->dst_object)
7180 && !NILP (coding->src_object))
7170 dst_end = (unsigned char *) src; 7181 dst_end = (unsigned char *) src;
7171 } 7182 }
7172 } 7183 }
@@ -7175,7 +7186,8 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
7175 } 7186 }
7176 else 7187 else
7177 { 7188 {
7178 if (!EQ (coding->src_object, coding->dst_object)) 7189 if (!EQ (coding->src_object, coding->dst_object)
7190 && !NILP (coding->src_object))
7179 { 7191 {
7180 ptrdiff_t require = coding->src_bytes - coding->dst_bytes; 7192 ptrdiff_t require = coding->src_bytes - coding->dst_bytes;
7181 7193