Subject: bug#60872: 29.0.60; emacsql broken after Jan 12 change

From: Eli Zaretskii <[email-masked]>
Date: Tue, 17 Jan 2023 15:58:10 +0200

> From: Robert Pluim <[email-masked]>
> Cc: Jonas Bernoulli <[email-masked]>,  [email-masked],
>   [email-masked]
> Date: Tue, 17 Jan 2023 14:10:13 +0100
> 
> This fails:
> 
>          (coding-system-for-write 'utf-8-auto)
>          (coding-system-for-read 'utf-8)
> 
> This works:
> 
>          (coding-system-for-write 'utf-8)
>          (coding-system-for-read 'utf-8-auto)
> 
>     Eli> Anyway, it sounds like someone else thought utf-8-auto is about EOL
>     Eli> format?  Setting coding-system-for-write to utf-8-auto makes no sense;
>     Eli> that coding-system's _only_ raison d'être is for using in
>     Eli> coding-system-for-read, i.e. when decoding stuff that may or may not
>     Eli> start with a BOM.
> 
> Is it enough of an error for us to silently replace `utf-8-auto' with
> `utf-8' when itʼs specified for `coding-system-for-write'?

That's what the bug I fixed effectively did.  But no, I don't think
this is something we can do, let alone silently.  It could be that
some extremely rare/obscure, but nevertheless legitimate use case does
really want to produce BOM on encoding.

>     Eli> If indeed there's sometimes a need to send to the process stuff that
>     Eli> is encoded in UTF-8 with BOM, then instead of binding
>     Eli> coding-system-for-write around start-process, you should set it using
>     Eli> set-process-coding-system only _after_ the process starts, because the
>     Eli> way the code is written now, utf-8-auto is also used to encode the
>     Eli> command-line arguments to the sub-process, and so, for example,
>     Eli> fullfile (which I presume is a file name?) gets the BOM prepended, and
>     Eli> I'm guessing the program emacsql-sqlite isn't prepared for that, and
>     Eli> exits abnormally.
> 
> Either that or use `make-process' directly and pass `:coding'

No, that will suffer from the same problem:

     :coding CODING
          If CODING is a symbol, it specifies the coding system to be
          used for both reading and writing of data from and to the
          connection.  If CODING is a cons cell ‘(DECODING . ENCODING)’,
          then DECODING will be used for reading and ENCODING for
          writing.  The coding system used for encoding the data written
          to the program is also used for encoding the command-line
          arguments[...]