tcl 8.6.14 (self-compiled from source), Windows 11,
hostname contains an Umlaut: foo-läptop (Umlaut-a)
% wish8.6
% info hostname
foo-läptop
% info hostname
foo-läpt
The second time, the hostname is encoded another time.
Looking at the code for [info hostname] on Windows, it seems to me:
- information is stored in global variable
static ProcessGlobalValue hostName =
{0, 0, NULL, NULL, InitializeHostName, NULL, NULL};
(win/tclWinSock.c)
- the first time the information is retrieved by
TclGetProcessGlobalValue(), it is initialized by a
call to InitializeHostName(), which sets the encoding of the
information to utf-8 after retrieving it from windows and converting
it to utf-8
*encodingPtr = Tcl_GetEncoding(NULL, "utf-8");
(win/tclWinSock.c)
- the next time the information is retrieved by
TclGetProcessGlobalValue(), it sees that the encoding is non-NULL and
compares it to the system encoding, which on Windows is not utf-8, but
(in my case) cp1252. So the information is converted again.
TclGetProcessGlobalValue()
...
if (pgvPtr->encoding) {
Tcl_Encoding current = Tcl_GetEncoding(NULL, NULL);
if (pgvPtr->encoding != current) {
/*
* The system encoding has changed since the global string value
* was saved. Convert the global value to be based on the new
* system encoding.
*/
// !! wrong for [info hostname]
Can someone comfirm this?
R'
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 714 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 140:29:49 |
| Calls: | 12,087 |
| Files: | 14,998 |
| Messages: | 6,517,424 |