]> granicus.if.org Git - python/commitdiff
(Merge 3.2) Issue #16416: On Mac OS X, operating system data are now always
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 3 Dec 2012 11:48:53 +0000 (12:48 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 3 Dec 2012 11:48:53 +0000 (12:48 +0100)
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.

1  2 
Misc/NEWS
Modules/python.c
Objects/unicodeobject.c
Python/fileutils.c

diff --cc Misc/NEWS
index 6eff12c84ecc8b9cfe9790f98ca16252e129f551,fbcfe90c0b717f81655efd0309421f4bb967ae2f..c695be511ca1d8c6a95177df3c98a3f7777b2738
+++ b/Misc/NEWS
@@@ -12,12 -10,13 +12,18 @@@ What's New in Python 3.3.1
  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.
index c70bf37827913da623f4a3303d86f288073ed864,2be69f1f54524ca25e6db8c190992e8ce307f4ab..2c08b9685687e0fe119cffe517fdee80d05adf6d
@@@ -45,13 -41,8 +41,9 @@@ main(int argc, char **argv
      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);
Simple merge
index 976c04b1172be2a0e8a56ffab6f16dd1d4eb710b,cba6696695c7aad5dfb6a7406afa08b81e60c823..2e9ea359da0fcf322a87d14260fa1c431f357b15
@@@ -4,40 -3,10 +4,44 @@@
  #  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
@@@ -165,9 -141,9 +180,10 @@@ _Py_char2wchar(const char* arg, size_t 
          *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