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
Comments
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 |
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. |
Oops, didn't mean to assign this to anyone. |
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 #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. |
Oops, meant to say..... In pythonrun.c the setlocale() call is already wrapped inside the #ifdef so the problem ISN'T bumped into there. |
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. |
It looks like a real issue, but on which platform did you get the error?
What do you mean by "fail"? Is it an error at runtime? Or during the compilation? -- The include was added recently: changeset: 81257:c256764e2b3f 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. |
Oh by the way, please attach the patch as a file to the issue. |
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. |
Again, what is your platform (OS name, OS version)? What is the compiler error message? |
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': 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. |
The patch looks correct to me. locale.h is at least C99 (I don't have the earlier standards). |
New changeset f82b6ec1ae6e by Stefan Krah in branch '3.3': |
New changeset 3589980c98de by Victor Stinner in branch 'default': |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: