[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Unibyte strings in Lisp data structures

From: Eli Zaretskii
Subject: Unibyte strings in Lisp data structures
Date: Tue, 13 Jul 2010 17:28:50 +0300

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

             ;; 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)))

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.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]