Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2011-10-13
21:41 • Closed ticket [2987075fff]: Tcl function ‘string toupper’ is failing to conv... artifact: a7acbeae23 user: nijtmans
2011-09-09
15:27 • Pending ticket [2987075fff]. artifact: b8617adf5e user: nijtmans
2010-04-15
15:01 • Ticket [2987075fff]: 4 changes artifact: eca16f3948 user: rkanherkar
05:15 • Ticket [2987075fff]: 4 changes artifact: 135c244c63 user: dkf
05:15 • Ticket [2987075fff]: 4 changes artifact: 44e4c6c39a user: dkf
2010-04-14
20:25 • Ticket [2987075fff]: 4 changes artifact: 7b5e444747 user: rkanherkar
18:18 • Ticket [2987075fff]: 4 changes artifact: b3a7c2fa11 user: dkf
18:18 • Ticket [2987075fff]: 4 changes artifact: 7a45ff4b9a user: dkf
18:07 • Ticket [2987075fff]: 1 change artifact: 9d676f1025 user: rkanherkar
11:04 • New ticket [2987075fff]. artifact: 78e808ab14 user: rkanherkar

Tcl function ‘string toupper’ is failing to convert non-asci

Closed / Invalid2987075fffffffffffffffffffffffffffffffffCreated 17 years agoUpdated 15 years ago
Descriptionplain2010-04-14 11:04:32
Problem:  Tcl function ‘string toupper’ is failing to convert non-ascii characters from lower case to upper case
=================

Tcl Version (Group field) 
=================
8.3.5

OS Platform and Version 
================= 
AIX 5.3 , Solaris 10, Linux (RHEL5.3, 5.4)

Problem Behavior 
=================
We are using TCL library function ‘Tcl_EvalFile’ to execute the .tcl script. Two arguments interp, filename are passed for function ‘Tcl_EvalFile’. After successful execution everything works fine but the statement ‘string toupper’ is failing to convert non-ascii characters to uppercase.
Tcl code file exit9.tcl is pasted in section Concise Code Sample
After successful execution of exit9.tcl script the exit9.log file contains following output which is unexpected  
     Exit 9 called
     Insert Person
     Person = râhuèïøû
     Upper Person = RâHUèïøû


Another interesting observation is that when we try using ‘tclsh’ interpreter on prompt, the statement ‘string toupper’ behaves as expected 

#> tclsh
% string toupper “râhuèïøû”

RÂHUÈÏØÛ 

% exit
#>

Expected Behavior 
================= 
Using TCL library function ‘Tcl_EvalFile’ the expected output for statement ‘string toupper’ should be   RÂHUÈÏØÛ

Concise Code Sample (if applicable)
=================

set log_file “/appl/ess.version/log/out/exit9.log”

if {[catch {set log_file [open $log_file a+]} err]} {
  puts “Error while opening log file”
  return
}

puts $log_file “Exit 9 called”
puts $log_file “Insert Person”
set USERNAME “râhuèïøû”
puts $log_file “Person = $USERNAME”
set USER_UPPER [string toupper $USERNAME]
puts $log_file “Upper Person = $USER_UPPER”

if {[catch {close $log_file} err]} {
  puts $log_file “Error while writing to log file”
}
rkanherkar Ticket [2987075fff]: 1 change [History diff]2010-04-14 18:07:09
dkfplain2010-04-14 18:18:34
data_type - 360894

Known issue. Requires API changes (correct behaviour depends on locale!) so won't be done in 8.6
dkf Ticket [2987075fff]: 4 changes [History diff]2010-04-14 18:18:35
rkanherkarplain2010-04-14 20:25:15
Hi Donal,
On AIX I tried using locale C, en_US, en_US.8859-15,en_US.ISO8859-1 and EN_US.UTF-8 but I got the unexpected result.
We are using TCL version 8.3.5 
Can u elaborate the workaround ? do we need to change the TCL version?

Regards
Rahul
dkfplain2010-04-15 05:15:18
Oops, misread it slightly. There are two issues here.

There are several issues here:
 1) 8.3.5 isn't really supported by us any more.
 2) Tcl strongly prefers to work with characters, but the underlying C toupper() function is byte-oriented. (And we don't do locale handling right either.) What happens is dependent on the platform too; some get this 99% right and others get nowhere close. This is basically what I was referring to.
 3) I've no idea why it might be working at the console but failling from a file on a single platform. :-(
dkfplain2010-04-15 05:15:56
Hmm, that's three things. Can't count either...
rkanherkarplain2010-04-15 15:01:13
Hi Donal,

Today I tried with Solaris and AIX and Linux platform and along with the TCL version is 8.5.8.
But I observed same behaviour which is wrong.
As you mentioned this is known ISSUE with TCL, So do u have any defect/bug created for this?
If Yes, can you please provide the defect-id ? It will be greate if you provide the defect-id
Your help appriciated 

Regards
Rahul
nijtmansplain2011-09-09 15:27:50
The problem here looks like that the function Tcl_FindExecutable()
was not called before the interpreter was created. This function is
used to set up various encodings. Earler Tcl
versions were more critical on that, in later Tcl versions more
encodings were built in, so it might work fine already.

Still, if you want to be sure that all character encodings
work as expected, please call Tcl_FindExecutable()
before doing anything else.
nijtmansplain2011-10-13 21:41:11
allow_comments - 1

Assuming everything is fixed now, otherwise please re-open
Log in (anonymous is fine) to add a comment.