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: Tue, 10 Feb 2009 09:12:42 +0900	[thread overview]
Message-ID: <b4mmycvp2th.fsf@jpl.org> (raw)
In-Reply-To: <8763jjchs7.fsf@liv.ac.uk>

>>>>> Dave Love wrote:
> Katsumi Yamaoka <yamaoka@jpl.org> writes:

>> 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?

> I think it doesn't cons a new string in the trivial case like that, when
> it won't matter.  Use this version if you want always to cons a
> multibyte string.

I verified how (eval-when-compile (string-as-multibyte ""))
behaves with this test.el file:

(defun test ()
  (let ((s1 "")
	(s2 (eval-when-compile (string-as-multibyte "")))
	(s3 (eval-when-compile (string-as-unibyte ""))))
    (message "%s %s %s"
	     (multibyte-string-p s1)
	     (multibyte-string-p s2)
	     (multibyte-string-p s3))))
(test)

$ emacs-21.4 -batch -q -l ./test.el
 => nil t nil
$ emacs-21.4 -batch -q -f batch-byte-compile ./test.el
$ emacs-21.4 -batch -q -l ./test.elc
 => nil nil nil

So there seems to be no difference in those ""s in the byte
compiled file.

> 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	9 Feb 2009 23:26:20 -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))
> +  "Non-ASCII translation table that applies the identity translation.")
> +
> +(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,9 @@
>     ((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
> +	(concat s (eval-when-compile (string-as-multibyte ""))))))))

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



      reply	other threads:[~2009-02-10  0:12 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
2009-02-09 23:27   ` Dave Love
2009-02-10  0:12     ` Katsumi Yamaoka [this message]

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=b4mmycvp2th.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).