all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Dmitry Antipov <dmantipov@yandex.ru>
Cc: 16448@debbugs.gnu.org, stselikh@gmail.com
Subject: bug#16448: 24.3; Messages from (error "...") with UTF-8 chars are printed wrongly in	Emacs Lisp scripts
Date: Wed, 15 Jan 2014 17:35:43 +0200	[thread overview]
Message-ID: <83vbxl45rk.fsf@gnu.org> (raw)
In-Reply-To: <52D60869.1000206@yandex.ru>

> Date: Wed, 15 Jan 2014 08:02:49 +0400
> From: Dmitry Antipov <dmantipov@yandex.ru>
> Cc: 16448@debbugs.gnu.org
> 
> On 01/15/2014 04:10 AM, Sergey Tselikh wrote:
> 
> > In a script, when (error "...") instruction is executed with some UTF-8
> > characters in its text, the message is not printed correctly.
> 
> In batch mode, (error ...) is handled by external-debugging-output, and the
> latter just does:
> 
> putc (XINT (character) & 0xFF, stderr);
>                         ^^^^^^
> To allow multibyte sequences here, we should use something like:
> 
> === modified file 'src/print.c'
> --- src/print.c	2014-01-01 07:43:34 +0000
> +++ src/print.c	2014-01-15 03:55:39 +0000
> @@ -709,8 +709,14 @@
>   to make it write to the debugging output.  */)
>     (Lisp_Object character)
>   {
> +  unsigned char str[MAX_MULTIBYTE_LENGTH];
> +  unsigned int ch;
> +  ptrdiff_t len;
> +
>     CHECK_NUMBER (character);
> -  putc (XINT (character) & 0xFF, stderr);
> +  ch = XINT (character);
> +  len = CHAR_STRING (ch, str);
> +  fwrite (str, len, 1, stderr);

This will only work correctly in a UTF-8 locale.  In the general case,
we need to run the resulting multibyte sequence through ENCODE_SYSTEM,
before writing it to stderr.

Btw, the way we output text in this case cries for refactoring: we
first assemble individual characters from their multibyte sequences,
then pass those characters one by one to external-debugging-output,
which will now have to unroll each character back into its multibyte
sequence, and encode each character individually.  Something for after
the branch, I guess.





  reply	other threads:[~2014-01-15 15:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-15  0:10 bug#16448: 24.3; Messages from (error "...") with UTF-8 chars are printed wrongly in Emacs Lisp scripts Sergey Tselikh
2014-01-15  4:02 ` Dmitry Antipov
2014-01-15 15:35   ` Eli Zaretskii [this message]
2014-02-01 12:00     ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83vbxl45rk.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=16448@debbugs.gnu.org \
    --cc=dmantipov@yandex.ru \
    --cc=stselikh@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.