From: Eli Zaretskii <eliz@gnu.org>
To: Kenichi Handa <handa@m17n.org>
Cc: emacs-devel@gnu.org
Subject: Unibyte strings in Lisp data structures
Date: Tue, 13 Jul 2010 17:28:50 +0300 [thread overview]
Message-ID: <83aapvsbfh.fsf@gnu.org> (raw)
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.
next reply other threads:[~2010-07-13 14:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-13 14:28 Eli Zaretskii [this message]
2010-07-13 15:05 ` Unibyte strings in Lisp data structures Andreas Schwab
2010-07-13 16:13 ` Eli Zaretskii
2010-07-13 18:40 ` Andreas Schwab
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=83aapvsbfh.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=handa@m17n.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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.