|
2009-07-01
| ||
| 21:07 | • Closed ticket [2806622fff]: $tcl_platform(user) has garbage in sometimes on Win3... artifact: 5086c8cab2 user: patthoyts | |
| 21:07 | • Ticket [2806622fff]: 4 changes artifact: 53dbfa5bd8 user: patthoyts | |
|
2009-06-30
| ||
| 21:29 | • Ticket [2806622fff]: 4 changes artifact: 75db0d4269 user: patthoyts | |
| 21:29 | • Ticket [2806622fff]: 4 changes artifact: 0709bf38af user: patthoyts | |
| 21:29 | • Add attachment getusername.patch to ticket [2806622fffffffff|2806622fff... artifact: a10ab1291a user: patthoyts | |
|
2009-06-29
| ||
| 22:46 | • Ticket [2806622fff] $tcl_platform(user) has garbage in sometimes on Win32 st... artifact: 36eabda993 user: mpc_janssen | |
| 22:27 | • Ticket [2806622fff]: 4 changes artifact: 2ef3ce0266 user: mpc_janssen | |
| 19:55 | • Ticket [2806622fff]: 4 changes artifact: 920680d110 user: mpc_janssen | |
| 19:51 | • Ticket [2806622fff]: 4 changes artifact: e17333419e user: mpc_janssen | |
| 19:49 | • Ticket [2806622fff]: 4 changes artifact: af7cdcb92c user: mpc_janssen | |
|
2009-06-15
| ||
| 14:22 | • New ticket [2806622fff]. artifact: 566321c667 user: rkeene | |
$tcl_platform(user) has garbage in sometimes on Win32
Closed / Fixed2806622fffffffffffffffffffffffffffffffffCreated 17 years agoUpdated 17 years ago
Descriptionplain2009-06-15 14:22:20
$tcl_platform(user) has garbage in it when run as "SYSTEM" in a Windows Domain "Startup" script. Tested on Tcl 8.5.1
mpc_janssenplain2009-06-29 19:49:44
This seems to be caused by the call to
Tcl_WinTCharToUtf(szUserName, (int) dwUserNameLen, &ds);
at tclWinInit.c line 581. This code only gets exercised if env(USERNAME) is empty.
It seems that GetUserName doesn't return a TCHAR, but as simple char *
mpc_janssenplain2009-06-29 19:51:13
Note that this always fails if env(USERNAME) is not set: C:\src>set USERNAME Environment variable USERNAME not defined C:\src>c:\tcl\bin\tclsh85.exe % parray tcl_platform tcl_platform(byteOrder) = littleEndian tcl_platform(machine) = intel tcl_platform(os) = Windows NT tcl_platform(osVersion) = 5.1 tcl_platform(platform) = windows tcl_platform(pointerSize) = 4 tcl_platform(threaded) = 1 tcl_platform(user) = ???2 tcl_platform(wordSize) = 4
mpc_janssenplain2009-06-29 19:55:49
eplacing the line with:
Tcl_ExternalToUtfDString(NULL,szUserName , (int)dwUserNameLen, &ds);
fixes the issue.
mpc_janssenplain2009-06-29 22:27:31
The line below was not quite correct:
Correct is:
Tcl_ExternalToUtfDString(NULL,szUserName , -1, &ds);
And a test case demonstrating failure without change and correct result after:
# Test that the username is set correctly
test platform-4.1 {tcl_platform(username) matches the username (bug #2806622) } \
-body {
set username $::env(USERNAME)
unset ::env(USERNAME)
interp create user_name
set result [user_name eval {set tcl_platform(user)}]
interp delete user_name
set ::env(USERNAME) $username
expr {$result eq $username}
} \
-result 1
mpc_janssenplain2009-06-29 22:46:22
It's a bit trickier than it intially looks, using the External call doesn't work for user names with non-ascii chars
patthoytsplain2009-06-30 21:29:07
File Added - 332938: getusername.patch
patthoytsplain2009-06-30 21:29:34
You might try the attached patch. In general the Tcl code is compiled as narrow (TCHAR == char) and it switches the win32 api functions at runtime using the tclWinProcs global. So GetUserName should have been indirectly accessed using this. This patch seems to work for me and I tried forcing a cyrillic name through it and that was ok too.
patthoytsplain2009-07-01 21:07:10
I've tested this using an accented account and also by launching a tcl process as SYSTEM as a scheduled task and in all cases the username is coming up ok now. Committed to 8.5 and HEAD
patthoytsplain2009-07-01 21:07:13
allow_comments - 1
Log in (anonymous is fine) to add a comment.
Attachments:
- getusername.patch [download] added by patthoyts on 2009-06-30 21:29:07. [details]