Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2001-04-06
03:21 • Ticket [218663ffff] Should NOT call setlocale() if don't want to status ... artifact: 10e4efde4d user: dgp
2000-10-26
08:26 • Closed ticket [218663ffff]. artifact: 11c16c24a7 user: welch
01:03 • New ticket [218663ffff]. artifact: 289c86f442 user: nobody

Should NOT call setlocale() if don't want to

Closed / Fixed218663ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 01:03:51
OriginalBugID: 1636 Bug
Version: 8.1b1
SubmitDate: '1999-03-25'
LastModified: '1999-04-21'
Severity: SER
Status: Released
Submitter: stanton
ChangedBy: redman
RelatedBugIDs: 1668
OS: All
OSVersion: NA
Machine: NA
FixedDate: '1999-04-21'
FixedInVersion: NA
ClosedDate: '2000-10-25'


  Hi folks. I am a maintainer of Tcl/Tk Japanization patch kit (AKA

tcl/tk[78]xjp). With my experience, I will report a bug of tcl8.1b1 B)



  I don't know exactly how many people might be stacked with this, but

I think it is not few B) of course I stacked with in these environments:



Linux/i386 RH 5.0 libc version 2.0.7

LANG=japanese



Description:

When I start tclsh, encoding is "iso-8859-1". By LANG

environment variable, it should be "euc-jp".



$ tclsh

% encoding system

iso-8859-1

%





Why this happen:

  unix/tclUnixInit.c:TclpSetInitialEncodings() calls setlocale() and

if the setlocale() fails (means that the locale is NOT supported by

the system), Tcl can't find proper encoding system for language

specified by user with LANG/LC_CTYPE environment variable.



  With my experience of making Japanization patch for Tcl/Tk 8.0x, I

know that many UNIX systems can't handle locales properly EXCEPT "C"

EVEN IF the systems are said as "Localized/Internationalized.".



  By ANSI specification, a C program MUST BE started by "C" locale

until the program changes it by calling setlocale(). Thus, In original

code, the locale always reset to "C" locale. If Tcl don't want (nor

need) to change the currnet locale, Tcl should NOT call setlocale()

ONLY to determine encoding system to be used. Because Tcl can handle

MANY encoding system WITHOUT the system's locale facilities or I18N'd

feature.





Solution:

  Except calling setlocale(), Tcl should call getenv("LANG") or/and

getenv("LC_CTYPE"), then compare its returned value and localeTable[]. 

I know this increase the I18N'd Tcl platform :)



Anyway, here's patch to avoid calling setlocale(). Define -DBUGFIX in

Makefile and make.



Hope this patch (or code to avoid calling setlocale()) is going to be

approved for users who's system can handle only "C" locale.



m-hirano

------------------------------ start ------------------------------

*** ../../org/tcl8.1b1/unix/tclUnixInit.cWed Dec  2 07:40:20 1998

--- ./tclUnixInit.cSat Dec 19 02:11:50 1998

***************

*** 323,328 ****

--- 323,352 ----

  void

  TclpSetInitialEncodings()

  {

+ #ifdef BUGFIX

+     CONST char *encoding;

+     int i;

+     Tcl_Obj *pathPtr;

+     char *langEnv = getenv("LC_CTYPE");

+ 

+     if (langEnv == NULL || langEnv[0] == '\0') {

+ langEnv = getenv("LANG");

+     }

+     if (langEnv == NULL || langEnv[0] == '\0') {

+ langEnv = NULL;

+     }

+ 

+     encoding = "iso-8859-1";

+     if (langEnv != NULL) {

+ for (i = 0; localeTable[i].lang != NULL; i++) {

+     if (strcmp(localeTable[i].lang, langEnv) == 0) {

+ encoding = localeTable[i].encoding;

+     }

+ }

+     }

+ 

+     Tcl_SetSystemEncoding(NULL, encoding);

+ #else

      CONST char *locale, *encoding;

      int i;

      Tcl_Obj *pathPtr;

***************

*** 361,366 ****

--- 385,391 ----

      Tcl_DStringFree(&ds);

  

      Tcl_SetSystemEncoding(NULL, encoding);

+ #endif /* BUGFIX */

  

      /*

       * Until the system encoding was actually set, the library path was



------------------------------- end -------------------------------

-- 

[email protected] ([email protected])

Real World Computing Partnership, Tsukuba, Japan

Software Research Associates, Inc., Japan 



Applied patch to handle detecting locale.  Will follow up to see what if anything needs to be done with respect to X11R5/6.  Moved description of X11 problem to 1668.
03/30/1999 14:59 - stanton -
04/21/1999 18:52 - redman - Scott S. fixed this (see above), except the X11R5/6 problem that was moved to a new Bug 1668.
welch Closed ticket [218663ffff]. [History diff]2000-10-26 08:26:11
dgp Ticket [218663ffff]: 3 changes [History diff]2001-04-06 03:21:22
Log in (anonymous is fine) to add a comment.