emacs-devel
[Top][All Lists]
Advanced

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

Re: (aset UNIBYTE-STRING MULTIBYTE-CHAR)


From: Harald Hanche-Olsen
Subject: Re: (aset UNIBYTE-STRING MULTIBYTE-CHAR)
Date: Wed, 14 May 2008 14:50:43 +0200 (CEST)

+ Stefan Monnier <address@hidden>:

> > + Harald Hanche-Olsen <address@hidden>:
> 
> >> This works as it should in the latest CVS:
> >> 
> >> (setq foo (make-string 4 ?a))
> >> (aset foo 1 ?€) ; <= that's a euro sign
> >> 
> >> But this fails:
> >> 
> >> (setq foo (make-string 4 ?a))
> >> (aset foo 1 ?å)
> >> (aset foo 1 ?€) ; => Error: args out of range
> 
> Show us the real code that bunmped into the problem and I'll tell you
> how to do it so as to avoid the risk of such problems.

You'd have to tell the author of mew (http://mew.org/), Kazu Yamamoto.
Actually, I have a one line patch to mew that fixes the problem, but
he seems unwilling to apply it.

Now don't get me wrong: I am not asking for a change in emacs to fix a
problem in mew. I am suggesting a change in emacs for the sake of
robustness: I think that if the problem of inserting multibyte
characters in unibyte strings is worth fixing at all, it is worth
fixing so it works in all cases. Otherwise, why bother? I do
understand the arguments against fixing it, but the current situation
where it will often work, but fail sometimes does not seem good to me.

But at least, it's documented, I see that now:

  4.4 Modifying Strings
  =====================

  The most basic way to alter the contents of an existing string is with
  `aset' (*note Array Functions::).  `(aset STRING IDX CHAR)' stores CHAR
  into STRING at index IDX.  Each character occupies one or more bytes,
  and if CHAR needs a different number of bytes from the character
  already present at that index, `aset' signals an error.

That last bit actually seems to be outdated: An error is not ALWAYS
signaled in the indicated situation, only sometimes.

Anyway, the code you're asking for (in case you're really curious):
In mew-header.el

(defun mew-addrstr-parse-syntax-list (str sep addrp &optional depth allow-spc)
  (when str
    (let* ((i 0) (len (length str))
           (par-cnt 0) (tmp-cnt 0) (sep-cnt 0)
           (tmp (mew-make-string len))
           c ret prevc)
      (catch 'max
        (while (< i len)
          (setq c (aref str i)) ; <= problem occurs here
          ... deleted ...)))))

My one-line fix consists of changing the definition (elsewhere)

(defun mew-make-string (len)
  (make-string len ?a))

into one that makes a multibyte string at the outset.

(I like mew (a lot), so I am willing to put up with its various
idiosynchrasies (and there are a some).)

- Harald




reply via email to

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