[SERVER-10359] Do not change code pages in Windows version of mongo shell Created: 26/Jul/13  Updated: 11/Jul/16  Resolved: 27/Jul/13

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 2.4.0
Fix Version/s: 2.4.6, 2.5.2

Type: Bug Priority: Minor - P4
Reporter: Tad Marshall Assignee: Tad Marshall
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows


Backwards Compatibility: Minor Change
Operating System: Windows
Participants:

 Description   

The Windows version of the mongo shell changes the console code page from its initial setting to CP_UTF8 (65001) in order to accomodate UTF-8 output that is not routed through the writeUtf8ToWindowsConsole() function in src/mongo/util/text.cpp.

This code page switching causes a problem if the shell is abnormally exited (segfault or some other abort) because the initial code page is not restored on exit in that case. This leaves the console set to the UTF-8 code page, and other programs (e.g. Python) may complain.

We should remove the code page switching code and let non-ASCII text displayed with, for example, "cout" just display badly (as corrupted text). This may encourage us to remove any remaining code paths that don't go through writeUtf8ToWindowsConsole().

Here's the code: src/mongo/shell/dbshell.cpp lines 1136 to 1154 in the current master branch:

int wmain(int argc, wchar_t* argvW[], wchar_t* envpW[]) {
    static mongo::StaticObserver staticObserver;
    UINT initialConsoleInputCodePage = GetConsoleCP();
    UINT initialConsoleOutputCodePage = GetConsoleOutputCP();
    SetConsoleCP( CP_UTF8 );
    SetConsoleOutputCP( CP_UTF8 );
    int returnCode;
    try {
        WindowsCommandLine wcl(argc, argvW, envpW);
        returnCode = _main(argc, wcl.argv(), wcl.envp());
    }
    catch ( mongo::DBException& e ) {
        cerr << "exception: " << e.what() << endl;
        returnCode = 1;
    }
    SetConsoleCP( initialConsoleInputCodePage );
    SetConsoleOutputCP( initialConsoleOutputCodePage );
    ::_exit(returnCode);
}

Lines 3 to 6 and 16 through 17 in this excerpt should be removed.



 Comments   
Comment by auto [ 29/Jul/13 ]

Author:

{u'username': u'tadmarshall', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}

Message: SERVER-10359 Remove code page switching from Windows shell
Branch: v2.4
https://github.com/mongodb/mongo/commit/ad46ea3318bd584ac27cca7b90fe6f68948c2530

Comment by auto [ 27/Jul/13 ]

Author:

{u'username': u'tadmarshall', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}

Message: SERVER-10359 Remove code page switching from Windows shell
Branch: master
https://github.com/mongodb/mongo/commit/4640e0776c8d5e7514f4484fa5fe42e0d54e3fe9

Generated at Thu Feb 08 03:22:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.