Subject: Re: bug#79376: [PATCH] [WIP] Fix mm multibyte

From: Eli Zaretskii <[email-masked]>
Date: Wed, 03 Sep 2025 15:57:36 +0300

> Cc: Lars Magne Ingebrigtsen <[email-masked]>,
>  MORIOKA Tomohiko <[email-masked]>
> From: Manuel Giraud <[email-masked]>
> Date: Wed, 03 Sep 2025 11:33:33 +0200
> 
> I'm trying to fix an issue in Gnus where some Atom sources (namely
> planet.emacslife.com/atom.xml, here) are not rendered correctly.
> 
> This seems to be related to multibyte/unibyte buffer.  Here is a minimal
> exemple to reproduce what I see:
> 
> --8<---------------cut here---------------start------------->8---
> (defun my/gen-handle ()
>   (with-current-buffer (get-buffer-create " foo")
>     (erase-buffer)
>     (insert "’…")
>     (list (current-buffer) '("text/html"))))
> 
> (defun my/test ()
>   (let ((handle (my/gen-handle)))
>     (mm-with-part handle
>       (buffer-string))))
> --8<---------------cut here---------------end--------------->8---
> 
> When evaluating (my/test), see that the buffer string content does not
> have the correct characters.

Hmm...  I'm not familiar with this code, but the comment in
mm-with-part says:

  ;; The handle-buffer's content is a sequence of bytes, not a sequence of
  ;; chars, so the buffer should be unibyte.  It may happen that the
  ;; handle-buffer is multibyte for some reason, in which case now is a good
  ;; time to adjust it, since we know at this point that it should
  ;; be unibyte.

But your test case inserts a multibyte string into the buffer, so
aren't you violating what this macro expects and should handle?  And
also, is a call to buffer-string something that this macro's body is
useful for?

Apologies if I'm not making sense.