[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [ANN] Lua 5.2.0 (beta-rc2) locale
- From: Edgar Toernig <froese@...>
- Date: Wed, 22 Jun 2011 22:05:55 +0200
Roberto Ierusalimschy wrote:
> > Do the new setlocale calls in ldo.c change thread safety assumptions
> > Lua? http://stackoverflow.com/questions/4057319/is-setlocale-thread-safe-function
> It seems so :(
If I got it right, setlocale was added mainly to support EBCDIC systems.
a) Declare the character set/encoding for Lua to be ASCII.
Let the EBCDIC users deal with the conversion.
b) Create the ctype table on the fly when building Lua.
Maybe become difficult when cross-compiling (HOST_CC needed
which uses the same encoding as the TARGET_CC).
c) Provide a dedicated EBCDIC ctype table selected via some
d) You could provide hooks to let EBCDIC/strange-encoding users
provide conversion routines. Maybe a simple LOCAL_TO_ASCII(c)
macro suffices. Whether that macro should be used for ranges
in Lua patterns (i.e. [k-p]) I don't know.
Afaik, newer gcc uses iconv-lib and "-finput/exec-charset"
to convert the charset on the fly...
Btw, setlocale is not really cheap. For example:
|# time src/lua -e 'os.setlocale"de_DE" for i=1,100000 do loadstring"a=1" end'
|# time src/lua-no-setlocale -e 'os.setlocale"de_DE" for i=1,100000 do loadstring"a=1" end'
The lua-no-setlocale has only the two setlocale("C"/savedlocale) calls
in ldo.c disabled.
I think I even saw some trivial implementations that loaded the tables
from disk each time setlocale was called.
And the newlocale stuff is rather new (introduced in POSIX 2008) and probably
not available on EBCDIC systems (not even on one of my older Linux systems).