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

setlocale fails due to locale.h being wrapped up in LANGINFO check. #63236

Closed
alanh mannequin opened this issue Sep 16, 2013 · 14 comments
Closed

setlocale fails due to locale.h being wrapped up in LANGINFO check. #63236

alanh mannequin opened this issue Sep 16, 2013 · 14 comments
Labels
build The build process and cross-build

Comments

@alanh
Copy link
Mannequin

alanh mannequin commented Sep 16, 2013

BPO 19036
Nosy @vstinner, @bitdancer, @skrah
Files
  • python-3.3.2.patch
  • 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 2014-01-20.14:37:56.549>
    created_at = <Date 2013-09-16.16:02:37.761>
    labels = ['build']
    title = 'setlocale fails due to locale.h being wrapped up in LANGINFO check.'
    updated_at = <Date 2014-03-18.01:32:24.523>
    user = 'https://bugs.python.org/alanh'

    bugs.python.org fields:

    activity = <Date 2014-03-18.01:32:24.523>
    actor = 'python-dev'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-01-20.14:37:56.549>
    closer = 'skrah'
    components = ['Build']
    creation = <Date 2013-09-16.16:02:37.761>
    creator = 'alanh'
    dependencies = []
    files = ['31801']
    hgrepos = []
    issue_num = 19036
    keywords = ['patch']
    message_count = 14.0
    messages = ['197914', '197920', '197922', '197923', '197924', '197928', '197936', '197937', '197939', '197940', '197942', '207745', '208543', '213931']
    nosy_count = 5.0
    nosy_names = ['vstinner', 'r.david.murray', 'alanh', 'skrah', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'compile error'
    url = 'https://bugs.python.org/issue19036'
    versions = ['Python 3.2', 'Python 3.3', 'Python 3.4']

    @alanh
    Copy link
    Mannequin Author

    alanh mannequin commented Sep 16, 2013

    Patch....

    --- Python/fileutils.c.old	2013-09-11 07:04:42.000000000 +0000
    +++ Python/fileutils.c	2013-09-11 07:05:01.000000000 +0000
    @@ -4,8 +4,8 @@
     #  include <windows.h>
     #endif
     
    -#ifdef HAVE_LANGINFO_H
     #include <locale.h>
    +#ifdef HAVE_LANGINFO_H
     #include <langinfo.h>
     #endif

    @alanh alanh mannequin added the build The build process and cross-build label Sep 16, 2013
    @bitdancer
    Copy link
    Member

    Can you provide more information about the circumstances in which this is a problem? Presumably there is a reason why the code is currently the way it is, especially since it is done this way in several of the source files, and has been that way for a *long* time.

    @bitdancer
    Copy link
    Member

    Oops, didn't mean to assign this to anyone.

    @alanh
    Copy link
    Mannequin Author

    alanh mannequin commented Sep 16, 2013

    Sure, Look in the function.....

    check_force_ascii()

    You'll see a hunk of code that is ifdef'd for ...

    #if defined(HAVE_LANGINFO_H) && defined(CODESET)
    

    Then you'll see

    setlocale()

    is called outside of that check, just before another hunk of code is
    ifdef'd with the same....

    #if defined(HAVE_LANGINFO_H) && defined(CODESET)
    

    Basically making setlocale() outside of the check, and therefore requiring the #include <locale.h> outside of the above check as well.

    In pythonrun.c the setlocale() call is already wrapped inside the #ifdef so the problem is bumped into there.

    @alanh
    Copy link
    Mannequin Author

    alanh mannequin commented Sep 16, 2013

    Oops, meant to say.....

    In pythonrun.c the setlocale() call is already wrapped inside the #ifdef so the problem ISN'T bumped into there.

    @bitdancer
    Copy link
    Member

    So the real problem is that the setlocale call is outside the ifdef, which means Victor is the right person to look at this, since it was his patch that introduced the code in question. I'll remove MAL from nosy, since I only added him by accident.

    @vstinner
    Copy link
    Member

    It looks like a real issue, but on which platform did you get the error?

    setlocale fails due to locale.h being wrapped up in LANGINFO check.

    What do you mean by "fail"? Is it an error at runtime? Or during the compilation?

    --

    The include was added recently:

    changeset: 81257:c256764e2b3f
    branch: 3.2
    parent: 81253:c4a4863b85b2
    user: Victor Stinner <victor.stinner@gmail.com>
    date: Thu Jan 03 01:08:58 2013 +0100
    files: Misc/NEWS Objects/unicodeobject.c Python/fileutils.c
    description:
    Issue bpo-16455: On FreeBSD and Solaris, if the locale is C, the
    ASCII/surrogateescape codec is now used, instead of the locale encoding, to
    decode the command line arguments. This change fixes inconsistencies with
    os.fsencode() and os.fsdecode() because these operating systems announces an
    ASCII locale encoding, whereas the ISO-8859-1 encoding is used in practice.

    The commit was integrated in Python 3.2.5 and Python 3.3.2 .

    If I remember correctly, I copied/pasted the code from Python/pythonrun.c:

    #ifdef HAVE_LANGINFO_H 
    #include <locale.h>
    #include <langinfo.h>
    #endif

    Many other files use "#include <locale.h>" without #ifdef HAVE_LANGINFO_H: Modules/main.c, Modules/python.c, Modules/readline.c, Python/frozenmain.c, Python/pystrtod.c and Modules/_localemodule.c. The #include in Modules/main.c was added 5 years ago by changeset 22a74eaf6b22.

    @vstinner
    Copy link
    Member

    Oh by the way, please attach the patch as a file to the issue.

    @alanh
    Copy link
    Mannequin Author

    alanh mannequin commented Sep 16, 2013

    Yes, it's a "Build" issue as mentioned using the "Components" field.

    But cut & pasting from other files is incorrect in this case because setlocale() is still used outside of the #ifdef.

    File attached.

    @vstinner
    Copy link
    Member

    Yes, it's a "Build" issue as mentioned using the "Components" field.

    Again, what is your platform (OS name, OS version)?

    What is the compiler error message?

    @alanh
    Copy link
    Mannequin Author

    alanh mannequin commented Sep 16, 2013

    You'll see the error on any platform that doesn't include "locale.h" when it should, i.e. a platform that doesn't have NL_LANGINFO. This is the build error.....

    Python/fileutils.c: In function 'check_force_ascii':
    Python/fileutils.c:101:5: warning: implicit declaration of function 'setlocale' [-Wimplicit-function-declaration]
    Python/fileutils.c:101:21: error: 'LC_CTYPE' undeclared (first use in this function)
    Python/fileutils.c:101:21: note: each undeclared identifier is reported only once for each function it appears in

    You can simulate it on Linux, by just commenting out the #include for "locale.h" and voila.

    But for completeness, it's an m68k Atari platform.

    @skrah
    Copy link
    Mannequin

    skrah mannequin commented Jan 9, 2014

    The patch looks correct to me. locale.h is at least C99 (I don't have the earlier standards).

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 20, 2014

    New changeset f82b6ec1ae6e by Stefan Krah in branch '3.3':
    Issue bpo-19036: Including locale.h should not depend on HAVE_LANGINFO_H.
    http://hg.python.org/cpython/rev/f82b6ec1ae6e

    @skrah skrah mannequin closed this as completed Jan 20, 2014
    @skrah skrah mannequin added the build The build process and cross-build label Jan 20, 2014
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Mar 18, 2014

    New changeset 3589980c98de by Victor Stinner in branch 'default':
    Issue bpo-19977, bpo-19036: Always include <locale.h> in pythonrun.c
    http://hg.python.org/cpython/rev/3589980c98de

    @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
    build The build process and cross-build
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants