Core and Builtins
-----------------
-- Issue #16588: Silence unused-but-set warnings in Python/thread_pthread.h
+ - Issue #16416: On Mac OS X, operating system data are now always
+ encoded/decoded to/from UTF-8/surrogateescape, instead of the locale encoding
+ (which may be ASCII if no locale environment variable is set), to avoid
+ inconsistencies with os.fsencode() and os.fsdecode() functions which are
+ already using UTF-8/surrogateescape.
+
+- Issue #16588: Silence unused-but-set warnings in Python/thread_pthread
+
+- Issue #16546: Fix: ast.YieldFrom argument is now mandatory.
+
+- Issue #16514: Fix regression causing a traceback when sys.path[0] is None
+ (actually, any non-string or non-bytes type).
- Issue #16306: Fix multiple error messages when unknown command line
parameters where passed to the interpreter. Patch by Hieu Nguyen.
oldloc = strdup(setlocale(LC_ALL, NULL));
setlocale(LC_ALL, "");
for (i = 0; i < argc; i++) {
- #ifdef __APPLE__
- argv_copy[i] = _Py_DecodeUTF8_surrogateescape(argv[i], strlen(argv[i]));
- #else
argv_copy[i] = _Py_char2wchar(argv[i], NULL);
- #endif
if (!argv_copy[i]) {
+ free(oldloc);
fprintf(stderr, "Fatal Python error: "
"unable to decode the command line argument #%i\n",
i + 1);
# include <windows.h>
#endif
+#ifdef HAVE_LANGINFO_H
+#include <langinfo.h>
+#endif
+
+ #ifdef __APPLE__
+ extern wchar_t* _Py_DecodeUTF8_surrogateescape(const char *s, Py_ssize_t size);
+ #endif
+
+PyObject *
+_Py_device_encoding(int fd)
+{
+#if defined(MS_WINDOWS) || defined(MS_WIN64)
+ UINT cp;
+#endif
+ if (!_PyVerify_fd(fd) || !isatty(fd)) {
+ Py_RETURN_NONE;
+ }
+#if defined(MS_WINDOWS) || defined(MS_WIN64)
+ if (fd == 0)
+ cp = GetConsoleCP();
+ else if (fd == 1 || fd == 2)
+ cp = GetConsoleOutputCP();
+ else
+ cp = 0;
+ /* GetConsoleCP() and GetConsoleOutputCP() return 0 if the application
+ has no console */
+ if (cp != 0)
+ return PyUnicode_FromFormat("cp%u", (unsigned int)cp);
+#elif defined(CODESET)
+ {
+ char *codeset = nl_langinfo(CODESET);
+ if (codeset != NULL && codeset[0] != 0)
+ return PyUnicode_FromString(codeset);
+ }
+#endif
+ Py_RETURN_NONE;
+}
+
#ifdef HAVE_STAT
/* Decode a byte string from the locale encoding with the
*size = out - res;
return res;
oom:
- fprintf(stderr, "out of memory\n");
+ if (size != NULL)
+ *size = (size_t)-1;
return NULL;
+ #endif /* __APPLE__ */
}
/* Encode a (wide) character string to the locale encoding with the