Subject: bug#481: Crashes with non-default language environments

From: Kenichi Handa <[email-masked]>
Date: Wed, 25 Jun 2008 11:58:03 +0900

This is the thread of long ago.

In article <[email-masked]>, Stefan Monnier <[email-masked]> writes:

> > But, even if we implement string-to-unibyte, it should be
> > used for a string containing only ascii and eight-bit chars.
> > And in that case, string-make-unibyte behaves exactly the
> > same as string-to-unibyte.

> No it would be different: it would also signal an error if some
> non-binary char is found.  (I might potentially be convinced that it's
> OK to additionally accept the 128-255 latin1 chars as alternatives to
> eight-bit chars, since they now get character codes 128-255).

I've just installed a change to implement string-to-unibyte
as below and used it to fix the problem of jpeg detection.

(string-to-unibyte string &optional accept-latin-1)

Return a unibyte string with the same individual chars as string.
If string is unibyte, the result is string itself.
Otherwise it is a newly created string, with no text properties,
where each `eight-bit' character is converted to the corresponding byte.
If string contains a non-ASCII, non-`eight-bit' character,
an error is signalled.
If the optional 2nd arg accept-latin-1 is non-nil, a Latin-1 character
doesn't cause an error, but is converted to a byte of same code.

---
Kenichi Handa
[email-masked]