Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in C locale coercion with PYTHONCOERCECLOCALE=1 #79517

Closed
vstinner opened this issue Nov 28, 2018 · 4 comments
Closed

Bug in C locale coercion with PYTHONCOERCECLOCALE=1 #79517

vstinner opened this issue Nov 28, 2018 · 4 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@vstinner
Copy link
Member

BPO 35336
Nosy @vstinner
PRs
  • bpo-35336: Fix PYTHONCOERCECLOCALE=1 #10806
  • [3.7] bpo-35336: Fix PYTHONCOERCECLOCALE=1 (GH-10806) #10813
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2018-11-30.11:20:02.030>
    created_at = <Date 2018-11-28.10:42:16.416>
    labels = ['interpreter-core', '3.7', '3.8']
    title = 'Bug in C locale coercion with PYTHONCOERCECLOCALE=1'
    updated_at = <Date 2018-11-30.11:20:02.030>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2018-11-30.11:20:02.030>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-11-30.11:20:02.030>
    closer = 'vstinner'
    components = ['Interpreter Core']
    creation = <Date 2018-11-28.10:42:16.416>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 35336
    keywords = ['patch']
    message_count = 4.0
    messages = ['330590', '330768', '330771', '330772']
    nosy_count = 1.0
    nosy_names = ['vstinner']
    pr_nums = ['10806', '10813']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue35336'
    versions = ['Python 3.7', 'Python 3.8']

    @vstinner
    Copy link
    Member Author

    PYTHONCOERCECLOCALE=1 should not force C locale coercion, Python should still check if the LC_CTYPE locale is "C".

    Bug:

    $ ./python -c 'import locale; print(locale.setlocale(locale.LC_CTYPE, None))'
    fr_FR.UTF-8
    $ PYTHONCOERCECLOCALE=1 ./python -c 'import locale; print(locale.setlocale(locale.LC_CTYPE, None))'
    C.UTF-8

    It should be fr_FR.UTF-8 as well in the second example :-( It seems to be a regression that I introduced in the middle of my refactoring on the Python initialization.

    The bug is around:

    static void
    config_init_locale(_PyCoreConfig *config)
    {
        if (config->coerce_c_locale < 0) {
            /* The C locale enables the C locale coercion (PEP 538) */
            if (_Py_LegacyLocaleDetected()) {
                config->coerce_c_locale = 1;
            }
        }
        ...
    }

    The 3.7 branch and the 3.7.0 release are affected :-(

    $ ./python -V
    Python 3.7.0
    $ PYTHONCOERCECLOCALE=1 ./python -c 'import locale; print(locale.setlocale(locale.LC_CTYPE, None))'
    C.UTF-8

    @vstinner vstinner added 3.7 (EOL) end of life 3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Nov 28, 2018
    @vstinner
    Copy link
    Member Author

    New changeset 55e4980 by Victor Stinner in branch 'master':
    bpo-35336: Fix PYTHONCOERCECLOCALE=1 (GH-10806)
    55e4980

    @vstinner
    Copy link
    Member Author

    PYTHONCOERCECLOCALE=1 should not force C locale coercion, Python should still check if the LC_CTYPE locale is "C".

    Reference:

    https://docs.python.org/dev/using/cmdline.html#envvar-PYTHONCOERCECLOCALE

    "If (...) the current locale reported for the LC_CTYPE category is either the default C locale, or else the explicitly ASCII-based POSIX locale, (...)"

    @vstinner
    Copy link
    Member Author

    New changeset df738d5 by Victor Stinner in branch '3.7':
    bpo-35336: Fix PYTHONCOERCECLOCALE=1 (GH-10806) (GH-10813)
    df738d5

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant