From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/68255 Path: news.gmane.org!not-for-mail From: Katsumi Yamaoka Newsgroups: gmane.emacs.gnus.general Subject: Re: sanitized mm-string-to-multibyte Date: Mon, 09 Feb 2009 19:28:03 +0900 Organization: Emacsen advocacy group Message-ID: References: <8763jkg7cu.fsf@liv.ac.uk> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1234175440 16458 80.91.229.12 (9 Feb 2009 10:30:40 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 9 Feb 2009 10:30:40 +0000 (UTC) Cc: bugs@gnus.org, ding@gnus.org To: Dave Love Original-X-From: ding-owner+M16695@lists.math.uh.edu Mon Feb 09 11:31:55 2009 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by lo.gmane.org with esmtp (Exim 4.50) id 1LWTQS-0001lB-8v for ding-account@gmane.org; Mon, 09 Feb 2009 11:31:40 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1LWTNv-0002XI-UI; Mon, 09 Feb 2009 04:29:03 -0600 Original-Received: from mx1.math.uh.edu ([129.7.128.32]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1LWTNu-0002X4-27 for ding@lists.math.uh.edu; Mon, 09 Feb 2009 04:29:02 -0600 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx1.math.uh.edu with esmtp (Exim 4.69) (envelope-from ) id 1LWTNq-00082v-S7 for ding@lists.math.uh.edu; Mon, 09 Feb 2009 04:29:01 -0600 Original-Received: from orlando.hostforweb.net ([216.246.45.90]) by quimby.gnus.org with esmtp (Exim 3.36 #1 (Debian)) id 1LWTOA-0002NO-00; Mon, 09 Feb 2009 11:29:18 +0100 Original-Received: from localhost ([127.0.0.1]:60099) by orlando.hostforweb.net with esmtpa (Exim 4.69) (envelope-from ) id 1LWTNH-0000Xo-QL; Mon, 09 Feb 2009 04:28:24 -0600 X-Hashcash: 1:20:090209:fx@gnu.org::btIIlLSG0/gTqdJS:000000061v9 X-Hashcash: 1:20:090209:bugs@gnus.org::HQTx8oZRaD374Zlt:0000Mh1f X-Hashcash: 1:20:090209:ding@gnus.org::ps1M7KLuJmTSPFiG:0000Glfa X-Face: #kKnN,xUnmKia.'[pp`;Omh}odZK)?7wQSl"4o04=EixTF+V[""w~iNbM9ZL+.b*_CxUmFk B#Fu[*?MZZH@IkN:!"\w%I_zt>[$nm7nQosZ<3eu;B:$Q_:p!',P.c0-_Cy[dz4oIpw0ESA^D*1Lw= L&i*6&( User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.90 (gnu/linux) Cancel-Lock: sha1:K/L2eQOTEGCGjxSQ5/QSI7Q5O4I= X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - orlando.hostforweb.net X-AntiAbuse: Original Domain - gnus.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - jpl.org X-Source: X-Source-Args: X-Source-Dir: X-Spam-Score: -2.6 (--) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:68255 Archived-At: >>>>> 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 > * 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