unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Unibyte strings in Lisp data structures
@ 2010-07-13 14:28 Eli Zaretskii
  2010-07-13 15:05 ` Andreas Schwab
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2010-07-13 14:28 UTC (permalink / raw)
  To: Kenichi Handa; +Cc: emacs-devel

Take a look at jka-compr-compression-info-list: each compression
method has a magic signature there, which is the 9th element of the
vector describing that compression method.

Now evaluate this:

  (multibyte-string-p (aref (car jka-compr-compression-info-list) 9))
     => nil

These magic signatures are unibyte strings.  But why are they unibyte?
What code decides that they should be unibyte, when Emacs reads
jka-cmpr-hook.el?  Can we rely on the fact that these strings will
always be unibyte?

I bumped into this while debugging a problem in rmailmm.el: saving
attachments whose file names end in .gz produces a file that is
gzip-compressed twice.  I finally traced this to this fragment in
jka-compr.el:

	     ;; If the contents to be written out
	     ;; are properly compressed already,
	     ;; don't try to compress them over again.
	     (not (and magic
		       (equal (if (stringp start)
				  (substring start 0 (min (length start)
							  (length magic)))
                                (let* ((from (or start (point-min)))
                                       (to (min (or end (point-max))
                                                (+ from (length magic)))))
                                  (buffer-substring from to)))
			      magic))))

This test failed, because `magic' is a unibyte string, while
buffer-substring was returning a multibyte string.

The fix seems to be easy: modify rmail-mime-save to make the temporary
buffer it uses be a unibyte buffer.  But then I started to wonder how
come `magic' is a unibyte string, and can I rely on that?

There is, of course, the alternative to convert both strings to
unibyte and compare that.  Still, I think it would be good to know how
come these strings are unibyte to begin with.



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-07-13 18:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-13 14:28 Unibyte strings in Lisp data structures Eli Zaretskii
2010-07-13 15:05 ` Andreas Schwab
2010-07-13 16:13   ` Eli Zaretskii
2010-07-13 18:40     ` Andreas Schwab

Code repositories for project(s) associated with this public inbox

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

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 read-only IMAP folder(s) and NNTP newsgroup(s).