Gnus development mailing list
 help / color / mirror / Atom feed
From: Katsumi Yamaoka <yamaoka@jpl.org>
To: Dave Love <fx@gnu.org>
Cc: bugs@gnus.org, ding@gnus.org
Subject: Re: sanitized mm-string-to-multibyte
Date: Mon, 09 Feb 2009 19:28:03 +0900	[thread overview]
Message-ID: <b4m7i3zx5u4.fsf@jpl.org> (raw)
In-Reply-To: <8763jkg7cu.fsf@liv.ac.uk>

>>>>> Dave Love wrote:
> I found some IMAP messages were crashing Emacs, and I was led to
> mm-string-to-multibyte.  I'm not sure exactly what the crash was due to,
> but the function isn't very sane in Emacs 21.  This version doesn't cons
> a string for each character.  Various uses of the function are at least
> dubious, and I'll send patches later.  mm-with-preserved-unibyte is
> useful for those changes and elsewhere.

> 2009-02-08  Dave Love  <fx@gnu.org>

> 	* mm-util.el (mm-identity-nat, mm-with-preserved-unibyte): New.
> 	(mm-string-to-multibyte): Use them.

Your version of `mm-string-to-multibyte' doesn't seem to convert
a unibyte string to a multibyte string.  In Emacs 21.1~21.4 I got:

(let* ((s1 (string-as-unibyte "a"))
       (s2 (mm-with-preserved-unibyte (string-make-multibyte s1))))
  (list (multibyte-string-p s1) (multibyte-string-p s2)))
 => (nil nil)

(let* ((s1 (string-as-multibyte "a"))
       (s2 (mm-with-preserved-unibyte (string-make-multibyte s1))))
  (list (multibyte-string-p s1) (multibyte-string-p s2)))
 => (t t)

Did I miss something?

> Index: mm-util.el
> ===================================================================
> RCS file: /usr/local/cvsroot/gnus/lisp/mm-util.el,v
> retrieving revision 7.91
> diff -u -r7.91 mm-util.el
> --- mm-util.el	14 Jan 2009 00:52:01 -0000	7.91
> +++ mm-util.el	8 Feb 2009 17:27:12 -0000
> @@ -202,6 +202,22 @@
>      (defalias 'mm-decode-coding-region 'decode-coding-region)
>      (defalias 'mm-encode-coding-region 'encode-coding-region)))

> +(defconst mm-identity-nat (let (l)
> +			    (dotimes (i 256)
> +			      (push (cons i i) l))
> +			    (make-translation-table l))
> +  "Translation table that applies the identity trasnlation.")
> +
> +(defmacro mm-with-preserved-unibyte (&rest body)
> +  "Execute BODY forms while preserving unibyte characters.
> +Such characters are not converted automatically to multibyte ones
> +when, for instance, inserted into a multibyte buffer within the
> +BODY forms."
> +  `(let ((nonascii-translation-table mm-identity-nat))
> +     ,@body))
> +(put 'mm-with-preserved-unibyte 'lisp-indent-function 0)
> +(put 'mm-with-preserved-unibyte 'edebug-form-spec '(body))
> +
>  ;; `string-to-multibyte' is available only in Emacs 22.1 or greater.
>  (defalias 'mm-string-to-multibyte
>    (cond
> @@ -210,11 +226,8 @@
>     ((fboundp 'string-to-multibyte)
>      'string-to-multibyte)
>     (t
> -    (lambda (string)
> -      "Return a multibyte string with the same individual chars as STRING."
> -      (mapconcat
> -       (lambda (ch) (mm-string-as-multibyte (char-to-string ch)))
> -       string "")))))
> +    (lambda (s)
> +      (mm-with-preserved-unibyte (string-make-multibyte s))))))

>  ;; `char-or-char-int-p' is an XEmacs function, not available in Emacs.
>  (eval-and-compile



       reply	other threads:[~2009-02-09 10:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <8763jkg7cu.fsf@liv.ac.uk>
2009-02-09 10:28 ` Katsumi Yamaoka [this message]
2009-02-09 23:27   ` Dave Love
2009-02-10  0:12     ` Katsumi Yamaoka

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=b4m7i3zx5u4.fsf@jpl.org \
    --to=yamaoka@jpl.org \
    --cc=bugs@gnus.org \
    --cc=ding@gnus.org \
    --cc=fx@gnu.org \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).